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