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