]>
Commit | Line | Data |
---|---|---|
d7463f75 JS |
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 | |
4fe30bce | 9 | // Licence: |
d7463f75 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
71ada1a5 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
f8105809 | 13 | #pragma implementation "appsettings.h" |
d7463f75 JS |
14 | #endif |
15 | ||
d9ab621e WS |
16 | // For compilers that support precompilation, includes "wx/wx.h". |
17 | #include "wx/wxprec.h" | |
d7463f75 JS |
18 | |
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
d7463f75 | 24 | |
d7463f75 | 25 | #include "wx/datstrm.h" |
d7463f75 | 26 | #include "wx/dir.h" |
d7463f75 JS |
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 | ||
d9ab621e WS |
33 | #endif |
34 | ||
35 | #include "wx/wfstream.h" | |
36 | #include "wx/config.h" | |
37 | #include "wx/fileconf.h" | |
38 | #include "wx/valgen.h" | |
d7463f75 JS |
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; | |
4fe30bce WS |
55 | m_showToolBar = true; |
56 | m_showWelcomeDialog = true; | |
d7463f75 JS |
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 | ||
be5a51fb | 63 | m_appName = wxT("wxWidgets Configuration Tool"); |
d7463f75 | 64 | m_appNameShort = wxT("Configuration Tool"); |
4fe30bce | 65 | m_showSplashScreen = false; |
d7463f75 JS |
66 | m_userName = wxEmptyString; |
67 | m_frameStatus = ctSHOW_STATUS_NORMAL; | |
4fe30bce WS |
68 | m_loadLastDocument = true; |
69 | m_firstTimeRun = true; | |
70 | m_smallToolbar = true; | |
d7463f75 | 71 | m_mainSashSize = 200; |
4fe30bce WS |
72 | m_useToolTips = true; |
73 | m_showTrayIcon = true; | |
74 | m_trayIconIsShown = false; | |
75 | m_useEnvironmentVariable = true; | |
d7463f75 | 76 | m_frameworkDir = wxEmptyString; |
4fe30bce WS |
77 | m_matchWholeWord = false; |
78 | m_matchCase = false; | |
afc51590 | 79 | m_defaultFileKind = wxT("Setup file"); |
d7463f75 JS |
80 | } |
81 | ||
82 | // Copy constructor | |
83 | ctSettings::ctSettings(const ctSettings& settings) | |
84 | { | |
85 | Copy(settings); | |
86 | } | |
87 | ||
88 | ||
89 | ctSettings::~ctSettings() | |
90 | { | |
91 | } | |
92 | ||
93 | void ctSettings::operator = (const ctSettings& settings) | |
94 | { | |
95 | Copy(settings); | |
96 | } | |
97 | ||
98 | void ctSettings::Copy (const ctSettings& settings) | |
99 | { | |
afc51590 | 100 | m_lastSetupSaveDir = settings.m_lastSetupSaveDir; |
d7463f75 JS |
101 | m_lastDocument = settings.m_lastDocument; |
102 | m_showToolBar = settings.m_showToolBar; | |
103 | m_frameSize = settings.m_frameSize; | |
104 | m_editWindowFont = settings.m_editWindowFont; | |
105 | m_showSplashScreen = settings.m_showSplashScreen; | |
106 | m_userName = settings.m_userName; | |
107 | m_loadLastDocument = settings.m_loadLastDocument; | |
108 | m_exportDir = settings.m_exportDir; | |
109 | m_firstTimeRun = settings.m_firstTimeRun; | |
110 | m_noUses = settings.m_noUses; | |
111 | m_smallToolbar = settings.m_smallToolbar; | |
112 | m_useToolTips = settings.m_useToolTips; | |
113 | m_showWelcomeDialog = settings.m_showWelcomeDialog; | |
114 | m_mainSashSize = settings.m_mainSashSize; | |
115 | ||
116 | m_showTrayIcon = settings.m_showTrayIcon; | |
117 | m_trayIconIsShown = settings.m_trayIconIsShown; | |
118 | ||
119 | m_useEnvironmentVariable = settings.m_useEnvironmentVariable; | |
120 | m_frameworkDir = settings.m_frameworkDir; | |
e7767867 JS |
121 | m_matchWholeWord = settings.m_matchWholeWord; |
122 | m_matchCase = settings.m_matchCase; | |
afc51590 | 123 | m_defaultFileKind = settings.m_defaultFileKind ; |
d7463f75 JS |
124 | } |
125 | ||
126 | // Do some initialisation within stApp::OnInit | |
127 | bool ctSettings::Init() | |
128 | { | |
afc51590 | 129 | m_lastSetupSaveDir = wxEmptyString; |
d7463f75 JS |
130 | if (m_userName.IsEmpty()) |
131 | m_userName = wxGetUserName(); | |
132 | ||
4fe30bce | 133 | return true; |
d7463f75 JS |
134 | } |
135 | ||
136 | // Create new filename | |
137 | wxString ctSettings::GenerateFilename(const wxString& rootName) | |
138 | { | |
139 | wxString path; | |
140 | if (!m_lastFilename.IsEmpty()) | |
141 | path = wxPathOnly(m_lastFilename); | |
142 | else | |
143 | path = wxGetApp().GetAppDir(); | |
144 | ||
145 | wxString filename(path); | |
146 | if (filename.Last() != wxFILE_SEP_PATH ) | |
147 | filename += wxFILE_SEP_PATH; | |
148 | filename += rootName; | |
149 | ||
150 | wxString fullFilename = filename + wxT(".wxs"); | |
151 | int i = 0; | |
152 | wxString postfixStr; | |
153 | while (wxFileExists(fullFilename)) | |
154 | { | |
155 | i ++; | |
69da0d99 | 156 | postfixStr.Printf(_T("%d"), i); |
d7463f75 JS |
157 | fullFilename = filename + postfixStr + wxT(".wxs"); |
158 | } | |
159 | ||
160 | m_lastFilename = fullFilename; | |
161 | return fullFilename; | |
162 | } | |
163 | ||
164 | // Load config info | |
165 | bool ctSettings::LoadConfig() | |
166 | { | |
be5a51fb | 167 | wxConfig config(wxGetApp().GetSettings().GetAppName(), wxT("wxWidgets")); |
d7463f75 JS |
168 | |
169 | config.Read(wxT("Files/LastFile"), & m_lastFilename); | |
afc51590 | 170 | config.Read(wxT("Files/LastSetupSaveDir"), & m_lastSetupSaveDir); |
d7463f75 JS |
171 | config.Read(wxT("Files/ExportDir"), & m_exportDir); |
172 | config.Read(wxT("Files/FrameworkDir"), & m_frameworkDir); | |
173 | config.Read(wxT("Files/UseEnvironmentVariable"), (bool*) & m_useEnvironmentVariable); | |
174 | ||
175 | config.Read(wxT("Misc/UserName"), & m_userName); | |
176 | config.Read(wxT("Misc/FrameStatus"), & m_frameStatus); | |
177 | config.Read(wxT("Misc/ShowToolTips"), (bool*) & m_useToolTips); | |
178 | config.Read(wxT("Misc/LastDocument"), & m_lastDocument); | |
179 | config.Read(wxT("Misc/LoadLastDocument"), (bool*) & m_loadLastDocument); | |
180 | config.Read(wxT("Misc/ShowWelcomeDialog"), (bool*) & m_showWelcomeDialog); | |
181 | config.Read(wxT("Misc/Ran"), & m_noUses); | |
182 | config.Read(wxT("Misc/ShowTrayIcon"), (bool*) & m_showTrayIcon); | |
e7767867 JS |
183 | config.Read(wxT("Misc/MatchWholeWord"), (bool*) & m_matchWholeWord); |
184 | config.Read(wxT("Misc/MatchCase"), (bool*) & m_matchCase); | |
afc51590 | 185 | config.Read(wxT("Misc/BuildMode"), & m_defaultFileKind ); |
d7463f75 JS |
186 | |
187 | m_noUses ++; | |
188 | ||
189 | config.Read(wxT("Windows/ShowToolBar"), (bool*) & m_showToolBar); | |
190 | ||
191 | m_firstTimeRun = !(config.Read(wxT("Windows/WindowX"), & m_frameSize.x)); | |
192 | config.Read(wxT("Windows/WindowY"), & m_frameSize.y); | |
193 | config.Read(wxT("Windows/WindowWidth"), & m_frameSize.width); | |
194 | config.Read(wxT("Windows/WindowHeight"), & m_frameSize.height); | |
195 | config.Read(wxT("Windows/ShowSplashScreen"), (bool*) & m_showSplashScreen); | |
196 | config.Read(wxT("Windows/SmallToolbar"), (bool*) & m_smallToolbar); | |
197 | config.Read(wxT("Windows/MainSashSize"), & m_mainSashSize); | |
198 | ||
199 | wxString fontSpec; | |
200 | ||
201 | fontSpec = wxEmptyString; | |
202 | config.Read(wxT("Style/EditWindowFont"), & fontSpec); | |
203 | if (!fontSpec.IsEmpty()) | |
204 | m_editWindowFont = apStringToFont(fontSpec); | |
205 | ||
206 | // Crash-resistance | |
207 | int runningProgram = 0; | |
208 | config.Read(wxT("Misc/RunningProgram"), & runningProgram); | |
209 | ||
210 | #ifndef __WXDEBUG__ | |
211 | // runningProgram should be zero if all is well. If 1, | |
212 | // it crashed during a run, so we should disable the auto-load | |
213 | // facility just in case it's trying to load a damaged file. | |
214 | if (runningProgram != 0) | |
215 | { | |
4fe30bce | 216 | m_loadLastDocument = false; |
d7463f75 JS |
217 | } |
218 | #endif | |
219 | ||
220 | config.Write(wxT("Misc/RunningProgram"), (long) 1); | |
221 | ||
4fe30bce | 222 | return true; |
d7463f75 JS |
223 | } |
224 | ||
225 | // Save config info | |
226 | bool ctSettings::SaveConfig() | |
227 | { | |
be5a51fb | 228 | wxConfig config(wxGetApp().GetSettings().GetAppName(), wxT("wxWidgets")); |
d7463f75 JS |
229 | |
230 | config.Write(wxT("Files/LastFile"), m_lastFilename); | |
afc51590 | 231 | config.Write(wxT("Files/LastSetupSaveDir"), m_lastSetupSaveDir); |
d7463f75 JS |
232 | config.Write(wxT("Files/ExportDir"), m_exportDir); |
233 | config.Write(wxT("Files/FrameworkDir"), m_frameworkDir); | |
234 | config.Write(wxT("Files/UseEnvironmentVariable"), m_useEnvironmentVariable); | |
235 | ||
236 | config.Write(wxT("Misc/UserName"), m_userName); | |
237 | config.Write(wxT("Misc/FrameStatus"), (long) m_frameStatus); | |
238 | config.Write(wxT("Misc/ShowToolTips"), m_useToolTips); | |
239 | config.Write(wxT("Misc/LastDocument"), m_lastDocument); | |
240 | config.Write(wxT("Misc/LoadLastDocument"), (long) m_loadLastDocument); | |
241 | config.Write(wxT("Misc/ShowWelcomeDialog"), (long) m_showWelcomeDialog); | |
242 | config.Write(wxT("Misc/Ran"), m_noUses); | |
243 | config.Write(wxT("Misc/ShowTrayIcon"), (long) m_showTrayIcon); | |
e7767867 JS |
244 | config.Write(wxT("Misc/MatchWholeWord"), (long) m_matchWholeWord); |
245 | config.Write(wxT("Misc/MatchCase"), (long) m_matchCase); | |
afc51590 | 246 | config.Write(wxT("Misc/BuildMode"), m_defaultFileKind); |
d7463f75 JS |
247 | |
248 | config.Write(wxT("Windows/ShowToolBar"), m_showToolBar); | |
249 | config.Write(wxT("Windows/WindowX"), (long) m_frameSize.x); | |
250 | config.Write(wxT("Windows/WindowY"), (long) m_frameSize.y); | |
251 | config.Write(wxT("Windows/WindowWidth"), (long) m_frameSize.width); | |
252 | config.Write(wxT("Windows/WindowHeight"), (long) m_frameSize.height); | |
253 | ||
254 | config.Write(wxT("Windows/ShowSplashScreen"), m_showSplashScreen); | |
255 | config.Write(wxT("Windows/SmallToolbar"), (long) m_smallToolbar); | |
256 | config.Write(wxT("Windows/MainSashSize"), (long) m_mainSashSize); | |
257 | ||
258 | /* | |
259 | wxString backgroundColour(apColourToHexString(m_backgroundColour)); | |
260 | config.Write(wxT("Style/BackgroundColour"), backgroundColour); | |
261 | */ | |
262 | ||
263 | config.Write(wxT("Style/EditWindowFont"), apFontToString(m_editWindowFont)); | |
264 | ||
265 | // Indicate that we're no longer running, so we know if the program | |
266 | // crashed last time around. | |
267 | config.Write(wxT("Misc/RunningProgram"), (long) 0); | |
268 | ||
269 | { | |
270 | config.SetPath(wxT("FileHistory/")); | |
271 | wxGetApp().GetDocManager()->FileHistorySave(config); | |
272 | } | |
273 | ||
4fe30bce | 274 | return true; |
d7463f75 JS |
275 | } |
276 | ||
69da0d99 | 277 | void ctSettings::ShowSettingsDialog(const wxString& WXUNUSED(page)) |
d7463f75 JS |
278 | { |
279 | ctSettingsDialog* dialog = new ctSettingsDialog(wxGetApp().GetTopWindow()); | |
280 | // if (!page.IsEmpty()) | |
281 | // dialog->GetNotebook()->SetSelection(apFindNotebookPage(dialog->GetNotebook(), page)); | |
282 | ||
283 | /* int ret = */ dialog->ShowModal(); | |
284 | dialog->Destroy(); | |
285 | } |