Mercurial > wow > devian
comparison Devian.lua @ 89:b3ed963f482d v.2.1.92
- /dvc command needed a pre-defined enclosure to properly work through SlashCmdList
- /dvn <profile name> and /dvn save <profile name> should resolve to and update the correct profile.
- set some globals indicating the name and index of the workspace in use
- DEVIAN_WORKSPACE (bool)
- DEVIAN_PNAME (string)
- DEVIAN_PID (number)
| author | Nenue |
|---|---|
| date | Wed, 10 Aug 2016 06:58:27 -0400 |
| parents | e80723841888 |
| children | bb403e03d82d |
comparison
equal
deleted
inserted
replaced
| 88:7ff0579e5a6e | 89:b3ed963f482d |
|---|---|
| 16 local currentProfile | 16 local currentProfile |
| 17 local playerName = UnitName("player") | 17 local playerName = UnitName("player") |
| 18 local playerRealm = playerName .. '-' .. GetRealmName() | 18 local playerRealm = playerName .. '-' .. GetRealmName() |
| 19 local num_dock_tabs = 0 | 19 local num_dock_tabs = 0 |
| 20 DEVIAN_WORKSPACE = false | 20 DEVIAN_WORKSPACE = false |
| 21 DEVIAN_PNAME = 'Dvn' | |
| 22 DEVIAN_PID = 0 | |
| 21 | 23 |
| 22 | 24 |
| 23 DevianLoadMessage = setmetatable({}, { | 25 DevianLoadMessage = setmetatable({}, { |
| 24 __call = function(t, msg) | 26 __call = function(t, msg) |
| 25 rawset(t, #t+1, msg) | 27 rawset(t, #t+1, msg) |
| 222 | 224 |
| 223 | 225 |
| 224 currentProfile.char[playerRealm] = currentProfile.char[playerRealm] or {} | 226 currentProfile.char[playerRealm] = currentProfile.char[playerRealm] or {} |
| 225 if currentProfile.workspace then | 227 if currentProfile.workspace then |
| 226 DEVIAN_WORKSPACE = true | 228 DEVIAN_WORKSPACE = true |
| 229 DEVIAN_PNAME = name | |
| 230 DEVIAN_PID = id | |
| 227 setprinthandler(D.Message) | 231 setprinthandler(D.Message) |
| 228 else | 232 else |
| 229 DEVIAN_WORKSPACE = false | 233 DEVIAN_WORKSPACE = false |
| 234 DEVIAN_PNAME = '' | |
| 230 print = function() end | 235 print = function() end |
| 231 end | 236 end |
| 237 DEVIAN_PID =id | |
| 232 | 238 |
| 233 D.unlisted = currentProfile.unlisted | 239 D.unlisted = currentProfile.unlisted |
| 234 D.channels = currentProfile.channels | 240 D.channels = currentProfile.channels |
| 235 D.tags = currentProfile.tags | 241 D.tags = currentProfile.tags |
| 236 D.channelinfo = currentProfile.channels | 242 D.channelinfo = currentProfile.channels |
| 276 return D.Tag(self, tag, dest) | 282 return D.Tag(self, tag, dest) |
| 277 elseif mode == 'new' then | 283 elseif mode == 'new' then |
| 278 return D.New(self, tag) | 284 return D.New(self, tag) |
| 279 elseif mode == 'remove' then | 285 elseif mode == 'remove' then |
| 280 return D.Remove(self, tag) | 286 return D.Remove(self, tag) |
| 281 elseif tonumber(mode) ~= nil or mode == 'save' then | 287 elseif mode ~= nil then |
| 282 -- either a number of the save command | 288 -- profile selector or save command |
| 283 if mode == 'save' then | 289 if mode == 'save' then |
| 284 list_id = tonumber(tag) | 290 list_id = tonumber(tag) |
| 285 if list_id == nil then | 291 else |
| 286 D:Print(L('Invalid ID from arg', tag)) | 292 list_id = tonumber(mode) |
| 287 end | 293 end |
| 294 | |
| 295 if not list_id then | |
| 296 if db.profilesName[tostring(list_id)] then | |
| 297 list_id = db.profilesName[tostring(list_id)] | |
| 298 else | |
| 299 | |
| 300 D:Print(L('Unable to resolve profile ID/name', list_id, dest)) | |
| 301 return | |
| 302 end | |
| 303 end | |
| 304 | |
| 305 | |
| 306 if mode == 'save' then | |
| 288 D.Profile(list_id, dest) | 307 D.Profile(list_id, dest) |
| 289 scan_func = D.Save | 308 scan_func = D.Save |
| 290 D:Print("Profile |cFFFFFF00".. list_id .."|r saved.") | 309 |
| 291 else | 310 |
| 292 | 311 local name = currentProfile.name |
| 293 D.LoadMessage "Switched profiles." | 312 if dest then |
| 294 | 313 dest = dest:gsub("$%s+", ''):gsub("%s+^", '') |
| 295 list_id = tonumber(mode) | 314 if dest then |
| 296 if list_id ~= db.main_profile then | 315 if name then |
| 297 db.last_profile = list_id | 316 db.profilesName[name] = nil |
| 298 end | 317 end |
| 299 db.current_profile = list_id | 318 db.profiles[list_id].name = dest |
| 300 scan_func = D.Load | 319 db.profilesName[dest] = list_id |
| 320 end | |
| 321 end | |
| 322 | |
| 323 | |
| 324 D:Print("Profile |cFFFFFF00".. list_id .."|r:|cFF00FFFF".. name .."|r saved.") | |
| 325 else | |
| 326 | |
| 327 if db.profiles[list_id] then | |
| 328 D.LoadMessage ("Switched profiles.") | |
| 329 if list_id ~= db.main_profile then | |
| 330 db.last_profile = list_id | |
| 331 end | |
| 332 db.current_profile = list_id | |
| 333 scan_func = D.Load | |
| 334 else | |
| 335 return D:PrintHelp() | |
| 336 end | |
| 337 | |
| 301 end | 338 end |
| 302 elseif mode == nil then | 339 elseif mode == nil then |
| 303 list_id = (db.current_profile ~= db.main_profile) and db.main_profile or db.last_profile | 340 list_id = (db.current_profile ~= db.main_profile) and db.main_profile or db.last_profile |
| 304 D.LoadMessage ("Switched between main and recent profile ("..db.current_profile..' and '..list_id..')') | 341 D.LoadMessage ("Switched between main and recent profile ("..db.current_profile..' and '..list_id..')') |
| 305 db.current_profile = list_id | 342 db.current_profile = list_id |
| 306 scan_func = D.Load | 343 scan_func = D.Load |
| 307 else | 344 else |
| 345 | |
| 346 | |
| 308 return D:PrintHelp() | 347 return D:PrintHelp() |
| 309 end | 348 end |
| 310 | 349 |
| 311 if not db.profiles[list_id] then | 350 if not db.profiles[list_id] then |
| 312 db.profiles[list_id] = {global = {}, char = {} } | 351 db.profiles[list_id] = {global = {}, char = {} } |
| 593 D.UnsetColors = function() | 632 D.UnsetColors = function() |
| 594 db.tagcolor = {} | 633 db.tagcolor = {} |
| 595 D:Print('Tag color cache cleared.') | 634 D:Print('Tag color cache cleared.') |
| 596 end | 635 end |
| 597 | 636 |
| 598 function D:OnEnable() | 637 |
| 638 function D.ConsoleCommand (cmd) | |
| 639 D:Console_Toggle(cmd) | |
| 640 end | |
| 641 | |
| 642 | |
| 643 function D:OnInitialize() | |
| 644 L = D.L | |
| 645 | |
| 646 -- pull defaults | |
| 647 if not _G.DevianDB then | |
| 648 _G.DevianDB = defaults | |
| 649 end | |
| 650 db = _G.DevianDB | |
| 651 self.db = db | |
| 652 | |
| 653 --- | |
| 654 if #_G.DevianLoadMessage >= 1 then | |
| 655 for i, msg in ipairs(_G.DevianLoadMessage) do | |
| 656 D:Print(msg) | |
| 657 end | |
| 658 | |
| 659 table.wipe(_G.DevianLoadMessage) | |
| 660 end | |
| 661 | |
| 599 | 662 |
| 600 -- commands | 663 -- commands |
| 601 local cmdlist = { | 664 local cmdlist = { |
| 602 ['dfs'] = 'FrameHelper_Update', | |
| 603 ['dvn'] = "Command", | 665 ['dvn'] = "Command", |
| 604 ['devian'] = "Command", | 666 ['devian'] = "Command", |
| 605 ['dvc'] = function() D:Console_Toggle() end, | 667 ['dvc'] = "ConsoleCommand", |
| 606 ['dvncolors'] = "UnsetColors", | 668 ['dvncolors'] = "UnsetColors", |
| 607 ['cleandvn'] = "SetDefaultsAll", | 669 ['cleandvn'] = "SetDefaultsAll", |
| 608 ['resetdvn'] = "SetDefaults", | 670 ['resetdvn'] = "SetDefaults", |
| 609 } | 671 } |
| 610 for cmd, func in pairs(cmdlist) do | 672 for cmd, func in pairs(cmdlist) do |
| 611 local CMD = cmd:upper() | 673 local CMD = cmd:upper() |
| 612 _G['SLASH_' .. CMD:upper() .. '1'] = "/"..cmd | 674 _G['SLASH_' .. CMD .. '1'] = "/"..cmd |
| 675 | |
| 613 if type(func == 'string') then | 676 if type(func == 'string') then |
| 677 print('SLASH_' .. CMD .. '1','/'.. cmd, func) | |
| 614 SlashCmdList[CMD] = D[func] | 678 SlashCmdList[CMD] = D[func] |
| 615 else | 679 else |
| 680 print('SLASH_' .. CMD .. '1','/'.. cmd, func) | |
| 616 SlashCmdList[CMD] = func | 681 SlashCmdList[CMD] = func |
| 617 end | 682 end |
| 618 | 683 end |
| 619 end | |
| 620 end | |
| 621 | |
| 622 function D:OnInitialize() | |
| 623 L = D.L | |
| 624 | |
| 625 -- pull defaults | |
| 626 if not _G.DevianDB then | |
| 627 _G.DevianDB = defaults | |
| 628 end | |
| 629 db = _G.DevianDB | |
| 630 self.db = db | |
| 631 | |
| 632 --- | |
| 633 if #_G.DevianLoadMessage >= 1 then | |
| 634 for i, msg in ipairs(_G.DevianLoadMessage) do | |
| 635 D:Print(msg) | |
| 636 end | |
| 637 | |
| 638 table.wipe(_G.DevianLoadMessage) | |
| 639 end | |
| 640 | |
| 641 | 684 |
| 642 --- initialize the current profile | 685 --- initialize the current profile |
| 643 local id, name = D.Profile(db.current_profile or 1) | 686 local id, name = D.Profile(db.current_profile or 1) |
| 644 D:Print('Using profile |cFFFFFF00'.. id ..'|r: |cFF00FF00'..currentProfile.name..'|r') | 687 D:Print('Using profile |cFFFFFF00'.. id ..'|r: |cFF00FF00'..currentProfile.name..'|r') |
| 645 if currentProfile.workspace then | 688 if currentProfile.workspace then |
| 675 end | 718 end |
| 676 _G.DevianDock:Show() | 719 _G.DevianDock:Show() |
| 677 D:UpdateDock() | 720 D:UpdateDock() |
| 678 end | 721 end |
| 679 end | 722 end |
| 723 |
