]>
git.saurik.com Git - wxWidgets.git/blob - utils/configtool/src/appsettings.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: appsettings.cpp
3 // Purpose: Implements settings-related functionality
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/datstrm.h"
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"
28 #include "wx/settings.h"
32 #include "wx/wfstream.h"
33 #include "wx/config.h"
34 #include "wx/fileconf.h"
35 #include "wx/valgen.h"
37 #include "wxconfigtool.h"
38 #include "appsettings.h"
39 #include "mainframe.h"
41 #include "settingsdialog.h"
44 * User-changeable settings
47 IMPLEMENT_DYNAMIC_CLASS(ctSettings
, wxObject
)
49 ctSettings::ctSettings()
53 m_showWelcomeDialog
= true;
54 m_exportDir
= wxEmptyString
;
56 m_frameSize
= wxRect(10, 10, 600, 500);
57 // m_backgroundColour = wxColour(140, 172, 179); // blue-grey
58 m_editWindowFont
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
60 m_appName
= wxT("wxWidgets Configuration Tool");
61 m_appNameShort
= wxT("Configuration Tool");
62 m_showSplashScreen
= false;
63 m_userName
= wxEmptyString
;
64 m_frameStatus
= ctSHOW_STATUS_NORMAL
;
65 m_loadLastDocument
= true;
66 m_firstTimeRun
= true;
67 m_smallToolbar
= true;
70 m_showTrayIcon
= true;
71 m_trayIconIsShown
= false;
72 m_useEnvironmentVariable
= true;
73 m_frameworkDir
= wxEmptyString
;
74 m_matchWholeWord
= false;
76 m_defaultFileKind
= wxT("Setup file");
80 ctSettings::ctSettings(const ctSettings
& settings
) : wxObject()
86 void ctSettings::operator = (const ctSettings
& settings
)
91 void ctSettings::Copy (const ctSettings
& settings
)
93 m_lastSetupSaveDir
= settings
.m_lastSetupSaveDir
;
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
;
109 m_showTrayIcon
= settings
.m_showTrayIcon
;
110 m_trayIconIsShown
= settings
.m_trayIconIsShown
;
112 m_useEnvironmentVariable
= settings
.m_useEnvironmentVariable
;
113 m_frameworkDir
= settings
.m_frameworkDir
;
114 m_matchWholeWord
= settings
.m_matchWholeWord
;
115 m_matchCase
= settings
.m_matchCase
;
116 m_defaultFileKind
= settings
.m_defaultFileKind
;
119 // Do some initialisation within stApp::OnInit
120 bool ctSettings::Init()
122 m_lastSetupSaveDir
= wxEmptyString
;
123 if (m_userName
.empty())
124 m_userName
= wxGetUserName();
129 // Create new filename
130 wxString
ctSettings::GenerateFilename(const wxString
& rootName
)
133 if (!m_lastFilename
.empty())
134 path
= wxPathOnly(m_lastFilename
);
136 path
= wxGetApp().GetAppDir();
138 wxString
filename(path
);
139 if (filename
.Last() != wxFILE_SEP_PATH
)
140 filename
+= wxFILE_SEP_PATH
;
141 filename
+= rootName
;
143 wxString fullFilename
= filename
+ wxT(".wxs");
146 while (wxFileExists(fullFilename
))
149 postfixStr
.Printf(_T("%d"), i
);
150 fullFilename
= filename
+ postfixStr
+ wxT(".wxs");
153 m_lastFilename
= fullFilename
;
158 bool ctSettings::LoadConfig()
160 wxConfig
config(wxGetApp().GetSettings().GetAppName(), wxT("wxWidgets"));
162 config
.Read(wxT("Files/LastFile"), & m_lastFilename
);
163 config
.Read(wxT("Files/LastSetupSaveDir"), & m_lastSetupSaveDir
);
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
);
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 config
.Read(wxT("Misc/MatchWholeWord"), (bool*) & m_matchWholeWord
);
177 config
.Read(wxT("Misc/MatchCase"), (bool*) & m_matchCase
);
178 config
.Read(wxT("Misc/BuildMode"), & m_defaultFileKind
);
182 config
.Read(wxT("Windows/ShowToolBar"), (bool*) & m_showToolBar
);
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
);
194 fontSpec
= wxEmptyString
;
195 config
.Read(wxT("Style/EditWindowFont"), & fontSpec
);
196 if (!fontSpec
.empty())
197 m_editWindowFont
= apStringToFont(fontSpec
);
200 int runningProgram
= 0;
201 config
.Read(wxT("Misc/RunningProgram"), & runningProgram
);
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)
209 m_loadLastDocument
= false;
213 config
.Write(wxT("Misc/RunningProgram"), (long) 1);
219 bool ctSettings::SaveConfig()
221 wxConfig
config(wxGetApp().GetSettings().GetAppName(), wxT("wxWidgets"));
223 config
.Write(wxT("Files/LastFile"), m_lastFilename
);
224 config
.Write(wxT("Files/LastSetupSaveDir"), m_lastSetupSaveDir
);
225 config
.Write(wxT("Files/ExportDir"), m_exportDir
);
226 config
.Write(wxT("Files/FrameworkDir"), m_frameworkDir
);
227 config
.Write(wxT("Files/UseEnvironmentVariable"), m_useEnvironmentVariable
);
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
);
237 config
.Write(wxT("Misc/MatchWholeWord"), (long) m_matchWholeWord
);
238 config
.Write(wxT("Misc/MatchCase"), (long) m_matchCase
);
239 config
.Write(wxT("Misc/BuildMode"), m_defaultFileKind
);
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
);
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
);
252 wxString backgroundColour(apColourToHexString(m_backgroundColour));
253 config.Write(wxT("Style/BackgroundColour"), backgroundColour);
256 config
.Write(wxT("Style/EditWindowFont"), apFontToString(m_editWindowFont
));
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);
263 config
.SetPath(wxT("FileHistory/"));
264 wxGetApp().GetDocManager()->FileHistorySave(config
);
270 void ctSettings::ShowSettingsDialog(const wxString
& WXUNUSED(page
))
272 ctSettingsDialog
* dialog
= new ctSettingsDialog(wxGetApp().GetTopWindow());
273 // if (!page.IsEmpty())
274 // dialog->GetNotebook()->SetSelection(apFindNotebookPage(dialog->GetNotebook(), page));
276 /* int ret = */ dialog
->ShowModal();