vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1  
2 local dewdrop = AceLibrary("Dewdrop-2.0")
3 local compost = AceLibrary("Compost-2.0")
4 local console = AceLibrary("AceConsole-2.0")
5  
6 local curraddon
7 local reasons, sortauthors, sortcategories, sorttags = {}, {}, {}, {}
8 local deps, tagstrings = {"Ace", "FuBar", "oRA"}, {
9 Ace2 = "cff7fff7f.*Ace2",
10 FuBar = "FuBar",
11 }
12  
13  
14 FuBar_ModMenuTuFu = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceConsole-2.0", "AceDB-2.0", "FuBarPlugin-2.0")
15 FuBar_ModMenuTuFu:RegisterDB("ModMenuTuFuDB")
16 FuBar_ModMenuTuFu.hasIcon = "Interface\\Icons\\Trade_Engineering"
17 FuBar_ModMenuTuFu.overrideMenu = true
18 FuBar_ModMenuTuFu.hasNoText = true
19  
20  
21 local function ValidateAuthor(i, auth)
22 return auth == GetAddOnMetadata(i, "Author")
23 end
24  
25  
26 local function ValidateCategory(i, cat)
27 if cat == "Unknown" then cat = nil end
28 return cat == "All Mods" or cat == GetAddOnMetadata(i, "X-Category")
29 end
30  
31  
32 local function ValidateDependant(i, dep)
33 local _, title = GetAddOnInfo(i)
34 if tagstrings[dep] and string.find(title, tagstrings[dep]) then return true end
35  
36 local d = compost:Acquire(GetAddOnDependencies(i))
37 local found
38 for _,v in pairs(d) do if v == dep then found = true end end
39 compost:Reclaim(d)
40 return found
41 end
42  
43  
44 function FuBar_ModMenuTuFu:OnInitialize()
45 local authors, categories, tags = compost:Acquire(), compost:Acquire(), compost:Acquire()
46  
47 for i=1,GetNumAddOns() do
48 local name, title, notes, enabled, loadable, reason, security = GetAddOnInfo(i)
49 local isondemand = IsAddOnLoadOnDemand(i)
50 local author = GetAddOnMetadata(i, "Author")
51 local category = GetAddOnMetadata(i, "X-Category")
52 local addname = self:GetOnDemandText(i)
53  
54 if author then authors[author] = true end
55 if category then categories[category] = true end
56  
57 for dep in pairs(tagstrings) do if ValidateDependant(i, dep) then tags[dep] = true end end
58 for _,dep in pairs(deps) do if ValidateDependant(i, dep) then tags[dep] = true end end
59 end
60  
61 for i in pairs(authors) do table.insert(sortauthors, i) end
62 for i in pairs(categories) do table.insert(sortcategories, i) end
63 for i in pairs(tags) do table.insert(sorttags, i) end
64 table.sort(sortauthors)
65 table.sort(sortcategories)
66 table.sort(sorttags)
67  
68 compost:ReclaimMulti(authors, categories, tags)
69 end
70  
71  
72 function FuBar_ModMenuTuFu:OnMenuRequest(level, v1, intip, v2, v3, v4)
73 if level == 1 then
74 dewdrop:AddLine("text", "By Category", "value", "By Category", "hasArrow", true)
75 dewdrop:AddLine("text", "By Author", "value", "By Author", "hasArrow", true)
76 dewdrop:AddLine("text", "By Dependancy", "value", "By Dependancy", "hasArrow", true)
77 dewdrop:AddLine("text", "FuBar Options", "value", "FuBar Options", "hasArrow", true)
78 elseif level == 2 then
79 if v1 == "By Category" then
80 for _,i in ipairs(sortcategories) do dewdrop:AddLine("text", i, "value", i, "hasArrow", true) end
81 dewdrop:AddLine()
82 dewdrop:AddLine("text", "Unknown", "value", "Unknown", "hasArrow", true)
83 dewdrop:AddLine()
84 dewdrop:AddLine("text", "All Mods", "value", "All Mods", "hasArrow", true)
85 elseif v1 == "By Author" then
86 for _,i in ipairs(sortauthors) do dewdrop:AddLine("text", i, "value", i, "hasArrow", true) end
87 elseif v1 == "By Dependancy" then
88 for _,i in ipairs(sorttags) do dewdrop:AddLine("text", i, "value", i, "hasArrow", true) end
89 elseif v1 == "FuBar Options" then self:AddImpliedMenuOptions(2) end
90 elseif self:AddImpliedMenuOptions(2) then
91 elseif level == 3 then
92 if v2 == "By Category" then self:BuildAddonMenu(v1, ValidateCategory)
93 elseif v2 == "By Author" then self:BuildAddonMenu(v1, ValidateAuthor)
94 elseif v2 == "By Dependancy" then self:BuildAddonMenu(v1, ValidateDependant) end
95 else
96 if level == 4 then curraddon = v1 end
97 dewdrop:FeedAceOptionsTable(curraddon, 3)
98 end
99 end
100  
101  
102 function FuBar_ModMenuTuFu:BuildAddonMenu(value, validator)
103 for i=1,GetNumAddOns() do
104 if validator(i, value) then
105 local name, title, notes = GetAddOnInfo(i)
106 local cmds = self:GetAddonCommandTable(name)
107 dewdrop:AddLine("text", self:GetOnDemandText(i), "func", self.HandleModClick, "arg1", self, "arg2", name,
108 "tooltipTitle", title, "tooltipText", notes, "hasArrow", cmds, "value", cmds)
109 end
110 end
111 end
112  
113  
114 function FuBar_ModMenuTuFu:GetAddonCommandTable(addon)
115 for k,v in pairs(console.registry) do
116 if type(v) == "table" and v.handler and v.handler.name == addon then
117 return v
118 end
119 end
120 end
121  
122  
123 function FuBar_ModMenuTuFu:HandleModClick(addon)
124 local name, _, _, enabled = GetAddOnInfo(addon)
125  
126 if enabled then DisableAddOn(name)
127 else EnableAddOn(name) end
128 end
129  
130  
131 local function getreason(r)
132 if not reasons[r] then reasons[r] = TEXT(getglobal("ADDON_"..r)) end
133 return reasons[r]
134 end
135  
136  
137 function FuBar_ModMenuTuFu:GetOnDemandText(i)
138 local name, title, notes, enabled, loadable, reason, security = GetAddOnInfo(i)
139 local loaded = IsAddOnLoaded(i)
140 local isondemand = IsAddOnLoadOnDemand(i)
141 local color, note
142  
143 if reason == "DISABLED" then color, note = "|cff9d9d9d", getreason(reason) -- Grey
144 elseif reason == "NOT_DEMAND_LOADED" then color, note = "|cff0070dd", getreason(reason) -- Blue
145 elseif reason then color, note = "|cffff8000", getreason(reason) -- Orange
146 elseif loadable and isondemand and not loaded and enabled then color, note = "|cff1eff00", "Loadable OnDemand" -- Green
147 elseif loaded and not enabled then color, note = "|cffa335ee", "Disabled on reloadUI" -- Purple
148 else return title end -- White
149  
150 return string.format("%s%s %s(%s)|r", color, title, color, note)
151 end
152  
153  
154