annotate ReAction.lua @ 95:168cae4aa8bd

Fixes: - brute-force fix for invalid snippets - copying profile data now results in immediate changes - fixed keybinding tooltip display for pet bar simple actions Also did a little condensing of the state driver rule string generation
author Flick <flickerstreak@gmail.com>
date Wed, 22 Oct 2008 21:39:07 +0000
parents 5f1d7a81317c
children 3699d7dad312
rev   line source
flickerstreak@63 1 --[[
flickerstreak@63 2 ReAction.lua
flickerstreak@63 3
flickerstreak@63 4 The ReAction core manages 4 collections:
flickerstreak@63 5 - modules (via AceAddon)
flickerstreak@63 6 - bars
flickerstreak@63 7 - options
flickerstreak@63 8 - bar-type constructors
flickerstreak@63 9
flickerstreak@90 10 and publishes events when those collections change. It also implements a couple properties
flickerstreak@63 11 and has a couple convenience methods which drill down to particular modules.
flickerstreak@63 12
flickerstreak@90 13 Most of the "real work" of the addon happens in Bar.lua, Overlay.lua, State.lua, and the various modules.
flickerstreak@63 14
flickerstreak@63 15 Events (with handler arguments):
flickerstreak@63 16 --------------------------------
flickerstreak@63 17 "OnCreateBar" (bar, name) : after a bar object is created
flickerstreak@63 18 "OnDestroyBar" (bar, name) : before a bar object is destroyed
flickerstreak@63 19 "OnEraseBar" (bar, name) : before a bar config is removed from the profile db
flickerstreak@63 20 "OnRenameBar" (bar, oldname, newname) : after a bar is renamed
flickerstreak@63 21 "OnRefreshBar" (bar, name) : after a bar's state has been updated
flickerstreak@63 22 "OnOptionsRefreshed" () : after the global options tree is refreshed
flickerstreak@63 23 "OnConfigModeChanged" (mode) : after the config mode is changed
flickerstreak@63 24 "OnBarOptionGeneratorRegistered" (module, function) : after an options generator function is registered
flickerstreak@63 25
flickerstreak@63 26 ReAction is also an AceAddon-3.0 and contains an AceDB-3.0, which in turn publish more events.
flickerstreak@63 27 ]]--
flickerstreak@63 28 local version = GetAddOnMetadata("ReAction","Version")
flickerstreak@27 29
flickerstreak@27 30 ------ CORE ------
flickerstreak@30 31 local ReAction = LibStub("AceAddon-3.0"):NewAddon( "ReAction",
flickerstreak@33 32 "AceConsole-3.0",
flickerstreak@33 33 "AceEvent-3.0"
flickerstreak@30 34 )
flickerstreak@33 35 ReAction.revision = tonumber(("$Revision$"):match("%d+"))
flickerstreak@27 36
flickerstreak@28 37 ------ GLOBALS ------
flickerstreak@28 38 _G["ReAction"] = ReAction
flickerstreak@27 39
flickerstreak@28 40 ------ DEBUGGING ------
flickerstreak@25 41 ReAction.debug = true
flickerstreak@36 42 local dbprint
flickerstreak@25 43 if ReAction.debug then
flickerstreak@36 44 dbprint = function(msg)
flickerstreak@25 45 DEFAULT_CHAT_FRAME:AddMessage(msg)
flickerstreak@25 46 end
flickerstreak@25 47 else
flickerstreak@36 48 dbprint = function() end
flickerstreak@25 49 end
flickerstreak@36 50 ReAction.dbprint = dbprint
flickerstreak@25 51
flickerstreak@33 52 ------ LIBRARIES ------
flickerstreak@63 53 local callbacks = LibStub("CallbackHandler-1.0"):New(ReAction)
flickerstreak@88 54 local KB = LibStub("LibKeyBound-1.0")
flickerstreak@33 55 local L = LibStub("AceLocale-3.0"):GetLocale("ReAction")
flickerstreak@33 56 ReAction.L = L
flickerstreak@33 57
flickerstreak@28 58 ------ PRIVATE ------
flickerstreak@88 59 local weak = {__mode="k"}
flickerstreak@88 60 local private = {
flickerstreak@88 61 allKB = setmetatable({}, weak),
flickerstreak@88 62 kbHooked = setmetatable({}, weak),
flickerstreak@88 63 }
flickerstreak@63 64 local bars = {}
flickerstreak@63 65 local defaultBarConfig = {}
flickerstreak@63 66 local barOptionGenerators = { }
flickerstreak@63 67 local options = {
flickerstreak@63 68 type = "group",
flickerstreak@63 69 name = "ReAction",
flickerstreak@63 70 childGroups = "tab",
flickerstreak@63 71 args = {
flickerstreak@63 72 _desc = {
flickerstreak@63 73 type = "description",
flickerstreak@63 74 name = L["Customizable replacement for Blizzard's Action Bars"],
flickerstreak@63 75 order = 1,
flickerstreak@63 76 },
flickerstreak@63 77 global = {
flickerstreak@63 78 type = "group",
flickerstreak@63 79 name = L["Global Settings"],
flickerstreak@63 80 desc = L["Global configuration settings"],
flickerstreak@63 81 args = {
flickerstreak@63 82 unlock = {
flickerstreak@63 83 type = "toggle",
flickerstreak@63 84 name = L["Unlock Bars"],
flickerstreak@63 85 desc = L["Unlock bars for dragging and resizing with the mouse"],
flickerstreak@63 86 handler = ReAction,
flickerstreak@63 87 get = "GetConfigMode",
flickerstreak@63 88 set = function(info, value) ReAction:SetConfigMode(value) end,
flickerstreak@63 89 disabled = InCombatLockdown,
flickerstreak@63 90 order = 1
flickerstreak@63 91 },
flickerstreak@63 92 },
flickerstreak@63 93 plugins = { },
flickerstreak@63 94 order = 2,
flickerstreak@63 95 },
flickerstreak@63 96 module = {
flickerstreak@63 97 type = "group",
flickerstreak@63 98 childGroups = "select",
flickerstreak@63 99 name = L["Module Settings"],
flickerstreak@63 100 desc = L["Configuration settings for each module"],
flickerstreak@63 101 args = { },
flickerstreak@63 102 plugins = { },
flickerstreak@63 103 order = 3,
flickerstreak@63 104 },
flickerstreak@63 105 },
flickerstreak@63 106 plugins = { }
flickerstreak@63 107 }
flickerstreak@63 108 ReAction.options = options
flickerstreak@63 109
flickerstreak@92 110 local SelectBar, DestroyBar, InitializeBars, TearDownBars, DeepCopy, CallModuleMethod, SlashHandler, KBAttach
flickerstreak@28 111 do
flickerstreak@28 112 local pcall = pcall
flickerstreak@28 113 local geterrorhandler = geterrorhandler
flickerstreak@63 114 local self = ReAction
flickerstreak@63 115 local inited = false
flickerstreak@28 116
flickerstreak@92 117 local function kb_onEnter( self )
flickerstreak@92 118 if ReAction:GetKeybindMode() then
flickerstreak@92 119 KB:Set(self)
flickerstreak@92 120 end
flickerstreak@92 121 end
flickerstreak@92 122
flickerstreak@63 123 function SelectBar(x)
flickerstreak@28 124 local bar, name
flickerstreak@28 125 if type(x) == "string" then
flickerstreak@28 126 name = x
flickerstreak@63 127 bar = self:GetBar(name)
flickerstreak@50 128 else
flickerstreak@63 129 for k,v in pairs(bars) do
flickerstreak@50 130 if v == x then
flickerstreak@28 131 name = k
flickerstreak@50 132 bar = x
flickerstreak@28 133 end
flickerstreak@28 134 end
flickerstreak@28 135 end
flickerstreak@28 136 return bar, name
flickerstreak@28 137 end
flickerstreak@28 138
flickerstreak@63 139 function DestroyBar(x)
flickerstreak@28 140 local bar, name = SelectBar(x)
flickerstreak@63 141 if bar and name then
flickerstreak@63 142 bars[name] = nil
flickerstreak@63 143 callbacks:Fire("OnDestroyBar", bar, name)
flickerstreak@28 144 bar:Destroy()
flickerstreak@28 145 end
flickerstreak@28 146 end
flickerstreak@28 147
flickerstreak@63 148 function InitializeBars()
flickerstreak@63 149 if not inited then
flickerstreak@63 150 for name, config in pairs(self.db.profile.bars) do
flickerstreak@28 151 if config then
flickerstreak@63 152 self:CreateBar(name, config)
flickerstreak@28 153 end
flickerstreak@28 154 end
flickerstreak@63 155 -- re-anchor in case anchor order does not match init order
flickerstreak@63 156 for name, bar in pairs(bars) do
flickerstreak@63 157 bar:ApplyAnchor()
flickerstreak@63 158 end
flickerstreak@63 159 inited = true
flickerstreak@28 160 end
flickerstreak@28 161 end
flickerstreak@28 162
flickerstreak@63 163 function TearDownBars()
flickerstreak@63 164 for name, bar in pairs(bars) do
flickerstreak@28 165 if bar then
flickerstreak@63 166 bars[name] = DestroyBar(bar)
flickerstreak@28 167 end
flickerstreak@28 168 end
flickerstreak@63 169 inited = false
flickerstreak@28 170 end
flickerstreak@28 171
flickerstreak@63 172 function DeepCopy(x)
flickerstreak@28 173 if type(x) ~= "table" then
flickerstreak@28 174 return x
flickerstreak@28 175 end
flickerstreak@28 176 local r = {}
flickerstreak@28 177 for k,v in pairs(x) do
flickerstreak@28 178 r[k] = DeepCopy(v)
flickerstreak@28 179 end
flickerstreak@28 180 return r
flickerstreak@28 181 end
flickerstreak@28 182
flickerstreak@63 183 function CallModuleMethod(modulename, method, ...)
flickerstreak@63 184 local m = self:GetModule(modulename,true)
flickerstreak@63 185 if not m then
flickerstreak@63 186 LoadAddOn(("ReAction_%s"):format(modulename))
flickerstreak@63 187 m = self:GetModule(modulename,true)
flickerstreak@63 188 if m then
flickerstreak@63 189 dbprint(("succesfully loaded LOD module: %s"):format(modulename))
flickerstreak@28 190 end
flickerstreak@28 191 end
flickerstreak@63 192 if m then
flickerstreak@63 193 if type(m) == "table" and type(m[method]) == "function" then
flickerstreak@63 194 m[method](m,...)
flickerstreak@63 195 else
flickerstreak@63 196 dbprint(("Bad call '%s' to %s module"):format(tostring(method),modulename));
flickerstreak@63 197 end
flickerstreak@63 198 else
flickerstreak@63 199 self:Print(("Module '%s' not found"):format(tostring(modulename)))
flickerstreak@63 200 end
flickerstreak@28 201 end
flickerstreak@28 202
flickerstreak@63 203 function SlashHandler(option)
flickerstreak@30 204 if option == "config" then
flickerstreak@63 205 self:ShowConfig()
flickerstreak@58 206 elseif option == "edit" then
flickerstreak@63 207 self:ShowEditor()
flickerstreak@50 208 elseif option == "unlock" then
flickerstreak@63 209 self:SetConfigMode(true)
flickerstreak@50 210 elseif option == "lock" then
flickerstreak@63 211 self:SetConfigMode(false)
flickerstreak@88 212 elseif option == "kb" then
flickerstreak@88 213 self:SetKeybindMode(true)
flickerstreak@30 214 else
flickerstreak@63 215 self:Print(("%3.1f.%d"):format(version,self.revision))
flickerstreak@63 216 self:Print("/rxn config")
flickerstreak@63 217 self:Print("/rxn edit")
flickerstreak@63 218 self:Print("/rxn lock")
flickerstreak@63 219 self:Print("/rxn unlock")
flickerstreak@88 220 self:Print("/rxn kb")
flickerstreak@30 221 end
flickerstreak@30 222 end
flickerstreak@92 223
flickerstreak@92 224 function KBAttach( frame )
flickerstreak@92 225 if not private.kbHooked[frame] then
flickerstreak@92 226 -- avoid taint, particularly with SecureAnchorEnterTemplate
flickerstreak@92 227 -- don't hook scripts multiple times, there isn't any unhook!
flickerstreak@92 228 frame:HookScript("OnEnter",kb_onEnter)
flickerstreak@92 229 private.kbHooked[frame] = true
flickerstreak@92 230 end
flickerstreak@92 231 end
flickerstreak@92 232
flickerstreak@28 233 end
flickerstreak@28 234
flickerstreak@28 235
flickerstreak@28 236 ------ HANDLERS ------
flickerstreak@28 237 function ReAction:OnInitialize()
flickerstreak@28 238 self.db = LibStub("AceDB-3.0"):New("ReAction_DB",
flickerstreak@28 239 {
flickerstreak@28 240 profile = {
flickerstreak@28 241 bars = { },
flickerstreak@28 242 defaultBar = { }
flickerstreak@28 243 }
flickerstreak@28 244 }
flickerstreak@90 245 -- initial profile is character-specific
flickerstreak@28 246 )
flickerstreak@28 247 self.db.RegisterCallback(self,"OnProfileChanged")
flickerstreak@95 248 self.db.RegisterCallback(self,"OnProfileReset", "OnProfileChanged")
flickerstreak@95 249 self.db.RegisterCallback(self,"OnProfileCopied","OnProfileChanged")
flickerstreak@63 250
flickerstreak@88 251 KB.RegisterCallback(self,"LIBKEYBOUND_ENABLED")
flickerstreak@88 252 KB.RegisterCallback(self,"LIBKEYBOUND_DISABLED")
flickerstreak@88 253
flickerstreak@63 254 options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
flickerstreak@63 255
flickerstreak@30 256 self:RegisterChatCommand("reaction", SlashHandler)
flickerstreak@30 257 self:RegisterChatCommand("rxn", SlashHandler)
flickerstreak@33 258 self:RegisterEvent("PLAYER_REGEN_DISABLED")
flickerstreak@28 259 end
flickerstreak@28 260
flickerstreak@28 261 function ReAction:OnEnable()
flickerstreak@28 262 InitializeBars()
flickerstreak@28 263 end
flickerstreak@28 264
flickerstreak@28 265 function ReAction:OnDisable()
flickerstreak@28 266 TearDownBars()
flickerstreak@28 267 end
flickerstreak@28 268
flickerstreak@28 269 function ReAction:OnProfileChanged()
flickerstreak@33 270 TearDownBars()
flickerstreak@33 271 InitializeBars()
flickerstreak@28 272 end
flickerstreak@28 273
flickerstreak@33 274 function ReAction:PLAYER_REGEN_DISABLED()
flickerstreak@63 275 if private.configMode == true then
flickerstreak@63 276 self:UserError(L["ReAction config mode disabled during combat."])
flickerstreak@33 277 self:SetConfigMode(false)
flickerstreak@88 278 self:SetKeybindMode(false)
flickerstreak@33 279 end
flickerstreak@33 280 end
flickerstreak@33 281
flickerstreak@88 282 function ReAction:LIBKEYBOUND_ENABLED( evt )
flickerstreak@88 283 self:SetKeybindMode(true)
flickerstreak@88 284 end
flickerstreak@88 285
flickerstreak@88 286 function ReAction:LIBKEYBOUND_DISABLED( evt )
flickerstreak@88 287 return self:SetKeybindMode(false)
flickerstreak@88 288 end
flickerstreak@88 289
flickerstreak@33 290
flickerstreak@28 291
flickerstreak@28 292 ------ API ------
flickerstreak@77 293 function ReAction:UpdateRevision(str)
flickerstreak@77 294 local revision = tonumber(str:match("%d+"))
flickerstreak@77 295 if revision and revision > ReAction.revision then
flickerstreak@77 296 ReAction.revision = revision
flickerstreak@77 297 end
flickerstreak@77 298 end
flickerstreak@77 299
flickerstreak@61 300 function ReAction:UserError(msg)
flickerstreak@61 301 -- any user errors should be flashed to the UIErrorsFrame
flickerstreak@61 302 UIErrorsFrame:AddMessage(msg)
flickerstreak@61 303 end
flickerstreak@61 304
flickerstreak@63 305 -- usage:
flickerstreak@91 306 -- (1) ReAction:CreateBar(name, [cfgTable])
flickerstreak@63 307 -- (2) ReAction:CreateBar(name, "barType", [nRows], [nCols], [btnSize], [btnSpacing])
flickerstreak@91 308 function ReAction:CreateBar(name, config, ...)
flickerstreak@91 309 local profile = self.db.profile
flickerstreak@91 310
flickerstreak@91 311 if not name then
flickerstreak@91 312 local prefix = L["Bar "]
flickerstreak@91 313 local i = 1
flickerstreak@91 314 repeat
flickerstreak@91 315 name = prefix..i
flickerstreak@91 316 i = i + 1
flickerstreak@91 317 until bars[name] == nil
flickerstreak@91 318 end
flickerstreak@91 319
flickerstreak@91 320 if type(config) == "string" then
flickerstreak@91 321 config = defaultBarConfig[config]
flickerstreak@48 322 if not config then
flickerstreak@91 323 error(("ReAction:CreateBar() - unknown bar type '%s'"):format(tostring(select(1,...))))
flickerstreak@48 324 end
flickerstreak@48 325 config = DeepCopy(config)
flickerstreak@91 326 config.btnRows = select(1,...) or config.btnRows or 1
flickerstreak@91 327 config.btnColumns = select(2,...) or config.btnColumns or 12
flickerstreak@91 328 config.btnWidth = select(3,...) or config.btnWidth or 36
flickerstreak@91 329 config.btnHeight = select(3,...) or config.btnHeight or 36
flickerstreak@91 330 config.spacing = select(4,...) or config.spacing or 3
flickerstreak@48 331 config.width = config.width or config.btnColumns*(config.btnWidth + config.spacing) + 1
flickerstreak@48 332 config.height = config.height or config.btnRows*(config.btnHeight + config.spacing) + 1
flickerstreak@81 333 config.anchor = config.anchor or "UIParent"
flickerstreak@81 334 config.point = config.point or "BOTTOM"
flickerstreak@81 335 config.relpoint = config.relpoint or "BOTTOM"
flickerstreak@48 336 config.y = config.y or 200
flickerstreak@48 337 config.x = config.x or 0
flickerstreak@48 338 end
flickerstreak@91 339 config = config or profile.bars[name] or DeepCopy(profile.defaultBar)
flickerstreak@91 340
flickerstreak@91 341 profile.bars[name] = config
flickerstreak@91 342 local bar = self.Bar:New( name, config ) -- ReAction.Bar defined in Bar.lua
flickerstreak@63 343 bars[name] = bar
flickerstreak@63 344 callbacks:Fire("OnCreateBar", bar, name)
flickerstreak@63 345 if private.configMode then
flickerstreak@33 346 bar:ShowControls(true)
flickerstreak@33 347 end
flickerstreak@33 348
flickerstreak@28 349 return bar
flickerstreak@28 350 end
flickerstreak@28 351
flickerstreak@28 352 function ReAction:EraseBar(x)
flickerstreak@28 353 local bar, name = SelectBar(x)
flickerstreak@63 354 if bar and name then
flickerstreak@63 355 callbacks:Fire("OnEraseBar", bar, name)
flickerstreak@28 356 DestroyBar(bar)
flickerstreak@28 357 self.db.profile.bars[name] = nil
flickerstreak@28 358 end
flickerstreak@28 359 end
flickerstreak@28 360
flickerstreak@28 361 function ReAction:GetBar(name)
flickerstreak@63 362 return bars[name]
flickerstreak@63 363 end
flickerstreak@63 364
flickerstreak@90 365 -- returns pairs of name, bar
flickerstreak@63 366 function ReAction:IterateBars()
flickerstreak@63 367 return pairs(bars)
flickerstreak@28 368 end
flickerstreak@28 369
flickerstreak@28 370 function ReAction:RenameBar(x, newname)
flickerstreak@28 371 local bar, name = SelectBar(x)
flickerstreak@63 372 if type(newname) ~= "string" then
flickerstreak@63 373 error("ReAction:RenameBar() - second argument must be a string")
flickerstreak@63 374 end
flickerstreak@63 375 if bar and name and #newname > 0 then
flickerstreak@63 376 if bars[newname] then
flickerstreak@63 377 self:UserError(("%s ('%s')"):format(L["ReAction: name already in use"],newname))
flickerstreak@47 378 else
flickerstreak@63 379 bars[newname], bars[name] = bars[name], nil
flickerstreak@47 380 bar:SetName(newname or "")
flickerstreak@47 381 local cfg = self.db.profile.bars
flickerstreak@47 382 cfg[newname], cfg[name] = cfg[name], nil
flickerstreak@63 383 callbacks:Fire("OnRenameBar", bar, name, newname)
flickerstreak@28 384 end
flickerstreak@28 385 end
flickerstreak@28 386 end
flickerstreak@28 387
flickerstreak@63 388 function ReAction:RefreshBar(x)
flickerstreak@63 389 local bar, name = SelectBar(x)
flickerstreak@63 390 if bar and name then
flickerstreak@63 391 callbacks:Fire("OnRefreshBar", bar, name)
flickerstreak@63 392 end
flickerstreak@63 393 end
flickerstreak@63 394
flickerstreak@53 395 function ReAction:RegisterBarType( name, config, isDefaultChoice )
flickerstreak@63 396 defaultBarConfig[name] = config
flickerstreak@48 397 if isDefaultChoice then
flickerstreak@81 398 private.defaultBarConfigChoice = name
flickerstreak@48 399 end
flickerstreak@48 400 self:RefreshOptions()
flickerstreak@48 401 end
flickerstreak@48 402
flickerstreak@53 403 function ReAction:UnregisterBarType( name )
flickerstreak@63 404 defaultBarConfig[name] = nil
flickerstreak@63 405 if private.defaultBarConfigChoice == name then
flickerstreak@63 406 private.defaultBarConfigChoice = nil
flickerstreak@48 407 end
flickerstreak@48 408 self:RefreshOptions()
flickerstreak@48 409 end
flickerstreak@48 410
flickerstreak@63 411 function ReAction:IterateBarTypes()
flickerstreak@63 412 return pairs(defaultBarConfig)
flickerstreak@63 413 end
flickerstreak@63 414
flickerstreak@63 415 function ReAction:GetBarTypeConfig(name)
flickerstreak@63 416 if name then
flickerstreak@63 417 return defaultBarConfig[name]
flickerstreak@63 418 end
flickerstreak@63 419 end
flickerstreak@63 420
flickerstreak@63 421 function ReAction:GetBarTypeOptions( fill )
flickerstreak@63 422 fill = fill or { }
flickerstreak@63 423 for k in self:IterateBarTypes() do
flickerstreak@63 424 fill[k] = k
flickerstreak@63 425 end
flickerstreak@63 426 return fill
flickerstreak@63 427 end
flickerstreak@63 428
flickerstreak@63 429 function ReAction:GetDefaultBarType()
flickerstreak@63 430 return private.defaultBarConfigChoice
flickerstreak@63 431 end
flickerstreak@63 432
flickerstreak@63 433 function ReAction:RegisterOptions(module, opts, global)
flickerstreak@63 434 options.args[global and "global" or "module"].plugins[module:GetName()] = opts
flickerstreak@63 435 self:RefreshOptions()
flickerstreak@30 436 end
flickerstreak@30 437
flickerstreak@30 438 function ReAction:RefreshOptions()
flickerstreak@63 439 callbacks:Fire("OnOptionsRefreshed")
flickerstreak@63 440 end
flickerstreak@63 441
flickerstreak@63 442 --
flickerstreak@63 443 -- In addition to global and general module options, options tables
flickerstreak@63 444 -- must be generated dynamically for each bar.
flickerstreak@63 445 --
flickerstreak@63 446 -- 'func' should be a function or a method string.
flickerstreak@63 447 -- The function or method will be passed the bar as its parameter.
flickerstreak@63 448 -- (methods will of course get the module as the first 'self' parameter)
flickerstreak@63 449 --
flickerstreak@63 450 -- A generator can be unregistered by passing a nil func.
flickerstreak@63 451 --
flickerstreak@63 452 function ReAction:RegisterBarOptionGenerator( module, func )
flickerstreak@63 453 if not module or type(module) ~= "table" then -- doesn't need to be a proper module, strictly
flickerstreak@63 454 error("ReAction:RegisterBarOptionGenerator() : Invalid module")
flickerstreak@63 455 end
flickerstreak@63 456 if type(func) == "string" then
flickerstreak@63 457 if not module[func] then
flickerstreak@63 458 error(("ReAction:RegisterBarOptionGenerator() : Invalid method '%s'"):format(func))
flickerstreak@63 459 end
flickerstreak@63 460 elseif func and type(func) ~= "function" then
flickerstreak@63 461 error("ReAction:RegisterBarOptionGenerator() : Invalid function")
flickerstreak@63 462 end
flickerstreak@63 463 barOptionGenerators[module] = func
flickerstreak@63 464 callbacks:Fire("OnBarOptionGeneratorRegistered", module, func)
flickerstreak@63 465 end
flickerstreak@63 466
flickerstreak@63 467 -- builds a table suitable for use as an AceConfig3 group 'plugins' sub-table
flickerstreak@63 468 function ReAction:GenerateBarOptionsTable( bar )
flickerstreak@63 469 local opts = { }
flickerstreak@63 470 for module, func in pairs(barOptionGenerators) do
flickerstreak@63 471 local success, r
flickerstreak@63 472 if type(func) == "string" then
flickerstreak@63 473 success, r = pcall(module[func], module, bar)
flickerstreak@63 474 else
flickerstreak@63 475 success, r = pcall(func, bar)
flickerstreak@63 476 end
flickerstreak@63 477 if success then
flickerstreak@90 478 if r then
flickerstreak@90 479 opts[module:GetName()] = { [module:GetName()] = r }
flickerstreak@90 480 end
flickerstreak@63 481 else
flickerstreak@63 482 geterrorhandler()(r)
flickerstreak@63 483 end
flickerstreak@63 484 end
flickerstreak@63 485 return opts
flickerstreak@30 486 end
flickerstreak@33 487
flickerstreak@33 488 function ReAction:SetConfigMode( mode )
flickerstreak@77 489 if mode ~= private.configMode then
flickerstreak@77 490 private.configMode = mode
flickerstreak@77 491 callbacks:Fire("OnConfigModeChanged", mode)
flickerstreak@77 492 end
flickerstreak@63 493 end
flickerstreak@63 494
flickerstreak@63 495 function ReAction:GetConfigMode()
flickerstreak@63 496 return private.configMode
flickerstreak@33 497 end
flickerstreak@38 498
flickerstreak@38 499 function ReAction:ShowConfig()
flickerstreak@63 500 CallModuleMethod("ConfigUI","OpenConfig")
flickerstreak@38 501 end
flickerstreak@38 502
flickerstreak@81 503 function ReAction:ShowEditor(bar, ...)
flickerstreak@81 504 CallModuleMethod("ConfigUI","LaunchBarEditor",bar, ...)
flickerstreak@47 505 end
flickerstreak@88 506
flickerstreak@88 507 function ReAction:SetKeybindMode( mode )
flickerstreak@88 508 if mode ~= private.kbMode then
flickerstreak@88 509 if mode then
flickerstreak@88 510 for f in pairs(private.allKB) do
flickerstreak@92 511 KBAttach(f)
flickerstreak@88 512 end
flickerstreak@88 513 KB:Activate()
flickerstreak@88 514 else
flickerstreak@88 515 KB:Deactivate()
flickerstreak@88 516 end
flickerstreak@88 517 private.kbMode = KB:IsShown() or false
flickerstreak@88 518 end
flickerstreak@88 519 end
flickerstreak@88 520
flickerstreak@88 521 function ReAction:GetKeybindMode( mode )
flickerstreak@88 522 return private.kbMode
flickerstreak@88 523 end
flickerstreak@88 524
flickerstreak@88 525 function ReAction:RegisterKeybindFrame( f )
flickerstreak@88 526 private.allKB[f] = true
flickerstreak@92 527 if private.kbMode then
flickerstreak@92 528 KBAttach(f)
flickerstreak@92 529 end
flickerstreak@88 530 end
flickerstreak@88 531
flickerstreak@88 532 function ReAction:FreeOverrideHotkey( key )
flickerstreak@88 533 for f in pairs(private.allKB) do
flickerstreak@88 534 if f.GetBindings then
flickerstreak@88 535 for i = 1, select('#', f:GetBindings()) do
flickerstreak@88 536 if select(i, f:GetBindings()) == key then
flickerstreak@88 537 if f.FreeKey then
flickerstreak@88 538 return f:FreeKey(key)
flickerstreak@88 539 else
flickerstreak@88 540 local action = f.GetActionName and f:GetActionName() or f:GetName()
flickerstreak@88 541 SetOverrideBinding(f, false, key, nil)
flickerstreak@88 542 return action
flickerstreak@88 543 end
flickerstreak@88 544 end
flickerstreak@88 545 end
flickerstreak@88 546 end
flickerstreak@88 547 end
flickerstreak@88 548 end