1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "mainframe.h"
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"
29 #include "wxconfigtool.h"
30 #include "mainframe.h"
31 #include "appsettings.h"
33 #include "configtree.h"
34 #include "propeditor.h"
35 #include "configtooldoc.h"
36 #include "configtoolview.h"
37 #include "configbrowser.h"
39 #include "bitmaps/wxconfigtool.xpm"
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"
53 IMPLEMENT_CLASS(ctMainFrame
, wxDocParentFrame
)
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
)
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
)
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
)
84 EVT_UPDATE_UI(ctID_SAVE_SETUP_FILE
, ctMainFrame::OnUpdateDisable
)
85 EVT_UPDATE_UI(ctID_SAVE_CONFIGURE_COMMAND
, ctMainFrame::OnUpdateDisable
)
87 EVT_UPDATE_UI(wxID_FIND
, ctMainFrame::OnUpdateDisable
)
89 EVT_UPDATE_UI(ctID_GO
, ctMainFrame::OnUpdateDisable
)
92 // Define my frame constructor
93 ctMainFrame::ctMainFrame(wxDocManager
*manager
, wxFrame
*parent
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
,
95 wxDocParentFrame(manager
, parent
, id
, title
, pos
, size
, style
)
99 m_configurePage
= NULL
;
101 #ifdef USE_CONFIG_BROWSER_PAGE
102 m_configBrowserPage
= NULL
;
104 m_mainNotebook
= NULL
;
107 m_treeSplitterWindow
= new wxSplitterWindow(this, -1, wxDefaultPosition
, wxSize(400, 300),
108 wxSP_3DSASH
|wxSP_3DBORDER
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
110 m_configTreeCtrl
= new ctConfigTreeCtrl(m_treeSplitterWindow
, -1, wxDefaultPosition
, wxDefaultSize
,
111 wxTR_HAS_BUTTONS
|wxNO_BORDER
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
113 m_mainNotebook
= new wxNotebook(m_treeSplitterWindow
, -1, wxDefaultPosition
, wxSize(300, 300),
114 wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
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
);
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
);
128 m_mainNotebook
->AddPage(m_propertyEditor
, _T("Properties"));
129 #ifdef USE_CONFIG_BROWSER_PAGE
130 m_mainNotebook
->AddPage(m_configBrowserPage
, _T("Configuration Browser"));
132 m_mainNotebook
->AddPage(m_setupPage
, _T("setup.h"));
133 m_mainNotebook
->AddPage(m_configurePage
, _T("configure"));
135 // Need to do this afterwards since wxWin sets the XP background
137 m_propertyEditor
->GetDescriptionWindow()->SetBackgroundColour(ctDESCRIPTION_BACKGROUND_COLOUR
);
139 int sashPos
= wxGetApp().GetSettings().m_mainSashSize
;
140 m_treeSplitterWindow
->SplitVertically(m_configTreeCtrl
, m_mainNotebook
, sashPos
);
142 SetIcon(wxIcon(wxconfigtool_xpm
));
146 wxMenuBar
* menuBar
= CreateMenuBar();
149 CreateToolBar(wxNO_BORDER
|wxTB_FLAT
|wxTB_HORIZONTAL
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
150 InitToolBar(GetToolBar());
152 if (wxGetApp().GetSettings().m_showToolBar
)
154 menuBar
->Check(ctID_SHOW_TOOLBAR
, TRUE
);
158 menuBar
->Check(ctID_SHOW_TOOLBAR
, FALSE
);
159 GetToolBar()->Show(FALSE
);
164 void ctMainFrame::OnCloseWindow(wxCloseEvent
& event
)
168 if (!GetDocument()->DeleteAllViews() && event
.CanVeto())
177 m_findDialog
->Destroy();
184 wxGetApp().GetSettings().m_frameStatus
= ctSHOW_STATUS_MAXIMIZED
;
185 else if (IsIconized())
186 wxGetApp().GetSettings().m_frameStatus
= ctSHOW_STATUS_MINIMIZED
;
188 wxGetApp().GetSettings().m_frameStatus
= ctSHOW_STATUS_NORMAL
;
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();
194 if (!IsMaximized() && !IsIconized())
196 wxGetApp().GetSettings().m_frameSize
= GetRect();
197 wxGetApp().GetSettings().m_mainSashSize
= m_treeSplitterWindow
->GetSashPosition();
203 void ctMainFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
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
);
210 void ctMainFrame::OnOpen(wxCommandEvent
& event
)
212 wxGetApp().GetDocManager()->OnFileOpen(event
);
215 void ctMainFrame::OnNew(wxCommandEvent
& event
)
217 wxGetApp().GetDocManager()->OnFileNew(event
);
220 void ctMainFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
225 void ctMainFrame::OnSettings(wxCommandEvent
& WXUNUSED(event
))
227 wxGetApp().GetSettings().ShowSettingsDialog();
230 void ctMainFrame::InitToolBar(wxToolBar
* toolBar
)
232 toolBar
->SetHelpText(wxT("The toolbar gives you easy access to commonly used commands."));
235 wxBitmap toolBarBitmaps
[20];
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
);
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"));
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"));
267 // after adding the buttons to the toolbar, must call Realize() to reflect
272 wxMenuBar
* ctMainFrame::CreateMenuBar()
275 wxMenu
*fileMenu
= new wxMenu
;
277 wxGetApp().GetFileHistory().UseMenu(fileMenu
);
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"));
293 wxGetApp().GetDocManager()->FileHistoryUseMenu(fileMenu
);
295 wxMenu
*editMenu
= new wxMenu
;
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();
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"));
315 editMenu
->Append(ctID_ADD_ITEM
, wxT("Add &Option"), itemMenu
, _("Add a configuration option"));
316 editMenu
->AppendSeparator();
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"));
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"));
330 // Save for the command processor.
331 m_editMenu
= editMenu
;
333 wxMenu
*viewMenu
= new wxMenu
;
334 viewMenu
->Append(ctID_SHOW_TOOLBAR
, wxT("Show &Toolbar"), wxT("Toggle the toolbar on and off"),
336 viewMenu
->Append(ctID_SETTINGS
, wxT("&Settings...\tCtrl+T"), wxT("Show application settings"));
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("&wxWidgets Help Contents"), wxT("Show wxWidgets 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"));
347 wxMenuBar
*menuBar
= new wxMenuBar
;
349 menuBar
->Append(fileMenu
, wxT("&File"));
350 menuBar
->Append(editMenu
, wxT("&Edit"));
351 menuBar
->Append(viewMenu
, wxT("&View"));
352 menuBar
->Append(helpMenu
, wxT("&Help"));
355 wxConfig
config(wxGetApp().GetSettings().GetAppName(), wxT("wxWidgets"));
356 config
.SetPath(wxT("FileHistory/"));
357 wxGetApp().GetDocManager()->FileHistoryLoad(config
);
363 /// Handles the Show Toolbar menu event.
364 void ctMainFrame::OnShowToolbar(wxCommandEvent
& WXUNUSED(event
))
366 wxGetApp().GetSettings().m_showToolBar
= !wxGetApp().GetSettings().m_showToolBar
;
367 GetToolBar()->Show(wxGetApp().GetSettings().m_showToolBar
);
371 /// Handles the Help Contents menu event.
372 void ctMainFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
374 wxGetApp().GetHelpController().DisplayContents();
377 /// Handles context help
378 void ctMainFrame::OnContextHelp(wxCommandEvent
& WXUNUSED(event
))
380 wxContextHelp contextHelp
;
383 /// Handles the Help Contents menu event for the reference manual.
384 void ctMainFrame::OnReferenceHelp(wxCommandEvent
& WXUNUSED(event
))
386 wxGetApp().GetReferenceHelpController().DisplayContents();
389 /// Resizes the main frame according to the
390 /// state of the toolbar
391 void ctMainFrame::ResizeFrame()
394 wxSizeEvent
event(GetSize(), GetId());
395 this->ProcessEvent(event
);
398 /// Update the frame title.
399 void ctMainFrame::UpdateFrameTitle()
405 void ctMainFrame::OnUpdateDisable(wxUpdateUIEvent
& event
)
407 event
.Enable( FALSE
);
411 * ctOutputWindow represents a page showing a setup.h file or config command.
414 IMPLEMENT_CLASS(ctOutputWindow
, wxPanel
)
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
)
425 ctOutputWindow::ctOutputWindow(wxWindow
* parent
, wxWindowID id
,
426 const wxPoint
& pos
, const wxSize
& size
, long style
):
427 wxPanel(parent
, id
, pos
, size
, style
)
430 m_filenameCtrl
= NULL
;
435 ctOutputWindow::~ctOutputWindow()
439 /// Initialise the windows.
440 void ctOutputWindow::CreateWindows()
442 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
444 wxBoxSizer
*item2
= new wxBoxSizer( wxHORIZONTAL
);
445 item0
->Add( item2
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
, 5 );
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."));
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."));
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."));
460 m_filenameCtrl
= NULL
;
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 );
467 SetAutoLayout( TRUE
);
471 /// Copies the text to the clipboard.
472 void ctOutputWindow::OnCopyToClipboard(wxCommandEvent
& WXUNUSED(event
))
474 // Try to copy the selection first
475 long int selFrom
, selTo
;
476 m_codeCtrl
->GetSelection(& selFrom
, & selTo
);
477 if (selFrom
!= selTo
)
483 // Copy the whole amount
484 if (!wxTheClipboard
->Open())
486 wxMessageBox(_("Sorry, could not open the clipboard."), _("Clipboard problem"), wxICON_EXCLAMATION
|wxOK
);
490 wxString
value(m_codeCtrl
->GetValue());
492 value
.Replace(_T("\n"), _T("\r\n"));
494 wxTextDataObject
*data
= new wxTextDataObject( value
);
496 if (!wxTheClipboard
->SetData( data
))
498 wxTheClipboard
->Close();
499 wxMessageBox(_("Sorry, could not copy to the clipboard."), _("Clipboard problem"), wxICON_EXCLAMATION
|wxOK
);
503 wxTheClipboard
->Close();
507 /// Sets the code in the text control.
508 void ctOutputWindow::SetText(const wxString
& text
)
511 m_codeCtrl
->SetValue(text
);
514 /// Sets the filename.
515 void ctOutputWindow::SetFilename(const wxString
& filename
)
518 m_filenameCtrl
->SetValue(filename
);
522 void ctOutputWindow::OnSaveText(wxCommandEvent
& WXUNUSED(event
))
524 if (m_codeCtrl
->IsModified())
526 wxString
filename(m_filenameCtrl
->GetValue());
527 if (!filename
.IsEmpty())
529 m_codeCtrl
->SaveFile(filename
);
530 m_codeCtrl
->DiscardEdits();
535 void ctOutputWindow::OnUpdateSaveText(wxUpdateUIEvent
& event
)
537 event
.Enable(m_doc
&& m_codeCtrl
&& m_codeCtrl
->IsModified());
540 void ctOutputWindow::OnRegenerate(wxCommandEvent
& WXUNUSED(event
))
544 ctConfigToolView
* view
= (ctConfigToolView
*) m_doc
->GetFirstView();
545 view
->RegenerateSetup();
549 void ctOutputWindow::OnUpdateRegenerate(wxUpdateUIEvent
& event
)
551 event
.Enable( m_doc
!= NULL
);
554 void ctOutputWindow::OnUpdateCopy(wxUpdateUIEvent
& event
)
556 event
.Enable( m_doc
!= NULL
);