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