1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/splitter.h"
25 #include "wx/cshelp.h"
26 #include "wx/html/htmlwin.h"
27 #include "wx/notebook.h"
28 #include "wx/dataobj.h"
29 #include "wx/clipbrd.h"
30 #include "wx/stockitem.h"
31 #include "wxconfigtool.h"
32 #include "mainframe.h"
33 #include "appsettings.h"
35 #include "configtree.h"
36 #include "propeditor.h"
37 #include "configtooldoc.h"
38 #include "configtoolview.h"
39 #include "configbrowser.h"
41 #include "bitmaps/wxconfigtool.xpm"
43 #include "bitmaps/copy.xpm"
44 #include "bitmaps/cut.xpm"
45 #include "bitmaps/paste.xpm"
46 #include "bitmaps/open.xpm"
47 #include "bitmaps/save.xpm"
48 #include "bitmaps/new.xpm"
49 #include "bitmaps/help.xpm"
50 #include "bitmaps/undo.xpm"
51 #include "bitmaps/redo.xpm"
52 #include "bitmaps/helpcs.xpm"
53 #include "bitmaps/go.xpm"
55 IMPLEMENT_CLASS(ctMainFrame
, wxDocParentFrame
)
57 BEGIN_EVENT_TABLE(ctMainFrame
, wxDocParentFrame
)
58 EVT_CLOSE(ctMainFrame::OnCloseWindow
)
59 EVT_MENU(wxID_ABOUT
, ctMainFrame::OnAbout
)
60 EVT_MENU(wxID_OPEN
, ctMainFrame::OnOpen
)
61 EVT_MENU(wxID_NEW
, ctMainFrame::OnNew
)
62 EVT_MENU(wxID_EXIT
, ctMainFrame::OnExit
)
63 EVT_MENU(ctID_SETTINGS
, ctMainFrame::OnSettings
)
64 EVT_MENU(ctID_SHOW_TOOLBAR
, ctMainFrame::OnShowToolbar
)
65 EVT_MENU(wxID_HELP
, ctMainFrame::OnHelp
)
66 EVT_MENU(ctID_REFERENCE_CONTENTS
, ctMainFrame::OnReferenceHelp
)
67 EVT_MENU(wxID_HELP_CONTEXT
, ctMainFrame::OnContextHelp
)
69 EVT_UPDATE_UI(ctID_ADD_ITEM_CHECKBOX
, ctMainFrame::OnUpdateDisable
)
70 EVT_UPDATE_UI(ctID_ADD_ITEM_RADIOBUTTON
, ctMainFrame::OnUpdateDisable
)
71 EVT_UPDATE_UI(ctID_ADD_ITEM_GROUP
, ctMainFrame::OnUpdateDisable
)
72 EVT_UPDATE_UI(ctID_ADD_ITEM_CHECK_GROUP
, ctMainFrame::OnUpdateDisable
)
73 EVT_UPDATE_UI(ctID_ADD_ITEM_RADIO_GROUP
, ctMainFrame::OnUpdateDisable
)
74 EVT_UPDATE_UI(ctID_ADD_ITEM_STRING
, ctMainFrame::OnUpdateDisable
)
75 EVT_UPDATE_UI(ctID_DELETE_ITEM
, ctMainFrame::OnUpdateDisable
)
76 EVT_UPDATE_UI(ctID_RENAME_ITEM
, ctMainFrame::OnUpdateDisable
)
77 EVT_UPDATE_UI(wxID_COPY
, ctMainFrame::OnUpdateDisable
)
78 EVT_UPDATE_UI(wxID_CUT
, ctMainFrame::OnUpdateDisable
)
79 EVT_UPDATE_UI(wxID_PASTE
, ctMainFrame::OnUpdateDisable
)
80 EVT_UPDATE_UI(ctID_ITEM_HELP
, ctMainFrame::OnUpdateDisable
)
82 EVT_UPDATE_UI(ctID_ADD_CUSTOM_PROPERTY
, ctMainFrame::OnUpdateDisable
)
83 EVT_UPDATE_UI(ctID_EDIT_CUSTOM_PROPERTY
, ctMainFrame::OnUpdateDisable
)
84 EVT_UPDATE_UI(ctID_DELETE_CUSTOM_PROPERTY
, ctMainFrame::OnUpdateDisable
)
86 EVT_UPDATE_UI(ctID_SAVE_SETUP_FILE
, ctMainFrame::OnUpdateDisable
)
87 EVT_UPDATE_UI(ctID_SAVE_CONFIGURE_COMMAND
, ctMainFrame::OnUpdateDisable
)
89 EVT_UPDATE_UI(wxID_FIND
, ctMainFrame::OnUpdateDisable
)
91 EVT_UPDATE_UI(ctID_GO
, ctMainFrame::OnUpdateDisable
)
94 // Define my frame constructor
95 ctMainFrame::ctMainFrame(wxDocManager
*manager
, wxFrame
*parent
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
, long style
):
96 wxDocParentFrame(manager
, parent
, id
, title
, pos
, size
, style
)
100 m_configurePage
= NULL
;
102 #ifdef USE_CONFIG_BROWSER_PAGE
103 m_configBrowserPage
= NULL
;
105 m_mainNotebook
= NULL
;
108 m_treeSplitterWindow
= new wxSplitterWindow(this, wxID_ANY
, wxDefaultPosition
, wxSize(400, 300),
109 wxSP_3DSASH
|wxSP_3DBORDER
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
|wxSP_NO_XP_THEME
);
111 m_configTreeCtrl
= new ctConfigTreeCtrl(m_treeSplitterWindow
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
,
112 wxTR_HAS_BUTTONS
|wxNO_BORDER
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
114 m_mainNotebook
= new wxNotebook(m_treeSplitterWindow
, wxID_ANY
, wxDefaultPosition
, wxSize(300, 300),
115 wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
117 m_propertyEditor
= new ctPropertyEditor(m_mainNotebook
, wxID_ANY
, wxDefaultPosition
, wxSize(300, 200),
118 wxNO_BORDER
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
119 m_setupPage
= new ctOutputWindow(m_mainNotebook
, wxID_ANY
, wxDefaultPosition
, wxSize(300, 200),
120 wxNO_BORDER
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
121 m_configurePage
= new ctOutputWindow(m_mainNotebook
, wxID_ANY
, wxDefaultPosition
, wxSize(300, 200),
122 wxNO_BORDER
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
124 #ifdef USE_CONFIG_BROWSER_PAGE
125 m_configBrowserPage
= new ctConfigurationBrowserWindow(m_mainNotebook
, wxID_ANY
, wxDefaultPosition
, wxSize(300, 200),
126 wxNO_BORDER
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
129 m_mainNotebook
->AddPage(m_propertyEditor
, _T("Properties"));
130 #ifdef USE_CONFIG_BROWSER_PAGE
131 m_mainNotebook
->AddPage(m_configBrowserPage
, _T("Configuration Browser"));
133 m_mainNotebook
->AddPage(m_setupPage
, _T("setup.h"));
134 m_mainNotebook
->AddPage(m_configurePage
, _T("configure"));
136 // Need to do this afterwards since wxWin sets the XP background
138 m_propertyEditor
->GetDescriptionWindow()->SetBackgroundColour(ctDESCRIPTION_BACKGROUND_COLOUR
);
140 int sashPos
= wxGetApp().GetSettings().m_mainSashSize
;
141 m_treeSplitterWindow
->SplitVertically(m_configTreeCtrl
, m_mainNotebook
, sashPos
);
143 SetIcon(wxIcon(wxconfigtool_xpm
));
147 #endif // wxUSE_STATUSBAR
149 wxMenuBar
* menuBar
= CreateMenuBar();
152 CreateToolBar(wxNO_BORDER
|wxTB_FLAT
|wxTB_HORIZONTAL
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
153 InitToolBar(GetToolBar());
155 if (wxGetApp().GetSettings().m_showToolBar
)
157 menuBar
->Check(ctID_SHOW_TOOLBAR
, true);
161 menuBar
->Check(ctID_SHOW_TOOLBAR
, false);
162 GetToolBar()->Show(false);
167 void ctMainFrame::OnCloseWindow(wxCloseEvent
& event
)
171 if (!GetDocument()->DeleteAllViews() && event
.CanVeto())
180 m_findDialog
->Destroy();
187 wxGetApp().GetSettings().m_frameStatus
= ctSHOW_STATUS_MAXIMIZED
;
188 else if (IsIconized())
189 wxGetApp().GetSettings().m_frameStatus
= ctSHOW_STATUS_MINIMIZED
;
191 wxGetApp().GetSettings().m_frameStatus
= ctSHOW_STATUS_NORMAL
;
193 // Must delete this now since the DLL loading library will be
194 // uninitialised by the time the app object is deleted
195 wxGetApp().ClearHelpControllers();
197 if (!IsMaximized() && !IsIconized())
199 wxGetApp().GetSettings().m_frameSize
= GetRect();
200 wxGetApp().GetSettings().m_mainSashSize
= m_treeSplitterWindow
->GetSashPosition();
206 void ctMainFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
208 wxString msg
= wxGetApp().GetSettings().GetAppName() + wxT(" (c) Julian Smart");
209 wxString caption
= wxT("About ") + wxGetApp().GetSettings().GetAppName();
210 wxMessageBox(msg
, caption
, wxOK
|wxICON_INFORMATION
);
213 void ctMainFrame::OnOpen(wxCommandEvent
& event
)
215 wxGetApp().GetDocManager()->OnFileOpen(event
);
218 void ctMainFrame::OnNew(wxCommandEvent
& event
)
220 wxGetApp().GetDocManager()->OnFileNew(event
);
223 void ctMainFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
228 void ctMainFrame::OnSettings(wxCommandEvent
& WXUNUSED(event
))
230 wxGetApp().GetSettings().ShowSettingsDialog();
233 void ctMainFrame::InitToolBar(wxToolBar
* toolBar
)
235 toolBar
->SetHelpText(wxT("The toolbar gives you easy access to commonly used commands."));
238 wxBitmap toolBarBitmaps
[20];
240 toolBarBitmaps
[0] = wxBitmap(new_xpm
);
241 toolBarBitmaps
[1] = wxBitmap(open_xpm
);
242 toolBarBitmaps
[2] = wxBitmap(save_xpm
);
243 toolBarBitmaps
[3] = wxBitmap(copy_xpm
);
244 toolBarBitmaps
[4] = wxBitmap(cut_xpm
);
245 toolBarBitmaps
[5] = wxBitmap(paste_xpm
);
246 toolBarBitmaps
[6] = wxBitmap(go_xpm
);
247 toolBarBitmaps
[7] = wxBitmap(help_xpm
);
248 toolBarBitmaps
[10] = wxBitmap(undo_xpm
);
249 toolBarBitmaps
[11] = wxBitmap(redo_xpm
);
250 toolBarBitmaps
[12] = wxBitmap(help_xpm
);
251 toolBarBitmaps
[13] = wxBitmap(helpcs_xpm
);
253 toolBar
->AddTool(wxID_NEW
, toolBarBitmaps
[0], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("New project"));
254 toolBar
->AddTool(wxID_OPEN
, toolBarBitmaps
[1], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("Open project"));
255 toolBar
->AddTool(wxID_SAVE
, toolBarBitmaps
[2], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("Save project"));
257 toolBar
->AddSeparator();
258 toolBar
->AddTool(wxID_CUT
, toolBarBitmaps
[4], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxGetStockLabel(wxID_CUT
, false));
259 toolBar
->AddTool(wxID_COPY
, toolBarBitmaps
[3], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxGetStockLabel(wxID_COPY
, false));
260 toolBar
->AddTool(wxID_PASTE
, toolBarBitmaps
[5], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxGetStockLabel(wxID_PASTE
, false));
261 toolBar
->AddSeparator();
262 toolBar
->AddTool(wxID_UNDO
, toolBarBitmaps
[10], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxGetStockLabel(wxID_UNDO
, false));
263 toolBar
->AddTool(wxID_REDO
, toolBarBitmaps
[11], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxGetStockLabel(wxID_REDO
, false));
264 toolBar
->AddSeparator();
265 toolBar
->AddTool(ctID_GO
, toolBarBitmaps
[6], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("Save setup.h or configurewx.sh"));
266 toolBar
->AddSeparator();
267 toolBar
->AddTool(ctID_ITEM_HELP
, toolBarBitmaps
[12], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("Show help for this option"));
268 toolBar
->AddTool(wxID_HELP_CONTEXT
, toolBarBitmaps
[13], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("Show help on the clicked item"));
270 // after adding the buttons to the toolbar, must call Realize() to reflect
275 wxMenuBar
* ctMainFrame::CreateMenuBar()
278 wxMenu
*fileMenu
= new wxMenu
;
280 wxGetApp().GetFileHistory().UseMenu(fileMenu
);
282 fileMenu
->Append(wxID_NEW
, wxGetStockLabel(wxID_NEW
, true, wxT("Ctrl+N")), wxT("Create a new settings document"));
283 fileMenu
->Append(wxID_OPEN
, wxGetStockLabel(wxID_OPEN
, true, wxT("Ctrl+O")), wxT("Open a settings document"));
284 fileMenu
->Append(wxID_CLOSE
, wxGetStockLabel(wxID_CLOSE
, true, wxT("Ctrl+W")), wxT("Close the current settings document"));
285 fileMenu
->AppendSeparator();
286 fileMenu
->Append(wxID_SAVE
, wxGetStockLabel(wxID_SAVE
, true, wxT("Ctrl+S")), wxT("Save the settings document"));
287 fileMenu
->Append(wxID_SAVEAS
, wxGetStockLabel(wxID_SAVEAS
), wxT("Save the settings document under a new filename"));
288 fileMenu
->AppendSeparator();
289 fileMenu
->Append(ctID_SAVE_SETUP_FILE
, wxT("Save Setup.&h...\tCtrl+H"), wxT("Save the setup.h file"));
290 fileMenu
->Append(ctID_SAVE_CONFIGURE_COMMAND
, wxT("Save Configure Script...\tCtrl+G"), wxT("Save the configure script file"));
291 fileMenu
->AppendSeparator();
292 fileMenu
->Append(ctID_GO
, wxT("&Go\tF5"), wxT("Quick-save the setup.h or configure.sh file"));
293 fileMenu
->AppendSeparator();
294 fileMenu
->Append(wxID_EXIT
, wxGetStockLabel(wxID_EXIT
, true, wxT("Alt+F4")), wxT("Exit the application"));
296 wxGetApp().GetDocManager()->FileHistoryUseMenu(fileMenu
);
298 wxMenu
*editMenu
= new wxMenu
;
300 editMenu
->Append(wxID_UNDO
, wxGetStockLabel(wxID_UNDO
, true, wxT("Ctrl+Z")));
301 editMenu
->Append(wxID_REDO
, wxGetStockLabel(wxID_REDO
, true, wxT("Ctrl+Y")));
302 editMenu
->AppendSeparator();
303 editMenu
->Append(wxID_COPY
, wxGetStockLabel(wxID_CLOSE
, true, wxT("Ctrl+C")));
304 editMenu
->Append(wxID_CUT
, wxGetStockLabel(wxID_CUT
, true, wxT("Ctrl+X")));
305 editMenu
->Append(wxID_PASTE
, wxGetStockLabel(wxID_PASTE
, true, wxT("Ctrl+V")));
306 editMenu
->AppendSeparator();
308 wxMenu
* itemMenu
= new wxMenu
;
309 itemMenu
->Append(ctID_ADD_ITEM_CHECKBOX
, _("Add &Checkbox Option"), _("Add a checkbox configuration option"));
310 itemMenu
->Append(ctID_ADD_ITEM_RADIOBUTTON
, _("Add &Radio Button Option"), _("Add a radio button configuration option"));
311 // TODO. However we can also simply use custom properties;
312 // but then the C++ code has to be special-cased.
313 // itemMenu->Append(ctID_ADD_ITEM_STRING, _("Add &String Option"), _("Add a string configuration option"));
314 itemMenu
->Append(ctID_ADD_ITEM_GROUP
, _("Add &Group Option"), _("Add a group configuration option"));
315 itemMenu
->Append(ctID_ADD_ITEM_CHECK_GROUP
, _("Add Chec&k Group Option"), _("Add a check group configuration option"));
316 itemMenu
->Append(ctID_ADD_ITEM_RADIO_GROUP
, _("Add Rad&io Group Option"), _("Add a radio group configuration option"));
318 editMenu
->Append(ctID_ADD_ITEM
, wxT("Add &Option"), itemMenu
, _("Add a configuration option"));
319 editMenu
->AppendSeparator();
321 wxMenu
* propertyMenu
= new wxMenu
;
322 propertyMenu
->Append(ctID_ADD_CUSTOM_PROPERTY
, _("&Add Custom Property"), _("Adds a custom property to the current option"));
323 propertyMenu
->Append(ctID_EDIT_CUSTOM_PROPERTY
, _("&Edit Custom Property"), _("Edits the currently selected custom property"));
324 propertyMenu
->Append(ctID_DELETE_CUSTOM_PROPERTY
, _("&Delete Custom Property"), _("Deletes the currently selected custom property"));
325 editMenu
->Append(ctID_CUSTOM_PROPERTY
, _("Custom P&roperty"), propertyMenu
, _("Custom property commands"));
327 editMenu
->AppendSeparator();
328 editMenu
->Append(ctID_DELETE_ITEM
, _("&Delete Option"), _("Delete a configuration option"));
329 editMenu
->Append(ctID_RENAME_ITEM
, _("&Rename Option"), _("Rename a configuration option"));
330 editMenu
->AppendSeparator();
331 editMenu
->Append(wxID_FIND
, wxGetStockLabel(wxID_FIND
, true, wxT("Ctrl+F")), _("Search for a string in the settings document"));
333 // Save for the command processor.
334 m_editMenu
= editMenu
;
336 wxMenu
*viewMenu
= new wxMenu
;
337 viewMenu
->Append(ctID_SHOW_TOOLBAR
, wxT("Show &Toolbar"), wxT("Toggle the toolbar on and off"),
339 viewMenu
->Append(ctID_SETTINGS
, wxT("&Settings...\tCtrl+T"), wxT("Show application settings"));
341 wxMenu
*helpMenu
= new wxMenu
;
342 helpMenu
->Append(wxID_HELP
, wxT("&Help Contents"), wxT("Show Configuration Tool help"));
343 helpMenu
->Append(ctID_REFERENCE_CONTENTS
, wxT("&wxWidgets Help Contents"), wxT("Show wxWidgets reference"));
344 helpMenu
->AppendSeparator();
345 helpMenu
->Append(ctID_ITEM_HELP
, wxT("&Configuration Option Help\tF1"), wxT("Show help for the selected option"));
346 helpMenu
->Append(wxID_HELP_CONTEXT
, wxT("&What's this?"), wxT("Show help on the clicked item"));
347 helpMenu
->AppendSeparator();
348 helpMenu
->Append(wxID_ABOUT
, wxT("&About..."), wxT("Show details about this application"));
350 wxMenuBar
*menuBar
= new wxMenuBar
;
352 menuBar
->Append(fileMenu
, wxT("&File"));
353 menuBar
->Append(editMenu
, wxT("&Edit"));
354 menuBar
->Append(viewMenu
, wxT("&View"));
355 menuBar
->Append(helpMenu
, wxT("&Help"));
358 wxConfig
config(wxGetApp().GetSettings().GetAppName(), wxT("wxWidgets"));
359 config
.SetPath(wxT("FileHistory/"));
360 wxGetApp().GetDocManager()->FileHistoryLoad(config
);
366 /// Handles the Show Toolbar menu event.
367 void ctMainFrame::OnShowToolbar(wxCommandEvent
& WXUNUSED(event
))
369 wxGetApp().GetSettings().m_showToolBar
= !wxGetApp().GetSettings().m_showToolBar
;
370 GetToolBar()->Show(wxGetApp().GetSettings().m_showToolBar
);
374 /// Handles the Help Contents menu event.
375 void ctMainFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
377 wxGetApp().GetHelpController().DisplayContents();
380 /// Handles context help
381 void ctMainFrame::OnContextHelp(wxCommandEvent
& WXUNUSED(event
))
383 wxContextHelp contextHelp
;
386 /// Handles the Help Contents menu event for the reference manual.
387 void ctMainFrame::OnReferenceHelp(wxCommandEvent
& WXUNUSED(event
))
389 wxGetApp().GetReferenceHelpController().DisplayContents();
392 /// Resizes the main frame according to the
393 /// state of the toolbar
394 void ctMainFrame::ResizeFrame()
397 wxSizeEvent
event(GetSize(), GetId());
398 this->ProcessEvent(event
);
401 /// Update the frame title.
402 void ctMainFrame::UpdateFrameTitle()
408 void ctMainFrame::OnUpdateDisable(wxUpdateUIEvent
& event
)
410 event
.Enable( false );
414 * ctOutputWindow represents a page showing a setup.h file or config command.
417 IMPLEMENT_CLASS(ctOutputWindow
, wxPanel
)
419 BEGIN_EVENT_TABLE(ctOutputWindow
, wxPanel
)
421 EVT_BUTTON(wxID_COPY
, ctOutputWindow::OnCopyToClipboard
)
422 #endif // wxUSE_CLIPBOARD
423 EVT_BUTTON(wxID_SAVE
, ctOutputWindow::OnSaveText
)
424 EVT_BUTTON(ctID_REGENERATE
, ctOutputWindow::OnRegenerate
)
425 EVT_UPDATE_UI(wxID_SAVE
, ctOutputWindow::OnUpdateSaveText
)
426 EVT_UPDATE_UI(ctID_REGENERATE
, ctOutputWindow::OnUpdateRegenerate
)
427 EVT_UPDATE_UI(wxID_COPY
, ctOutputWindow::OnUpdateCopy
)
430 ctOutputWindow::ctOutputWindow(wxWindow
* parent
, wxWindowID id
,
431 const wxPoint
& pos
, const wxSize
& size
, long style
):
432 wxPanel(parent
, id
, pos
, size
, style
)
435 m_filenameCtrl
= NULL
;
440 /// Initialise the windows.
441 void ctOutputWindow::CreateWindows()
443 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
445 wxBoxSizer
*item2
= new wxBoxSizer( wxHORIZONTAL
);
446 item0
->Add( item2
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
, 5 );
448 wxButton
*item4
= new wxButton( this, wxID_COPY
, _("&Copy"), wxDefaultPosition
, wxDefaultSize
, 0 );
449 item2
->Add( item4
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxLEFT
|wxTOP
|wxBOTTOM
|wxRIGHT
, 5 );
450 item4
->SetHelpText(_("Copies the selection or whole file to the clipboard."));
452 wxButton
*item5
= new wxButton( this, ctID_REGENERATE
, _("Re&generate"), wxDefaultPosition
, wxDefaultSize
, 0 );
453 item2
->Add( item5
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxTOP
|wxBOTTOM
|wxRIGHT
, 5 );
454 item5
->SetHelpText(_("Regenerates the code."));
457 m_filenameCtrl
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, wxSUNKEN_BORDER
|wxTE_READONLY
);
458 item2
->Add( m_filenameCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxTOP
|wxBOTTOM
|wxRIGHT
, 5 );
459 m_filenameCtrl
->SetHelpText(_("Shows the filename where the code is being saved."));
461 m_filenameCtrl
= NULL
;
465 m_codeCtrl
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(100, 100), wxTE_RICH
|wxTE_MULTILINE
|wxSUNKEN_BORDER
);
466 item0
->Add( m_codeCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5 );
468 SetAutoLayout( true );
473 /// Copies the text to the clipboard.
474 void ctOutputWindow::OnCopyToClipboard(wxCommandEvent
& WXUNUSED(event
))
476 // Try to copy the selection first
477 long int selFrom
, selTo
;
478 m_codeCtrl
->GetSelection(& selFrom
, & selTo
);
479 if (selFrom
!= selTo
)
485 // Copy the whole amount
486 if (!wxTheClipboard
->Open())
488 wxMessageBox(_("Sorry, could not open the clipboard."), _("Clipboard problem"), wxICON_EXCLAMATION
|wxOK
);
492 wxString
value(m_codeCtrl
->GetValue());
494 value
.Replace(_T("\n"), _T("\r\n"));
496 wxTextDataObject
*data
= new wxTextDataObject( value
);
498 if (!wxTheClipboard
->SetData( data
))
500 wxTheClipboard
->Close();
501 wxMessageBox(_("Sorry, could not copy to the clipboard."), _("Clipboard problem"), wxICON_EXCLAMATION
|wxOK
);
505 wxTheClipboard
->Close();
508 #endif // wxUSE_CLIPBOARD
510 /// Sets the code in the text control.
511 void ctOutputWindow::SetText(const wxString
& text
)
514 m_codeCtrl
->SetValue(text
);
517 /// Sets the filename.
518 void ctOutputWindow::SetFilename(const wxString
& filename
)
521 m_filenameCtrl
->SetValue(filename
);
525 void ctOutputWindow::OnSaveText(wxCommandEvent
& WXUNUSED(event
))
527 if (m_codeCtrl
->IsModified())
529 wxString
filename(m_filenameCtrl
->GetValue());
530 if (!filename
.empty())
532 m_codeCtrl
->SaveFile(filename
);
533 m_codeCtrl
->DiscardEdits();
538 void ctOutputWindow::OnUpdateSaveText(wxUpdateUIEvent
& event
)
540 event
.Enable(m_doc
&& m_codeCtrl
&& m_codeCtrl
->IsModified());
543 void ctOutputWindow::OnRegenerate(wxCommandEvent
& WXUNUSED(event
))
547 ctConfigToolView
* view
= (ctConfigToolView
*) m_doc
->GetFirstView();
548 view
->RegenerateSetup();
552 void ctOutputWindow::OnUpdateRegenerate(wxUpdateUIEvent
& event
)
554 event
.Enable( m_doc
!= NULL
);
557 void ctOutputWindow::OnUpdateCopy(wxUpdateUIEvent
& event
)
559 event
.Enable( m_doc
!= NULL
);