Mercurial > wow > hotcorners
comparison HotCorners.lua @ 1:018fc9f0c471
continuing the development.
| author | tercio |
|---|---|
| date | Sat, 09 Aug 2014 17:28:04 -0300 |
| parents | fc346da3afd9 |
| children | a6fb0ff113b1 |
comparison
equal
deleted
inserted
replaced
| 0:fc346da3afd9 | 1:018fc9f0c471 |
|---|---|
| 1 | 1 |
| 2 LibHotCorners = LibStub ("AceAddon-3.0"):NewAddon ("HotCorners", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0") | 2 LibHotCorners = LibStub ("AceAddon-3.0"):NewAddon ("HotCorners", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0") |
| 3 _G.HotCorners = LibHotCorners | |
| 3 local LibHotCorners = LibHotCorners | 4 local LibHotCorners = LibHotCorners |
| 4 | 5 |
| 5 local LBD = LibStub ("LibDataBroker-1.1") | 6 local LBD = LibStub ("LibDataBroker-1.1") |
| 6 | 7 |
| 7 local debug = false | 8 local debug = false |
| 9 | 10 |
| 10 local default_db = { | 11 local default_db = { |
| 11 profile = { | 12 profile = { |
| 12 is_enabled = true, | 13 is_enabled = true, |
| 13 topleft_enabled = true, | 14 topleft_enabled = true, |
| 14 quickfunc = false, | 15 topleft_quickfunc = false, |
| 15 clicks = {}, | 16 clicks = {}, |
| 16 disabled = {} | 17 disabled = {} |
| 17 }, | 18 }, |
| 18 } | 19 } |
| 20 | |
| 21 LibHotCorners.RegistredQuickFunctions = {} | |
| 22 LibHotCorners.QuickFunctions = {topleft = false} | |
| 19 | 23 |
| 20 function LibHotCorners:OnEnable() | 24 function LibHotCorners:OnEnable() |
| 21 | 25 |
| 22 end | 26 end |
| 23 | 27 |
| 47 desc = "Enable or Disable the Top Left bar.", | 51 desc = "Enable or Disable the Top Left bar.", |
| 48 order = 2, | 52 order = 2, |
| 49 get = function() return LibHotCorners.db.profile.topleft_enabled end, | 53 get = function() return LibHotCorners.db.profile.topleft_enabled end, |
| 50 set = function (self, val) LibHotCorners.db.profile.topleft_enabled = not LibHotCorners.db.profile.topleft_enabled; refresh_topleft() end, | 54 set = function (self, val) LibHotCorners.db.profile.topleft_enabled = not LibHotCorners.db.profile.topleft_enabled; refresh_topleft() end, |
| 51 }, | 55 }, |
| 56 QuickClickFunc = { | |
| 57 type = "select", | |
| 58 name = "Quick Click", | |
| 59 desc = "Select the behavior when clicking over the absolute topleft corner.", | |
| 60 values = function() | |
| 61 local options = {} | |
| 62 for index, quickfunc in ipairs (LibHotCorners.RegistredQuickFunctions) do | |
| 63 options [quickfunc.name] = quickfunc.name | |
| 64 end | |
| 65 return options | |
| 66 end, | |
| 67 get = function() return LibHotCorners.db.profile.topleft_quickfunc or "" end, | |
| 68 set = function (self, funcname) | |
| 69 LibHotCorners.db.profile.topleft_quickfunc = funcname; | |
| 70 for index, quickfunc in ipairs (LibHotCorners.RegistredQuickFunctions) do | |
| 71 if (quickfunc.name == funcname) then | |
| 72 LibHotCorners.QuickFunctions.topleft = quickfunc.func | |
| 73 break | |
| 74 end | |
| 75 end | |
| 76 end, | |
| 77 order = 4, | |
| 78 } | |
| 52 } | 79 } |
| 53 } | 80 } |
| 54 | 81 |
| 55 function LibHotCorners:OnInitialize() | 82 function LibHotCorners:OnInitialize() |
| 56 | 83 |
| 90 | 117 |
| 91 LibHotCorners.embeds = LibHotCorners.embeds or {} | 118 LibHotCorners.embeds = LibHotCorners.embeds or {} |
| 92 local embed_functions = { | 119 local embed_functions = { |
| 93 "RegisterHotCornerButton", | 120 "RegisterHotCornerButton", |
| 94 "HideHotCornerButton", | 121 "HideHotCornerButton", |
| 95 "QuickHotCornerEnable" | |
| 96 } | 122 } |
| 97 | 123 |
| 98 function LibHotCorners:Embed (target) | 124 function LibHotCorners:Embed (target) |
| 99 for k, v in pairs (embed_functions) do | 125 for k, v in pairs (embed_functions) do |
| 100 target[v] = self[v] | 126 target[v] = self[v] |
| 113 | 139 |
| 114 local function test (corner) | 140 local function test (corner) |
| 115 assert (corner == "topleft" or corner == "bottomleft" or corner == "topright" or corner == "bottomright", "LibHotCorners:RegisterAddon expects a corner on #1 argument.") | 141 assert (corner == "topleft" or corner == "bottomleft" or corner == "topright" or corner == "bottomright", "LibHotCorners:RegisterAddon expects a corner on #1 argument.") |
| 116 end | 142 end |
| 117 | 143 |
| 118 function LibHotCorners:RegisterHotCornerButton (name, corner, savedtable, fname, icon, tooltip, clickfunc, menus, quickfunc, onenter, onleave, is_install) | 144 function LibHotCorners:AddQuickFunction (quickfunc, corner) |
| 145 | |
| 146 local current_quickfunc = LibHotCorners.db.profile [corner .. "_quickfunc"] or "" | |
| 147 | |
| 148 --> passed only one table | |
| 149 if (quickfunc.name) then | |
| 150 --> check if already exists | |
| 151 local already_exists = false | |
| 152 for _, registred in ipairs (LibHotCorners.RegistredQuickFunctions) do | |
| 153 if (registred.name == quickfunc.name) then | |
| 154 registred.func = quickfunc.func | |
| 155 if (current_quickfunc == quickfunc.name) then | |
| 156 LibHotCorners.QuickFunctions [corner] = quickfunc.func | |
| 157 end | |
| 158 already_exists = true | |
| 159 break | |
| 160 end | |
| 161 end | |
| 162 --> add table | |
| 163 if (not already_exists) then | |
| 164 table.insert (LibHotCorners.RegistredQuickFunctions, quickfunc) | |
| 165 if (current_quickfunc == quickfunc.name) then | |
| 166 LibHotCorners.QuickFunctions [corner] = quickfunc.func | |
| 167 end | |
| 168 end | |
| 169 --> check if there is a quickfunc to be use | |
| 170 if (current_quickfunc == "") then | |
| 171 LibHotCorners.db.profile [corner .. "_quickfunc"] = quickfunc.name | |
| 172 LibHotCorners.QuickFunctions [corner] = quickfunc.func | |
| 173 end | |
| 174 else | |
| 175 --> passed a table of tables | |
| 176 for _, this_quickfunc in ipairs (quickfunc) do | |
| 177 --> check if already exists | |
| 178 local already_exists = false | |
| 179 for _, registred in ipairs (LibHotCorners.RegistredQuickFunctions) do | |
| 180 if (registred.name == this_quickfunc.name) then | |
| 181 registred.func = this_quickfunc.func | |
| 182 if (current_quickfunc == this_quickfunc.name) then | |
| 183 LibHotCorners.QuickFunctions [corner] = this_quickfunc.func | |
| 184 end | |
| 185 already_exists = true | |
| 186 break | |
| 187 end | |
| 188 end | |
| 189 --> add table | |
| 190 if (not already_exists) then | |
| 191 table.insert (LibHotCorners.RegistredQuickFunctions, this_quickfunc) | |
| 192 if (current_quickfunc == this_quickfunc.name) then | |
| 193 LibHotCorners.QuickFunctions [corner] = this_quickfunc.func | |
| 194 end | |
| 195 end | |
| 196 --> check if there is a quickfunc to be use | |
| 197 if (current_quickfunc == "") then | |
| 198 LibHotCorners.db.profile [corner .. "_quickfunc"] = this_quickfunc.name | |
| 199 LibHotCorners.QuickFunctions [corner] = this_quickfunc.func | |
| 200 current_quickfunc = this_quickfunc.name | |
| 201 end | |
| 202 end | |
| 203 end | |
| 204 | |
| 205 end | |
| 206 | |
| 207 function LibHotCorners:RegisterHotCornerButton (name, corner, optionstable, fname, icon, tooltip, clickfunc, menus, quickfunc, onenter, onleave, is_install) | |
| 119 corner = string.lower (corner) | 208 corner = string.lower (corner) |
| 120 test (corner) | 209 test (corner) |
| 121 | 210 |
| 211 optionstable = optionstable or {hide = false} | |
| 212 | |
| 122 if (is_install) then | 213 if (is_install) then |
| 123 --> overwrite if already exists a widget | 214 --> overwrite if already exists a widget |
| 124 for i, widget in ipairs (LibHotCorners [corner]) do | 215 for i, widget in ipairs (LibHotCorners [corner]) do |
| 125 if (widget.name == name) then | 216 if (widget.name == name) then |
| 126 table.remove (LibHotCorners [corner], i) | 217 table.remove (LibHotCorners [corner], i) |
| 127 table.insert (LibHotCorners [corner], i, {name = name, fname = fname, savedtable = savedtable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave, is_install = true}) | 218 table.insert (LibHotCorners [corner], i, {name = name, fname = fname, optionstable = optionstable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave, is_install = true}) |
| 219 if (quickfunc) then | |
| 220 LibHotCorners:AddQuickFunction (quickfunc, corner) | |
| 221 end | |
| 128 return LibHotCorners [corner].map [name] | 222 return LibHotCorners [corner].map [name] |
| 129 end | 223 end |
| 130 end | 224 end |
| 131 | 225 --> add |
| 132 table.insert (LibHotCorners [corner], {name = name, fname = fname, savedtable = savedtable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave, is_install = true}) | 226 table.insert (LibHotCorners [corner], {name = name, fname = fname, optionstable = optionstable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave, is_install = true}) |
| 133 LibHotCorners [corner].map [name] = #LibHotCorners [corner] | 227 LibHotCorners [corner].map [name] = #LibHotCorners [corner] |
| 228 if (quickfunc) then | |
| 229 LibHotCorners:AddQuickFunction (quickfunc, corner) | |
| 230 end | |
| 134 return LibHotCorners [corner].map [name] | 231 return LibHotCorners [corner].map [name] |
| 135 else | 232 else |
| 136 tinsert (LibHotCorners [corner], {name = name, fname = fname, savedtable = savedtable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave}) | 233 --> check if already exists |
| 234 for i, widget in ipairs (LibHotCorners [corner]) do | |
| 235 if (widget.name == name) then | |
| 236 return | |
| 237 end | |
| 238 end | |
| 239 --> add | |
| 240 table.insert (LibHotCorners [corner], {name = name, fname = fname, optionstable = optionstable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave}) | |
| 137 LibHotCorners [corner].map [name] = #LibHotCorners [corner] | 241 LibHotCorners [corner].map [name] = #LibHotCorners [corner] |
| 242 if (quickfunc) then | |
| 243 LibHotCorners:AddQuickFunction (quickfunc, corner) | |
| 244 end | |
| 138 return LibHotCorners [corner].map [name] | 245 return LibHotCorners [corner].map [name] |
| 139 end | 246 end |
| 140 end | 247 end |
| 141 | 248 |
| 142 function LibHotCorners:QuickHotCornerEnable (name, corner, value) | 249 function LibHotCorners:HideHotCornerButton (name, corner, value) |
| 143 | 250 |
| 144 corner = string.lower (corner) | 251 corner = string.lower (corner) |
| 145 test (corner) | 252 test (corner) |
| 146 | 253 |
| 147 local corner_table = LibHotCorners [corner] | 254 local corner_table = LibHotCorners [corner] |
| 148 local addon_table = corner_table [corner_table.map [name]] | 255 local addon_table = corner_table [corner_table.map [name]] |
| 149 | 256 |
| 150 addon_table.savedtable [corner .. "_quickclick"] = value | 257 if (addon_table) then |
| 151 | 258 addon_table.optionstable.hide = value |
| 152 if (value and addon_table.quickfunc) then | 259 end |
| 153 corner_table.quickfunc = addon_table.quickfunc | 260 |
| 154 else | |
| 155 local got = false | |
| 156 for index, button_table in ipairs (corner_table) do | |
| 157 if (button_table.savedtable.quickclick) then | |
| 158 corner_table.quickfunc = button_table.quickfunc | |
| 159 got = true | |
| 160 break | |
| 161 end | |
| 162 end | |
| 163 | |
| 164 if (not got) then | |
| 165 corner_table.quickfunc = nil | |
| 166 end | |
| 167 end | |
| 168 end | |
| 169 | |
| 170 function LibHotCorners:HideHotCornerButton (name, corner, value) | |
| 171 | |
| 172 corner = string.lower (corner) | |
| 173 test (corner) | |
| 174 | |
| 175 local corner_table = LibHotCorners [corner] | |
| 176 local addon_table = corner_table [corner_table.map [name]] | |
| 177 | |
| 178 addon_table.savedtable.hide = value | |
| 179 | |
| 180 --print (LibHotCorners, corner) | |
| 181 LibHotCorners [corner].is_enabled = false | 261 LibHotCorners [corner].is_enabled = false |
| 182 | 262 |
| 183 for index, button_table in ipairs (corner_table) do | 263 for index, button_table in ipairs (corner_table) do |
| 184 if (not button_table.savedtable.hide) then | 264 if (not button_table.optionstable.hide) then |
| 185 LibHotCorners [corner].is_enabled = true | 265 LibHotCorners [corner].is_enabled = true |
| 186 break | 266 break |
| 187 end | 267 end |
| 188 end | 268 end |
| 189 | 269 |
| 279 LibHotCorners:CreateAddonWidget (self, button_table, index, self.position) | 359 LibHotCorners:CreateAddonWidget (self, button_table, index, self.position) |
| 280 end | 360 end |
| 281 | 361 |
| 282 button_table.widget:ClearAllPoints() | 362 button_table.widget:ClearAllPoints() |
| 283 | 363 |
| 284 if (not disabled [button_table.name]) then | 364 if (not disabled [button_table.name] and not button_table.optionstable.hide) then |
| 285 if (self.position == "topleft" or self.position == "topright") then | 365 if (self.position == "topleft" or self.position == "topright") then |
| 286 local y = i * 35 * -1 | 366 local y = i * 35 * -1 |
| 287 button_table.widget:SetPoint ("topleft", self, "topleft", 4, y) | 367 button_table.widget:SetPoint ("topleft", self, "topleft", 4, y) |
| 288 button_table.widget.y = y | 368 button_table.widget.y = y |
| 289 else | 369 else |
| 310 | 390 |
| 311 --> corner frame on leave | 391 --> corner frame on leave |
| 312 function HotCornersOnLeave (self) | 392 function HotCornersOnLeave (self) |
| 313 self:SetSize (1, 1) | 393 self:SetSize (1, 1) |
| 314 for index, button_table in ipairs (LibHotCorners [self.position]) do | 394 for index, button_table in ipairs (LibHotCorners [self.position]) do |
| 315 button_table.widget:Hide() | 395 if (button_table.widget) then |
| 396 button_table.widget:Hide() | |
| 397 end | |
| 316 end | 398 end |
| 317 local OptionsButton = LibHotCorners [self.position].optionsbutton | 399 local OptionsButton = LibHotCorners [self.position].optionsbutton |
| 318 OptionsButton:Hide() | 400 OptionsButton:Hide() |
| 319 end | 401 end |
| 320 | 402 |
| 321 --> quick corner on click | 403 --> quick corner on click |
| 322 function HotCornersOnQuickClick (self, button) | 404 function HotCornersOnQuickClick (self, button) |
| 323 local parent_position = self:GetParent().position | 405 local parent_position = self:GetParent().position |
| 324 if (LibHotCorners [parent_position].quickfunc) then | 406 local func = LibHotCorners.QuickFunctions [parent_position] |
| 325 LibHotCorners [parent_position].quickfunc (self, button) | 407 if (func) then |
| 408 func (self, button) | |
| 326 end | 409 end |
| 327 end | 410 end |
| 328 | 411 |
| 329 --> options button onenter | 412 --> options button onenter |
| 330 function HotCornersOptionsButtonOnEnter (self) | 413 function HotCornersOptionsButtonOnEnter (self) |
