]>
Commit | Line | Data |
---|---|---|
d7463f75 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: mainframe.cpp | |
3 | // Purpose: Main frame | |
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 | ||
f8105809 JS |
12 | #ifdef __GNUG__ |
13 | #pragma implementation "mainframe.h" | |
14 | #endif | |
15 | ||
d7463f75 JS |
16 | #include "wx/wx.h" |
17 | ||
18 | #ifdef __BORLANDC__ | |
19 | #pragma hdrstop | |
20 | #endif | |
21 | ||
22 | #include "wx/html/htmlwin.h" | |
23 | #include "wx/notebook.h" | |
24 | #include "wx/splitter.h" | |
25 | #include "wx/clipbrd.h" | |
26 | #include "wx/cshelp.h" | |
27 | ||
28 | #include "wxconfigtool.h" | |
29 | #include "mainframe.h" | |
30 | #include "appsettings.h" | |
31 | #include "symbols.h" | |
32 | #include "configtree.h" | |
33 | #include "propeditor.h" | |
34 | #include "configtooldoc.h" | |
35 | #include "configtoolview.h" | |
61775320 | 36 | #include "configbrowser.h" |
d7463f75 JS |
37 | |
38 | #include "bitmaps/wxconfigtool.xpm" | |
39 | ||
40 | #include "bitmaps/copy.xpm" | |
41 | #include "bitmaps/cut.xpm" | |
42 | #include "bitmaps/paste.xpm" | |
43 | #include "bitmaps/open.xpm" | |
44 | #include "bitmaps/save.xpm" | |
d7463f75 JS |
45 | #include "bitmaps/new.xpm" |
46 | #include "bitmaps/help.xpm" | |
47 | #include "bitmaps/undo.xpm" | |
48 | #include "bitmaps/redo.xpm" | |
49 | #include "bitmaps/helpcs.xpm" | |
afc51590 | 50 | #include "bitmaps/go.xpm" |
d7463f75 JS |
51 | |
52 | IMPLEMENT_CLASS(ctMainFrame, wxDocParentFrame) | |
53 | ||
54 | BEGIN_EVENT_TABLE(ctMainFrame, wxDocParentFrame) | |
55 | EVT_CLOSE(ctMainFrame::OnCloseWindow) | |
56 | EVT_MENU(wxID_ABOUT, ctMainFrame::OnAbout) | |
57 | EVT_MENU(wxID_OPEN, ctMainFrame::OnOpen) | |
58 | EVT_MENU(wxID_NEW, ctMainFrame::OnNew) | |
59 | EVT_MENU(wxID_EXIT, ctMainFrame::OnExit) | |
60 | EVT_MENU(ctID_SETTINGS, ctMainFrame::OnSettings) | |
61 | EVT_MENU(ctID_SHOW_TOOLBAR, ctMainFrame::OnShowToolbar) | |
62 | EVT_MENU(wxID_HELP, ctMainFrame::OnHelp) | |
63 | EVT_MENU(ctID_REFERENCE_CONTENTS, ctMainFrame::OnReferenceHelp) | |
64 | EVT_MENU(wxID_HELP_CONTEXT, ctMainFrame::OnContextHelp) | |
65 | ||
66 | EVT_UPDATE_UI(ctID_ADD_ITEM_CHECKBOX, ctMainFrame::OnUpdateDisable) | |
67 | EVT_UPDATE_UI(ctID_ADD_ITEM_RADIOBUTTON, ctMainFrame::OnUpdateDisable) | |
68 | EVT_UPDATE_UI(ctID_ADD_ITEM_GROUP, ctMainFrame::OnUpdateDisable) | |
69 | EVT_UPDATE_UI(ctID_ADD_ITEM_CHECK_GROUP, ctMainFrame::OnUpdateDisable) | |
70 | EVT_UPDATE_UI(ctID_ADD_ITEM_RADIO_GROUP, ctMainFrame::OnUpdateDisable) | |
71 | EVT_UPDATE_UI(ctID_ADD_ITEM_STRING, ctMainFrame::OnUpdateDisable) | |
72 | EVT_UPDATE_UI(ctID_DELETE_ITEM, ctMainFrame::OnUpdateDisable) | |
73 | EVT_UPDATE_UI(ctID_RENAME_ITEM, ctMainFrame::OnUpdateDisable) | |
74 | EVT_UPDATE_UI(wxID_COPY, ctMainFrame::OnUpdateDisable) | |
75 | EVT_UPDATE_UI(wxID_CUT, ctMainFrame::OnUpdateDisable) | |
76 | EVT_UPDATE_UI(wxID_PASTE, ctMainFrame::OnUpdateDisable) | |
77 | EVT_UPDATE_UI(ctID_ITEM_HELP, ctMainFrame::OnUpdateDisable) | |
78 | ||
79 | EVT_UPDATE_UI(ctID_ADD_CUSTOM_PROPERTY, ctMainFrame::OnUpdateDisable) | |
80 | EVT_UPDATE_UI(ctID_EDIT_CUSTOM_PROPERTY, ctMainFrame::OnUpdateDisable) | |
81 | EVT_UPDATE_UI(ctID_DELETE_CUSTOM_PROPERTY, ctMainFrame::OnUpdateDisable) | |
82 | ||
83 | EVT_UPDATE_UI(ctID_SAVE_SETUP_FILE, ctMainFrame::OnUpdateDisable) | |
84 | EVT_UPDATE_UI(ctID_SAVE_CONFIGURE_COMMAND, ctMainFrame::OnUpdateDisable) | |
e7767867 JS |
85 | |
86 | EVT_UPDATE_UI(wxID_FIND, ctMainFrame::OnUpdateDisable) | |
afc51590 JS |
87 | |
88 | EVT_UPDATE_UI(ctID_GO, ctMainFrame::OnUpdateDisable) | |
d7463f75 JS |
89 | END_EVENT_TABLE() |
90 | ||
91 | // Define my frame constructor | |
92 | ctMainFrame::ctMainFrame(wxDocManager *manager, wxFrame *parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, | |
93 | long style): | |
94 | wxDocParentFrame(manager, parent, id, title, pos, size, style) | |
95 | { | |
96 | m_document = NULL; | |
97 | m_editMenu = NULL; | |
98 | m_configurePage = NULL; | |
99 | m_setupPage = NULL; | |
61775320 | 100 | m_configBrowserPage = NULL; |
d7463f75 | 101 | m_mainNotebook = NULL; |
e7767867 | 102 | m_findDialog = NULL; |
d7463f75 JS |
103 | |
104 | m_treeSplitterWindow = new wxSplitterWindow(this, -1, wxDefaultPosition, wxSize(400, 300), | |
61775320 | 105 | wxSP_3DSASH|wxSP_3DBORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN); |
d7463f75 JS |
106 | |
107 | m_configTreeCtrl = new ctConfigTreeCtrl(m_treeSplitterWindow, -1, wxDefaultPosition, wxDefaultSize, | |
61775320 | 108 | wxTR_HAS_BUTTONS|wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN); |
d7463f75 | 109 | |
61775320 JS |
110 | m_mainNotebook = new wxNotebook(m_treeSplitterWindow, -1, wxDefaultPosition, wxSize(300, 300), |
111 | wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN); | |
d7463f75 JS |
112 | |
113 | m_propertyEditor = new ctPropertyEditor(m_mainNotebook, -1, wxDefaultPosition, wxSize(300, 200), | |
61775320 | 114 | wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN); |
d7463f75 | 115 | m_setupPage = new ctOutputWindow(m_mainNotebook, -1, wxDefaultPosition, wxSize(300, 200), |
61775320 | 116 | wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN); |
d7463f75 | 117 | m_configurePage = new ctOutputWindow(m_mainNotebook, -1, wxDefaultPosition, wxSize(300, 200), |
61775320 JS |
118 | wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN); |
119 | ||
120 | #if 0 | |
121 | m_configBrowserPage = new ctConfigurationBrowserWindow(m_mainNotebook, -1, wxDefaultPosition, wxSize(300, 200), | |
122 | wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN); | |
123 | #endif | |
124 | ||
d7463f75 | 125 | m_mainNotebook->AddPage(m_propertyEditor, _T("Properties")); |
61775320 JS |
126 | #if 0 |
127 | m_mainNotebook->AddPage(m_configBrowserPage, _T("Configuration Browser")); | |
128 | #endif | |
d7463f75 JS |
129 | m_mainNotebook->AddPage(m_setupPage, _T("setup.h")); |
130 | m_mainNotebook->AddPage(m_configurePage, _T("configure")); | |
131 | ||
132 | // Need to do this afterwards since wxWin sets the XP background | |
133 | // in AddPage | |
134 | m_propertyEditor->GetDescriptionWindow()->SetBackgroundColour(ctDESCRIPTION_BACKGROUND_COLOUR); | |
135 | ||
136 | int sashPos = wxGetApp().GetSettings().m_mainSashSize; | |
137 | m_treeSplitterWindow->SplitVertically(m_configTreeCtrl, m_mainNotebook, sashPos); | |
138 | ||
139 | SetIcon(wxIcon(wxconfigtool_xpm)); | |
140 | ||
141 | CreateStatusBar(2); | |
142 | ||
143 | wxMenuBar* menuBar = CreateMenuBar(); | |
144 | SetMenuBar(menuBar); | |
145 | ||
61775320 | 146 | CreateToolBar(wxNO_BORDER|wxTB_FLAT|wxTB_HORIZONTAL|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN); |
d7463f75 JS |
147 | InitToolBar(GetToolBar()); |
148 | ||
149 | if (wxGetApp().GetSettings().m_showToolBar) | |
150 | { | |
151 | menuBar->Check(ctID_SHOW_TOOLBAR, TRUE); | |
152 | } | |
153 | else | |
154 | { | |
155 | menuBar->Check(ctID_SHOW_TOOLBAR, FALSE); | |
156 | GetToolBar()->Show(FALSE); | |
157 | ResizeFrame(); | |
158 | } | |
159 | } | |
160 | ||
161 | void ctMainFrame::OnCloseWindow(wxCloseEvent& event) | |
162 | { | |
163 | if (GetDocument()) | |
164 | { | |
165 | if (!GetDocument()->DeleteAllViews() && event.CanVeto()) | |
166 | { | |
167 | event.Veto(); | |
168 | return; | |
169 | } | |
170 | } | |
171 | ||
e7767867 JS |
172 | if (m_findDialog) |
173 | { | |
174 | m_findDialog->Destroy(); | |
175 | m_findDialog = NULL; | |
176 | } | |
177 | ||
d7463f75 JS |
178 | Show(FALSE); |
179 | ||
180 | if (IsMaximized()) | |
181 | wxGetApp().GetSettings().m_frameStatus = ctSHOW_STATUS_MAXIMIZED ; | |
182 | else if (IsIconized()) | |
183 | wxGetApp().GetSettings().m_frameStatus = ctSHOW_STATUS_MINIMIZED ; | |
184 | else | |
185 | wxGetApp().GetSettings().m_frameStatus = ctSHOW_STATUS_NORMAL ; | |
186 | ||
187 | // Must delete this now since the DLL loading library will be | |
188 | // uninitialised by the time the app object is deleted | |
189 | wxGetApp().ClearHelpControllers(); | |
190 | ||
191 | if (!IsMaximized() && !IsIconized()) | |
192 | { | |
193 | wxGetApp().GetSettings().m_frameSize = GetRect(); | |
194 | wxGetApp().GetSettings().m_mainSashSize = m_treeSplitterWindow->GetSashPosition(); | |
195 | } | |
196 | ||
197 | Destroy(); | |
198 | } | |
199 | ||
200 | void ctMainFrame::OnAbout(wxCommandEvent& event) | |
201 | { | |
202 | wxString msg = wxGetApp().GetSettings().GetAppName() + wxT(" (c) Julian Smart"); | |
203 | wxString caption = wxT("About ") + wxGetApp().GetSettings().GetAppName(); | |
eac703e9 | 204 | wxMessageBox(msg, caption, wxOK|wxICON_INFORMATION); |
d7463f75 JS |
205 | } |
206 | ||
207 | void ctMainFrame::OnOpen(wxCommandEvent& event) | |
208 | { | |
209 | wxGetApp().GetDocManager()->OnFileOpen(event); | |
210 | } | |
211 | ||
212 | void ctMainFrame::OnNew(wxCommandEvent& event) | |
213 | { | |
214 | wxGetApp().GetDocManager()->OnFileNew(event); | |
215 | } | |
216 | ||
217 | void ctMainFrame::OnExit(wxCommandEvent& event) | |
218 | { | |
219 | Close(); | |
220 | } | |
221 | ||
222 | void ctMainFrame::OnSettings(wxCommandEvent& event) | |
223 | { | |
224 | wxGetApp().GetSettings().ShowSettingsDialog(); | |
225 | } | |
226 | ||
227 | void ctMainFrame::InitToolBar(wxToolBar* toolBar) | |
228 | { | |
229 | toolBar->SetHelpText(wxT("The toolbar gives you easy access to commonly used commands.")); | |
230 | ||
231 | // Set up toolbar | |
232 | wxBitmap toolBarBitmaps[20]; | |
233 | ||
234 | toolBarBitmaps[0] = wxBitmap(new_xpm); | |
235 | toolBarBitmaps[1] = wxBitmap(open_xpm); | |
236 | toolBarBitmaps[2] = wxBitmap(save_xpm); | |
237 | toolBarBitmaps[3] = wxBitmap(copy_xpm); | |
238 | toolBarBitmaps[4] = wxBitmap(cut_xpm); | |
239 | toolBarBitmaps[5] = wxBitmap(paste_xpm); | |
afc51590 | 240 | toolBarBitmaps[6] = wxBitmap(go_xpm); |
d7463f75 JS |
241 | toolBarBitmaps[7] = wxBitmap(help_xpm); |
242 | toolBarBitmaps[10] = wxBitmap(undo_xpm); | |
243 | toolBarBitmaps[11] = wxBitmap(redo_xpm); | |
244 | toolBarBitmaps[12] = wxBitmap(help_xpm); | |
245 | toolBarBitmaps[13] = wxBitmap(helpcs_xpm); | |
246 | ||
247 | toolBar->AddTool(wxID_NEW, toolBarBitmaps[0], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, wxT("New project")); | |
248 | toolBar->AddTool(wxID_OPEN, toolBarBitmaps[1], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, wxT("Open project")); | |
249 | toolBar->AddTool(wxID_SAVE, toolBarBitmaps[2], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, wxT("Save project")); | |
250 | ||
251 | toolBar->AddSeparator(); | |
252 | toolBar->AddTool(wxID_CUT, toolBarBitmaps[4], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, wxT("Cut")); | |
253 | toolBar->AddTool(wxID_COPY, toolBarBitmaps[3], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, wxT("Copy")); | |
254 | toolBar->AddTool(wxID_PASTE, toolBarBitmaps[5], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, wxT("Paste")); | |
255 | toolBar->AddSeparator(); | |
256 | toolBar->AddTool(wxID_UNDO, toolBarBitmaps[10], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, wxT("Undo")); | |
257 | toolBar->AddTool(wxID_REDO, toolBarBitmaps[11], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, wxT("Redo")); | |
258 | toolBar->AddSeparator(); | |
afc51590 JS |
259 | toolBar->AddTool(ctID_GO, toolBarBitmaps[6], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, wxT("Save setup.h or configurewx.sh")); |
260 | toolBar->AddSeparator(); | |
d7463f75 JS |
261 | toolBar->AddTool(ctID_ITEM_HELP, toolBarBitmaps[12], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, wxT("Show help for this option")); |
262 | toolBar->AddTool(wxID_HELP_CONTEXT, toolBarBitmaps[13], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, wxT("Show help on the clicked item")); | |
263 | ||
264 | // after adding the buttons to the toolbar, must call Realize() to reflect | |
265 | // the changes | |
266 | toolBar->Realize(); | |
267 | } | |
268 | ||
269 | wxMenuBar* ctMainFrame::CreateMenuBar() | |
270 | { | |
271 | // Make a menubar | |
272 | wxMenu *fileMenu = new wxMenu; | |
273 | ||
274 | wxGetApp().GetFileHistory().UseMenu(fileMenu); | |
275 | ||
276 | fileMenu->Append(wxID_NEW, wxT("&New...\tCtrl+N"), wxT("Create a new settings document")); | |
277 | fileMenu->Append(wxID_OPEN, wxT("&Open...\tCtrl+O"), wxT("Open a settings document")); | |
278 | fileMenu->Append(wxID_CLOSE, wxT("&Close\tCtrl+W"), wxT("Close the current settings document")); | |
279 | fileMenu->AppendSeparator(); | |
280 | fileMenu->Append(wxID_SAVE, wxT("&Save\tCtrl+S"), wxT("Save the settings document")); | |
281 | fileMenu->Append(wxID_SAVEAS, wxT("&Save As..."), wxT("Save the settings document under a new filename")); | |
282 | fileMenu->AppendSeparator(); | |
283 | fileMenu->Append(ctID_SAVE_SETUP_FILE, wxT("Save Setup.&h...\tCtrl+H"), wxT("Save the setup.h file")); | |
284 | fileMenu->Append(ctID_SAVE_CONFIGURE_COMMAND, wxT("Save Configure Script...\tCtrl+G"), wxT("Save the configure script file")); | |
285 | fileMenu->AppendSeparator(); | |
afc51590 JS |
286 | fileMenu->Append(ctID_GO, wxT("&Go\tF5"), wxT("Quick-save the setup.h or configure.sh file")); |
287 | fileMenu->AppendSeparator(); | |
d7463f75 JS |
288 | fileMenu->Append(wxID_EXIT, wxT("E&xit\tAlt+F4"), wxT("Exit the application")); |
289 | ||
290 | wxGetApp().GetDocManager()->FileHistoryUseMenu(fileMenu); | |
291 | ||
292 | wxMenu *editMenu = new wxMenu; | |
293 | ||
294 | editMenu->Append(wxID_UNDO, _("&Undo\tCtrl+Z")); | |
295 | editMenu->Append(wxID_REDO, _("&Redo\tCtrl+Y")); | |
296 | editMenu->AppendSeparator(); | |
297 | editMenu->Append(wxID_COPY, _("&Copy\tCtrl+C")); | |
298 | editMenu->Append(wxID_CUT, _("Cu&t\tCtrl+X")); | |
299 | editMenu->Append(wxID_PASTE, _("&Paste\tCtrl+V")); | |
300 | editMenu->AppendSeparator(); | |
301 | ||
302 | wxMenu* itemMenu = new wxMenu; | |
303 | itemMenu->Append(ctID_ADD_ITEM_CHECKBOX, _("Add &Checkbox Option"), _("Add a checkbox configuration option")); | |
304 | itemMenu->Append(ctID_ADD_ITEM_RADIOBUTTON, _("Add &Radio Button Option"), _("Add a radio button configuration option")); | |
305 | // TODO. However we can also simply use custom properties; | |
306 | // but then the C++ code has to be special-cased. | |
307 | // itemMenu->Append(ctID_ADD_ITEM_STRING, _("Add &String Option"), _("Add a string configuration option")); | |
308 | itemMenu->Append(ctID_ADD_ITEM_GROUP, _("Add &Group Option"), _("Add a group configuration option")); | |
309 | itemMenu->Append(ctID_ADD_ITEM_CHECK_GROUP, _("Add Chec&k Group Option"), _("Add a check group configuration option")); | |
310 | itemMenu->Append(ctID_ADD_ITEM_RADIO_GROUP, _("Add Rad&io Group Option"), _("Add a radio group configuration option")); | |
311 | ||
312 | editMenu->Append(ctID_ADD_ITEM, wxT("Add &Option"), itemMenu, _("Add a configuration option")); | |
313 | editMenu->AppendSeparator(); | |
314 | ||
315 | wxMenu* propertyMenu = new wxMenu; | |
316 | propertyMenu->Append(ctID_ADD_CUSTOM_PROPERTY, _("&Add Custom Property"), _("Adds a custom property to the current option")); | |
317 | propertyMenu->Append(ctID_EDIT_CUSTOM_PROPERTY, _("&Edit Custom Property"), _("Edits the currently selected custom property")); | |
318 | propertyMenu->Append(ctID_DELETE_CUSTOM_PROPERTY, _("&Delete Custom Property"), _("Deletes the currently selected custom property")); | |
319 | editMenu->Append(ctID_CUSTOM_PROPERTY, _("Custom P&roperty"), propertyMenu, _("Custom property commands")); | |
320 | ||
321 | editMenu->AppendSeparator(); | |
322 | editMenu->Append(ctID_DELETE_ITEM, _("&Delete Option"), _("Delete a configuration option")); | |
323 | editMenu->Append(ctID_RENAME_ITEM, _("&Rename Option"), _("Rename a configuration option")); | |
e7767867 JS |
324 | editMenu->AppendSeparator(); |
325 | editMenu->Append(wxID_FIND, _("&Find...\tCtrl+F"), _("Search for a string in the settings document")); | |
d7463f75 JS |
326 | |
327 | // Save for the command processor. | |
328 | m_editMenu = editMenu; | |
329 | ||
330 | wxMenu *viewMenu = new wxMenu; | |
331 | viewMenu->Append(ctID_SHOW_TOOLBAR, wxT("Show &Toolbar"), wxT("Toggle the toolbar on and off"), | |
332 | wxITEM_CHECK); | |
333 | viewMenu->Append(ctID_SETTINGS, wxT("&Settings...\tCtrl+T"), wxT("Show application settings")); | |
334 | ||
335 | wxMenu *helpMenu = new wxMenu; | |
336 | helpMenu->Append(wxID_HELP, wxT("&Help Contents"), wxT("Show Configuration Tool help")); | |
337 | helpMenu->Append(ctID_REFERENCE_CONTENTS, wxT("&wxWindows Help Contents"), wxT("Show wxWindows reference")); | |
338 | helpMenu->AppendSeparator(); | |
339 | helpMenu->Append(ctID_ITEM_HELP, wxT("&Configuration Option Help\tF1"), wxT("Show help for the selected option")); | |
340 | helpMenu->Append(wxID_HELP_CONTEXT, wxT("&What's this?"), wxT("Show help on the clicked item")); | |
341 | helpMenu->AppendSeparator(); | |
342 | helpMenu->Append(wxID_ABOUT, wxT("&About..."), wxT("Show details about this application")); | |
343 | ||
344 | wxMenuBar *menuBar = new wxMenuBar; | |
345 | ||
346 | menuBar->Append(fileMenu, wxT("&File")); | |
347 | menuBar->Append(editMenu, wxT("&Edit")); | |
348 | menuBar->Append(viewMenu, wxT("&View")); | |
349 | menuBar->Append(helpMenu, wxT("&Help")); | |
350 | ||
351 | { | |
352 | wxConfig config(wxGetApp().GetSettings().GetAppName(), wxT("wxWindows")); | |
353 | config.SetPath(wxT("FileHistory/")); | |
354 | wxGetApp().GetDocManager()->FileHistoryLoad(config); | |
355 | } | |
356 | ||
357 | return menuBar; | |
358 | } | |
359 | ||
360 | /// Handles the Show Toolbar menu event. | |
361 | void ctMainFrame::OnShowToolbar(wxCommandEvent& event) | |
362 | { | |
363 | wxGetApp().GetSettings().m_showToolBar = !wxGetApp().GetSettings().m_showToolBar; | |
364 | GetToolBar()->Show(wxGetApp().GetSettings().m_showToolBar); | |
365 | ResizeFrame(); | |
366 | } | |
367 | ||
368 | /// Handles the Help Contents menu event. | |
369 | void ctMainFrame::OnHelp(wxCommandEvent& event) | |
370 | { | |
371 | wxGetApp().GetHelpController().DisplayContents(); | |
372 | } | |
373 | ||
374 | /// Handles context help | |
375 | void ctMainFrame::OnContextHelp(wxCommandEvent& event) | |
376 | { | |
377 | wxContextHelp contextHelp; | |
378 | } | |
379 | ||
380 | /// Handles the Help Contents menu event for the reference manual. | |
381 | void ctMainFrame::OnReferenceHelp(wxCommandEvent& event) | |
382 | { | |
383 | wxGetApp().GetReferenceHelpController().DisplayContents(); | |
384 | } | |
385 | ||
386 | /// Resizes the main frame according to the | |
387 | /// state of the toolbar | |
388 | void ctMainFrame::ResizeFrame() | |
389 | { | |
390 | PositionToolBar(); | |
391 | wxSizeEvent event(GetSize(), GetId()); | |
392 | this->ProcessEvent(event); | |
393 | } | |
394 | ||
395 | /// Update the frame title. | |
396 | void ctMainFrame::UpdateFrameTitle() | |
397 | { | |
398 | // TODO | |
399 | } | |
400 | ||
401 | // General disabler | |
402 | void ctMainFrame::OnUpdateDisable(wxUpdateUIEvent& event) | |
403 | { | |
404 | event.Enable( FALSE ); | |
405 | } | |
406 | ||
407 | /*! | |
408 | * ctOutputWindow represents a page showing a setup.h file or config command. | |
409 | */ | |
410 | ||
411 | IMPLEMENT_CLASS(ctOutputWindow, wxPanel) | |
412 | ||
413 | BEGIN_EVENT_TABLE(ctOutputWindow, wxPanel) | |
414 | EVT_BUTTON(wxID_COPY, ctOutputWindow::OnCopyToClipboard) | |
415 | EVT_BUTTON(wxID_SAVE, ctOutputWindow::OnSaveText) | |
416 | EVT_BUTTON(ctID_REGENERATE, ctOutputWindow::OnRegenerate) | |
417 | EVT_UPDATE_UI(wxID_SAVE, ctOutputWindow::OnUpdateSaveText) | |
418 | EVT_UPDATE_UI(ctID_REGENERATE, ctOutputWindow::OnUpdateRegenerate) | |
419 | EVT_UPDATE_UI(wxID_COPY, ctOutputWindow::OnUpdateCopy) | |
420 | END_EVENT_TABLE() | |
421 | ||
422 | ctOutputWindow::ctOutputWindow(wxWindow* parent, wxWindowID id, | |
423 | const wxPoint& pos, const wxSize& size, long style): | |
424 | wxPanel(parent, id, pos, size, style) | |
425 | { | |
426 | m_codeCtrl = NULL; | |
427 | m_filenameCtrl = NULL; | |
428 | m_doc = NULL; | |
429 | CreateWindows(); | |
430 | } | |
431 | ||
432 | ctOutputWindow::~ctOutputWindow() | |
433 | { | |
434 | } | |
435 | ||
436 | /// Initialise the windows. | |
437 | void ctOutputWindow::CreateWindows() | |
438 | { | |
439 | wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL ); | |
440 | ||
441 | wxBoxSizer *item2 = new wxBoxSizer( wxHORIZONTAL ); | |
442 | item0->Add( item2, 0, wxGROW|wxALIGN_CENTER_VERTICAL, 5 ); | |
443 | ||
444 | wxButton *item4 = new wxButton( this, wxID_COPY, _("&Copy"), wxDefaultPosition, wxDefaultSize, 0 ); | |
445 | item2->Add( item4, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP|wxBOTTOM|wxRIGHT, 5 ); | |
446 | item4->SetHelpText(_("Copies the selection or whole file to the clipboard.")); | |
447 | ||
448 | wxButton *item5 = new wxButton( this, ctID_REGENERATE, _("Re&generate"), wxDefaultPosition, wxDefaultSize, 0 ); | |
449 | item2->Add( item5, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 ); | |
450 | item5->SetHelpText(_("Regenerates the code.")); | |
451 | ||
452 | #if 0 | |
453 | m_filenameCtrl = new wxTextCtrl(this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTE_READONLY); | |
454 | item2->Add( m_filenameCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 ); | |
455 | m_filenameCtrl->SetHelpText(_("Shows the filename where the code is being saved.")); | |
456 | #else | |
457 | m_filenameCtrl = NULL; | |
458 | #endif | |
459 | ||
460 | // The code editor | |
461 | m_codeCtrl = new wxTextCtrl(this, -1, wxEmptyString, wxDefaultPosition, wxSize(100, 100), wxTE_RICH|wxTE_MULTILINE|wxSUNKEN_BORDER); | |
462 | item0->Add( m_codeCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 ); | |
463 | ||
464 | SetAutoLayout( TRUE ); | |
465 | SetSizer( item0 ); | |
466 | } | |
467 | ||
468 | /// Copies the text to the clipboard. | |
469 | void ctOutputWindow::OnCopyToClipboard(wxCommandEvent& event) | |
470 | { | |
471 | // Try to copy the selection first | |
472 | long int selFrom, selTo; | |
473 | m_codeCtrl->GetSelection(& selFrom, & selTo); | |
474 | if (selFrom != selTo) | |
475 | { | |
476 | m_codeCtrl->Copy(); | |
477 | return; | |
478 | } | |
479 | ||
480 | // Copy the whole amount | |
481 | if (!wxTheClipboard->Open()) | |
482 | { | |
483 | wxMessageBox(_("Sorry, could not open the clipboard."), _("Clipboard problem"), wxICON_EXCLAMATION|wxOK); | |
484 | return; | |
485 | } | |
486 | ||
487 | wxString value(m_codeCtrl->GetValue()); | |
488 | #ifdef __WXMSW__ | |
489 | value.Replace(_T("\n"), _T("\r\n")); | |
490 | #endif | |
491 | wxTextDataObject *data = new wxTextDataObject( value ); | |
492 | ||
493 | if (!wxTheClipboard->SetData( data )) | |
494 | { | |
495 | wxTheClipboard->Close(); | |
496 | wxMessageBox(_("Sorry, could not copy to the clipboard."), _("Clipboard problem"), wxICON_EXCLAMATION|wxOK); | |
497 | } | |
498 | else | |
499 | { | |
500 | wxTheClipboard->Close(); | |
501 | } | |
502 | } | |
503 | ||
504 | /// Sets the code in the text control. | |
505 | void ctOutputWindow::SetText(const wxString& text) | |
506 | { | |
507 | if (m_codeCtrl) | |
508 | m_codeCtrl->SetValue(text); | |
509 | } | |
510 | ||
511 | /// Sets the filename. | |
512 | void ctOutputWindow::SetFilename(const wxString& filename) | |
513 | { | |
514 | if (m_filenameCtrl) | |
515 | m_filenameCtrl->SetValue(filename); | |
516 | } | |
517 | ||
518 | /// Saves the file. | |
519 | void ctOutputWindow::OnSaveText(wxCommandEvent& event) | |
520 | { | |
521 | if (m_codeCtrl->IsModified()) | |
522 | { | |
523 | wxString filename(m_filenameCtrl->GetValue()); | |
524 | if (!filename.IsEmpty()) | |
525 | { | |
526 | m_codeCtrl->SaveFile(filename); | |
527 | m_codeCtrl->DiscardEdits(); | |
528 | } | |
529 | } | |
530 | } | |
531 | ||
532 | void ctOutputWindow::OnUpdateSaveText(wxUpdateUIEvent& event) | |
533 | { | |
534 | event.Enable(m_doc && m_codeCtrl && m_codeCtrl->IsModified()); | |
535 | } | |
536 | ||
537 | void ctOutputWindow::OnRegenerate(wxCommandEvent& event) | |
538 | { | |
539 | if (m_doc) | |
540 | { | |
541 | ctConfigToolView* view = (ctConfigToolView*) m_doc->GetFirstView(); | |
542 | view->RegenerateSetup(); | |
543 | } | |
544 | } | |
545 | ||
546 | void ctOutputWindow::OnUpdateRegenerate(wxUpdateUIEvent& event) | |
547 | { | |
548 | event.Enable( m_doc != NULL ); | |
549 | } | |
550 | ||
551 | void ctOutputWindow::OnUpdateCopy(wxUpdateUIEvent& event) | |
552 | { | |
553 | event.Enable( m_doc != NULL ); | |
554 | } |