diff Modules/Config.lua @ 152:311eb97cb983

Added mass export to the extra panel of the config. Next step is to support an easy way to backup settings. :)
author Zerotorescue
date Thu, 20 Jan 2011 20:13:00 +0100
parents cd461a41723c
children 39df534c9856
line wrap: on
line diff
--- a/Modules/Config.lua	Thu Jan 20 06:57:03 2011 +0100
+++ b/Modules/Config.lua	Thu Jan 20 20:13:00 2011 +0100
@@ -834,17 +834,7 @@
 							get = function(info)
 								local groupName = groupIdToName[info[2]];
 								
-								-- We want to include the group name, so we copy the table then set another value
-								local temp = CopyTable(addon.db.profile.groups[groupName]);
-								temp.name = groupName;
-								temp.trackAtCharacters = nil;
-								temp.overrideTrackAtCharacters = nil;
-								
-								if not AceSerializer then
-									AceSerializer = LibStub("AceSerializer-3.0");
-								end
-								
-								return AceSerializer:Serialize(temp);
+								return mod:ExportGroup(groupName);
 							end,
 						},
 					},
@@ -1264,6 +1254,20 @@
 	Widgets:ConfigItemLinkButton();
 end
 
+function mod:ExportGroup(groupName)
+	-- We want to include the group name, so we copy the table then set another value
+	local temp = CopyTable(addon.db.profile.groups[groupName]);
+	temp.name = groupName;
+	temp.trackAtCharacters = nil;
+	temp.overrideTrackAtCharacters = nil;
+
+	if not AceSerializer then
+		AceSerializer = LibStub("AceSerializer-3.0");
+	end
+
+	return AceSerializer:Serialize(temp);
+end
+
 function mod:RefreshConfig()
 	self:PremadeGroupsCheck();
 	
@@ -1655,6 +1659,7 @@
 end
 
 function mod:FillExtraOptions()
+	local selectedExportGroups = {};
 	options.args.extra = {
 		order = 300,
 		type = "group",
@@ -1719,6 +1724,78 @@
 					},
 				},
 			},
+			export = {
+				order = 30,
+				type = "group",
+				inline = true,
+				name = "Export groups",
+				args = {
+					localItemData = {
+						order = 0,
+						type = "multiselect",
+						name = "Select groups",
+						desc = "Select which groups should be included in the export.",
+						values = function()
+							local temp = {};
+							
+							if addon.db.profile.groups then
+								temp["*InverseAll"] = "Inverse";
+								
+								for groupName, _ in pairs(addon.db.profile.groups) do
+									temp[groupName] = groupName;
+								end
+							end
+							
+							return temp;
+						end,
+						get = function(info, value)
+							--local groupName = groupIdToName[info[2]];
+							--local optionName = info[#info];
+							
+							return selectedExportGroups[value];
+						end,
+						set = function(info, name, value)
+							--local groupName = groupIdToName[info[2]];
+							--local optionName = info[#info];
+							
+							if name == "*InverseAll" then
+								for groupName, _ in pairs(addon.db.profile.groups) do
+									if selectedExportGroups[groupName] then
+										selectedExportGroups[groupName] = nil;
+									else
+										selectedExportGroups[groupName] = true;
+									end
+								end
+							else
+								if selectedExportGroups[name] then
+									selectedExportGroups[name] = nil;
+								else
+									selectedExportGroups[name] = true;
+								end
+							end
+						end,
+					},
+					input = {
+						order = 10,
+						type = "input",
+						multiline = true,
+						width = "full",
+						name = "Exported data",
+						desc = "Export the group data for the currently selected group. Press CTRL-A to select all and CTRL-C to copy the text.",
+						set = false,
+						get = function(info)
+							local result = "";
+							for groupName, v in pairs(selectedExportGroups) do
+								if v then
+									result = result .. mod:ExportGroup(groupName) .. "\n";
+								end
+							end
+							
+							return result;
+						end,
+					},
+				},
+			},
 			colorCodes = {
 				order = 30,
 				type = "group",
@@ -2000,47 +2077,49 @@
 							local data = { string.split("\n", value or "") };
 							
 							for _, current in pairs(data) do
-								if not AceSerializer then
-									AceSerializer = LibStub("AceSerializer-3.0");
-								end
-								
-								local result, temp = AceSerializer:Deserialize(current);
-								
-								if not temp.name then
-									addon:Print("The provided data is not supported.", addon.Colors.Red);
-								elseif ValidateGroupName(nil, temp.name) ~= true then
-									addon:Print(("Aborting: A group named \"%s\" already exists."):format(temp.name), addon.Colors.Red);
-								else
-									local name = temp.name;
-									temp.name = nil;
-									addon:Print(("Importing %s..."):format(name));
+								if current and string.trim(current) ~= "" then
+									if not AceSerializer then
+										AceSerializer = LibStub("AceSerializer-3.0");
+									end
 									
-									if temp.items then
-										-- Remove items that are already in another group
-										for value, count in pairs(temp.items) do
-											local itemId = tonumber(value);
-											
-											local itemData = addon.ItemData:New(itemId);
-											
-											if not itemId then
-												addon:Print(("\"%s\" is not a number."):format(value), addon.Colors.Red);
-												temp.items[value] = nil;
-											elseif itemData:InGroup() then
-												addon:Print(("Skipping %s as it is already in the group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), itemData:InGroup() ), addon.Colors.Red);
-												temp.items[value] = nil;
-											else
-												-- Ensure the keys are numeric
-												temp.items[value] = nil;
-												temp.items[itemId] = tonumber(count) or 0;
+									local result, temp = AceSerializer:Deserialize(current);
+									
+									if not temp.name then
+										addon:Print("The provided data is not supported.", addon.Colors.Red);
+									elseif ValidateGroupName(nil, temp.name) ~= true then
+										addon:Print(("Aborting: A group named \"%s\" already exists."):format(temp.name), addon.Colors.Red);
+									else
+										local name = temp.name;
+										temp.name = nil;
+										addon:Print(("Importing %s..."):format(name));
+										
+										if temp.items then
+											-- Remove items that are already in another group
+											for value, count in pairs(temp.items) do
+												local itemId = tonumber(value);
+												
+												local itemData = addon.ItemData:New(itemId);
+												
+												if not itemId then
+													addon:Print(("\"%s\" is not a number."):format(value), addon.Colors.Red);
+													temp.items[value] = nil;
+												elseif itemData:InGroup() then
+													addon:Print(("Skipping %s as it is already in the group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), itemData:InGroup() ), addon.Colors.Red);
+													temp.items[value] = nil;
+												else
+													-- Ensure the keys are numeric
+													temp.items[value] = nil;
+													temp.items[itemId] = tonumber(count) or 0;
+												end
 											end
 										end
+										
+										-- Ensure this data isn't received (this would be silly/buggy as exports from other accounts - with different characters - won't know what to do with this)
+										temp.trackAtCharacters = nil;
+										temp.overrideTrackAtCharacters = nil;
+										
+										addon.db.profile.groups[name] = temp;
 									end
-									
-									-- Ensure this data isn't received (this would be silly/buggy as exports from other accounts - with different characters - won't know what to do with this)
-									temp.trackAtCharacters = nil;
-									temp.overrideTrackAtCharacters = nil;
-									
-									addon.db.profile.groups[name] = temp;
 								end
 							end