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