diff Modules/Summary.lua @ 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 15f22a466596
children 72de51449286
line wrap: on
line diff
--- 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();