1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "mainframe.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
25 #include "wx/splitter.h"
29 #include "wx/cshelp.h"
30 #include "wx/html/htmlwin.h"
31 #include "wx/notebook.h"
32 #include "wx/dataobj.h"
33 #include "wx/clipbrd.h"
34 #include "wxconfigtool.h"
35 #include "mainframe.h"
36 #include "appsettings.h"
38 #include "configtree.h"
39 #include "propeditor.h"
40 #include "configtooldoc.h"
41 #include "configtoolview.h"
42 #include "configbrowser.h"
44 #include "bitmaps/wxconfigtool.xpm"
46 #include "bitmaps/copy.xpm"
47 #include "bitmaps/cut.xpm"
48 #include "bitmaps/paste.xpm"
49 #include "bitmaps/open.xpm"
50 #include "bitmaps/save.xpm"
51 #include "bitmaps/new.xpm"
52 #include "bitmaps/help.xpm"
53 #include "bitmaps/undo.xpm"
54 #include "bitmaps/redo.xpm"
55 #include "bitmaps/helpcs.xpm"
56 #include "bitmaps/go.xpm"
58 IMPLEMENT_CLASS(ctMainFrame
, wxDocParentFrame
)
60 BEGIN_EVENT_TABLE(ctMainFrame
, wxDocParentFrame
)
61 EVT_CLOSE(ctMainFrame::OnCloseWindow
)
62 EVT_MENU(wxID_ABOUT
, ctMainFrame::OnAbout
)
63 EVT_MENU(wxID_OPEN
, ctMainFrame::OnOpen
)
64 EVT_MENU(wxID_NEW
, ctMainFrame::OnNew
)
65 EVT_MENU(wxID_EXIT
, ctMainFrame::OnExit
)
66 EVT_MENU(ctID_SETTINGS
, ctMainFrame::OnSettings
)
67 EVT_MENU(ctID_SHOW_TOOLBAR
, ctMainFrame::OnShowToolbar
)
68 EVT_MENU(wxID_HELP
, ctMainFrame::OnHelp
)
69 EVT_MENU(ctID_REFERENCE_CONTENTS
, ctMainFrame::OnReferenceHelp
)
70 EVT_MENU(wxID_HELP_CONTEXT
, ctMainFrame::OnContextHelp
)
72 EVT_UPDATE_UI(ctID_ADD_ITEM_CHECKBOX
, ctMainFrame::OnUpdateDisable
)
73 EVT_UPDATE_UI(ctID_ADD_ITEM_RADIOBUTTON
, ctMainFrame::OnUpdateDisable
)
74 EVT_UPDATE_UI(ctID_ADD_ITEM_GROUP
, ctMainFrame::OnUpdateDisable
)
75 EVT_UPDATE_UI(ctID_ADD_ITEM_CHECK_GROUP
, ctMainFrame::OnUpdateDisable
)
76 EVT_UPDATE_UI(ctID_ADD_ITEM_RADIO_GROUP
, ctMainFrame::OnUpdateDisable
)
77 EVT_UPDATE_UI(ctID_ADD_ITEM_STRING
, ctMainFrame::OnUpdateDisable
)
78 EVT_UPDATE_UI(ctID_DELETE_ITEM
, ctMainFrame::OnUpdateDisable
)
79 EVT_UPDATE_UI(ctID_RENAME_ITEM
, ctMainFrame::OnUpdateDisable
)
80 EVT_UPDATE_UI(wxID_COPY
, ctMainFrame::OnUpdateDisable
)
81 EVT_UPDATE_UI(wxID_CUT
, ctMainFrame::OnUpdateDisable
)
82 EVT_UPDATE_UI(wxID_PASTE
, ctMainFrame::OnUpdateDisable
)
83 EVT_UPDATE_UI(ctID_ITEM_HELP
, ctMainFrame::OnUpdateDisable
)
85 EVT_UPDATE_UI(ctID_ADD_CUSTOM_PROPERTY
, ctMainFrame::OnUpdateDisable
)
86 EVT_UPDATE_UI(ctID_EDIT_CUSTOM_PROPERTY
, ctMainFrame::OnUpdateDisable
)
87 EVT_UPDATE_UI(ctID_DELETE_CUSTOM_PROPERTY
, ctMainFrame::OnUpdateDisable
)
89 EVT_UPDATE_UI(ctID_SAVE_SETUP_FILE
, ctMainFrame::OnUpdateDisable
)
90 EVT_UPDATE_UI(ctID_SAVE_CONFIGURE_COMMAND
, ctMainFrame::OnUpdateDisable
)
92 EVT_UPDATE_UI(wxID_FIND
, ctMainFrame::OnUpdateDisable
)
94 EVT_UPDATE_UI(ctID_GO
, ctMainFrame::OnUpdateDisable
)
97 // Define my frame constructor
98 ctMainFrame::ctMainFrame(wxDocManager
*manager
, wxFrame
*parent
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
, long style
):
99 wxDocParentFrame(manager
, parent
, id
, title
, pos
, size
, style
)
103 m_configurePage
= NULL
;
105 #ifdef USE_CONFIG_BROWSER_PAGE
106 m_configBrowserPage
= NULL
;
108 m_mainNotebook
= NULL
;
111 m_treeSplitterWindow
= new wxSplitterWindow(this, wxID_ANY
, wxDefaultPosition
, wxSize(400, 300),
112 wxSP_3DSASH
|wxSP_3DBORDER
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
114 m_configTreeCtrl
= new ctConfigTreeCtrl(m_treeSplitterWindow
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
,
115 wxTR_HAS_BUTTONS
|wxNO_BORDER
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
117 m_mainNotebook
= new wxNotebook(m_treeSplitterWindow
, wxID_ANY
, wxDefaultPosition
, wxSize(300, 300),
118 wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
120 m_propertyEditor
= new ctPropertyEditor(m_mainNotebook
, wxID_ANY
, wxDefaultPosition
, wxSize(300, 200),
121 wxNO_BORDER
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
122 m_setupPage
= new ctOutputWindow(m_mainNotebook
, wxID_ANY
, wxDefaultPosition
, wxSize(300, 200),
123 wxNO_BORDER
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
124 m_configurePage
= new ctOutputWindow(m_mainNotebook
, wxID_ANY
, wxDefaultPosition
, wxSize(300, 200),
125 wxNO_BORDER
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
127 #ifdef USE_CONFIG_BROWSER_PAGE
128 m_configBrowserPage
= new ctConfigurationBrowserWindow(m_mainNotebook
, wxID_ANY
, wxDefaultPosition
, wxSize(300, 200),
129 wxNO_BORDER
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
132 m_mainNotebook
->AddPage(m_propertyEditor
, _T("Properties"));
133 #ifdef USE_CONFIG_BROWSER_PAGE
134 m_mainNotebook
->AddPage(m_configBrowserPage
, _T("Configuration Browser"));
136 m_mainNotebook
->AddPage(m_setupPage
, _T("setup.h"));
137 m_mainNotebook
->AddPage(m_configurePage
, _T("configure"));
139 // Need to do this afterwards since wxWin sets the XP background
141 m_propertyEditor
->GetDescriptionWindow()->SetBackgroundColour(ctDESCRIPTION_BACKGROUND_COLOUR
);
143 int sashPos
= wxGetApp().GetSettings().m_mainSashSize
;
144 m_treeSplitterWindow
->SplitVertically(m_configTreeCtrl
, m_mainNotebook
, sashPos
);
146 SetIcon(wxIcon(wxconfigtool_xpm
));
150 #endif // wxUSE_STATUSBAR
152 wxMenuBar
* menuBar
= CreateMenuBar();
155 CreateToolBar(wxNO_BORDER
|wxTB_FLAT
|wxTB_HORIZONTAL
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
156 InitToolBar(GetToolBar());
158 if (wxGetApp().GetSettings().m_showToolBar
)
160 menuBar
->Check(ctID_SHOW_TOOLBAR
, true);
164 menuBar
->Check(ctID_SHOW_TOOLBAR
, false);
165 GetToolBar()->Show(false);
170 void ctMainFrame::OnCloseWindow(wxCloseEvent
& event
)
174 if (!GetDocument()->DeleteAllViews() && event
.CanVeto())
183 m_findDialog
->Destroy();
190 wxGetApp().GetSettings().m_frameStatus
= ctSHOW_STATUS_MAXIMIZED
;
191 else if (IsIconized())
192 wxGetApp().GetSettings().m_frameStatus
= ctSHOW_STATUS_MINIMIZED
;
194 wxGetApp().GetSettings().m_frameStatus
= ctSHOW_STATUS_NORMAL
;
196 // Must delete this now since the DLL loading library will be
197 // uninitialised by the time the app object is deleted
198 wxGetApp().ClearHelpControllers();
200 if (!IsMaximized() && !IsIconized())
202 wxGetApp().GetSettings().m_frameSize
= GetRect();
203 wxGetApp().GetSettings().m_mainSashSize
= m_treeSplitterWindow
->GetSashPosition();
209 void ctMainFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
211 wxString msg
= wxGetApp().GetSettings().GetAppName() + wxT(" (c) Julian Smart");
212 wxString caption
= wxT("About ") + wxGetApp().GetSettings().GetAppName();
213 wxMessageBox(msg
, caption
, wxOK
|wxICON_INFORMATION
);
216 void ctMainFrame::OnOpen(wxCommandEvent
& event
)
218 wxGetApp().GetDocManager()->OnFileOpen(event
);
221 void ctMainFrame::OnNew(wxCommandEvent
& event
)
223 wxGetApp().GetDocManager()->OnFileNew(event
);
226 void ctMainFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
231 void ctMainFrame::OnSettings(wxCommandEvent
& WXUNUSED(event
))
233 wxGetApp().GetSettings().ShowSettingsDialog();
236 void ctMainFrame::InitToolBar(wxToolBar
* toolBar
)
238 toolBar
->SetHelpText(wxT("The toolbar gives you easy access to commonly used commands."));
241 wxBitmap toolBarBitmaps
[20];
243 toolBarBitmaps
[0] = wxBitmap(new_xpm
);
244 toolBarBitmaps
[1] = wxBitmap(open_xpm
);
245 toolBarBitmaps
[2] = wxBitmap(save_xpm
);
246 toolBarBitmaps
[3] = wxBitmap(copy_xpm
);
247 toolBarBitmaps
[4] = wxBitmap(cut_xpm
);
248 toolBarBitmaps
[5] = wxBitmap(paste_xpm
);
249 toolBarBitmaps
[6] = wxBitmap(go_xpm
);
250 toolBarBitmaps
[7] = wxBitmap(help_xpm
);
251 toolBarBitmaps
[10] = wxBitmap(undo_xpm
);
252 toolBarBitmaps
[11] = wxBitmap(redo_xpm
);
253 toolBarBitmaps
[12] = wxBitmap(help_xpm
);
254 toolBarBitmaps
[13] = wxBitmap(helpcs_xpm
);
256 toolBar
->AddTool(wxID_NEW
, toolBarBitmaps
[0], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("New project"));
257 toolBar
->AddTool(wxID_OPEN
, toolBarBitmaps
[1], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("Open project"));
258 toolBar
->AddTool(wxID_SAVE
, toolBarBitmaps
[2], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("Save project"));
260 toolBar
->AddSeparator();
261 toolBar
->AddTool(wxID_CUT
, toolBarBitmaps
[4], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("Cut"));
262 toolBar
->AddTool(wxID_COPY
, toolBarBitmaps
[3], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("Copy"));
263 toolBar
->AddTool(wxID_PASTE
, toolBarBitmaps
[5], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("Paste"));
264 toolBar
->AddSeparator();
265 toolBar
->AddTool(wxID_UNDO
, toolBarBitmaps
[10], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("Undo"));
266 toolBar
->AddTool(wxID_REDO
, toolBarBitmaps
[11], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("Redo"));
267 toolBar
->AddSeparator();
268 toolBar
->AddTool(ctID_GO
, toolBarBitmaps
[6], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("Save setup.h or configurewx.sh"));
269 toolBar
->AddSeparator();
270 toolBar
->AddTool(ctID_ITEM_HELP
, toolBarBitmaps
[12], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("Show help for this option"));
271 toolBar
->AddTool(wxID_HELP_CONTEXT
, toolBarBitmaps
[13], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("Show help on the clicked item"));
273 // after adding the buttons to the toolbar, must call Realize() to reflect
278 wxMenuBar
* ctMainFrame::CreateMenuBar()
281 wxMenu
*fileMenu
= new wxMenu
;
283 wxGetApp().GetFileHistory().UseMenu(fileMenu
);
285 fileMenu
->Append(wxID_NEW
, wxT("&New...\tCtrl+N"), wxT("Create a new settings document"));
286 fileMenu
->Append(wxID_OPEN
, wxT("&Open...\tCtrl+O"), wxT("Open a settings document"));
287 fileMenu
->Append(wxID_CLOSE
, wxT("&Close\tCtrl+W"), wxT("Close the current settings document"));
288 fileMenu
->AppendSeparator();
289 fileMenu
->Append(wxID_SAVE
, wxT("&Save\tCtrl+S"), wxT("Save the settings document"));
290 fileMenu
->Append(wxID_SAVEAS
, wxT("&Save As..."), wxT("Save the settings document under a new filename"));
291 fileMenu
->AppendSeparator();
292 fileMenu
->Append(ctID_SAVE_SETUP_FILE
, wxT("Save Setup.&h...\tCtrl+H"), wxT("Save the setup.h file"));
293 fileMenu
->Append(ctID_SAVE_CONFIGURE_COMMAND
, wxT("Save Configure Script...\tCtrl+G"), wxT("Save the configure script file"));
294 fileMenu
->AppendSeparator();
295 fileMenu
->Append(ctID_GO
, wxT("&Go\tF5"), wxT("Quick-save the setup.h or configure.sh file"));
296 fileMenu
->AppendSeparator();
297 fileMenu
->Append(wxID_EXIT
, wxT("E&xit\tAlt+F4"), wxT("Exit the application"));
299 wxGetApp().GetDocManager()->FileHistoryUseMenu(fileMenu
);
301 wxMenu
*editMenu
= new wxMenu
;
303 editMenu
->Append(wxID_UNDO
, _("&Undo\tCtrl+Z"));
304 editMenu
->Append(wxID_REDO
, _("&Redo\tCtrl+Y"));
305 editMenu
->AppendSeparator();
306 editMenu
->Append(wxID_COPY
, _("&Copy\tCtrl+C"));
307 editMenu
->Append(wxID_CUT
, _("Cu&t\tCtrl+X"));
308 editMenu
->Append(wxID_PASTE
, _("&Paste\tCtrl+V"));
309 editMenu
->AppendSeparator();
311 wxMenu
* itemMenu
= new wxMenu
;
312 itemMenu
->Append(ctID_ADD_ITEM_CHECKBOX
, _("Add &Checkbox Option"), _("Add a checkbox configuration option"));
313 itemMenu
->Append(ctID_ADD_ITEM_RADIOBUTTON
, _("Add &Radio Button Option"), _("Add a radio button configuration option"));
314 // TODO. However we can also simply use custom properties;
315 // but then the C++ code has to be special-cased.
316 // itemMenu->Append(ctID_ADD_ITEM_STRING, _("Add &String Option"), _("Add a string configuration option"));
317 itemMenu
->Append(ctID_ADD_ITEM_GROUP
, _("Add &Group Option"), _("Add a group configuration option"));
318 itemMenu
->Append(ctID_ADD_ITEM_CHECK_GROUP
, _("Add Chec&k Group Option"), _("Add a check group configuration option"));
319 itemMenu
->Append(ctID_ADD_ITEM_RADIO_GROUP
, _("Add Rad&io Group Option"), _("Add a radio group configuration option"));
321 editMenu
->Append(ctID_ADD_ITEM
, wxT("Add &Option"), itemMenu
, _("Add a configuration option"));
322 editMenu
->AppendSeparator();
324 wxMenu
* propertyMenu
= new wxMenu
;
325 propertyMenu
->Append(ctID_ADD_CUSTOM_PROPERTY
, _("&Add Custom Property"), _("Adds a custom property to the current option"));
326 propertyMenu
->Append(ctID_EDIT_CUSTOM_PROPERTY
, _("&Edit Custom Property"), _("Edits the currently selected custom property"));
327 propertyMenu
->Append(ctID_DELETE_CUSTOM_PROPERTY
, _("&Delete Custom Property"), _("Deletes the currently selected custom property"));
328 editMenu
->Append(ctID_CUSTOM_PROPERTY
, _("Custom P&roperty"), propertyMenu
, _("Custom property commands"));
330 editMenu
->AppendSeparator();
331 editMenu
->Append(ctID_DELETE_ITEM
, _("&Delete Option"), _("Delete a configuration option"));
332 editMenu
->Append(ctID_RENAME_ITEM
, _("&Rename Option"), _("Rename a configuration option"));
333 editMenu
->AppendSeparator();
334 editMenu
->Append(wxID_FIND
, _("&Find...\tCtrl+F"), _("Search for a string in the settings document"));
336 // Save for the command processor.
337 m_editMenu
= editMenu
;
339 wxMenu
*viewMenu
= new wxMenu
;
340 viewMenu
->Append(ctID_SHOW_TOOLBAR
, wxT("Show &Toolbar"), wxT("Toggle the toolbar on and off"),
342 viewMenu
->Append(ctID_SETTINGS
, wxT("&Settings...\tCtrl+T"), wxT("Show application settings"));
344 wxMenu
*helpMenu
= new wxMenu
;
345 helpMenu
->Append(wxID_HELP
, wxT("&Help Contents"), wxT("Show Configuration Tool help"));
346 helpMenu
->Append(ctID_REFERENCE_CONTENTS
, wxT("&wxWidgets Help Contents"), wxT("Show wxWidgets reference"));
347 helpMenu
->AppendSeparator();
348 helpMenu
->Append(ctID_ITEM_HELP
, wxT("&Configuration Option Help\tF1"), wxT("Show help for the selected option"));
349 helpMenu
->Append(wxID_HELP_CONTEXT
, wxT("&What's this?"), wxT("Show help on the clicked item"));
350 helpMenu
->AppendSeparator();
351 helpMenu
->Append(wxID_ABOUT
, wxT("&About..."), wxT("Show details about this application"));
353 wxMenuBar
*menuBar
= new wxMenuBar
;
355 menuBar
->Append(fileMenu
, wxT("&File"));
356 menuBar
->Append(editMenu
, wxT("&Edit"));
357 menuBar
->Append(viewMenu
, wxT("&View"));
358 menuBar
->Append(helpMenu
, wxT("&Help"));
361 wxConfig
config(wxGetApp().GetSettings().GetAppName(), wxT("wxWidgets"));
362 config
.SetPath(wxT("FileHistory/"));
363 wxGetApp().GetDocManager()->FileHistoryLoad(config
);
369 /// Handles the Show Toolbar menu event.
370 void ctMainFrame::OnShowToolbar(wxCommandEvent
& WXUNUSED(event
))
372 wxGetApp().GetSettings().m_showToolBar
= !wxGetApp().GetSettings().m_showToolBar
;
373 GetToolBar()->Show(wxGetApp().GetSettings().m_showToolBar
);
377 /// Handles the Help Contents menu event.
378 void ctMainFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
380 wxGetApp().GetHelpController().DisplayContents();
383 /// Handles context help
384 void ctMainFrame::OnContextHelp(wxCommandEvent
& WXUNUSED(event
))
386 wxContextHelp contextHelp
;
389 /// Handles the Help Contents menu event for the reference manual.
390 void ctMainFrame::OnReferenceHelp(wxCommandEvent
& WXUNUSED(event
))
392 wxGetApp().GetReferenceHelpController().DisplayContents();
395 /// Resizes the main frame according to the
396 /// state of the toolbar
397 void ctMainFrame::ResizeFrame()
400 wxSizeEvent
event(GetSize(), GetId());
401 this->ProcessEvent(event
);
404 /// Update the frame title.
405 void ctMainFrame::UpdateFrameTitle()
411 void ctMainFrame::OnUpdateDisable(wxUpdateUIEvent
& event
)
413 event
.Enable( false );
417 * ctOutputWindow represents a page showing a setup.h file or config command.
420 IMPLEMENT_CLASS(ctOutputWindow
, wxPanel
)
422 BEGIN_EVENT_TABLE(ctOutputWindow
, wxPanel
)
423 EVT_BUTTON(wxID_COPY
, ctOutputWindow::OnCopyToClipboard
)
424 EVT_BUTTON(wxID_SAVE
, ctOutputWindow::OnSaveText
)
425 EVT_BUTTON(ctID_REGENERATE
, ctOutputWindow::OnRegenerate
)
426 EVT_UPDATE_UI(wxID_SAVE
, ctOutputWindow::OnUpdateSaveText
)
427 EVT_UPDATE_UI(ctID_REGENERATE
, ctOutputWindow::OnUpdateRegenerate
)
428 EVT_UPDATE_UI(wxID_COPY
, ctOutputWindow::OnUpdateCopy
)
431 ctOutputWindow::ctOutputWindow(wxWindow
* parent
, wxWindowID id
,
432 const wxPoint
& pos
, const wxSize
& size
, long style
):
433 wxPanel(parent
, id
, pos
, size
, style
)
436 m_filenameCtrl
= NULL
;
441 ctOutputWindow::~ctOutputWindow()
445 /// Initialise the windows.
446 void ctOutputWindow::CreateWindows()
448 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
450 wxBoxSizer
*item2
= new wxBoxSizer( wxHORIZONTAL
);
451 item0
->Add( item2
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
, 5 );
453 wxButton
*item4
= new wxButton( this, wxID_COPY
, _("&Copy"), wxDefaultPosition
, wxDefaultSize
, 0 );
454 item2
->Add( item4
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxLEFT
|wxTOP
|wxBOTTOM
|wxRIGHT
, 5 );
455 item4
->SetHelpText(_("Copies the selection or whole file to the clipboard."));
457 wxButton
*item5
= new wxButton( this, ctID_REGENERATE
, _("Re&generate"), wxDefaultPosition
, wxDefaultSize
, 0 );
458 item2
->Add( item5
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxTOP
|wxBOTTOM
|wxRIGHT
, 5 );
459 item5
->SetHelpText(_("Regenerates the code."));
462 m_filenameCtrl
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, wxSUNKEN_BORDER
|wxTE_READONLY
);
463 item2
->Add( m_filenameCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxTOP
|wxBOTTOM
|wxRIGHT
, 5 );
464 m_filenameCtrl
->SetHelpText(_("Shows the filename where the code is being saved."));
466 m_filenameCtrl
= NULL
;
470 m_codeCtrl
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(100, 100), wxTE_RICH
|wxTE_MULTILINE
|wxSUNKEN_BORDER
);
471 item0
->Add( m_codeCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5 );
473 SetAutoLayout( true );
477 /// Copies the text to the clipboard.
478 void ctOutputWindow::OnCopyToClipboard(wxCommandEvent
& WXUNUSED(event
))
480 // Try to copy the selection first
481 long int selFrom
, selTo
;
482 m_codeCtrl
->GetSelection(& selFrom
, & selTo
);
483 if (selFrom
!= selTo
)
489 // Copy the whole amount
490 if (!wxTheClipboard
->Open())
492 wxMessageBox(_("Sorry, could not open the clipboard."), _("Clipboard problem"), wxICON_EXCLAMATION
|wxOK
);
496 wxString
value(m_codeCtrl
->GetValue());
498 value
.Replace(_T("\n"), _T("\r\n"));
500 wxTextDataObject
*data
= new wxTextDataObject( value
);
502 if (!wxTheClipboard
->SetData( data
))
504 wxTheClipboard
->Close();
505 wxMessageBox(_("Sorry, could not copy to the clipboard."), _("Clipboard problem"), wxICON_EXCLAMATION
|wxOK
);
509 wxTheClipboard
->Close();
513 /// Sets the code in the text control.
514 void ctOutputWindow::SetText(const wxString
& text
)
517 m_codeCtrl
->SetValue(text
);
520 /// Sets the filename.
521 void ctOutputWindow::SetFilename(const wxString
& filename
)
524 m_filenameCtrl
->SetValue(filename
);
528 void ctOutputWindow::OnSaveText(wxCommandEvent
& WXUNUSED(event
))
530 if (m_codeCtrl
->IsModified())
532 wxString
filename(m_filenameCtrl
->GetValue());
533 if (!filename
.IsEmpty())
535 m_codeCtrl
->SaveFile(filename
);
536 m_codeCtrl
->DiscardEdits();
541 void ctOutputWindow::OnUpdateSaveText(wxUpdateUIEvent
& event
)
543 event
.Enable(m_doc
&& m_codeCtrl
&& m_codeCtrl
->IsModified());
546 void ctOutputWindow::OnRegenerate(wxCommandEvent
& WXUNUSED(event
))
550 ctConfigToolView
* view
= (ctConfigToolView
*) m_doc
->GetFirstView();
551 view
->RegenerateSetup();
555 void ctOutputWindow::OnUpdateRegenerate(wxUpdateUIEvent
& event
)
557 event
.Enable( m_doc
!= NULL
);
560 void ctOutputWindow::OnUpdateCopy(wxUpdateUIEvent
& event
)
562 event
.Enable( m_doc
!= NULL
);