[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]

[XaraXtreme-commits] Commit Complete



Commit by  : alex
Repository : xara
Revision   : 1531
Date       : Tue Jul 25 17:05:49 BST 2006

Changed paths:
   M /Trunk/XaraLX/Kernel/app.cpp
   M /Trunk/XaraLX/wxOil/dlgmgr.cpp
   M /Trunk/XaraLX/wxOil/dlgmgr.h

Save gallery positions across sessions. There seems to still be a mysterious bug re saving sizes


Diff:
Index: Trunk/XaraLX/Kernel/app.cpp
===================================================================
--- Trunk/XaraLX/Kernel/app.cpp	(revision 1530)
+++ Trunk/XaraLX/Kernel/app.cpp	(revision 1531)
@@ -775,6 +775,10 @@
 	DestroyCCC();
 #endif
 
+	// DialogManager was deinitialized a while ago, but this bit needs to be done after
+	// the pref system has gone. It merely frees some memory
+	DialogManager::FreePaneInfoHash();
+
 	ObjectRegistry::Delete();
 }
 
Index: Trunk/XaraLX/wxOil/dlgmgr.h
===================================================================
--- Trunk/XaraLX/wxOil/dlgmgr.h	(revision 1530)
+++ Trunk/XaraLX/wxOil/dlgmgr.h	(revision 1531)
@@ -170,7 +170,7 @@
 
 #endif
 
-WX_DECLARE_STRING_HASH_MAP( wxString, IdToSerializedPaneInfo );
+WX_DECLARE_STRING_HASH_MAP( String_256, IdToSerializedPaneInfo );
 
 /********************************************************************************************
 
@@ -816,10 +816,14 @@
 	// Now our event handlers
 	static void Event (DialogEventHandler *pEvtHandler, wxEvent &event);
 
+	static void EnsurePanePreferenceDeclared(wxString key);
 	static void InitPaneInfoHash();
 	static void LoadPaneInfo(wxString key, wxPaneInfo &paneinfo);
 	static void SavePaneInfo(wxString key, wxPaneInfo &paneinfo);
 	static IdToSerializedPaneInfo * s_pPaneInfoHash;
+
+public:
+	static void FreePaneInfoHash();
 };         
 
 
Index: Trunk/XaraLX/wxOil/dlgmgr.cpp
===================================================================
--- Trunk/XaraLX/wxOil/dlgmgr.cpp	(revision 1530)
+++ Trunk/XaraLX/wxOil/dlgmgr.cpp	(revision 1531)
@@ -749,6 +749,77 @@
 
 /********************************************************************************************
 
+>	void DialogManager::FreePaneInfoHash
+
+	Author:		Alex Bligh <alex@xxxxxxxxxxx>
+	Created:	25/07/06
+	Inputs:		-
+	Outputs:	-
+	Returns:	-
+	Purpose:	Free the pane info hash if it exists
+	Scope:		protected
+
+This function MUST be called ONLY after the preference system has been de-inited. This
+may be after dialogmanager deinit.
+
+********************************************************************************************/
+
+void DialogManager::FreePaneInfoHash()
+{
+	if (s_pPaneInfoHash)
+	{
+		delete s_pPaneInfoHash;
+		s_pPaneInfoHash = NULL;
+	}
+}
+
+/********************************************************************************************
+
+>	void DialogManager::EnsurePanePreferenceDeclared(key)
+
+	Author:		Alex Bligh <alex@xxxxxxxxxxx>
+	Created:	25/07/06
+	Inputs:		key - the key the pane info will be stored under
+	Outputs:	None
+	Returns:	None
+	Purpose:	Ensures the relevant preference has been declared
+	Scope:		protected
+
+********************************************************************************************/
+
+void DialogManager::EnsurePanePreferenceDeclared(wxString key)
+{
+	if (!s_pPaneInfoHash)
+		InitPaneInfoHash();
+
+	if (!s_pPaneInfoHash)
+		return;
+
+	IdToSerializedPaneInfo::iterator i=s_pPaneInfoHash->find(key);
+	if (i==s_pPaneInfoHash->end())
+	{
+		// ok, it's not in the hash, so it can't have been declared as a preference
+		// yet. So we will declare it as a preference now
+		(*s_pPaneInfoHash)[key]=_T("");
+		i=s_pPaneInfoHash->find(key);
+		if (i==s_pPaneInfoHash->end())
+		{
+			ERROR3("This hash leaks like a seive");
+			return;
+		}
+		// --------------------------------------------------------------------------
+		// Detect first-time run and make Open File dialog default to Examples folder
+		if (Camelot.DeclareSection(_T("BarPositions"), 10))
+		{
+			Camelot.DeclarePref( NULL, (TCHAR *)(key.c_str()), &(i->second) );
+		}
+	}
+}
+
+
+
+/********************************************************************************************
+
 >	void DialogManager::LoadPaneInfo(wxString key, wxPaneInfo &paneinfo)
 
 	Author:		Alex Bligh <alex@xxxxxxxxxxx>
@@ -769,14 +840,21 @@
 	if (!s_pPaneInfoHash)
 		return;
 
+	EnsurePanePreferenceDeclared(key);
+
 	IdToSerializedPaneInfo::iterator i=s_pPaneInfoHash->find(key);
 	if (i==s_pPaneInfoHash->end())
 		return;
 
+	// do not bother trying to process empty strings
+	if (i->second.IsEmpty())
+		return;
+
 	TRACEUSER("amb", _T("key=%s"), (const TCHAR *)key);
 	TRACEUSER("amb", _T("val=%s"), (const TCHAR *)(i->second));
 
-	CCamFrame::GetFrameManager()->LoadPaneInfo(i->second, paneinfo);
+	wxString name = (wxString)((const TCHAR *)(i->second));
+	CCamFrame::GetFrameManager()->LoadPaneInfo(name, paneinfo);
 }
 
 /********************************************************************************************
@@ -801,6 +879,8 @@
 	if (!s_pPaneInfoHash)
 		return;
 
+	EnsurePanePreferenceDeclared(key);
+
 	(*s_pPaneInfoHash)[key]=CCamFrame::GetFrameManager()->SavePaneInfo(paneinfo);
 }
 
@@ -6203,12 +6283,7 @@
 		delete DialogPositionList.RemoveItem(DlgPos);
 		DlgPos = NextPos;
 	}
-
-	if (s_pPaneInfoHash)
-	{
-		delete s_pPaneInfoHash;
-		s_pPaneInfoHash = NULL;
-	}
+	// We do not delete s_pPaneInfoHash here because the preferences have not been written out
 }
 
 /********************************************************************************************


Xara