]>
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 | |
9 | // Licence: | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
f8105809 | 13 | #pragma implementation "appsettings.h" |
d7463f75 JS |
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; | |
e7767867 JS |
76 | m_matchWholeWord = FALSE; |
77 | m_matchCase = FALSE; | |
d7463f75 JS |
78 | } |
79 | ||
80 | // Copy constructor | |
81 | ctSettings::ctSettings(const ctSettings& settings) | |
82 | { | |
83 | Copy(settings); | |
84 | } | |
85 | ||
86 | ||
87 | ctSettings::~ctSettings() | |
88 | { | |
89 | } | |
90 | ||
91 | void ctSettings::operator = (const ctSettings& settings) | |
92 | { | |
93 | Copy(settings); | |
94 | } | |
95 | ||
96 | void ctSettings::Copy (const ctSettings& settings) | |
97 | { | |
98 | m_currentDocumentDir = settings.m_currentDocumentDir; | |
99 | m_lastDocument = settings.m_lastDocument; | |
100 | m_showToolBar = settings.m_showToolBar; | |
101 | m_frameSize = settings.m_frameSize; | |
102 | m_editWindowFont = settings.m_editWindowFont; | |
103 | m_showSplashScreen = settings.m_showSplashScreen; | |
104 | m_userName = settings.m_userName; | |
105 | m_loadLastDocument = settings.m_loadLastDocument; | |
106 | m_exportDir = settings.m_exportDir; | |
107 | m_firstTimeRun = settings.m_firstTimeRun; | |
108 | m_noUses = settings.m_noUses; | |
109 | m_smallToolbar = settings.m_smallToolbar; | |
110 | m_useToolTips = settings.m_useToolTips; | |
111 | m_showWelcomeDialog = settings.m_showWelcomeDialog; | |
112 | m_mainSashSize = settings.m_mainSashSize; | |
113 | ||
114 | m_showTrayIcon = settings.m_showTrayIcon; | |
115 | m_trayIconIsShown = settings.m_trayIconIsShown; | |
116 | ||
117 | m_useEnvironmentVariable = settings.m_useEnvironmentVariable; | |
118 | m_frameworkDir = settings.m_frameworkDir; | |
e7767867 JS |
119 | m_matchWholeWord = settings.m_matchWholeWord; |
120 | m_matchCase = settings.m_matchCase; | |
d7463f75 JS |
121 | } |
122 | ||
123 | // Do some initialisation within stApp::OnInit | |
124 | bool ctSettings::Init() | |
125 | { | |
126 | m_currentDocumentDir = wxEmptyString; | |
127 | if (m_userName.IsEmpty()) | |
128 | m_userName = wxGetUserName(); | |
129 | ||
130 | return TRUE; | |
131 | } | |
132 | ||
133 | // Create new filename | |
134 | wxString ctSettings::GenerateFilename(const wxString& rootName) | |
135 | { | |
136 | wxString path; | |
137 | if (!m_lastFilename.IsEmpty()) | |
138 | path = wxPathOnly(m_lastFilename); | |
139 | else | |
140 | path = wxGetApp().GetAppDir(); | |
141 | ||
142 | wxString filename(path); | |
143 | if (filename.Last() != wxFILE_SEP_PATH ) | |
144 | filename += wxFILE_SEP_PATH; | |
145 | filename += rootName; | |
146 | ||
147 | wxString fullFilename = filename + wxT(".wxs"); | |
148 | int i = 0; | |
149 | wxString postfixStr; | |
150 | while (wxFileExists(fullFilename)) | |
151 | { | |
152 | i ++; | |
153 | postfixStr.Printf("%d", i); | |
154 | fullFilename = filename + postfixStr + wxT(".wxs"); | |
155 | } | |
156 | ||
157 | m_lastFilename = fullFilename; | |
158 | return fullFilename; | |
159 | } | |
160 | ||
161 | // Load config info | |
162 | bool ctSettings::LoadConfig() | |
163 | { | |
164 | wxConfig config(wxGetApp().GetSettings().GetAppName(), wxT("wxWindows")); | |
165 | ||
166 | config.Read(wxT("Files/LastFile"), & m_lastFilename); | |
167 | config.Read(wxT("Files/DocumentDir"), & m_currentDocumentDir); | |
168 | config.Read(wxT("Files/ExportDir"), & m_exportDir); | |
169 | config.Read(wxT("Files/FrameworkDir"), & m_frameworkDir); | |
170 | config.Read(wxT("Files/UseEnvironmentVariable"), (bool*) & m_useEnvironmentVariable); | |
171 | ||
172 | config.Read(wxT("Misc/UserName"), & m_userName); | |
173 | config.Read(wxT("Misc/FrameStatus"), & m_frameStatus); | |
174 | config.Read(wxT("Misc/ShowToolTips"), (bool*) & m_useToolTips); | |
175 | config.Read(wxT("Misc/LastDocument"), & m_lastDocument); | |
176 | config.Read(wxT("Misc/LoadLastDocument"), (bool*) & m_loadLastDocument); | |
177 | config.Read(wxT("Misc/ShowWelcomeDialog"), (bool*) & m_showWelcomeDialog); | |
178 | config.Read(wxT("Misc/Ran"), & m_noUses); | |
179 | config.Read(wxT("Misc/ShowTrayIcon"), (bool*) & m_showTrayIcon); | |
e7767867 JS |
180 | config.Read(wxT("Misc/MatchWholeWord"), (bool*) & m_matchWholeWord); |
181 | config.Read(wxT("Misc/MatchCase"), (bool*) & m_matchCase); | |
d7463f75 JS |
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("wxWindows")); | |
225 | ||
226 | config.Write(wxT("Files/LastFile"), m_lastFilename); | |
227 | config.Write(wxT("Files/DocumentDir"), m_currentDocumentDir); | |
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); | |
e7767867 JS |
240 | config.Write(wxT("Misc/MatchWholeWord"), (long) m_matchWholeWord); |
241 | config.Write(wxT("Misc/MatchCase"), (long) m_matchCase); | |
d7463f75 JS |
242 | |
243 | config.Write(wxT("Windows/ShowToolBar"), m_showToolBar); | |
244 | config.Write(wxT("Windows/WindowX"), (long) m_frameSize.x); | |
245 | config.Write(wxT("Windows/WindowY"), (long) m_frameSize.y); | |
246 | config.Write(wxT("Windows/WindowWidth"), (long) m_frameSize.width); | |
247 | config.Write(wxT("Windows/WindowHeight"), (long) m_frameSize.height); | |
248 | ||
249 | config.Write(wxT("Windows/ShowSplashScreen"), m_showSplashScreen); | |
250 | config.Write(wxT("Windows/SmallToolbar"), (long) m_smallToolbar); | |
251 | config.Write(wxT("Windows/MainSashSize"), (long) m_mainSashSize); | |
252 | ||
253 | /* | |
254 | wxString backgroundColour(apColourToHexString(m_backgroundColour)); | |
255 | config.Write(wxT("Style/BackgroundColour"), backgroundColour); | |
256 | */ | |
257 | ||
258 | config.Write(wxT("Style/EditWindowFont"), apFontToString(m_editWindowFont)); | |
259 | ||
260 | // Indicate that we're no longer running, so we know if the program | |
261 | // crashed last time around. | |
262 | config.Write(wxT("Misc/RunningProgram"), (long) 0); | |
263 | ||
264 | { | |
265 | config.SetPath(wxT("FileHistory/")); | |
266 | wxGetApp().GetDocManager()->FileHistorySave(config); | |
267 | } | |
268 | ||
269 | return TRUE; | |
270 | } | |
271 | ||
272 | void ctSettings::ShowSettingsDialog(const wxString& page) | |
273 | { | |
274 | ctSettingsDialog* dialog = new ctSettingsDialog(wxGetApp().GetTopWindow()); | |
275 | // if (!page.IsEmpty()) | |
276 | // dialog->GetNotebook()->SetSelection(apFindNotebookPage(dialog->GetNotebook(), page)); | |
277 | ||
278 | /* int ret = */ dialog->ShowModal(); | |
279 | dialog->Destroy(); | |
280 | } |