[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]
[XaraXtreme-commits] Commit Complete
Commit by : phil
Repository : xara
Revision : 1271
Date : Thu Jun 8 17:02:31 BST 2006
Changed paths:
M /Trunk/XaraLX/Kernel/hotkeys.cpp
M /Trunk/XaraLX/Kernel/prefs.cpp
M /Trunk/XaraLX/wxOil/keypress.cpp
M /Trunk/XaraLX/wxOil/keypress.h
M /Trunk/XaraLX/wxOil/oilprefs.cpp
M /Trunk/XaraLX/wxOil/oilprefs.h
Moved OILy code out of hotkeys.cpp into keypress.cpp.
hotkeys file now picked up from ~/.xaralx folder.
Restored class derivation of OILPreferences.
Diff:
Index: Trunk/XaraLX/Kernel/hotkeys.cpp
===================================================================
--- Trunk/XaraLX/Kernel/hotkeys.cpp (revision 1270)
+++ Trunk/XaraLX/Kernel/hotkeys.cpp (revision 1271)
@@ -537,23 +537,10 @@
{
CCDiskFile file; // File
- // Find hotkeys file using binreloc
- PSTR pszDataPath = br_find_data_dir("/usr/share");
- wxString strFilename(pszDataPath, wxConvUTF8);
- free(pszDataPath);
- strFilename += _T("/xaralx/hotkeys");
+ FilePath filepath = KeyPress::GetHotKeysFilename();
+ if (!filepath.IsValid())
+ return FALSE;
-#if defined(_DEBUG)
- // Debug-only fallback
- if (!wxFile::Exists(strFilename))
- strFilename = _T("/usr/share/xaralx/hotkeys");
-#endif
-
-// if (!wxFile::Exists(strFilenmae))
-// return FALSE;
-
- PathName filepath(strFilename);
-
BOOL ok = TRUE;
// Prevent file errors from being reported directly to the user
@@ -581,7 +568,7 @@
file.SetThrowExceptions( OldThrowingState );
file.SetReportErrors( OldReportingState );
- return (ok);
+ return ok;
}
/********************************************************************************************
Index: Trunk/XaraLX/Kernel/prefs.cpp
===================================================================
--- Trunk/XaraLX/Kernel/prefs.cpp (revision 1270)
+++ Trunk/XaraLX/Kernel/prefs.cpp (revision 1271)
@@ -984,22 +984,17 @@
{
#if !defined(EXCLUDE_FROM_RALPH)
// Create a link to the OIL
- OILPrefs = new OILPreferences();
+ OILPrefs = OILPreferences::Init();
// Flag error if it failed
- if (OILPrefs == NULL || !OILPrefs->Init())
+ if (OILPrefs == NULL)
return FALSE;
- // TODO: Get Appname and orgnisation name from central location? product.h?
- //OILPrefs->SetAppName(_T("XaraLX"));
- //OILPrefs->SetVendorName(_T("XaraGroup"));
-
- // Flag that the class has been set up and initialised and so enable the writing out
- // on exit.
PrefsInitedOk = TRUE;
// Initialise the preference file for reading
return OILPrefs->OpenInput();
+
#else //EXCLUDE_FROM_RALPH
// Be gone you pesky prefs system :-)
OILPrefs = NULL;
Index: Trunk/XaraLX/wxOil/keypress.h
===================================================================
--- Trunk/XaraLX/wxOil/keypress.h (revision 1270)
+++ Trunk/XaraLX/wxOil/keypress.h (revision 1271)
@@ -190,6 +190,7 @@
public:
static BOOL Init();
+ static FilePath GetHotKeysFilename();
static BOOL DispatchKeyEvent(UINT32 nMsgID, UINT32 nChar, UINT32 nRepCnt, UINT32 nFlags);
static BOOL TranslateMessage( wxKeyEvent *pMsg );
static void ResetModifierKeys();
Index: Trunk/XaraLX/wxOil/oilprefs.h
===================================================================
--- Trunk/XaraLX/wxOil/oilprefs.h (revision 1270)
+++ Trunk/XaraLX/wxOil/oilprefs.h (revision 1271)
@@ -117,16 +117,20 @@
********************************************************************************************/
-class OILPreferences
+class OILPreferences : public wxConfig
{
-protected:
- std::auto_ptr<wxConfig> m_pConfig;
-
public:
- OILPreferences();
+ // Class factory/Initialise an OILPreferences object
+ static OILPreferences* Init();
- // Initialise the OILPreferences object
- BOOL Init();
+ // Constructor (I wish I didn't have to duplicate this here but don't know any way
+ // to avoid it)
+ OILPreferences( const wxString& appName = wxEmptyString,
+ const wxString& vendorName = wxEmptyString,
+ const wxString& localFilename = wxEmptyString,
+ const wxString& globalFilename = wxEmptyString,
+ long style = 0, wxMBConv& conv = wxConvUTF8)
+ : wxConfig(appName, vendorName, localFilename, globalFilename, style, conv) {;}
// Write a preference
void Write(LPTCHAR Section, LPTCHAR PrefName, PreferenceType Type, PrefData pData);
Index: Trunk/XaraLX/wxOil/oilprefs.cpp
===================================================================
--- Trunk/XaraLX/wxOil/oilprefs.cpp (revision 1270)
+++ Trunk/XaraLX/wxOil/oilprefs.cpp (revision 1271)
@@ -109,42 +109,43 @@
#include "product.h" // PRODUCT_OPTIONS_REGISTRYKEY
-OILPreferences::OILPreferences()
-{
-}
/********************************************************************************************
-> BOOL OILPreferences::Init()
+> static OILPreferences* OILPreferences::Init()
- Author: Tim_Browse (Xara Group Ltd) <camelotdev@xxxxxxxx>
- Created: 24/8/93
- Returns: TRUE if initialisation succeeded, FALSE otherwise.
+ Author: Luke_Hart & Phil_Martin (Xara Group Ltd) <camelotdev@xxxxxxxx>
+ Created: 8/Jun/2006
+ Returns: OILPreferences objects if initialisation succeeded, NULL otherwise.
Purpose: Performs any initialisation of the OIL layer preferences mechanisms that
- may fail. (Under Windows, this is all handled by MFC).
+ may fail.
********************************************************************************************/
-BOOL OILPreferences::Init()
+OILPreferences* OILPreferences::Init()
{
wxStandardPaths Paths;
wxString strPath( Paths.GetUserConfigDir() );
strPath += _T("/.xaralx");
+ // Delete any file that exists where the directory should be
+ if (wxFile::Exists(strPath))
+ ::wxRemoveFile(strPath);
+
// Create directory iff not exist
if( !wxDir::Exists( strPath ) )
::wxMkdir( strPath );
TRACEUSER( "jlh92", _T("OILPreferences::Init %s
"), PCTSTR(strPath) );
- // Open config file
+ // Open config storage
strPath += _T("/preferences");
- m_pConfig = std::auto_ptr<wxConfig>( new wxConfig( _T("xaralx"), _T("Xara"), strPath ) );
+ OILPreferences* pPrefs = new OILPreferences(_T("xaralx"), _T("Xara"), strPath);
TRACEUSER( "jlh92", _T("OILPreferences::Init2 %s
"), PCTSTR(strPath) );
- // Always succeed
- return TRUE;
+ // Return the object we made or a NULL pointer if we failed
+ return pPrefs;
}
/********************************************************************************************
@@ -160,7 +161,7 @@
void OILPreferences::WipePreferenceFile()
{
- m_pConfig->DeleteAll();
+ DeleteAll();
}
/********************************************************************************************
@@ -176,9 +177,9 @@
void OILPreferences::WipeDangerousPrefs()
{
// wipe the potentially dangerous settings from the registry
- m_pConfig->DeleteGroup(_T("Gallery"));
- m_pConfig->DeleteGroup(_T("Options/Templates"));
- m_pConfig->DeleteGroup(_T("Options/NewTemplates"));
+ DeleteGroup(_T("Gallery"));
+ DeleteGroup(_T("Options/Templates"));
+ DeleteGroup(_T("Options/NewTemplates"));
// DeleteRegKeyAndSubKeys (hAppStateRegKey, PRODUCT_REGISTRYKEY_GALLERY);
// HKEY optsKey = OpenRegKey(hAppStateRegKey, PRODUCT_REGISTRYKEY_OPTIONS);
@@ -217,7 +218,7 @@
case PREF_INT:
{
/*TYPENOTE: Correct*/ long l = (long)(*Data.pInt);
- Worked = m_pConfig->Write(strKey, l);
+ Worked = wxConfig::Write(strKey, l);
break;
}
@@ -229,17 +230,17 @@
// (Could write UINT32 prefs as strings...)
//
/*TYPENOTE: Correct*/ long l = (long)(*Data.pUInt);
- Worked = m_pConfig->Write(strKey, l);
+ Worked = wxConfig::Write(strKey, l);
break;
}
case PREF_DOUBLE:
- Worked = m_pConfig->Write(strKey, (double)*(Data.pDouble));
+ Worked = wxConfig::Write(strKey, (double)*(Data.pDouble));
break;
case PREF_STRING:
- Worked = m_pConfig->Write(strKey, wxString((TCHAR*)*(Data.pString)));
-// Worked = m_pConfig->Write(strKey, *(Data.pString)); // use this form when StringBase derived classes support direct conversion
+ Worked = wxConfig::Write(strKey, wxString((TCHAR*)*(Data.pString)));
+// Worked = wxConfig::Write(strKey, *(Data.pString)); // use this form when StringBase derived classes support direct conversion
break;
default:
@@ -302,7 +303,7 @@
// Use the value already in pData->Int as the value to return if the
// preference is not found.
/*TYPENOTE: Correct*/ long l;
- if (m_pConfig->Read(strKey, &l))
+ if (wxConfig::Read(strKey, &l))
*pData.pInt = (INT32)l; // Do not write directly as may be longer than 32 bits
break;
}
@@ -312,7 +313,7 @@
// Note that signed value is read and cast directly into Unsigned memory
// allocation reversing the effects fo the cast used in Write above...
/*TYPENOTE: Correct*/ long l;
- if (m_pConfig->Read(strKey, &l))
+ if (wxConfig::Read(strKey, &l))
*pData.pUInt = (UINT32)l; // Do not write directly as may be longer than 32 bits
break;
}
@@ -320,7 +321,7 @@
{
// Get the textual version of the double and convert it to a double.
// default to null string
- m_pConfig->Read(strKey, (double*)(pData.pDouble));
+ wxConfig::Read(strKey, (double*)(pData.pDouble));
break;
}
case PREF_STRING:
@@ -328,7 +329,7 @@
// Just get the string - need to ask for the address of the String's
// text buffer so we can pass it to the SDK profile API.
wxString str;
- m_pConfig->Read(strKey, &str);
+ wxConfig::Read(strKey, &str);
str.Truncate(256);
*(pData.pString) = (LPCTSTR)str;
// *(pData.pString) = String_256(str); // use this form when StringBase derived classes support direct conversion
@@ -354,6 +355,9 @@
BOOL OILPreferences::OpenInput()
{
+ // Tell wxWidgets this is the default wxConfig object
+ wxConfig::Set(this);
+
return TRUE;
}
@@ -371,6 +375,8 @@
BOOL OILPreferences::CloseInput()
{
+ wxConfig::Set(NULL);
+
return TRUE;
}
@@ -404,6 +410,6 @@
BOOL OILPreferences::CloseOutput()
{
- m_pConfig->Flush();
+ Flush();
return TRUE;
}
Index: Trunk/XaraLX/wxOil/keypress.cpp
===================================================================
--- Trunk/XaraLX/wxOil/keypress.cpp (revision 1270)
+++ Trunk/XaraLX/wxOil/keypress.cpp (revision 1271)
@@ -404,6 +404,35 @@
/********************************************************************************************
+
+> static FilePath KeyPress::GetHotKeysFilename()
+
+ Author: Phil_Martin (Xara Group Ltd) <camelotdev@xxxxxxxx>
+ Created: 8/Jun/2006
+ Inputs: -
+ Outputs: -
+ Returns: PathName reference to location of hotkeys config file
+ Purpose:
+
+********************************************************************************************/
+
+FilePath KeyPress::GetHotKeysFilename()
+{
+ FilePath result;
+
+ wxStandardPaths Paths;
+ wxString strPath( Paths.GetUserConfigDir() );
+ strPath += _T("/.xaralx/hotkeys");
+
+ if (wxFile::Exists(strPath))
+ result.SetPathName(strPath, FALSE);
+
+ return result;
+}
+
+
+
+/********************************************************************************************
> static BOOL KeyPress::DispatchKeyEvent(UINT32 nMsgID, UINT32 nChar, UINT32 nRepCnt, UINT32 nFlags)
Author: Justin_Flude (Xara Group Ltd) <camelotdev@xxxxxxxx>
Xara