1 /////////////////////////////////////////////////////////////////////////////
2 // Name: configtoolview.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "configtoolview.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
23 #include "wx/wfstream.h"
24 #include "configtoolview.h"
25 #include "configtooldoc.h"
26 #include "configtree.h"
27 #include "wxconfigtool.h"
28 #include "mainframe.h"
29 #include "propeditor.h"
31 #include "custompropertydialog.h"
33 IMPLEMENT_DYNAMIC_CLASS(ctConfigToolView
, wxView
)
35 BEGIN_EVENT_TABLE(ctConfigToolView
, wxView
)
36 EVT_MENU(ctID_ADD_ITEM_CHECKBOX
, ctConfigToolView::OnAddCheckBoxItem
)
37 EVT_MENU(ctID_ADD_ITEM_RADIOBUTTON
, ctConfigToolView::OnAddRadioButtonItem
)
38 EVT_MENU(ctID_ADD_ITEM_GROUP
, ctConfigToolView::OnAddGroupItem
)
39 EVT_MENU(ctID_ADD_ITEM_CHECK_GROUP
, ctConfigToolView::OnAddCheckGroupItem
)
40 EVT_MENU(ctID_ADD_ITEM_RADIO_GROUP
, ctConfigToolView::OnAddRadioGroupItem
)
41 EVT_MENU(ctID_ADD_ITEM_STRING
, ctConfigToolView::OnAddStringItem
)
42 EVT_MENU(ctID_RENAME_ITEM
, ctConfigToolView::OnRenameItem
)
43 EVT_MENU(ctID_DELETE_ITEM
, ctConfigToolView::OnDeleteItem
)
45 EVT_MENU(wxID_COPY
, ctConfigToolView::OnCopy
)
46 EVT_MENU(wxID_CUT
, ctConfigToolView::OnCut
)
47 EVT_MENU(wxID_PASTE
, ctConfigToolView::OnPaste
)
49 EVT_UPDATE_UI(wxID_COPY
, ctConfigToolView::OnUpdateCopy
)
50 EVT_UPDATE_UI(wxID_CUT
, ctConfigToolView::OnUpdateCut
)
51 EVT_UPDATE_UI(wxID_PASTE
, ctConfigToolView::OnUpdatePaste
)
53 EVT_MENU(ctID_ITEM_HELP
, ctConfigToolView::OnItemHelp
)
55 EVT_UPDATE_UI(ctID_ADD_ITEM_CHECKBOX
, ctConfigToolView::OnUpdateAddItem
)
56 EVT_UPDATE_UI(ctID_ADD_ITEM_RADIOBUTTON
, ctConfigToolView::OnUpdateAddItem
)
57 EVT_UPDATE_UI(ctID_ADD_ITEM_GROUP
, ctConfigToolView::OnUpdateAddItem
)
58 EVT_UPDATE_UI(ctID_ADD_ITEM_CHECK_GROUP
, ctConfigToolView::OnUpdateAddItem
)
59 EVT_UPDATE_UI(ctID_ADD_ITEM_RADIO_GROUP
, ctConfigToolView::OnUpdateAddItem
)
60 EVT_UPDATE_UI(ctID_ADD_ITEM_STRING
, ctConfigToolView::OnUpdateAddItem
)
61 EVT_UPDATE_UI(ctID_RENAME_ITEM
, ctConfigToolView::OnUpdateCut
)
62 EVT_UPDATE_UI(ctID_DELETE_ITEM
, ctConfigToolView::OnUpdateCut
)
63 EVT_UPDATE_UI(ctID_ITEM_HELP
, ctConfigToolView::OnUpdateItemHelp
)
65 EVT_MENU(ctID_TREE_COPY
, ctConfigToolView::OnContextCopy
)
66 EVT_MENU(ctID_TREE_CUT
, ctConfigToolView::OnContextCut
)
67 EVT_MENU(ctID_TREE_PASTE_BEFORE
, ctConfigToolView::OnContextPasteBefore
)
68 EVT_MENU(ctID_TREE_PASTE_AFTER
, ctConfigToolView::OnContextPasteAfter
)
69 EVT_MENU(ctID_TREE_PASTE_AS_CHILD
, ctConfigToolView::OnContextPasteAsChild
)
70 EVT_UPDATE_UI(ctID_TREE_COPY
, ctConfigToolView::OnUpdateContextCopy
)
71 EVT_UPDATE_UI(ctID_TREE_CUT
, ctConfigToolView::OnUpdateContextCut
)
72 EVT_UPDATE_UI(ctID_TREE_PASTE_BEFORE
, ctConfigToolView::OnUpdateContextPasteBefore
)
73 EVT_UPDATE_UI(ctID_TREE_PASTE_AFTER
, ctConfigToolView::OnUpdateContextPasteAfter
)
74 EVT_UPDATE_UI(ctID_TREE_PASTE_AS_CHILD
, ctConfigToolView::OnUpdateContextPasteAsChild
)
76 EVT_MENU(ctID_ADD_CUSTOM_PROPERTY
, ctConfigToolView::OnAddCustomProperty
)
77 EVT_MENU(ctID_EDIT_CUSTOM_PROPERTY
, ctConfigToolView::OnEditCustomProperty
)
78 EVT_MENU(ctID_DELETE_CUSTOM_PROPERTY
, ctConfigToolView::OnDeleteCustomProperty
)
79 EVT_UPDATE_UI(ctID_ADD_CUSTOM_PROPERTY
, ctConfigToolView::OnUpdateAddCustomProperty
)
80 EVT_UPDATE_UI(ctID_EDIT_CUSTOM_PROPERTY
, ctConfigToolView::OnUpdateEditCustomProperty
)
81 EVT_UPDATE_UI(ctID_DELETE_CUSTOM_PROPERTY
, ctConfigToolView::OnUpdateDeleteCustomProperty
)
83 EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY
, ctConfigToolView::OnTabSelect
)
85 EVT_MENU(ctID_SAVE_SETUP_FILE
, ctConfigToolView::OnSaveSetupFile
)
86 EVT_MENU(ctID_SAVE_CONFIGURE_COMMAND
, ctConfigToolView::OnSaveConfigureCommand
)
87 EVT_UPDATE_UI(ctID_SAVE_SETUP_FILE
, ctConfigToolView::OnUpdateSaveSetupFile
)
88 EVT_UPDATE_UI(ctID_SAVE_CONFIGURE_COMMAND
, ctConfigToolView::OnUpdateSaveConfigureCommand
)
90 EVT_MENU(wxID_FIND
, ctConfigToolView::OnFind
)
91 EVT_UPDATE_UI(wxID_FIND
, ctConfigToolView::OnUpdateFind
)
93 EVT_MENU(ctID_GO
, ctConfigToolView::OnGo
)
94 EVT_UPDATE_UI(ctID_GO
, ctConfigToolView::OnUpdateGo
)
98 ctConfigToolView::ctConfigToolView()
102 // What to do when a view is created. Creates actual
103 // windows for displaying the view.
104 bool ctConfigToolView::OnCreate(wxDocument
*doc
, long WXUNUSED(flags
) )
106 wxGetApp().GetDocManager()->ActivateView(this, true);
107 wxGetApp().GetMainFrame()->SetDocument((ctConfigToolDoc
*) doc
);
108 wxGetApp().GetMainFrame()->GetSetupPage()->SetDocument((ctConfigToolDoc
*) doc
) ;
109 wxGetApp().GetMainFrame()->GetConfigurePage()->SetDocument((ctConfigToolDoc
*) doc
) ;
114 void ctConfigToolView::OnDraw(wxDC
*WXUNUSED(dc
))
118 void ctConfigToolView::OnUpdate(wxView
*WXUNUSED(sender
), wxObject
*hintObj
)
120 ctConfigToolDoc
* doc
= wxDynamicCast(GetDocument(), ctConfigToolDoc
);
121 ctConfigTreeCtrl
* treeCtrl
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl();
125 wxASSERT (doc
!= NULL
);
127 ctConfigItem
* selItem
= NULL
;
129 wxTreeItemId sel
= treeCtrl
->GetSelection();
132 ctTreeItemData
* data
= (ctTreeItemData
*) treeCtrl
->GetItemData(sel
);
134 selItem
= data
->GetConfigItem() ;
137 ctConfigToolHint
* hint
= (ctConfigToolHint
*) hintObj
;
138 int hintOp
= ctNoHint
;
144 case ctInitialUpdate
:
146 if (doc
&& doc
->GetTopItem())
148 wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->DeleteAllItems();
149 AddItems(wxGetApp().GetMainFrame()->GetConfigTreeCtrl(), doc
->GetTopItem());
150 wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->Expand(doc
->GetTopItem()->GetTreeItemId());
158 wxGetApp().GetMainFrame()->GetPropertyEditor()->ShowItem(selItem
);
164 // TODO: update windows and frame title
167 case ctFilenameChanged
:
169 wxGetApp().GetMainFrame()->UpdateFrameTitle();
174 // TODO: update windows
175 treeCtrl
->DeleteAllItems();
176 wxGetApp().GetMainFrame()->GetPropertyEditor()->ShowItem(NULL
);
181 // ctConfigItem& ti = *(ctConfigItem *)hint->m_item;
182 wxGetApp().GetMainFrame()->GetPropertyEditor()->ShowItem(selItem
);
191 // Clean up windows used for displaying the view.
192 bool ctConfigToolView::OnClose(bool WXUNUSED(deleteWindow
))
194 if (!GetDocument()->Close())
197 ctConfigToolHint
hint(NULL
, ctClear
);
198 GetDocument()->UpdateAllViews (NULL
, & hint
);
200 wxGetApp().GetDocManager()->ActivateView(this, false);
204 wxGetApp().GetMainFrame()->SetDocument(NULL
);
205 wxGetApp().GetMainFrame()->GetSetupPage()->SetDocument(NULL
) ;
206 wxGetApp().GetMainFrame()->GetConfigurePage()->SetDocument(NULL
) ;
211 void ctConfigToolView::OnChangeFilename()
213 if (wxGetApp().GetTopWindow() && GetDocument())
215 wxString
docTitle(wxFileNameFromPath(GetDocument()->GetFilename()));
216 wxStripExtension(docTitle
);
217 GetDocument()->SetTitle(docTitle
);
219 wxString
name(GetDocument()->GetFilename());
220 wxStripExtension(name
);
224 wxString modifiedMarker
;
225 if (GetDocument()->IsModified())
226 modifiedMarker
= wxT("*");
228 title
= docTitle
+ modifiedMarker
+ wxString(wxT(" - ")) + wxGetApp().GetSettings().GetAppName() ;
230 ((wxFrame
*) wxGetApp().GetTopWindow())->SetTitle(title
);
235 void ctConfigToolView::OnUpdateDisable(wxUpdateUIEvent
& event
)
237 event
.Enable( false );
240 void ctConfigToolView::OnUpdateAddItem(wxUpdateUIEvent
& event
)
242 event
.Enable( true );
245 /// Add item and its children to the tree
246 void ctConfigToolView::AddItems(ctConfigTreeCtrl
* treeControl
, ctConfigItem
* item
)
248 SyncItem(treeControl
, item
);
250 int count
= item
->GetChildCount();
252 for (i
= 0; i
< count
; i
++)
254 ctConfigItem
* child
= item
->GetChild(i
);
255 AddItems(treeControl
, child
);
259 /// Gets the tree item in sync with the item
260 void ctConfigToolView::SyncItem(ctConfigTreeCtrl
* treeControl
, ctConfigItem
* item
)
262 if (!item
->GetTreeItemId().IsOk())
264 if (!item
->GetParent())
266 item
->SetTreeItem(treeControl
->AddRoot(_(""), -1, -1, new ctTreeItemData(item
)));
270 // Find the item to insert the new item after.
271 ctConfigItem
* previousItem
= item
->FindPreviousSibling();
272 if (previousItem
&& previousItem
->GetTreeItemId().IsOk())
274 item
->SetTreeItem(treeControl
->InsertItem(item
->GetParent()->GetTreeItemId(),
275 previousItem
->GetTreeItemId(),
276 item
->GetName(), -1, -1, new ctTreeItemData(item
)));
278 else if (!previousItem
&& item
->GetParent()->GetChildCount() > 1
281 // Insert at the beginning
282 item
->SetTreeItem(treeControl
->InsertItem(item
->GetParent()->GetTreeItemId(),
283 (size_t) 0, // Insert at first position
284 item
->GetName(), -1, -1, new ctTreeItemData(item
)));
288 item
->SetTreeItem(treeControl
->AppendItem(item
->GetParent()->GetTreeItemId(),
289 item
->GetName(), -1, -1, new ctTreeItemData(item
)));
294 if (item
->GetTreeItemId().IsOk())
296 treeControl
->SetItemText(item
->GetTreeItemId(), item
->GetName());
300 if (item
->GetType() == ctTypeGroup
)
302 iconId
= treeControl
->GetIconTable().GetIconId(wxT("Group"), 0, item
->IsActive());
304 else if (item
->GetType() == ctTypeCheckGroup
)
306 iconId
= treeControl
->GetIconTable().GetIconId(wxT("CheckGroup"), item
->IsEnabled() ? 0 : 1, item
->IsActive());
308 else if (item
->GetType() == ctTypeRadioGroup
)
310 iconId
= treeControl
->GetIconTable().GetIconId(wxT("RadioGroup"), item
->IsEnabled() ? 0 : 1, item
->IsActive());
312 else if (item
->GetType() == ctTypeBoolCheck
)
314 iconId
= treeControl
->GetIconTable().GetIconId(wxT("Checkbox"), item
->IsEnabled() ? 0 : 1, item
->IsActive());
316 else if (item
->GetType() == ctTypeBoolRadio
)
318 iconId
= treeControl
->GetIconTable().GetIconId(wxT("Radiobutton"), item
->IsEnabled() ? 0 : 1, item
->IsActive());
320 treeControl
->SetItemImage(item
->GetTreeItemId(), iconId
, wxTreeItemIcon_Normal
);
321 treeControl
->SetItemImage(item
->GetTreeItemId(), iconId
, wxTreeItemIcon_Selected
);
323 if (treeControl
->GetSelection() == item
->GetTreeItemId())
325 if (wxGetApp().GetMainFrame()->GetPropertyEditor()->GetItem())
326 wxGetApp().GetMainFrame()->GetPropertyEditor()->UpdateTitle();
332 void ctConfigToolView::OnIconLeftDown(ctConfigTreeCtrl
* treeControl
, ctConfigItem
* item
)
334 if (!item
->IsActive())
337 if (item
->GetType() == ctTypeCheckGroup
||
338 item
->GetType() == ctTypeBoolCheck
||
339 item
->GetType() == ctTypeBoolRadio
||
340 item
->GetType() == ctTypeRadioGroup
343 // Don't toggle a radio button that's already
345 if ((item
->GetType() == ctTypeBoolRadio
|| item
->GetType() == ctTypeRadioGroup
)
346 && item
->IsEnabled())
349 item
->Enable(!item
->IsEnabled());
351 GetDocument()->Modify(true);
354 SyncItem(treeControl
, item
);
357 if ((item
->GetType() == ctTypeBoolRadio
|| item
->GetType() == ctTypeRadioGroup
) && item
->IsEnabled())
359 item
->PropagateRadioButton(considered
);
361 item
->PropagateChange(considered
);
363 // Update the setup.h and configure text
364 if (wxGetApp().GetMainFrame()->GetMainNotebook()->GetSelection() > 0)
371 /// Returns the selected config item, if any.
372 ctConfigItem
* ctConfigToolView::GetSelection()
374 wxTreeCtrl
* treeCtrl
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl();
378 wxTreeItemId sel
= treeCtrl
->GetSelection();
381 ctTreeItemData
* data
= (ctTreeItemData
*) treeCtrl
->GetItemData(sel
);
383 return data
->GetConfigItem() ;
388 /// Add a checkbox item
389 void ctConfigToolView::OnAddCheckBoxItem(wxCommandEvent
& WXUNUSED(event
))
391 AddItem(ctTypeBoolCheck
, _("New checkbox item"));
394 /// Add a radiobutton item
395 void ctConfigToolView::OnAddRadioButtonItem(wxCommandEvent
& WXUNUSED(event
))
397 AddItem(ctTypeBoolRadio
, _("New radio button item"));
401 void ctConfigToolView::OnAddGroupItem(wxCommandEvent
& WXUNUSED(event
))
403 AddItem(ctTypeGroup
, _("New group item"));
406 /// Add a group option item
407 void ctConfigToolView::OnAddCheckGroupItem(wxCommandEvent
& WXUNUSED(event
))
409 AddItem(ctTypeCheckGroup
, _("New check group item"));
412 /// Add a group option item
413 void ctConfigToolView::OnAddRadioGroupItem(wxCommandEvent
& WXUNUSED(event
))
415 AddItem(ctTypeRadioGroup
, _("New radio group item"));
418 /// Add a string item
419 void ctConfigToolView::OnAddStringItem(wxCommandEvent
& WXUNUSED(event
))
421 AddItem(ctTypeString
, _("New string item"));
425 void ctConfigToolView::AddItem(ctConfigType type
, const wxString
& msg
)
427 ctConfigItem
* sel
= GetSelection();
430 wxString name
= wxGetTextFromUser(_("Please enter a name for the new item."),
434 ctConfigItem
* parent
;
435 ctConfigItem
* insertBefore
;
436 if (sel
->CanHaveChildren())
443 parent
= sel
->GetParent();
444 insertBefore
= sel
->FindNextSibling();
447 ctConfigItem
* newItem
= new ctConfigItem(NULL
, type
, name
);
448 newItem
->InitProperties();
450 newItem
->GetDocument()->GetCommandProcessor()->Submit(
451 new ctConfigCommand(msg
, ctCMD_NEW_ELEMENT
, NULL
, newItem
,
452 parent
, insertBefore
));
458 void ctConfigToolView::OnDeleteItem(wxCommandEvent
& WXUNUSED(event
))
460 ctConfigItem
* sel
= GetSelection();
463 wxString
name(sel
->GetName());
465 msg
.Printf(_("Delete %s?"), (const wxChar
*) name
);
466 if (wxYES
== wxMessageBox(msg
, _("Delete item"), wxICON_QUESTION
|wxYES_NO
))
468 wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->Delete(sel
->GetTreeItemId());
474 void ctConfigToolView::OnRenameItem(wxCommandEvent
& WXUNUSED(event
))
476 ctConfigItem
* sel
= GetSelection();
479 wxString name
= wxGetTextFromUser(_("Please enter a new name for the item."),
480 _("Rename item"), sel
->GetName());
484 SyncItem(wxGetApp().GetMainFrame()->GetConfigTreeCtrl(), sel
);
486 ctConfigToolHint
hint(NULL
, ctSelChanged
);
487 GetDocument()->UpdateAllViews (NULL
, & hint
);
492 /// Copy an item to the clipboard
493 void ctConfigToolView::OnCopy(wxCommandEvent
& WXUNUSED(event
))
495 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
496 ctConfigItem
* sel
= GetSelection();
499 doc
->SetClipboardItem(sel
->DeepClone());
503 /// Copy an item to the clipboard and cut the item
504 void ctConfigToolView::OnCut(wxCommandEvent
& WXUNUSED(event
))
506 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
507 ctConfigItem
* sel
= GetSelection();
511 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Cut Config Item"), ctCMD_CUT
,
512 sel
, (ctConfigItem
*) NULL
);
513 doc
->GetCommandProcessor()->Submit(cmd
);
518 /// Paste an item from the clipboard to the tree
519 void ctConfigToolView::OnPaste(wxCommandEvent
& WXUNUSED(event
))
521 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
522 ctConfigItem
* sel
= GetSelection();
523 if (sel
&& doc
->GetClipboardItem())
525 ctConfigItem
* parent
;
526 ctConfigItem
* insertBefore
;
527 if (sel
->CanHaveChildren())
534 parent
= sel
->GetParent();
535 insertBefore
= sel
->FindNextSibling();
538 ctConfigItem
* newItem
= doc
->GetClipboardItem()->DeepClone();
539 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE
,
540 NULL
, newItem
, parent
, insertBefore
);
541 doc
->GetCommandProcessor()->Submit(cmd
);
545 /// Update for copy command
546 void ctConfigToolView::OnUpdateCopy(wxUpdateUIEvent
& event
)
548 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
549 event
.Enable( doc
&& GetSelection() && GetSelection()->GetParent() );
553 void ctConfigToolView::OnUpdateCut(wxUpdateUIEvent
& event
)
555 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
556 event
.Enable( doc
&& GetSelection() && GetSelection()->GetParent() );
560 void ctConfigToolView::OnUpdatePaste(wxUpdateUIEvent
& event
)
562 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
563 event
.Enable( doc
&& doc
->GetClipboardItem() && GetSelection() );
566 /// Copy an item to the clipboard
567 void ctConfigToolView::OnContextCopy(wxCommandEvent
& WXUNUSED(event
))
569 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
570 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
573 doc
->SetClipboardItem(sel
->DeepClone());
577 /// Copy an item to the clipboard and cut the item
578 void ctConfigToolView::OnContextCut(wxCommandEvent
& WXUNUSED(event
))
580 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
581 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
585 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Cut Config Item"), ctCMD_CUT
,
586 sel
, (ctConfigItem
*) NULL
);
587 doc
->GetCommandProcessor()->Submit(cmd
);
592 /// Paste an item from the clipboard to the tree
593 void ctConfigToolView::OnContextPasteBefore(wxCommandEvent
& WXUNUSED(event
))
595 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
596 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
597 if (sel
&& doc
->GetClipboardItem())
599 ctConfigItem
* parent
= sel
->GetParent();
600 ctConfigItem
* insertBefore
= sel
;
602 ctConfigItem
* newItem
= doc
->GetClipboardItem()->DeepClone();
603 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE
,
604 NULL
, newItem
, parent
, insertBefore
);
605 doc
->GetCommandProcessor()->Submit(cmd
);
609 /// Paste an item from the clipboard to the tree
610 void ctConfigToolView::OnContextPasteAfter(wxCommandEvent
& WXUNUSED(event
))
612 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
613 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
614 if (sel
&& doc
->GetClipboardItem())
616 ctConfigItem
* parent
= sel
->GetParent();
617 ctConfigItem
* insertBefore
= sel
->FindNextSibling();
619 ctConfigItem
* newItem
= doc
->GetClipboardItem()->DeepClone();
620 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE
,
621 NULL
, newItem
, parent
, insertBefore
);
622 doc
->GetCommandProcessor()->Submit(cmd
);
626 /// Paste an item from the clipboard to the tree
627 void ctConfigToolView::OnContextPasteAsChild(wxCommandEvent
& WXUNUSED(event
))
629 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
630 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
631 if (sel
&& doc
->GetClipboardItem())
633 if (sel
->CanHaveChildren())
635 ctConfigItem
* parent
= sel
;
636 ctConfigItem
* insertBefore
= NULL
;
638 ctConfigItem
* newItem
= doc
->GetClipboardItem()->DeepClone();
639 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE
,
640 NULL
, newItem
, parent
, insertBefore
);
641 doc
->GetCommandProcessor()->Submit(cmd
);
646 /// Copy an item to the clipboard
647 void ctConfigToolView::OnUpdateContextCopy(wxUpdateUIEvent
& event
)
649 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
650 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
651 event
.Enable( doc
&& sel
&& sel
->GetParent() );
654 /// Copy an item to the clipboard and cut the item
655 void ctConfigToolView::OnUpdateContextCut(wxUpdateUIEvent
& event
)
657 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
658 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
659 event
.Enable( doc
&& sel
&& sel
->GetParent() );
662 /// Paste an item from the clipboard to the tree
663 void ctConfigToolView::OnUpdateContextPasteBefore(wxUpdateUIEvent
& event
)
665 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
666 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
667 event
.Enable( doc
&& sel
&& sel
->GetParent() && doc
->GetClipboardItem() );
670 /// Paste an item from the clipboard to the tree
671 void ctConfigToolView::OnUpdateContextPasteAfter(wxUpdateUIEvent
& event
)
673 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
674 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
675 event
.Enable( doc
&& sel
&& sel
->GetParent() && doc
->GetClipboardItem() );
678 /// Paste an item from the clipboard to the tree
679 void ctConfigToolView::OnUpdateContextPasteAsChild(wxUpdateUIEvent
& event
)
681 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
682 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
683 event
.Enable( doc
&& sel
&& sel
->CanHaveChildren() && doc
->GetClipboardItem() );
687 void ctConfigToolView::OnItemHelp(wxCommandEvent
& WXUNUSED(event
))
689 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
690 if ( doc
&& GetSelection() )
692 wxString helpTopic
= GetSelection()->GetPropertyString(wxT("help-topic"));
693 if (!helpTopic
.IsEmpty())
695 wxGetApp().GetReferenceHelpController().DisplaySection(helpTopic
);
701 void ctConfigToolView::OnUpdateItemHelp(wxUpdateUIEvent
& event
)
703 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
704 event
.Enable( doc
&& GetSelection() );
707 /// Add a custom property
708 void ctConfigToolView::OnAddCustomProperty(wxCommandEvent
& WXUNUSED(event
))
710 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
711 ctConfigItem
* sel
= GetSelection();
712 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
713 if (doc
&& sel
&& editor
)
715 ctCustomPropertyDialog
dialog(wxGetApp().GetMainFrame(),
716 wxID_ANY
, _("Add a custom property"));
717 if (dialog
.ShowModal() == wxID_OK
)
719 wxString name
= dialog
.GetPropertyName();
720 wxString type
= dialog
.GetPropertyType();
721 wxString descr
= dialog
.GetPropertyDescription();
722 wxString editorType
= dialog
.GetEditorType();
723 wxArrayString choices
= dialog
.GetChoices();
725 if (sel
->GetProperties().FindProperty(name
))
727 wxMessageBox(_("Sorry, this name already exists."), _T("Add custom property"),
728 wxOK
|wxICON_INFORMATION
);
731 ctProperty
* property
= new ctProperty
;
732 if (type
== wxT("bool"))
733 property
->GetVariant() = wxVariant(false, name
);
734 else if (type
== wxT("double"))
735 property
->GetVariant() = wxVariant((double) 0.0, name
);
736 else if (type
== wxT("long"))
737 property
->GetVariant() = wxVariant((long) 0, name
);
739 property
->GetVariant() = wxVariant(wxT(""), name
);
740 property
->SetCustom(true);
741 property
->SetDescription(descr
);
742 property
->SetChoices(choices
);
743 property
->SetEditorType(editorType
);
745 sel
->GetProperties().AddProperty(property
);
746 editor
->ShowItem(sel
);
752 /// Edit a custom property
753 void ctConfigToolView::OnEditCustomProperty(wxCommandEvent
& WXUNUSED(event
))
755 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
756 ctConfigItem
* sel
= GetSelection();
757 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
758 if (doc
&& sel
&& editor
)
761 ctProperty
* property
= editor
->FindSelectedProperty(row
) ;
762 if (property
&& property
->IsCustom())
764 wxString oldName
= property
->GetName();
765 wxString oldDescription
= property
->GetDescription();
766 wxString oldType
= property
->GetVariant().GetType();
767 wxString oldEditorType
= property
->GetEditorType();
768 wxArrayString oldChoices
= property
->GetChoices();
770 ctCustomPropertyDialog
dialog(wxGetApp().GetMainFrame(),
771 wxID_ANY
, _("Edit custom property"));
772 dialog
.SetPropertyName(oldName
);
773 dialog
.SetPropertyType(oldType
);
774 dialog
.SetPropertyDescription(oldDescription
);
775 if (dialog
.ShowModal() == wxID_OK
)
777 wxString name
= dialog
.GetPropertyName();
778 wxString type
= dialog
.GetPropertyType();
779 wxString editorType
= dialog
.GetEditorType();
780 wxArrayString choices
= dialog
.GetChoices();
781 wxString descr
= dialog
.GetPropertyDescription();
783 if (name
!= oldName
&& sel
->GetProperties().FindProperty(name
))
785 wxMessageBox(_("Sorry, this name already exists."), _T("Add custom property"),
786 wxOK
|wxICON_INFORMATION
);
791 if (type
== wxT("bool"))
792 property
->GetVariant() = wxVariant(false, name
);
793 else if (type
== wxT("double"))
794 property
->GetVariant() = wxVariant((double) 0.0, name
);
795 else if (type
== wxT("long"))
796 property
->GetVariant() = wxVariant((long) 0, name
);
798 property
->GetVariant() = wxVariant(wxT(""), name
);
801 property
->GetVariant().SetName(name
);
803 if (choices
!= oldChoices
)
804 property
->SetChoices(choices
);
806 if (editorType
!= oldEditorType
)
807 property
->SetEditorType(editorType
);
810 property
->GetVariant().SetName(name
);
812 property
->SetCustom(true);
814 if (descr
!= oldDescription
)
815 property
->SetDescription(descr
);
817 editor
->ShowItem(sel
);
824 /// Delete a custom property
825 void ctConfigToolView::OnDeleteCustomProperty(wxCommandEvent
& WXUNUSED(event
))
827 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
828 ctConfigItem
* sel
= GetSelection();
829 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
830 if (doc
&& sel
&& editor
)
833 ctProperty
* property
= editor
->FindSelectedProperty(row
) ;
834 if (property
&& property
->IsCustom())
836 wxString
name(property
->GetName());
838 msg
.Printf(_("Delete custom property '%s'?"), (const wxChar
*) name
);
839 if (wxYES
== wxMessageBox(msg
, _("Delete property"), wxICON_EXCLAMATION
|wxYES_NO
))
841 sel
->GetProperties().RemoveProperty(property
);
842 editor
->ShowItem(sel
);
850 /// Add a custom property: update event
851 void ctConfigToolView::OnUpdateAddCustomProperty(wxUpdateUIEvent
& event
)
853 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
854 event
.Enable( doc
&& GetSelection() && GetSelection()->GetParent() );
857 /// Edit a custom property: update event
858 void ctConfigToolView::OnUpdateEditCustomProperty(wxUpdateUIEvent
& event
)
860 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
861 ctConfigItem
* sel
= GetSelection();
862 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
864 event
.Enable( doc
&& sel
&& sel
->GetParent() && editor
&&
865 editor
->FindSelectedProperty(row
) &&
866 editor
->FindSelectedProperty(row
)->IsCustom() );
869 /// Delete a custom property: update event
870 void ctConfigToolView::OnUpdateDeleteCustomProperty(wxUpdateUIEvent
& event
)
872 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
873 ctConfigItem
* sel
= GetSelection();
874 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
876 event
.Enable( doc
&& sel
&& sel
->GetParent() && editor
&&
877 editor
->FindSelectedProperty(row
) &&
878 editor
->FindSelectedProperty(row
)->IsCustom() );
881 /// Regenerate setup.h and configure command
882 void ctConfigToolView::RegenerateSetup()
884 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
885 ctOutputWindow
* setupPage
= wxGetApp().GetMainFrame()->GetSetupPage() ;
886 ctOutputWindow
* configurePage
= wxGetApp().GetMainFrame()->GetConfigurePage() ;
888 wxString setupStr
= doc
->GenerateSetup();
889 wxString configureStr
= doc
->GenerateConfigureCommand();
891 setupPage
->SetText(setupStr
);
892 configurePage
->SetText(configureStr
);
895 /// Regenerate if selected a tab
896 void ctConfigToolView::OnTabSelect(wxNotebookEvent
& event
)
898 if (wxGetApp().GetMainFrame()->GetMainNotebook() != event
.GetEventObject())
904 if (event
.GetSelection() > 0)
910 void ctConfigToolView::OnSaveSetupFile(wxCommandEvent
& WXUNUSED(event
))
912 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
913 wxString setupStr
= doc
->GenerateSetup();
915 wxString filename
= _T("setup.h");
916 wxString path
= wxGetApp().GetSettings().m_lastSetupSaveDir
;
918 path
= doc
->GetFrameworkDir(false);
919 wxString wildcard
= _T("Header files (*.h)|*.h|All files (*.*)|*.*");
921 wxFileDialog
dialog(wxTheApp
->GetTopWindow(),
922 _("Save Setup File As"),
924 wildcard
, wxSAVE
|wxOVERWRITE_PROMPT
);
926 if (dialog
.ShowModal() == wxID_OK
)
928 wxString fullPath
= dialog
.GetPath();
929 wxGetApp().GetSettings().m_lastSetupSaveDir
= wxPathOnly(fullPath
);
931 wxFileOutputStream
stream(fullPath
);
934 wxMessageBox(_("Sorry, could not save this file."), _("Save Setup File"), wxICON_EXCLAMATION
|wxOK
);
942 void ctConfigToolView::OnSaveConfigureCommand(wxCommandEvent
& WXUNUSED(event
))
944 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
945 wxString configureStr
= doc
->GenerateConfigureCommand();
947 wxString filename
= _T("configurewx.sh");
948 wxString path
= wxGetApp().GetSettings().m_lastSetupSaveDir
;
950 path
= doc
->GetFrameworkDir(false);
951 wxString wildcard
= _T("Shell script files (*.sh)|*.sh|All files (*.*)|*.*");
953 wxFileDialog
dialog(wxTheApp
->GetTopWindow(),
954 _("Save Configure Command File As"),
956 wildcard
, wxSAVE
|wxOVERWRITE_PROMPT
);
958 if (dialog
.ShowModal() == wxID_OK
)
960 wxString fullPath
= dialog
.GetPath();
961 wxGetApp().GetSettings().m_lastSetupSaveDir
= wxPathOnly(fullPath
);
963 wxFileOutputStream
stream(fullPath
);
966 wxMessageBox(_("Sorry, could not save this file."), _("Save Configure Command File"), wxICON_EXCLAMATION
|wxOK
);
970 stream
<< configureStr
;
974 void ctConfigToolView::OnUpdateSaveSetupFile(wxUpdateUIEvent
& event
)
979 void ctConfigToolView::OnUpdateSaveConfigureCommand(wxUpdateUIEvent
& event
)
985 void ctConfigToolView::OnFind(wxCommandEvent
& WXUNUSED(event
))
987 ctFindReplaceDialog
* dialog
= wxGetApp().GetMainFrame()->GetFindDialog();
995 int style
= wxFR_NOUPDOWN
;
996 wxString
caption(wxT("Find text in settings"));
997 int flags
= wxFR_DOWN
;
998 if (wxGetApp().GetSettings().m_matchCase
)
999 flags
|=wxFR_MATCHCASE
;
1000 if (wxGetApp().GetSettings().m_matchWholeWord
)
1001 flags
|=wxFR_WHOLEWORD
;
1003 ctFindReplaceDialog::sm_findData
.SetFlags(flags
);
1005 dialog
= new ctFindReplaceDialog(wxGetApp().GetMainFrame(), caption
, style
);
1010 /// Update find text
1011 void ctConfigToolView::OnUpdateFind(wxUpdateUIEvent
& event
)
1016 /// Save default file type
1017 void ctConfigToolView::OnGo(wxCommandEvent
& WXUNUSED(event
))
1019 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
1020 wxString path
= wxGetApp().GetSettings().m_lastSetupSaveDir
;
1021 if (!path
.IsEmpty())
1023 if (wxGetApp().GetSettings().m_defaultFileKind
== wxT("Setup file"))
1026 wxString setupStr
= doc
->GenerateSetup();
1028 wxString fullPath
= path
+ wxFILE_SEP_PATH
+ wxT("setup.h");
1029 if (wxFileExists(fullPath
))
1032 msg
.Printf(wxT("Overwrite existing file %s?"), (const wxChar
*) fullPath
);
1033 int ans
= wxMessageBox(msg
, _("Save Setup File"), wxICON_QUESTION
|wxYES_NO
|wxCANCEL
);
1034 if (ans
== wxCANCEL
)
1039 wxFileOutputStream
stream(fullPath
);
1042 wxMessageBox(_("Sorry, could not save this file."), _("Save Setup File"), wxICON_EXCLAMATION
|wxOK
);
1047 else if (wxGetApp().GetSettings().m_defaultFileKind
== wxT("Configure script"))
1050 wxString configureStr
= doc
->GenerateConfigureCommand();
1052 wxString fullPath
= path
+ wxFILE_SEP_PATH
+ wxT("configurewx.sh");
1053 if (wxFileExists(fullPath
))
1056 msg
.Printf(wxT("Overwrite existing file %s?"), (const wxChar
*) fullPath
);
1057 int ans
= wxMessageBox(msg
, _("Save Configure Script"), wxICON_QUESTION
|wxYES_NO
|wxCANCEL
);
1058 if (ans
== wxCANCEL
)
1063 wxFileOutputStream
stream(fullPath
);
1066 wxMessageBox(_("Sorry, could not save this file."), _("Save Configure Script"), wxICON_EXCLAMATION
|wxOK
);
1069 stream
<< configureStr
;
1073 wxMessageBox(wxT("Unrecognised default file type."));
1079 void ctConfigToolView::OnUpdateGo(wxUpdateUIEvent
& event
)
1081 wxString path
= wxGetApp().GetSettings().m_lastSetupSaveDir
;
1082 event
.Enable(!path
.IsEmpty());
1085 //----------------------------------------------------------------------------
1086 // ctFindReplaceDialog
1087 //----------------------------------------------------------------------------
1089 BEGIN_EVENT_TABLE(ctFindReplaceDialog
, wxFindReplaceDialog
)
1090 EVT_FIND(wxID_ANY
, ctFindReplaceDialog::OnFind
)
1091 EVT_FIND_NEXT(wxID_ANY
, ctFindReplaceDialog::OnFind
)
1092 EVT_FIND_CLOSE(wxID_ANY
, ctFindReplaceDialog::OnClose
)
1095 wxFindReplaceData
ctFindReplaceDialog::sm_findData
;
1096 wxString
ctFindReplaceDialog::sm_currentItem
= wxEmptyString
;
1098 ctFindReplaceDialog::ctFindReplaceDialog( wxWindow
*parent
, const wxString
& title
,
1100 wxFindReplaceDialog( parent
, & sm_findData
, title
, style
)
1102 sm_currentItem
= wxEmptyString
;
1105 ((ctMainFrame
*) parent
)->SetFindDialog(this);
1108 void ctFindReplaceDialog::OnFind(wxFindDialogEvent
& event
)
1110 wxString textToFind
= event
.GetFindString();
1111 bool matchCase
= ((event
.GetFlags() & wxFR_MATCHCASE
) != 0);
1112 bool wholeWord
= ((event
.GetFlags() & wxFR_WHOLEWORD
) != 0);
1114 wxGetApp().GetSettings().m_matchCase
= matchCase
;
1115 wxGetApp().GetSettings().m_matchWholeWord
= wholeWord
;
1117 if (!DoFind(textToFind
, matchCase
, wholeWord
))
1119 wxMessageBox(wxT("No more matches."), wxT("Search"), wxOK
|wxICON_INFORMATION
, this);
1123 bool ctFindReplaceDialog::DoFind(const wxString
& textToFind
, bool matchCase
, bool wholeWord
, bool wrap
)
1125 ctConfigToolDoc
* doc
= wxGetApp().GetMainFrame()->GetDocument();
1128 ctConfigToolView
* view
= (ctConfigToolView
*) doc
->GetFirstView();
1130 ctConfigItem
* currentItem
= NULL
;
1131 ctConfigItem
* focusItem
= view
->GetSelection();
1134 focusItem
= doc
->GetTopItem();
1139 if (!sm_currentItem
.IsEmpty())
1141 currentItem
= doc
->GetTopItem()->FindItem(sm_currentItem
);
1144 // If we were at this item last time, skip the first one.
1145 bool skipFirstItem
= (currentItem
== focusItem
);
1146 currentItem
= FindNextItem(doc
, currentItem
, textToFind
, matchCase
, wholeWord
, wrap
,
1151 sm_currentItem
= currentItem
->GetName();
1152 wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->SelectItem(currentItem
->GetTreeItemId());
1157 sm_currentItem
= wxEmptyString
;
1163 ctConfigItem
* ctFindReplaceDialog::FindNextItem(ctConfigToolDoc
* doc
,
1165 const wxString
& text
,
1171 ctConfigItem
* firstInDoc
= NULL
;
1173 wxString
text2(text
);
1177 ctConfigItem
* found
= NULL
;
1178 ctConfigItem
* next
= item
;
1183 // If starting the search from beginning, we can now
1184 // set the value of 'item' in the 2nd iteration without immediately
1185 // dropping out of the while loop because card == next
1186 if (!item
&& (i
> 0))
1189 // We might want to start from this item if skipFirst is false.
1190 if ((i
== 0) && !skipFirst
&& next
)
1194 next
= doc
->FindNextItem(next
, wrap
);
1196 // Save to be used in iteration 2
1197 if ((i
== 0) && !item
)
1202 wxString
str(next
->GetName());
1203 wxString
description(next
->GetPropertyString(wxT("description")));
1204 wxString
notes(next
->GetPropertyString(wxT("notes")));
1208 description
.MakeLower();
1211 if (ctMatchString(str
, text2
, matchWordOnly
) ||
1212 ctMatchString(description
, text2
, matchWordOnly
) ||
1213 ctMatchString(notes
, text2
, matchWordOnly
))
1219 break; // Didn't find an item at all
1223 while (!found
&& item
!= next
);
1225 if (item
== found
&& !firstInDoc
)
1231 void ctFindReplaceDialog::OnClose(wxFindDialogEvent
& event
)
1233 bool matchCase
= ((event
.GetFlags() & wxFR_MATCHCASE
) != 0);
1234 bool wholeWord
= ((event
.GetFlags() & wxFR_WHOLEWORD
) != 0);
1235 wxGetApp().GetSettings().m_matchCase
= matchCase
;
1236 wxGetApp().GetSettings().m_matchWholeWord
= wholeWord
;
1239 ((ctMainFrame
*) GetParent())->SetFindDialog(NULL
);