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