]> git.saurik.com Git - wxWidgets.git/blob - utils/configtool/src/appsettings.cpp
Added first cut wxWindows Configuration Tool
[wxWidgets.git] / utils / configtool / src / appsettings.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: appsettings.cpp
3 // Purpose: Implements settings-related functionality
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 2002-09-04
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence:
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation appsettings.h
14 #endif
15
16 #include "wx/wx.h"
17
18 #ifdef __BORLANDC__
19 #pragma hdrstop
20 #endif
21
22 #ifndef WX_PRECOMP
23 #include "wx/wx.h"
24 #endif
25
26 #include "wx/wfstream.h"
27 #include "wx/datstrm.h"
28 #include "wx/config.h"
29 #include "wx/fileconf.h"
30 #include "wx/dir.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"
37
38 #include "utils.h"
39 #include "wxconfigtool.h"
40 #include "appsettings.h"
41 #include "mainframe.h"
42 #include "symbols.h"
43 #include "settingsdialog.h"
44
45 /*
46 * User-changeable settings
47 */
48
49 IMPLEMENT_DYNAMIC_CLASS(ctSettings, wxObject)
50
51 ctSettings::ctSettings()
52 {
53 m_noUses = 0;
54 m_showToolBar = TRUE;
55 m_showWelcomeDialog = TRUE;
56 m_exportDir = wxEmptyString;
57
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);
61
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;
70 m_mainSashSize = 200;
71 m_useToolTips = TRUE;
72 m_showTrayIcon = TRUE;
73 m_trayIconIsShown = FALSE;
74 m_useEnvironmentVariable = TRUE;
75 m_frameworkDir = wxEmptyString;
76 }
77
78 // Copy constructor
79 ctSettings::ctSettings(const ctSettings& settings)
80 {
81 Copy(settings);
82 }
83
84
85 ctSettings::~ctSettings()
86 {
87 }
88
89 void ctSettings::operator = (const ctSettings& settings)
90 {
91 Copy(settings);
92 }
93
94 void ctSettings::Copy (const ctSettings& settings)
95 {
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;
111
112 m_showTrayIcon = settings.m_showTrayIcon;
113 m_trayIconIsShown = settings.m_trayIconIsShown;
114
115 m_useEnvironmentVariable = settings.m_useEnvironmentVariable;
116 m_frameworkDir = settings.m_frameworkDir;
117 }
118
119 // Do some initialisation within stApp::OnInit
120 bool ctSettings::Init()
121 {
122 m_currentDocumentDir = wxEmptyString;
123 if (m_userName.IsEmpty())
124 m_userName = wxGetUserName();
125
126 return TRUE;
127 }
128
129 // Create new filename
130 wxString ctSettings::GenerateFilename(const wxString& rootName)
131 {
132 wxString path;
133 if (!m_lastFilename.IsEmpty())
134 path = wxPathOnly(m_lastFilename);
135 else
136 path = wxGetApp().GetAppDir();
137
138 wxString filename(path);
139 if (filename.Last() != wxFILE_SEP_PATH )
140 filename += wxFILE_SEP_PATH;
141 filename += rootName;
142
143 wxString fullFilename = filename + wxT(".wxs");
144 int i = 0;
145 wxString postfixStr;
146 while (wxFileExists(fullFilename))
147 {
148 i ++;
149 postfixStr.Printf("%d", i);
150 fullFilename = filename + postfixStr + wxT(".wxs");
151 }
152
153 m_lastFilename = fullFilename;
154 return fullFilename;
155 }
156
157 // Load config info
158 bool ctSettings::LoadConfig()
159 {
160 wxConfig config(wxGetApp().GetSettings().GetAppName(), wxT("wxWindows"));
161
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);
167
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);
176
177 m_noUses ++;
178
179 config.Read(wxT("Windows/ShowToolBar"), (bool*) & m_showToolBar);
180
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);
188
189 wxString fontSpec;
190
191 fontSpec = wxEmptyString;
192 config.Read(wxT("Style/EditWindowFont"), & fontSpec);
193 if (!fontSpec.IsEmpty())
194 m_editWindowFont = apStringToFont(fontSpec);
195
196 // Crash-resistance
197 int runningProgram = 0;
198 config.Read(wxT("Misc/RunningProgram"), & runningProgram);
199
200 #ifndef __WXDEBUG__
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)
205 {
206 m_loadLastDocument = FALSE;
207 }
208 #endif
209
210 config.Write(wxT("Misc/RunningProgram"), (long) 1);
211
212 return TRUE;
213 }
214
215 // Save config info
216 bool ctSettings::SaveConfig()
217 {
218 wxConfig config(wxGetApp().GetSettings().GetAppName(), wxT("wxWindows"));
219
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);
225
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);
234
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);
240
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);
244
245 /*
246 wxString backgroundColour(apColourToHexString(m_backgroundColour));
247 config.Write(wxT("Style/BackgroundColour"), backgroundColour);
248 */
249
250 config.Write(wxT("Style/EditWindowFont"), apFontToString(m_editWindowFont));
251
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);
255
256 {
257 config.SetPath(wxT("FileHistory/"));
258 wxGetApp().GetDocManager()->FileHistorySave(config);
259 }
260
261 return TRUE;
262 }
263
264 void ctSettings::ShowSettingsDialog(const wxString& page)
265 {
266 ctSettingsDialog* dialog = new ctSettingsDialog(wxGetApp().GetTopWindow());
267 // if (!page.IsEmpty())
268 // dialog->GetNotebook()->SetSelection(apFindNotebookPage(dialog->GetNotebook(), page));
269
270 /* int ret = */ dialog->ShowModal();
271 dialog->Destroy();
272 }