]> git.saurik.com Git - wxWidgets.git/blob - utils/configtool/src/appsettings.cpp
Regenerated makefiles for 3rd-party lib change
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "appsettings.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24
25 #include "wx/datstrm.h"
26 #include "wx/dir.h"
27 #include "wx/colordlg.h"
28 #include "wx/wxhtml.h"
29 #include "wx/effects.h"
30 #include "wx/spinctrl.h"
31 #include "wx/tooltip.h"
32
33 #endif
34
35 #include "wx/wfstream.h"
36 #include "wx/config.h"
37 #include "wx/fileconf.h"
38 #include "wx/valgen.h"
39 #include "utils.h"
40 #include "wxconfigtool.h"
41 #include "appsettings.h"
42 #include "mainframe.h"
43 #include "symbols.h"
44 #include "settingsdialog.h"
45
46 /*
47 * User-changeable settings
48 */
49
50 IMPLEMENT_DYNAMIC_CLASS(ctSettings, wxObject)
51
52 ctSettings::ctSettings()
53 {
54 m_noUses = 0;
55 m_showToolBar = true;
56 m_showWelcomeDialog = true;
57 m_exportDir = wxEmptyString;
58
59 m_frameSize = wxRect(10, 10, 600, 500);
60 // m_backgroundColour = wxColour(140, 172, 179); // blue-grey
61 m_editWindowFont = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
62
63 m_appName = wxT("wxWidgets Configuration Tool");
64 m_appNameShort = wxT("Configuration Tool");
65 m_showSplashScreen = false;
66 m_userName = wxEmptyString;
67 m_frameStatus = ctSHOW_STATUS_NORMAL;
68 m_loadLastDocument = true;
69 m_firstTimeRun = true;
70 m_smallToolbar = true;
71 m_mainSashSize = 200;
72 m_useToolTips = true;
73 m_showTrayIcon = true;
74 m_trayIconIsShown = false;
75 m_useEnvironmentVariable = true;
76 m_frameworkDir = wxEmptyString;
77 m_matchWholeWord = false;
78 m_matchCase = false;
79 m_defaultFileKind = wxT("Setup file");
80 }
81
82 // Copy constructor
83 ctSettings::ctSettings(const ctSettings& settings)
84 {
85 Copy(settings);
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_lastSetupSaveDir = settings.m_lastSetupSaveDir;
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 m_matchWholeWord = settings.m_matchWholeWord;
118 m_matchCase = settings.m_matchCase;
119 m_defaultFileKind = settings.m_defaultFileKind ;
120 }
121
122 // Do some initialisation within stApp::OnInit
123 bool ctSettings::Init()
124 {
125 m_lastSetupSaveDir = wxEmptyString;
126 if (m_userName.IsEmpty())
127 m_userName = wxGetUserName();
128
129 return true;
130 }
131
132 // Create new filename
133 wxString ctSettings::GenerateFilename(const wxString& rootName)
134 {
135 wxString path;
136 if (!m_lastFilename.IsEmpty())
137 path = wxPathOnly(m_lastFilename);
138 else
139 path = wxGetApp().GetAppDir();
140
141 wxString filename(path);
142 if (filename.Last() != wxFILE_SEP_PATH )
143 filename += wxFILE_SEP_PATH;
144 filename += rootName;
145
146 wxString fullFilename = filename + wxT(".wxs");
147 int i = 0;
148 wxString postfixStr;
149 while (wxFileExists(fullFilename))
150 {
151 i ++;
152 postfixStr.Printf(_T("%d"), i);
153 fullFilename = filename + postfixStr + wxT(".wxs");
154 }
155
156 m_lastFilename = fullFilename;
157 return fullFilename;
158 }
159
160 // Load config info
161 bool ctSettings::LoadConfig()
162 {
163 wxConfig config(wxGetApp().GetSettings().GetAppName(), wxT("wxWidgets"));
164
165 config.Read(wxT("Files/LastFile"), & m_lastFilename);
166 config.Read(wxT("Files/LastSetupSaveDir"), & m_lastSetupSaveDir);
167 config.Read(wxT("Files/ExportDir"), & m_exportDir);
168 config.Read(wxT("Files/FrameworkDir"), & m_frameworkDir);
169 config.Read(wxT("Files/UseEnvironmentVariable"), (bool*) & m_useEnvironmentVariable);
170
171 config.Read(wxT("Misc/UserName"), & m_userName);
172 config.Read(wxT("Misc/FrameStatus"), & m_frameStatus);
173 config.Read(wxT("Misc/ShowToolTips"), (bool*) & m_useToolTips);
174 config.Read(wxT("Misc/LastDocument"), & m_lastDocument);
175 config.Read(wxT("Misc/LoadLastDocument"), (bool*) & m_loadLastDocument);
176 config.Read(wxT("Misc/ShowWelcomeDialog"), (bool*) & m_showWelcomeDialog);
177 config.Read(wxT("Misc/Ran"), & m_noUses);
178 config.Read(wxT("Misc/ShowTrayIcon"), (bool*) & m_showTrayIcon);
179 config.Read(wxT("Misc/MatchWholeWord"), (bool*) & m_matchWholeWord);
180 config.Read(wxT("Misc/MatchCase"), (bool*) & m_matchCase);
181 config.Read(wxT("Misc/BuildMode"), & m_defaultFileKind );
182
183 m_noUses ++;
184
185 config.Read(wxT("Windows/ShowToolBar"), (bool*) & m_showToolBar);
186
187 m_firstTimeRun = !(config.Read(wxT("Windows/WindowX"), & m_frameSize.x));
188 config.Read(wxT("Windows/WindowY"), & m_frameSize.y);
189 config.Read(wxT("Windows/WindowWidth"), & m_frameSize.width);
190 config.Read(wxT("Windows/WindowHeight"), & m_frameSize.height);
191 config.Read(wxT("Windows/ShowSplashScreen"), (bool*) & m_showSplashScreen);
192 config.Read(wxT("Windows/SmallToolbar"), (bool*) & m_smallToolbar);
193 config.Read(wxT("Windows/MainSashSize"), & m_mainSashSize);
194
195 wxString fontSpec;
196
197 fontSpec = wxEmptyString;
198 config.Read(wxT("Style/EditWindowFont"), & fontSpec);
199 if (!fontSpec.IsEmpty())
200 m_editWindowFont = apStringToFont(fontSpec);
201
202 // Crash-resistance
203 int runningProgram = 0;
204 config.Read(wxT("Misc/RunningProgram"), & runningProgram);
205
206 #ifndef __WXDEBUG__
207 // runningProgram should be zero if all is well. If 1,
208 // it crashed during a run, so we should disable the auto-load
209 // facility just in case it's trying to load a damaged file.
210 if (runningProgram != 0)
211 {
212 m_loadLastDocument = false;
213 }
214 #endif
215
216 config.Write(wxT("Misc/RunningProgram"), (long) 1);
217
218 return true;
219 }
220
221 // Save config info
222 bool ctSettings::SaveConfig()
223 {
224 wxConfig config(wxGetApp().GetSettings().GetAppName(), wxT("wxWidgets"));
225
226 config.Write(wxT("Files/LastFile"), m_lastFilename);
227 config.Write(wxT("Files/LastSetupSaveDir"), m_lastSetupSaveDir);
228 config.Write(wxT("Files/ExportDir"), m_exportDir);
229 config.Write(wxT("Files/FrameworkDir"), m_frameworkDir);
230 config.Write(wxT("Files/UseEnvironmentVariable"), m_useEnvironmentVariable);
231
232 config.Write(wxT("Misc/UserName"), m_userName);
233 config.Write(wxT("Misc/FrameStatus"), (long) m_frameStatus);
234 config.Write(wxT("Misc/ShowToolTips"), m_useToolTips);
235 config.Write(wxT("Misc/LastDocument"), m_lastDocument);
236 config.Write(wxT("Misc/LoadLastDocument"), (long) m_loadLastDocument);
237 config.Write(wxT("Misc/ShowWelcomeDialog"), (long) m_showWelcomeDialog);
238 config.Write(wxT("Misc/Ran"), m_noUses);
239 config.Write(wxT("Misc/ShowTrayIcon"), (long) m_showTrayIcon);
240 config.Write(wxT("Misc/MatchWholeWord"), (long) m_matchWholeWord);
241 config.Write(wxT("Misc/MatchCase"), (long) m_matchCase);
242 config.Write(wxT("Misc/BuildMode"), m_defaultFileKind);
243
244 config.Write(wxT("Windows/ShowToolBar"), m_showToolBar);
245 config.Write(wxT("Windows/WindowX"), (long) m_frameSize.x);
246 config.Write(wxT("Windows/WindowY"), (long) m_frameSize.y);
247 config.Write(wxT("Windows/WindowWidth"), (long) m_frameSize.width);
248 config.Write(wxT("Windows/WindowHeight"), (long) m_frameSize.height);
249
250 config.Write(wxT("Windows/ShowSplashScreen"), m_showSplashScreen);
251 config.Write(wxT("Windows/SmallToolbar"), (long) m_smallToolbar);
252 config.Write(wxT("Windows/MainSashSize"), (long) m_mainSashSize);
253
254 /*
255 wxString backgroundColour(apColourToHexString(m_backgroundColour));
256 config.Write(wxT("Style/BackgroundColour"), backgroundColour);
257 */
258
259 config.Write(wxT("Style/EditWindowFont"), apFontToString(m_editWindowFont));
260
261 // Indicate that we're no longer running, so we know if the program
262 // crashed last time around.
263 config.Write(wxT("Misc/RunningProgram"), (long) 0);
264
265 {
266 config.SetPath(wxT("FileHistory/"));
267 wxGetApp().GetDocManager()->FileHistorySave(config);
268 }
269
270 return true;
271 }
272
273 void ctSettings::ShowSettingsDialog(const wxString& WXUNUSED(page))
274 {
275 ctSettingsDialog* dialog = new ctSettingsDialog(wxGetApp().GetTopWindow());
276 // if (!page.IsEmpty())
277 // dialog->GetNotebook()->SetSelection(apFindNotebookPage(dialog->GetNotebook(), page));
278
279 /* int ret = */ dialog->ShowModal();
280 dialog->Destroy();
281 }