]>
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 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "appsettings.h"
26 #include "wx/wfstream.h"
27 #include "wx/datstrm.h"
28 #include "wx/config.h"
29 #include "wx/fileconf.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"
39 #include "wxconfigtool.h"
40 #include "appsettings.h"
41 #include "mainframe.h"
43 #include "settingsdialog.h"
46 * User-changeable settings
49 IMPLEMENT_DYNAMIC_CLASS(ctSettings
, wxObject
)
51 ctSettings::ctSettings()
55 m_showWelcomeDialog
= TRUE
;
56 m_exportDir
= wxEmptyString
;
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
);
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
;
72 m_showTrayIcon
= TRUE
;
73 m_trayIconIsShown
= FALSE
;
74 m_useEnvironmentVariable
= TRUE
;
75 m_frameworkDir
= wxEmptyString
;
76 m_matchWholeWord
= FALSE
;
78 m_defaultFileKind
= wxT("Setup file");
82 ctSettings::ctSettings(const ctSettings
& settings
)
88 ctSettings::~ctSettings()
92 void ctSettings::operator = (const ctSettings
& settings
)
97 void ctSettings::Copy (const ctSettings
& settings
)
99 m_lastSetupSaveDir
= settings
.m_lastSetupSaveDir
;
100 m_lastDocument
= settings
.m_lastDocument
;
101 m_showToolBar
= settings
.m_showToolBar
;
102 m_frameSize
= settings
.m_frameSize
;
103 m_editWindowFont
= settings
.m_editWindowFont
;
104 m_showSplashScreen
= settings
.m_showSplashScreen
;
105 m_userName
= settings
.m_userName
;
106 m_loadLastDocument
= settings
.m_loadLastDocument
;
107 m_exportDir
= settings
.m_exportDir
;
108 m_firstTimeRun
= settings
.m_firstTimeRun
;
109 m_noUses
= settings
.m_noUses
;
110 m_smallToolbar
= settings
.m_smallToolbar
;
111 m_useToolTips
= settings
.m_useToolTips
;
112 m_showWelcomeDialog
= settings
.m_showWelcomeDialog
;
113 m_mainSashSize
= settings
.m_mainSashSize
;
115 m_showTrayIcon
= settings
.m_showTrayIcon
;
116 m_trayIconIsShown
= settings
.m_trayIconIsShown
;
118 m_useEnvironmentVariable
= settings
.m_useEnvironmentVariable
;
119 m_frameworkDir
= settings
.m_frameworkDir
;
120 m_matchWholeWord
= settings
.m_matchWholeWord
;
121 m_matchCase
= settings
.m_matchCase
;
122 m_defaultFileKind
= settings
.m_defaultFileKind
;
125 // Do some initialisation within stApp::OnInit
126 bool ctSettings::Init()
128 m_lastSetupSaveDir
= wxEmptyString
;
129 if (m_userName
.IsEmpty())
130 m_userName
= wxGetUserName();
135 // Create new filename
136 wxString
ctSettings::GenerateFilename(const wxString
& rootName
)
139 if (!m_lastFilename
.IsEmpty())
140 path
= wxPathOnly(m_lastFilename
);
142 path
= wxGetApp().GetAppDir();
144 wxString
filename(path
);
145 if (filename
.Last() != wxFILE_SEP_PATH
)
146 filename
+= wxFILE_SEP_PATH
;
147 filename
+= rootName
;
149 wxString fullFilename
= filename
+ wxT(".wxs");
152 while (wxFileExists(fullFilename
))
155 postfixStr
.Printf("%d", i
);
156 fullFilename
= filename
+ postfixStr
+ wxT(".wxs");
159 m_lastFilename
= fullFilename
;
164 bool ctSettings::LoadConfig()
166 wxConfig
config(wxGetApp().GetSettings().GetAppName(), wxT("wxWindows"));
168 config
.Read(wxT("Files/LastFile"), & m_lastFilename
);
169 config
.Read(wxT("Files/LastSetupSaveDir"), & m_lastSetupSaveDir
);
170 config
.Read(wxT("Files/ExportDir"), & m_exportDir
);
171 config
.Read(wxT("Files/FrameworkDir"), & m_frameworkDir
);
172 config
.Read(wxT("Files/UseEnvironmentVariable"), (bool*) & m_useEnvironmentVariable
);
174 config
.Read(wxT("Misc/UserName"), & m_userName
);
175 config
.Read(wxT("Misc/FrameStatus"), & m_frameStatus
);
176 config
.Read(wxT("Misc/ShowToolTips"), (bool*) & m_useToolTips
);
177 config
.Read(wxT("Misc/LastDocument"), & m_lastDocument
);
178 config
.Read(wxT("Misc/LoadLastDocument"), (bool*) & m_loadLastDocument
);
179 config
.Read(wxT("Misc/ShowWelcomeDialog"), (bool*) & m_showWelcomeDialog
);
180 config
.Read(wxT("Misc/Ran"), & m_noUses
);
181 config
.Read(wxT("Misc/ShowTrayIcon"), (bool*) & m_showTrayIcon
);
182 config
.Read(wxT("Misc/MatchWholeWord"), (bool*) & m_matchWholeWord
);
183 config
.Read(wxT("Misc/MatchCase"), (bool*) & m_matchCase
);
184 config
.Read(wxT("Misc/BuildMode"), & m_defaultFileKind
);
188 config
.Read(wxT("Windows/ShowToolBar"), (bool*) & m_showToolBar
);
190 m_firstTimeRun
= !(config
.Read(wxT("Windows/WindowX"), & m_frameSize
.x
));
191 config
.Read(wxT("Windows/WindowY"), & m_frameSize
.y
);
192 config
.Read(wxT("Windows/WindowWidth"), & m_frameSize
.width
);
193 config
.Read(wxT("Windows/WindowHeight"), & m_frameSize
.height
);
194 config
.Read(wxT("Windows/ShowSplashScreen"), (bool*) & m_showSplashScreen
);
195 config
.Read(wxT("Windows/SmallToolbar"), (bool*) & m_smallToolbar
);
196 config
.Read(wxT("Windows/MainSashSize"), & m_mainSashSize
);
200 fontSpec
= wxEmptyString
;
201 config
.Read(wxT("Style/EditWindowFont"), & fontSpec
);
202 if (!fontSpec
.IsEmpty())
203 m_editWindowFont
= apStringToFont(fontSpec
);
206 int runningProgram
= 0;
207 config
.Read(wxT("Misc/RunningProgram"), & runningProgram
);
210 // runningProgram should be zero if all is well. If 1,
211 // it crashed during a run, so we should disable the auto-load
212 // facility just in case it's trying to load a damaged file.
213 if (runningProgram
!= 0)
215 m_loadLastDocument
= FALSE
;
219 config
.Write(wxT("Misc/RunningProgram"), (long) 1);
225 bool ctSettings::SaveConfig()
227 wxConfig
config(wxGetApp().GetSettings().GetAppName(), wxT("wxWindows"));
229 config
.Write(wxT("Files/LastFile"), m_lastFilename
);
230 config
.Write(wxT("Files/LastSetupSaveDir"), m_lastSetupSaveDir
);
231 config
.Write(wxT("Files/ExportDir"), m_exportDir
);
232 config
.Write(wxT("Files/FrameworkDir"), m_frameworkDir
);
233 config
.Write(wxT("Files/UseEnvironmentVariable"), m_useEnvironmentVariable
);
235 config
.Write(wxT("Misc/UserName"), m_userName
);
236 config
.Write(wxT("Misc/FrameStatus"), (long) m_frameStatus
);
237 config
.Write(wxT("Misc/ShowToolTips"), m_useToolTips
);
238 config
.Write(wxT("Misc/LastDocument"), m_lastDocument
);
239 config
.Write(wxT("Misc/LoadLastDocument"), (long) m_loadLastDocument
);
240 config
.Write(wxT("Misc/ShowWelcomeDialog"), (long) m_showWelcomeDialog
);
241 config
.Write(wxT("Misc/Ran"), m_noUses
);
242 config
.Write(wxT("Misc/ShowTrayIcon"), (long) m_showTrayIcon
);
243 config
.Write(wxT("Misc/MatchWholeWord"), (long) m_matchWholeWord
);
244 config
.Write(wxT("Misc/MatchCase"), (long) m_matchCase
);
245 config
.Write(wxT("Misc/BuildMode"), m_defaultFileKind
);
247 config
.Write(wxT("Windows/ShowToolBar"), m_showToolBar
);
248 config
.Write(wxT("Windows/WindowX"), (long) m_frameSize
.x
);
249 config
.Write(wxT("Windows/WindowY"), (long) m_frameSize
.y
);
250 config
.Write(wxT("Windows/WindowWidth"), (long) m_frameSize
.width
);
251 config
.Write(wxT("Windows/WindowHeight"), (long) m_frameSize
.height
);
253 config
.Write(wxT("Windows/ShowSplashScreen"), m_showSplashScreen
);
254 config
.Write(wxT("Windows/SmallToolbar"), (long) m_smallToolbar
);
255 config
.Write(wxT("Windows/MainSashSize"), (long) m_mainSashSize
);
258 wxString backgroundColour(apColourToHexString(m_backgroundColour));
259 config.Write(wxT("Style/BackgroundColour"), backgroundColour);
262 config
.Write(wxT("Style/EditWindowFont"), apFontToString(m_editWindowFont
));
264 // Indicate that we're no longer running, so we know if the program
265 // crashed last time around.
266 config
.Write(wxT("Misc/RunningProgram"), (long) 0);
269 config
.SetPath(wxT("FileHistory/"));
270 wxGetApp().GetDocManager()->FileHistorySave(config
);
276 void ctSettings::ShowSettingsDialog(const wxString
& page
)
278 ctSettingsDialog
* dialog
= new ctSettingsDialog(wxGetApp().GetTopWindow());
279 // if (!page.IsEmpty())
280 // dialog->GetNotebook()->SetSelection(apFindNotebookPage(dialog->GetNotebook(), page));
282 /* int ret = */ dialog
->ShowModal();