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