diff --git a/AddonClearer.lua b/AddonClearer.lua index 65c64e3..c76171a 100644 --- a/AddonClearer.lua +++ b/AddonClearer.lua @@ -1,89 +1,89 @@ -AddonClearer = {} - -function AddonClearer:SetAddons(toDo) - table.sort(ZO_AddOnsList.data, function(a,b) return a.data.addOnFileName == "AddonClearer" end) -- In place sorting. oh dear - local thisAddonIndex = ZO_AddOnsList.data[1].data.index - - local notEmpty = false - - if not toDo then -- Save current setup - AddonClearer.settings.savedSetup = {} - for i,v in ipairs(ZO_AddOnsList.data) do AddonClearer.settings.savedSetup[v.data.index] = v.data.addOnEnabled end - end - - if not toDo then - local fullHouse = true - local emptyHouse = true - for i,v in ipairs(AddonClearer.settings.savedSetup) do - if i ~= thisAddonIndex and not v then fullHouse = false end - if i ~= thisAddonIndex and v then emptyHouse = false end - end - if not fullHouse and not emptyHouse then - SelectAddonButton:SetText("Select Saved") - else - SelectAddonButton:SetText("Select All") - end - end - - local AddOnManager = GetAddOnManager() - local numAddons = AddOnManager:GetNumAddOns() - for i = 1, numAddons do - if i ~= thisAddonIndex then -- ignore this addon - if SelectAddonButton.nameLabel:GetText() == "Select Saved" and toDo then -- Are we restoring from save? - AddOnManager:SetAddOnEnabled(i, AddonClearer.settings.savedSetup[i]) - else -- Otherwise continue as normal - AddOnManager:SetAddOnEnabled(i, toDo) - end - end - end - - ZO_AddOnManager.isDirty = true - -- Reset the view - SCENE_MANAGER:RemoveFragment(ADDONS_FRAGMENT) - SCENE_MANAGER:AddFragment(ADDONS_FRAGMENT) -end - -local firstControl = nil - -function AddonClearer:MultiSelect(button) - if not IsShiftKeyDown() then firstControl = self return false end - if self ~= firstControl and IsShiftKeyDown() then - local firstRow = firstControl:GetParent().data - local currentRow = self:GetParent().data - local AddOnManager = GetAddOnManager() - local step = firstRow.sortIndex - currentRow.sortIndex < 0 and 1 or -1 - for i = firstRow.sortIndex, currentRow.sortIndex, step do - AddOnManager:SetAddOnEnabled(AddonClearer.ReverseLookup[i], firstRow.addOnEnabled) - end - end - return false -end - -function AddonClearer:ShowPanel(...) - local _, a,b = ... - - if not (a == 14 and b == 5) then return end - - for i,control in ipairs(ZO_AddOnsList.activeControls) do - local name = control:GetNamedChild("Name") - local enabled = control:GetNamedChild("Enabled") - local enabledClick = enabled:GetHandler("OnClicked") - name:SetMouseEnabled(true) - name:SetHandler("OnMouseDown", function(self, button) AddonClearer.MultiSelect(enabled, button) enabledClick(enabled, button) end) - ZO_PreHookHandler(enabled, "OnClicked", function(...) AddonClearer.MultiSelect(...) return false end) - end - - AddonClearer.ReverseLookup = {} - - for i,v in ipairs(ZO_AddOnsList.data) do - AddonClearer.ReverseLookup[v.data.sortIndex] = v.data.index - end -end - -function AddonClearer:Loaded(eventCode, addonName) - if(addonName ~= "AddonClearer") then return end - AddonClearer.settings = ZO_SavedVars:NewAccountWide("AddonClearerSV", 1, nil, {savedSetup = {}}) - EVENT_MANAGER:RegisterForEvent("AddonClearerShowing", EVENT_ACTION_LAYER_PUSHED, function(...) AddonClearer:ShowPanel(...) end) -end - +AddonClearer = {} + +function AddonClearer:SetAddons(toDo) + table.sort(ZO_AddOnsList.data, function(a,b) return a.data.addOnFileName == "AddonClearer" end) -- In place sorting. oh dear + local thisAddonIndex = ZO_AddOnsList.data[1].data.index + + local notEmpty = false + + if not toDo then -- Save current setup + AddonClearer.settings.savedSetup = {} + for i,v in ipairs(ZO_AddOnsList.data) do AddonClearer.settings.savedSetup[v.data.index] = v.data.addOnEnabled end + end + + if not toDo then + local fullHouse = true + local emptyHouse = true + for i,v in ipairs(AddonClearer.settings.savedSetup) do + if i ~= thisAddonIndex and not v then fullHouse = false end + if i ~= thisAddonIndex and v then emptyHouse = false end + end + if not fullHouse and not emptyHouse then + SelectAddonButton:SetText("Select Saved") + else + SelectAddonButton:SetText("Select All") + end + end + + local AddOnManager = GetAddOnManager() + local numAddons = AddOnManager:GetNumAddOns() + for i = 1, numAddons do + if i ~= thisAddonIndex then -- ignore this addon + if SelectAddonButton.nameLabel:GetText() == "Select Saved" and toDo then -- Are we restoring from save? + AddOnManager:SetAddOnEnabled(i, AddonClearer.settings.savedSetup[i]) + else -- Otherwise continue as normal + AddOnManager:SetAddOnEnabled(i, toDo) + end + end + end + + ZO_AddOnManager.isDirty = true + -- Reset the view + SCENE_MANAGER:RemoveFragment(ADDONS_FRAGMENT) + SCENE_MANAGER:AddFragment(ADDONS_FRAGMENT) +end + +local firstControl = nil + +function AddonClearer:MultiSelect(button) + if not IsShiftKeyDown() then firstControl = self return false end + if self ~= firstControl and IsShiftKeyDown() then + local firstRow = firstControl:GetParent().data + local currentRow = self:GetParent().data + local AddOnManager = GetAddOnManager() + local step = firstRow.sortIndex - currentRow.sortIndex < 0 and 1 or -1 + for i = firstRow.sortIndex, currentRow.sortIndex, step do + AddOnManager:SetAddOnEnabled(AddonClearer.ReverseLookup[i], firstRow.addOnEnabled) + end + end + return false +end + +function AddonClearer:ShowPanel(...) + local _, a,b = ... + + if not (a == 14 and b == 5) then return end + + for i,control in ipairs(ZO_AddOnsList.activeControls) do + local name = control:GetNamedChild("Name") + local enabled = control:GetNamedChild("Enabled") + local enabledClick = enabled:GetHandler("OnClicked") + name:SetMouseEnabled(true) + name:SetHandler("OnMouseDown", function(self, button) AddonClearer.MultiSelect(enabled, button) enabledClick(enabled, button) end) + ZO_PreHookHandler(enabled, "OnClicked", function(...) AddonClearer.MultiSelect(...) return false end) + end + + AddonClearer.ReverseLookup = {} + + for i,v in ipairs(ZO_AddOnsList.data) do + AddonClearer.ReverseLookup[v.data.sortIndex] = v.data.index + end +end + +function AddonClearer:Loaded(eventCode, addonName) + if(addonName ~= "AddonClearer") then return end + AddonClearer.settings = ZO_SavedVars:NewAccountWide("AddonClearerSV", 1, nil, {savedSetup = {}}) + EVENT_MANAGER:RegisterForEvent("AddonClearerShowing", EVENT_ACTION_LAYER_PUSHED, function(...) AddonClearer:ShowPanel(...) end) +end + EVENT_MANAGER:RegisterForEvent("AddonClearerLoaded", EVENT_ADD_ON_LOADED, function(...) AddonClearer:Loaded(...) end) \ No newline at end of file diff --git a/AddonClearer.txt b/AddonClearer.txt index 3ad26e4..2f49995 100644 --- a/AddonClearer.txt +++ b/AddonClearer.txt @@ -1,9 +1,9 @@ -## Title: |cFFFFB0AddonClearer|r by |c00C000Wobin & CrazyDutchGuy|r -## Author: CrazyDutchGuy and Wobin -## Version: @project-version@ -## APIVersion: 100007 -## SavedVariables: AddonClearerSV - -AddonClearer.lua -AddonClearer.xml +## Title: |cFFFFB0AddonClearer|r by |c00C000Wobin & CrazyDutchGuy|r +## Author: CrazyDutchGuy and Wobin +## Version: @project-version@ +## APIVersion: 100008 +## SavedVariables: AddonClearerSV + +AddonClearer.lua +AddonClearer.xml bindings.xml \ No newline at end of file diff --git a/AddonClearer.xml b/AddonClearer.xml index c66e3f9..5cb31f4 100644 --- a/AddonClearer.xml +++ b/AddonClearer.xml @@ -1,22 +1,22 @@ -<GuiXml> - <Controls> - <TopLevelControl> - <Controls> - <Control name="ClearAddonButton" inherits="ZO_DialogButton"> - <Anchor point="TOPLEFT" relativeTo="ZO_AddOnsList" relativePoint="BOTTOMLEFT" offsetY="5" /> - <OnInitialized> - self:SetParent(ZO_AddOns) - ZO_KeybindButtonTemplate_Setup(self, "ADDONS_CLEAR_ALL", function() AddonClearer:SetAddons(false) end, "Unselect All") - </OnInitialized> - </Control> - <Control name="SelectAddonButton" inherits="ZO_DialogButton"> - <Anchor point="TOP" relativeTo="ZO_AddOnsList" relativePoint="BOTTOM" offsetY="5" /> - <OnInitialized> - self:SetParent(ZO_AddOns) - ZO_KeybindButtonTemplate_Setup(self, "ADDONS_SELECT_ALL", function() AddonClearer:SetAddons(true) end, "Select All") - </OnInitialized> - </Control> - </Controls> - </TopLevelControl> - </Controls> +<GuiXml> + <Controls> + <TopLevelControl> + <Controls> + <Control name="ClearAddonButton" inherits="ZO_DialogButton"> + <Anchor point="TOPLEFT" relativeTo="ZO_AddOnsList" relativePoint="BOTTOMLEFT" offsetY="5" /> + <OnInitialized> + self:SetParent(ZO_AddOns) + ZO_KeybindButtonTemplate_Setup(self, "ADDONS_CLEAR_ALL", function() AddonClearer:SetAddons(false) end, "Unselect All") + </OnInitialized> + </Control> + <Control name="SelectAddonButton" inherits="ZO_DialogButton"> + <Anchor point="TOP" relativeTo="ZO_AddOnsList" relativePoint="BOTTOM" offsetY="5" /> + <OnInitialized> + self:SetParent(ZO_AddOns) + ZO_KeybindButtonTemplate_Setup(self, "ADDONS_SELECT_ALL", function() AddonClearer:SetAddons(true) end, "Select All") + </OnInitialized> + </Control> + </Controls> + </TopLevelControl> + </Controls> </GuiXml> \ No newline at end of file diff --git a/bindings.xml b/bindings.xml index 9da99a6..2ec6659 100644 --- a/bindings.xml +++ b/bindings.xml @@ -1,12 +1,12 @@ -<Bindings> - <Layer name="Addons"> - <Category> - <Action name="ADDONS_CLEAR_ALL" hideAction="true" inheritsBindFrom="UI_SHORTCUT_SECONDARY"> - <Down>AddonClearer:SetAddons(false)</Down> - </Action> - <Action name="ADDONS_SELECT_ALL" hideAction="true" inheritsBindFrom="UI_SHORTCUT_TERTIARY"> - <Down>AddonClearer:SetAddons(true)</Down> - </Action> - </Category> - </Layer> +<Bindings> + <Layer name="Addons"> + <Category> + <Action name="ADDONS_CLEAR_ALL" hideAction="true" inheritsBindFrom="UI_SHORTCUT_SECONDARY"> + <Down>AddonClearer:SetAddons(false)</Down> + </Action> + <Action name="ADDONS_SELECT_ALL" hideAction="true" inheritsBindFrom="UI_SHORTCUT_TERTIARY"> + <Down>AddonClearer:SetAddons(true)</Down> + </Action> + </Category> + </Layer> </Bindings> \ No newline at end of file