changeset 205:0ea991d9093c

Config and Summary windows are now toggled rather than always shown.
author Zerotorescue
date Sat, 05 Feb 2011 19:36:35 +0100
parents 4f5e114fe15f
children 5d13830e8b0d
files Modules/Config.lua Modules/Summary.lua
diffstat 2 files changed, 85 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/Modules/Config.lua	Sat Feb 05 19:36:15 2011 +0100
+++ b/Modules/Config.lua	Sat Feb 05 19:36:35 2011 +0100
@@ -1306,15 +1306,12 @@
 function mod:OnEnable()
 	-- Register our config slash command
 	-- /im config
-	addon:RegisterSlash(function(this)
-		-- We don't want any other windows open at this time.
-		for name, module in this:IterateModules() do
-			if module.CloseFrame then
-				module:CloseFrame();
-			end
+	addon:RegisterSlash(function()
+		if mod:IsFrameOpen() then
+			mod:CloseFrame();
+		else
+			mod:Show();
 		end
-		
-		this:GetModule("Config"):Show();
 	end, { "c", "config", "conf", "option", "options", "opt", "setting", "settings" }, "|Hfunction:InventoriumCommandHandler:config|h|cff00fff7/im config|r|h (or /im c) - Open the config window to change the settings and manage groups.");
 	
 	self:Load(false);
@@ -1330,6 +1327,27 @@
 	Widgets:ConfigItemLinkButton();
 end
 
+function mod:Show()
+	-- We don't want any other windows open at this time.
+	for name, module in addon:IterateModules() do
+		if module.CloseFrame then
+			module:CloseFrame();
+		end
+	end
+	
+	self:Load(true);
+	
+	AceConfigDialog:Open("Inventorium");
+end
+
+function mod:IsFrameOpen()
+	return (AceConfigDialog.OpenFrames["Inventorium"] ~= nil);
+end
+
+function mod:CloseFrame()
+	LibStub("AceConfigDialog-3.0"):Close("Inventorium");
+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]);
@@ -1378,12 +1396,6 @@
 	end
 end
 
-function mod:Show()
-	self:Load(true);
-	
-	AceConfigDialog:Open("Inventorium");
-end
-
 function mod:FillOptions()
 	options = {
 		type = "group",	
--- a/Modules/Summary.lua	Sat Feb 05 19:36:15 2011 +0100
+++ b/Modules/Summary.lua	Sat Feb 05 19:36:35 2011 +0100
@@ -1,5 +1,5 @@
 local addon = select(2, ...); -- Get a reference to the main addon object
-local mod = addon:NewModule("Summary"); -- register a new module, Summary: resposible for building the summary window
+local mod = addon:NewModule("Summary", "AceTimer-3.0"); -- register a new module, Summary: resposible for building the summary window
 
 local _G = _G; -- prevent looking up of the global table
 local sformat, sgsub, supper, mceil, mfloor, tinsert, twipe, tsort = _G.string.format, _G.string.gsub, _G.string.upper, _G.math.ceil, _G.math.floor, _G.table.insert, _G.table.wipe, _G.table.sort;
@@ -19,8 +19,11 @@
 	-- Register our own slash commands
 	-- /im summary
 	addon:RegisterSlash(function()
-		mod:BuildMain();
-		mod:Build();
+		if self:IsFrameOpen() then
+			self:CloseFrame();
+		else
+			self:Show();
+		end
 	end, { "s", "sum", "summary" }, "|Hfunction:InventoriumCommandHandler:summary|h|cff00fff7/im summary|r|h (or /im s) - Show the summary window containing an overview of all items within the groups tracked at this current character.");
 	
 	-- /im reset
@@ -54,45 +57,61 @@
 end
 
 function mod:BuildMain()
-	LibStub("AceConfigDialog-3.0"):Close("InventoriumOptions");
+	if not self.frame then
+		-- Main Window
+		self.frame = AceGUI:Create("Frame");
+		_G["InventoriumSummary"] = self.frame; -- name the global frame so it can be put in the UISpecialFrames
+		self.frame:SetTitle("Inventory Summary");
+		self.frame:SetLayout("Fill");
+		self.frame:SetCallback("OnClose", function(widget)
+			mod:CancelTimer(self.tmrUpdater, true);
+			mod:CloseFrame();
+		end);
+		self.frame:SetWidth(addon.db.profile.defaults.summary.width);
+		self.frame:SetHeight(addon.db.profile.defaults.summary.height);
+		self.frame.OnWidthSet = function(_, width)
+			addon.db.profile.defaults.summary.width = width;
+		end;
+		self.frame.OnHeightSet = function(_, height)
+			addon.db.profile.defaults.summary.height = height;
+		end;
+		
+		-- Close on escape
+		tinsert(UISpecialFrames, "InventoriumSummary");
+		
+		-- ScrollFrame child
+		self.scrollFrame = AceGUI:Create("ScrollFrame");
+		self.scrollFrame:SetLayout("Flow");
+		
+		self.frame:AddChild(self.scrollFrame);
+		
+		-- Reset items cache
+		twipe(itemsCache);
+	end
+end
+
+function mod:Show()
+	-- We don't want any other windows open at this time.
+	for name, module in addon:IterateModules() do
+		if module.CloseFrame then
+			module:CloseFrame();
+		end
+	end
 	
-	self:CloseFrame();
-	
-	-- Main Window
-	mod.frame = AceGUI:Create("Frame");
-	_G["InventoriumSummary"] = mod.frame; -- name the global frame so it can be put in the UISpecialFrames
-	mod.frame:SetTitle("Inventory Summary");
-	mod.frame:SetLayout("Fill");
-	mod.frame:SetCallback("OnClose", function(widget)
-		mod:CancelTimer(self.tmrUpdater, true);
-		mod:CloseFrame();
-	end);
-	mod.frame:SetWidth(addon.db.profile.defaults.summary.width);
-	mod.frame:SetHeight(addon.db.profile.defaults.summary.height);
-	mod.frame.OnWidthSet = function(_, width)
-		addon.db.profile.defaults.summary.width = width;
-	end;
-	mod.frame.OnHeightSet = function(_, height)
-		addon.db.profile.defaults.summary.height = height;
-	end;
-	
-	-- Close on escape
-	tinsert(UISpecialFrames, "InventoriumSummary");
-	
-	-- ScrollFrame child
-	mod.scrollFrame = AceGUI:Create("ScrollFrame");
-	mod.scrollFrame:SetLayout("Flow");
-	
-	mod.frame:AddChild(mod.scrollFrame);
-	
-	-- Reset items cache
-	twipe(itemsCache);
+	self:BuildMain();
+	self:Build();
+end
+
+function mod:IsFrameOpen()
+	return (self.frame and self.frame:IsShown());
 end
 
 function mod:CloseFrame()
-	if mod.frame then
-		mod.frame:Release();
-		mod.frame = nil;
+	if self:IsFrameOpen() then
+		--self.scrollFrame:Release();
+		--self.scrollFrame = nil;
+		
+		self.frame:Hide();
 		
 		-- Stop caching
 		
@@ -136,6 +155,8 @@
 function mod:Build()
 	local buildStartTime, times = GetTime(), {};
 	
+	self.frame:Show();
+	
 	-- We are going to add hunderds of widgets to this container, but don't want it to also cause hunderds of reflows, thus pause reflowing and just do it once when everything is prepared
 	-- This appears to be required for each container we wish to pause, so also do this for the contents
 	mod.scrollFrame:PauseLayout();