--[[ Copyright (c) 2014 Eyal Shilony <Lynxium> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]] local addonName, addon = ... local ui = addon:GetModule("Options.UI") local options = addon:NewModule("Options.Menu") local L = LibStub("AceLocale-3.0"):GetLocale(addonName) local function menuItems() local index = 0 return function () index = index + 1 for name, order in pairs(addon.db.profile.menu) do if order == index then return name end end end end local function updateMenu(list) local menu = {} for i, item in list:Items() do local interface = addon.display:GetInterface(item:GetText()) menu[interface.name] = i end addon.db.profile.menu = menu addon.updateMenu = true end function options:OnInitialize() local order = addon.options:AddSubCategory(L["Menu"]) local availableItems = ui:CreateList(order) availableItems:SetTitle("Available Interfaces") availableItems:SetPoint("TOPLEFT", 10, -120) availableItems:SetSize(220, 400) for i, interface in addon.display:Interfaces() do local exists = addon.db.profile.menu[interface.name] if not exists then local item = ui:CreateListItem() item:SetText(interface.title) availableItems:AddItem(item) end end local visibleItems = ui:CreateList(order) visibleItems:SetTitle("Visible Menu Items") visibleItems:SetPoint("TOPLEFT", availableItems, "TOPRIGHT", 23, 0) visibleItems:SetSize(220, 400) for name in menuItems() do local interface = addon.display:GetInterface(name) local item = ui:CreateListItem() item:SetText(interface.title) visibleItems:AddItem(item) end local addToButton = ui:CreateButton(availableItems) addToButton:SetSize(24, 24) addToButton:SetPoint("CENTER", availableItems, "RIGHT", 12, 0) addToButton:SetNormalTexture([[Interface\Buttons\UI-SpellbookIcon-NextPage-Up]]) addToButton:SetPushedTexture([[Interface\Buttons\UI-SpellbookIcon-NextPage-Down]]) addToButton:OnClick(function() availableItems:MoveSelectedTo(visibleItems) updateMenu(visibleItems) end) local removeFromButton = ui:CreateButton(availableItems) removeFromButton:SetSize(24, 24) removeFromButton:SetPoint("TOP", addToButton, "BOTTOM") removeFromButton:SetNormalTexture([[Interface\Buttons\UI-SpellbookIcon-PrevPage-Up]]) removeFromButton:SetPushedTexture([[Interface\Buttons\UI-SpellbookIcon-PrevPage-Down]]) removeFromButton:OnClick(function() visibleItems:MoveSelectedTo(availableItems) updateMenu(visibleItems) end) local moveUpButton = ui:CreateButton(visibleItems) moveUpButton:SetSize(24, 24) moveUpButton:SetPoint("TOPLEFT", visibleItems, "TOPRIGHT", 0, 5) moveUpButton:SetNormalTexture([[Interface\ChatFrame\UI-ChatIcon-ScrollUp-Up]]) moveUpButton:SetPushedTexture([[Interface\ChatFrame\UI-ChatIcon-ScrollUp-Down]]) moveUpButton:OnClick(function() visibleItems:MoveSelectedUp() updateMenu(visibleItems) end) local moveDownButton = ui:CreateButton(visibleItems) moveDownButton:SetSize(24, 24) moveDownButton:SetPoint("TOP", moveUpButton, "BOTTOM") moveDownButton:SetNormalTexture([[Interface\ChatFrame\UI-ChatIcon-ScrollDown-Up]]) moveDownButton:SetPushedTexture([[Interface\ChatFrame\UI-ChatIcon-ScrollDown-Down]]) moveDownButton:OnClick(function() visibleItems:MoveSelectedDown() updateMenu(visibleItems) end) end