Mercurial > wow > inventory
comparison Modules/Config.lua @ 189:90e5911a2ff1
Added full backup functionality.
Added a description to the export groups inline-group.
author | Zerotorescue |
---|---|
date | Mon, 31 Jan 2011 23:18:24 +0100 |
parents | 679d3664849d |
children | 0ea991d9093c |
comparison
equal
deleted
inserted
replaced
188:5cee31b1418a | 189:90e5911a2ff1 |
---|---|
1858 }, | 1858 }, |
1859 }; | 1859 }; |
1860 end | 1860 end |
1861 | 1861 |
1862 function mod:FillExtraOptions() | 1862 function mod:FillExtraOptions() |
1863 local selectedExportGroups = {}; | 1863 local selectedExportGroups, enableBackupGeneration; |
1864 options.args.extra = { | 1864 options.args.extra = { |
1865 order = 300, | 1865 order = 300, |
1866 type = "group", | 1866 type = "group", |
1867 name = "Extra", | 1867 name = "Extra", |
1868 desc = "Change additional (but completely optional) settings.", | 1868 desc = "Change additional (but completely optional) settings.", |
1951 end | 1951 end |
1952 end, | 1952 end, |
1953 }, | 1953 }, |
1954 }, | 1954 }, |
1955 }, | 1955 }, |
1956 export = { | |
1957 order = 20, | |
1958 type = "group", | |
1959 inline = true, | |
1960 name = "Export groups", | |
1961 args = { | |
1962 localItemData = { | |
1963 order = 0, | |
1964 type = "multiselect", | |
1965 name = "Select groups", | |
1966 desc = "Select which groups should be included in the export.", | |
1967 values = function() | |
1968 local temp = {}; | |
1969 | |
1970 if addon.db.profile.groups then | |
1971 temp["*InverseAll"] = "Inverse"; | |
1972 | |
1973 for groupName, _ in pairs(addon.db.profile.groups) do | |
1974 temp[groupName] = groupName; | |
1975 end | |
1976 end | |
1977 | |
1978 return temp; | |
1979 end, | |
1980 get = function(info, value) | |
1981 --local groupName = groupIdToName[info[2]]; | |
1982 --local optionName = info[#info]; | |
1983 | |
1984 return selectedExportGroups[value]; | |
1985 end, | |
1986 set = function(info, name, value) | |
1987 --local groupName = groupIdToName[info[2]]; | |
1988 --local optionName = info[#info]; | |
1989 | |
1990 if name == "*InverseAll" then | |
1991 for groupName, _ in pairs(addon.db.profile.groups) do | |
1992 if selectedExportGroups[groupName] then | |
1993 selectedExportGroups[groupName] = nil; | |
1994 else | |
1995 selectedExportGroups[groupName] = true; | |
1996 end | |
1997 end | |
1998 else | |
1999 if selectedExportGroups[name] then | |
2000 selectedExportGroups[name] = nil; | |
2001 else | |
2002 selectedExportGroups[name] = true; | |
2003 end | |
2004 end | |
2005 end, | |
2006 }, | |
2007 input = { | |
2008 order = 10, | |
2009 type = "input", | |
2010 multiline = true, | |
2011 width = "full", | |
2012 name = "Exported data", | |
2013 desc = "Export the group data for the currently selected group. Press CTRL-A to select all and CTRL-C to copy the text.", | |
2014 set = false, | |
2015 get = function(info) | |
2016 local result = ""; | |
2017 for groupName, v in pairs(selectedExportGroups) do | |
2018 if v then | |
2019 result = result .. mod:ExportGroup(groupName) .. "\n"; | |
2020 end | |
2021 end | |
2022 | |
2023 return result; | |
2024 end, | |
2025 }, | |
2026 }, | |
2027 }, | |
2028 colorCodes = { | 1956 colorCodes = { |
2029 order = 30, | 1957 order = 30, |
2030 type = "group", | 1958 type = "group", |
2031 inline = true, | 1959 inline = true, |
2032 name = "Color codes", | 1960 name = "Color codes", |
2088 isPercent = true, | 2016 isPercent = true, |
2089 name = "|cffff0000Red|r", | 2017 name = "|cffff0000Red|r", |
2090 desc = "Show quantity in red when at least this much of the minimum stock is available.", | 2018 desc = "Show quantity in red when at least this much of the minimum stock is available.", |
2091 get = function() return addon.db.profile.defaults.colors.red; end, | 2019 get = function() return addon.db.profile.defaults.colors.red; end, |
2092 set = function(i, v) addon.db.profile.defaults.colors.red = v; end, | 2020 set = function(i, v) addon.db.profile.defaults.colors.red = v; end, |
2021 }, | |
2022 }, | |
2023 }, | |
2024 export = { | |
2025 order = 80, | |
2026 type = "group", | |
2027 inline = true, | |
2028 name = "Export groups", | |
2029 args = { | |
2030 description = { | |
2031 order = 0, | |
2032 type = "description", | |
2033 name = "Select the groups you wish to export below. Each group will have any account specific data removed and can safely and freely be shared with other users. All exported groups can be imported at once at the bottom of the \"Groups\" category of the config.", | |
2034 hidden = function() return addon.db.profile.defaults.hideHelp; end, | |
2035 }, | |
2036 header = { | |
2037 order = 5, | |
2038 type = "header", | |
2039 name = "", | |
2040 hidden = function() return addon.db.profile.defaults.hideHelp; end, | |
2041 }, | |
2042 localItemData = { | |
2043 order = 9, | |
2044 type = "multiselect", | |
2045 name = "Select groups", | |
2046 desc = "Select which groups should be included in the export.", | |
2047 values = function() | |
2048 local temp = {}; | |
2049 | |
2050 if addon.db.profile.groups then | |
2051 temp["*InverseAll"] = "Inverse"; | |
2052 | |
2053 for groupName, _ in pairs(addon.db.profile.groups) do | |
2054 temp[groupName] = groupName; | |
2055 end | |
2056 end | |
2057 | |
2058 return temp; | |
2059 end, | |
2060 get = function(info, value) | |
2061 --local groupName = groupIdToName[info[2]]; | |
2062 --local optionName = info[#info]; | |
2063 | |
2064 return selectedExportGroups and selectedExportGroups[value]; | |
2065 end, | |
2066 set = function(info, name, value) | |
2067 --local groupName = groupIdToName[info[2]]; | |
2068 --local optionName = info[#info]; | |
2069 | |
2070 if not selectedExportGroups then | |
2071 selectedExportGroups = {}; | |
2072 end | |
2073 | |
2074 if name == "*InverseAll" then | |
2075 for groupName, _ in pairs(addon.db.profile.groups) do | |
2076 if selectedExportGroups and selectedExportGroups[groupName] then | |
2077 selectedExportGroups[groupName] = nil; | |
2078 else | |
2079 selectedExportGroups[groupName] = true; | |
2080 end | |
2081 end | |
2082 else | |
2083 if selectedExportGroups and selectedExportGroups[name] then | |
2084 selectedExportGroups[name] = nil; | |
2085 else | |
2086 selectedExportGroups[name] = true; | |
2087 end | |
2088 end | |
2089 end, | |
2090 }, | |
2091 input = { | |
2092 order = 10, | |
2093 type = "input", | |
2094 multiline = true, | |
2095 width = "full", | |
2096 name = "Exported data", | |
2097 desc = "Exported group data for the currently selected group(s). Press CTRL-A to select all and CTRL-C to copy the text.", | |
2098 set = false, | |
2099 get = function() | |
2100 local result = ""; | |
2101 if selectedExportGroups then | |
2102 for groupName, v in pairs(selectedExportGroups) do | |
2103 if v then | |
2104 result = result .. mod:ExportGroup(groupName) .. "\n"; | |
2105 end | |
2106 end | |
2107 end | |
2108 | |
2109 return result; | |
2110 end, | |
2111 }, | |
2112 }, | |
2113 }, | |
2114 backup = { | |
2115 order = 100, | |
2116 type = "group", | |
2117 inline = true, | |
2118 name = "Generate a full backup", | |
2119 args = { | |
2120 description = { | |
2121 order = 0, | |
2122 type = "description", | |
2123 name = "With this you can generate a full backup of all your Inventorium settings. You can store this in a text file on your computer so you can import it at a later time if anything breaks to prevent losing a time consuming setup. You can also use it to share with other users but keep in mind this will include account specific data which you might not want in the wrong hands.", | |
2124 hidden = function() return addon.db.profile.defaults.hideHelp; end, | |
2125 }, | |
2126 header = { | |
2127 order = 5, | |
2128 type = "header", | |
2129 name = "", | |
2130 hidden = function() return addon.db.profile.defaults.hideHelp; end, | |
2131 }, | |
2132 generate = { | |
2133 order = 9, | |
2134 type = "toggle", | |
2135 width = "full", | |
2136 name = "Generate a full backup (might take a second)", | |
2137 desc = "Generate a full backup. This process might take 1 to 2 seconds.", | |
2138 set = function(_, v) | |
2139 enableBackupGeneration = v; | |
2140 end, | |
2141 get = function() | |
2142 return enableBackupGeneration; | |
2143 end, | |
2144 }, | |
2145 input = { | |
2146 order = 10, | |
2147 type = "input", | |
2148 multiline = true, | |
2149 width = "full", | |
2150 name = "Exported data", | |
2151 desc = "Exported backup data. Press CTRL-A to select all and CTRL-C to copy the text.\n\nPlease note this includes character data.", | |
2152 set = false, | |
2153 get = function() | |
2154 if not enableBackupGeneration then | |
2155 return; | |
2156 end | |
2157 | |
2158 -- We want to include the group name, so we copy the table then set another value | |
2159 local temp = { | |
2160 ["type"] = "backup", | |
2161 ["global"] = addon.db.global or {}, | |
2162 ["profiles"] = addon.db.profiles or {}, | |
2163 ["factionrealm"] = addon.db.factionrealm or {}, | |
2164 }; | |
2165 | |
2166 if not AceSerializer then | |
2167 AceSerializer = LibStub("AceSerializer-3.0"); | |
2168 end | |
2169 | |
2170 return AceSerializer:Serialize(temp); | |
2171 end, | |
2172 }, | |
2173 }, | |
2174 }, | |
2175 importBackup = { | |
2176 order = 101, | |
2177 type = "group", | |
2178 inline = true, | |
2179 name = "Import a full backup", | |
2180 args = { | |
2181 description = { | |
2182 order = 0, | |
2183 type = "description", | |
2184 name = "With this you can import a full backup of all your Inventorium settings. |cffff0000Warning! Importing a backup will TRASH all your current settings and profiles. You are advised to store your own backup prior to importing one.|r", | |
2185 hidden = function() return addon.db.profile.defaults.hideHelp; end, | |
2186 }, | |
2187 header = { | |
2188 order = 5, | |
2189 type = "header", | |
2190 name = "", | |
2191 hidden = function() return addon.db.profile.defaults.hideHelp; end, | |
2192 }, | |
2193 input = { | |
2194 order = 10, | |
2195 type = "input", | |
2196 multiline = true, | |
2197 width = "full", | |
2198 name = "Paste the backup data here", | |
2199 desc = "Exported backup data. To copy the backup data, press CTRL-A to select all and CTRL-C to copy it. Then click this textblock and hit CTRL-V to paste it.", | |
2200 set = function(_, v) | |
2201 if v and string.trim(v) ~= "" then | |
2202 if not AceSerializer then | |
2203 AceSerializer = LibStub("AceSerializer-3.0"); | |
2204 end | |
2205 | |
2206 local result, temp = AceSerializer:Deserialize(v); | |
2207 | |
2208 if result and temp and type(temp) == "table" and temp.type and temp.type == "backup" then | |
2209 addon.db:ResetDB("TEMPPROFILENAME" .. GetTime()); | |
2210 | |
2211 local tempProfileName = addon.db:GetCurrentProfile(); | |
2212 | |
2213 if temp.global then | |
2214 print("Importing |cfffed000global|r data..."); | |
2215 | |
2216 -- Update by reference, rather than changing the reference | |
2217 for k, v in pairs(temp.global) do | |
2218 addon.db.global[k] = v; | |
2219 end | |
2220 end | |
2221 | |
2222 if temp.profiles then | |
2223 print("Importing |cfffed000profiles|r data..."); | |
2224 | |
2225 -- Update by reference, rather than changing the reference | |
2226 for profileName, profile in pairs(temp.profiles) do | |
2227 print("Importing profile |cfffed000" .. profileName .. "|r..."); | |
2228 | |
2229 addon.db.profiles[profileName] = profile; | |
2230 | |
2231 -- If the current profile is the temp profile, select the first profile in the backup | |
2232 if addon.db:GetCurrentProfile() == tempProfileName or profileName == "Default" then | |
2233 addon.db:SetProfile(profileName); | |
2234 end | |
2235 | |
2236 -- If our backup contains a profile with the same name as the temp profile, then don't delete the temp profile | |
2237 if profileName == tempProfileName then | |
2238 tempProfileName = nil; | |
2239 end | |
2240 end | |
2241 end | |
2242 | |
2243 -- Delete the temp profile | |
2244 if tempProfileName then | |
2245 addon.db:DeleteProfile(tempProfileName); | |
2246 end | |
2247 | |
2248 if temp.factionrealm then | |
2249 print("Importing |cfffed000character|r data..."); | |
2250 | |
2251 -- Update by reference, rather than changing the reference | |
2252 for k, v in pairs(temp.factionrealm) do | |
2253 addon.db.factionrealm[k] = v; | |
2254 end | |
2255 end | |
2256 | |
2257 mod:FillGroupOptions(); | |
2258 | |
2259 addon:Print("Import finished.", addon.Colors.Green); | |
2260 else | |
2261 addon:Print("The data provided is not supported.", addon.Colors.Red); | |
2262 end | |
2263 else | |
2264 addon:Print("The data provided is not supported.", addon.Colors.Red); | |
2265 end | |
2266 end, | |
2267 get = false, | |
2268 confirm = function() return "Are you sure you wish to override all your current settings with this data?"; end, | |
2093 }, | 2269 }, |
2094 }, | 2270 }, |
2095 }, | 2271 }, |
2096 }, | 2272 }, |
2097 }; | 2273 }; |