]>
git.saurik.com Git - wxWidgets.git/blob - utils/configtool/src/appsettings.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: appsettings.cpp
3 // Purpose: Implements settings-related functionality
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation appsettings.h
26 #include "wx/wfstream.h"
27 #include "wx/datstrm.h"
28 #include "wx/config.h"
29 #include "wx/fileconf.h"
31 #include "wx/valgen.h"
32 #include "wx/colordlg.h"
33 #include "wx/wxhtml.h"
34 #include "wx/effects.h"
35 #include "wx/spinctrl.h"
36 #include "wx/tooltip.h"
39 #include "wxconfigtool.h"
40 #include "appsettings.h"
41 #include "mainframe.h"
43 #include "settingsdialog.h"
46 * User-changeable settings
49 IMPLEMENT_DYNAMIC_CLASS(ctSettings
, wxObject
)
51 ctSettings::ctSettings()
55 m_showWelcomeDialog
= TRUE
;
56 m_exportDir
= wxEmptyString
;
58 m_frameSize
= wxRect(10, 10, 600, 500);
59 // m_backgroundColour = wxColour(140, 172, 179); // blue-grey
60 m_editWindowFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
62 m_appName
= wxT("wxWindows Configuration Tool");
63 m_appNameShort
= wxT("Configuration Tool");
64 m_showSplashScreen
= FALSE
;
65 m_userName
= wxEmptyString
;
66 m_frameStatus
= ctSHOW_STATUS_NORMAL
;
67 m_loadLastDocument
= TRUE
;
68 m_firstTimeRun
= TRUE
;
69 m_smallToolbar
= TRUE
;
72 m_showTrayIcon
= TRUE
;
73 m_trayIconIsShown
= FALSE
;
74 m_useEnvironmentVariable
= TRUE
;
75 m_frameworkDir
= wxEmptyString
;
79 ctSettings::ctSettings(const ctSettings
& settings
)
85 ctSettings::~ctSettings()
89 void ctSettings::operator = (const ctSettings
& settings
)
94 void ctSettings::Copy (const ctSettings
& settings
)
96 m_currentDocumentDir
= settings
.m_currentDocumentDir
;
97 m_lastDocument
= settings
.m_lastDocument
;
98 m_showToolBar
= settings
.m_showToolBar
;
99 m_frameSize
= settings
.m_frameSize
;
100 m_editWindowFont
= settings
.m_editWindowFont
;
101 m_showSplashScreen
= settings
.m_showSplashScreen
;
102 m_userName
= settings
.m_userName
;
103 m_loadLastDocument
= settings
.m_loadLastDocument
;
104 m_exportDir
= settings
.m_exportDir
;
105 m_firstTimeRun
= settings
.m_firstTimeRun
;
106 m_noUses
= settings
.m_noUses
;
107 m_smallToolbar
= settings
.m_smallToolbar
;
108 m_useToolTips
= settings
.m_useToolTips
;
109 m_showWelcomeDialog
= settings
.m_showWelcomeDialog
;
110 m_mainSashSize
= settings
.m_mainSashSize
;
112 m_showTrayIcon
= settings
.m_showTrayIcon
;
113 m_trayIconIsShown
= settings
.m_trayIconIsShown
;
115 m_useEnvironmentVariable
= settings
.m_useEnvironmentVariable
;
116 m_frameworkDir
= settings
.m_frameworkDir
;
119 // Do some initialisation within stApp::OnInit
120 bool ctSettings::Init()
122 m_currentDocumentDir
= wxEmptyString
;
123 if (m_userName
.IsEmpty())
124 m_userName
= wxGetUserName();
129 // Create new filename
130 wxString
ctSettings::GenerateFilename(const wxString
& rootName
)
133 if (!m_lastFilename
.IsEmpty())
134 path
= wxPathOnly(m_lastFilename
);
136 path
= wxGetApp().GetAppDir();
138 wxString
filename(path
);
139 if (filename
.Last() != wxFILE_SEP_PATH
)
140 filename
+= wxFILE_SEP_PATH
;
141 filename
+= rootName
;
143 wxString fullFilename
= filename
+ wxT(".wxs");
146 while (wxFileExists(fullFilename
))
149 postfixStr
.Printf("%d", i
);
150 fullFilename
= filename
+ postfixStr
+ wxT(".wxs");
153 m_lastFilename
= fullFilename
;
158 bool ctSettings::LoadConfig()
160 wxConfig
config(wxGetApp().GetSettings().GetAppName(), wxT("wxWindows"));
162 config
.Read(wxT("Files/LastFile"), & m_lastFilename
);
163 config
.Read(wxT("Files/DocumentDir"), & m_currentDocumentDir
);
164 config
.Read(wxT("Files/ExportDir"), & m_exportDir
);
165 config
.Read(wxT("Files/FrameworkDir"), & m_frameworkDir
);
166 config
.Read(wxT("Files/UseEnvironmentVariable"), (bool*) & m_useEnvironmentVariable
);
168 config
.Read(wxT("Misc/UserName"), & m_userName
);
169 config
.Read(wxT("Misc/FrameStatus"), & m_frameStatus
);
170 config
.Read(wxT("Misc/ShowToolTips"), (bool*) & m_useToolTips
);
171 config
.Read(wxT("Misc/LastDocument"), & m_lastDocument
);
172 config
.Read(wxT("Misc/LoadLastDocument"), (bool*) & m_loadLastDocument
);
173 config
.Read(wxT("Misc/ShowWelcomeDialog"), (bool*) & m_showWelcomeDialog
);
174 config
.Read(wxT("Misc/Ran"), & m_noUses
);
175 config
.Read(wxT("Misc/ShowTrayIcon"), (bool*) & m_showTrayIcon
);
179 config
.Read(wxT("Windows/ShowToolBar"), (bool*) & m_showToolBar
);
181 m_firstTimeRun
= !(config
.Read(wxT("Windows/WindowX"), & m_frameSize
.x
));
182 config
.Read(wxT("Windows/WindowY"), & m_frameSize
.y
);
183 config
.Read(wxT("Windows/WindowWidth"), & m_frameSize
.width
);
184 config
.Read(wxT("Windows/WindowHeight"), & m_frameSize
.height
);
185 config
.Read(wxT("Windows/ShowSplashScreen"), (bool*) & m_showSplashScreen
);
186 config
.Read(wxT("Windows/SmallToolbar"), (bool*) & m_smallToolbar
);
187 config
.Read(wxT("Windows/MainSashSize"), & m_mainSashSize
);
191 fontSpec
= wxEmptyString
;
192 config
.Read(wxT("Style/EditWindowFont"), & fontSpec
);
193 if (!fontSpec
.IsEmpty())
194 m_editWindowFont
= apStringToFont(fontSpec
);
197 int runningProgram
= 0;
198 config
.Read(wxT("Misc/RunningProgram"), & runningProgram
);
201 // runningProgram should be zero if all is well. If 1,
202 // it crashed during a run, so we should disable the auto-load
203 // facility just in case it's trying to load a damaged file.
204 if (runningProgram
!= 0)
206 m_loadLastDocument
= FALSE
;
210 config
.Write(wxT("Misc/RunningProgram"), (long) 1);
216 bool ctSettings::SaveConfig()
218 wxConfig
config(wxGetApp().GetSettings().GetAppName(), wxT("wxWindows"));
220 config
.Write(wxT("Files/LastFile"), m_lastFilename
);
221 config
.Write(wxT("Files/DocumentDir"), m_currentDocumentDir
);
222 config
.Write(wxT("Files/ExportDir"), m_exportDir
);
223 config
.Write(wxT("Files/FrameworkDir"), m_frameworkDir
);
224 config
.Write(wxT("Files/UseEnvironmentVariable"), m_useEnvironmentVariable
);
226 config
.Write(wxT("Misc/UserName"), m_userName
);
227 config
.Write(wxT("Misc/FrameStatus"), (long) m_frameStatus
);
228 config
.Write(wxT("Misc/ShowToolTips"), m_useToolTips
);
229 config
.Write(wxT("Misc/LastDocument"), m_lastDocument
);
230 config
.Write(wxT("Misc/LoadLastDocument"), (long) m_loadLastDocument
);
231 config
.Write(wxT("Misc/ShowWelcomeDialog"), (long) m_showWelcomeDialog
);
232 config
.Write(wxT("Misc/Ran"), m_noUses
);
233 config
.Write(wxT("Misc/ShowTrayIcon"), (long) m_showTrayIcon
);
235 config
.Write(wxT("Windows/ShowToolBar"), m_showToolBar
);
236 config
.Write(wxT("Windows/WindowX"), (long) m_frameSize
.x
);
237 config
.Write(wxT("Windows/WindowY"), (long) m_frameSize
.y
);
238 config
.Write(wxT("Windows/WindowWidth"), (long) m_frameSize
.width
);
239 config
.Write(wxT("Windows/WindowHeight"), (long) m_frameSize
.height
);
241 config
.Write(wxT("Windows/ShowSplashScreen"), m_showSplashScreen
);
242 config
.Write(wxT("Windows/SmallToolbar"), (long) m_smallToolbar
);
243 config
.Write(wxT("Windows/MainSashSize"), (long) m_mainSashSize
);
246 wxString backgroundColour(apColourToHexString(m_backgroundColour));
247 config.Write(wxT("Style/BackgroundColour"), backgroundColour);
250 config
.Write(wxT("Style/EditWindowFont"), apFontToString(m_editWindowFont
));
252 // Indicate that we're no longer running, so we know if the program
253 // crashed last time around.
254 config
.Write(wxT("Misc/RunningProgram"), (long) 0);
257 config
.SetPath(wxT("FileHistory/"));
258 wxGetApp().GetDocManager()->FileHistorySave(config
);
264 void ctSettings::ShowSettingsDialog(const wxString
& page
)
266 ctSettingsDialog
* dialog
= new ctSettingsDialog(wxGetApp().GetTopWindow());
267 // if (!page.IsEmpty())
268 // dialog->GetNotebook()->SetSelection(apFindNotebookPage(dialog->GetNotebook(), page));
270 /* int ret = */ dialog
->ShowModal();