1 /////////////////////////////////////////////////////////////////////////////
2 // Name: configtoolview.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "configtoolview.h"
16 // Includes other headers for precompiled compilation
23 #include "wx/wfstream.h"
25 #include "configtoolview.h"
26 #include "configtooldoc.h"
27 #include "configtree.h"
28 #include "wxconfigtool.h"
29 #include "mainframe.h"
30 #include "propeditor.h"
32 #include "custompropertydialog.h"
34 IMPLEMENT_DYNAMIC_CLASS(ctConfigToolView
, wxView
)
36 BEGIN_EVENT_TABLE(ctConfigToolView
, wxView
)
37 EVT_MENU(ctID_ADD_ITEM_CHECKBOX
, ctConfigToolView::OnAddCheckBoxItem
)
38 EVT_MENU(ctID_ADD_ITEM_RADIOBUTTON
, ctConfigToolView::OnAddRadioButtonItem
)
39 EVT_MENU(ctID_ADD_ITEM_GROUP
, ctConfigToolView::OnAddGroupItem
)
40 EVT_MENU(ctID_ADD_ITEM_CHECK_GROUP
, ctConfigToolView::OnAddCheckGroupItem
)
41 EVT_MENU(ctID_ADD_ITEM_RADIO_GROUP
, ctConfigToolView::OnAddRadioGroupItem
)
42 EVT_MENU(ctID_ADD_ITEM_STRING
, ctConfigToolView::OnAddStringItem
)
43 EVT_MENU(ctID_RENAME_ITEM
, ctConfigToolView::OnRenameItem
)
44 EVT_MENU(ctID_DELETE_ITEM
, ctConfigToolView::OnDeleteItem
)
46 EVT_MENU(wxID_COPY
, ctConfigToolView::OnCopy
)
47 EVT_MENU(wxID_CUT
, ctConfigToolView::OnCut
)
48 EVT_MENU(wxID_PASTE
, ctConfigToolView::OnPaste
)
50 EVT_UPDATE_UI(wxID_COPY
, ctConfigToolView::OnUpdateCopy
)
51 EVT_UPDATE_UI(wxID_CUT
, ctConfigToolView::OnUpdateCut
)
52 EVT_UPDATE_UI(wxID_PASTE
, ctConfigToolView::OnUpdatePaste
)
54 EVT_MENU(ctID_ITEM_HELP
, ctConfigToolView::OnItemHelp
)
56 EVT_UPDATE_UI(ctID_ADD_ITEM_CHECKBOX
, ctConfigToolView::OnUpdateAddItem
)
57 EVT_UPDATE_UI(ctID_ADD_ITEM_RADIOBUTTON
, ctConfigToolView::OnUpdateAddItem
)
58 EVT_UPDATE_UI(ctID_ADD_ITEM_GROUP
, ctConfigToolView::OnUpdateAddItem
)
59 EVT_UPDATE_UI(ctID_ADD_ITEM_CHECK_GROUP
, ctConfigToolView::OnUpdateAddItem
)
60 EVT_UPDATE_UI(ctID_ADD_ITEM_RADIO_GROUP
, ctConfigToolView::OnUpdateAddItem
)
61 EVT_UPDATE_UI(ctID_ADD_ITEM_STRING
, ctConfigToolView::OnUpdateAddItem
)
62 EVT_UPDATE_UI(ctID_RENAME_ITEM
, ctConfigToolView::OnUpdateCut
)
63 EVT_UPDATE_UI(ctID_DELETE_ITEM
, ctConfigToolView::OnUpdateCut
)
64 EVT_UPDATE_UI(ctID_ITEM_HELP
, ctConfigToolView::OnUpdateItemHelp
)
66 EVT_MENU(ctID_TREE_COPY
, ctConfigToolView::OnContextCopy
)
67 EVT_MENU(ctID_TREE_CUT
, ctConfigToolView::OnContextCut
)
68 EVT_MENU(ctID_TREE_PASTE_BEFORE
, ctConfigToolView::OnContextPasteBefore
)
69 EVT_MENU(ctID_TREE_PASTE_AFTER
, ctConfigToolView::OnContextPasteAfter
)
70 EVT_MENU(ctID_TREE_PASTE_AS_CHILD
, ctConfigToolView::OnContextPasteAsChild
)
71 EVT_UPDATE_UI(ctID_TREE_COPY
, ctConfigToolView::OnUpdateContextCopy
)
72 EVT_UPDATE_UI(ctID_TREE_CUT
, ctConfigToolView::OnUpdateContextCut
)
73 EVT_UPDATE_UI(ctID_TREE_PASTE_BEFORE
, ctConfigToolView::OnUpdateContextPasteBefore
)
74 EVT_UPDATE_UI(ctID_TREE_PASTE_AFTER
, ctConfigToolView::OnUpdateContextPasteAfter
)
75 EVT_UPDATE_UI(ctID_TREE_PASTE_AS_CHILD
, ctConfigToolView::OnUpdateContextPasteAsChild
)
77 EVT_MENU(ctID_ADD_CUSTOM_PROPERTY
, ctConfigToolView::OnAddCustomProperty
)
78 EVT_MENU(ctID_EDIT_CUSTOM_PROPERTY
, ctConfigToolView::OnEditCustomProperty
)
79 EVT_MENU(ctID_DELETE_CUSTOM_PROPERTY
, ctConfigToolView::OnDeleteCustomProperty
)
80 EVT_UPDATE_UI(ctID_ADD_CUSTOM_PROPERTY
, ctConfigToolView::OnUpdateAddCustomProperty
)
81 EVT_UPDATE_UI(ctID_EDIT_CUSTOM_PROPERTY
, ctConfigToolView::OnUpdateEditCustomProperty
)
82 EVT_UPDATE_UI(ctID_DELETE_CUSTOM_PROPERTY
, ctConfigToolView::OnUpdateDeleteCustomProperty
)
84 EVT_NOTEBOOK_PAGE_CHANGED(-1, ctConfigToolView::OnTabSelect
)
86 EVT_MENU(ctID_SAVE_SETUP_FILE
, ctConfigToolView::OnSaveSetupFile
)
87 EVT_MENU(ctID_SAVE_CONFIGURE_COMMAND
, ctConfigToolView::OnSaveConfigureCommand
)
88 EVT_UPDATE_UI(ctID_SAVE_SETUP_FILE
, ctConfigToolView::OnUpdateSaveSetupFile
)
89 EVT_UPDATE_UI(ctID_SAVE_CONFIGURE_COMMAND
, ctConfigToolView::OnUpdateSaveConfigureCommand
)
91 EVT_MENU(wxID_FIND
, ctConfigToolView::OnFind
)
92 EVT_UPDATE_UI(wxID_FIND
, ctConfigToolView::OnUpdateFind
)
94 EVT_MENU(ctID_GO
, ctConfigToolView::OnGo
)
95 EVT_UPDATE_UI(ctID_GO
, ctConfigToolView::OnUpdateGo
)
99 ctConfigToolView::ctConfigToolView()
103 // What to do when a view is created. Creates actual
104 // windows for displaying the view.
105 bool ctConfigToolView::OnCreate(wxDocument
*doc
, long WXUNUSED(flags
) )
107 wxGetApp().GetDocManager()->ActivateView(this, TRUE
);
108 wxGetApp().GetMainFrame()->SetDocument((ctConfigToolDoc
*) doc
);
109 wxGetApp().GetMainFrame()->GetSetupPage()->SetDocument((ctConfigToolDoc
*) doc
) ;
110 wxGetApp().GetMainFrame()->GetConfigurePage()->SetDocument((ctConfigToolDoc
*) doc
) ;
115 void ctConfigToolView::OnDraw(wxDC
*WXUNUSED(dc
))
119 void ctConfigToolView::OnUpdate(wxView
*WXUNUSED(sender
), wxObject
*hintObj
)
121 ctConfigToolDoc
* doc
= wxDynamicCast(GetDocument(), ctConfigToolDoc
);
122 ctConfigTreeCtrl
* treeCtrl
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl();
126 wxASSERT (doc
!= NULL
);
128 ctConfigItem
* selItem
= NULL
;
130 wxTreeItemId sel
= treeCtrl
->GetSelection();
133 ctTreeItemData
* data
= (ctTreeItemData
*) treeCtrl
->GetItemData(sel
);
135 selItem
= data
->GetConfigItem() ;
138 ctConfigToolHint
* hint
= (ctConfigToolHint
*) hintObj
;
139 int hintOp
= ctNoHint
;
145 case ctInitialUpdate
:
147 if (doc
&& doc
->GetTopItem())
149 wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->DeleteAllItems();
150 AddItems(wxGetApp().GetMainFrame()->GetConfigTreeCtrl(), doc
->GetTopItem());
151 wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->Expand(doc
->GetTopItem()->GetTreeItemId());
159 wxGetApp().GetMainFrame()->GetPropertyEditor()->ShowItem(selItem
);
165 // TODO: update windows and frame title
168 case ctFilenameChanged
:
170 wxGetApp().GetMainFrame()->UpdateFrameTitle();
175 // TODO: update windows
176 treeCtrl
->DeleteAllItems();
177 wxGetApp().GetMainFrame()->GetPropertyEditor()->ShowItem(NULL
);
182 // ctConfigItem& ti = *(ctConfigItem *)hint->m_item;
183 wxGetApp().GetMainFrame()->GetPropertyEditor()->ShowItem(selItem
);
192 // Clean up windows used for displaying the view.
193 bool ctConfigToolView::OnClose(bool WXUNUSED(deleteWindow
))
195 if (!GetDocument()->Close())
198 ctConfigToolHint
hint(NULL
, ctClear
);
199 GetDocument()->UpdateAllViews (NULL
, & hint
);
201 wxGetApp().GetDocManager()->ActivateView(this, FALSE
);
205 wxGetApp().GetMainFrame()->SetDocument(NULL
);
206 wxGetApp().GetMainFrame()->GetSetupPage()->SetDocument(NULL
) ;
207 wxGetApp().GetMainFrame()->GetConfigurePage()->SetDocument(NULL
) ;
212 void ctConfigToolView::OnChangeFilename()
214 if (wxGetApp().GetTopWindow() && GetDocument())
216 wxString
docTitle(wxFileNameFromPath(GetDocument()->GetFilename()));
217 wxStripExtension(docTitle
);
218 GetDocument()->SetTitle(docTitle
);
220 wxString
name(GetDocument()->GetFilename());
221 wxStripExtension(name
);
225 wxString modifiedMarker
;
226 if (GetDocument()->IsModified())
227 modifiedMarker
= wxT("*");
229 title
= docTitle
+ modifiedMarker
+ wxString(wxT(" - ")) + wxGetApp().GetSettings().GetAppName() ;
231 ((wxFrame
*) wxGetApp().GetTopWindow())->SetTitle(title
);
236 void ctConfigToolView::OnUpdateDisable(wxUpdateUIEvent
& event
)
238 event
.Enable( FALSE
);
241 void ctConfigToolView::OnUpdateAddItem(wxUpdateUIEvent
& event
)
243 event
.Enable( TRUE
);
246 /// Add item and its children to the tree
247 void ctConfigToolView::AddItems(ctConfigTreeCtrl
* treeControl
, ctConfigItem
* item
)
249 SyncItem(treeControl
, item
);
251 int count
= item
->GetChildCount();
253 for (i
= 0; i
< count
; i
++)
255 ctConfigItem
* child
= item
->GetChild(i
);
256 AddItems(treeControl
, child
);
260 /// Gets the tree item in sync with the item
261 void ctConfigToolView::SyncItem(ctConfigTreeCtrl
* treeControl
, ctConfigItem
* item
)
263 if (!item
->GetTreeItemId().IsOk())
265 if (!item
->GetParent())
267 item
->SetTreeItem(treeControl
->AddRoot(_(""), -1, -1, new ctTreeItemData(item
)));
271 // Find the item to insert the new item after.
272 ctConfigItem
* previousItem
= item
->FindPreviousSibling();
273 if (previousItem
&& previousItem
->GetTreeItemId().IsOk())
275 item
->SetTreeItem(treeControl
->InsertItem(item
->GetParent()->GetTreeItemId(),
276 previousItem
->GetTreeItemId(),
277 item
->GetName(), -1, -1, new ctTreeItemData(item
)));
279 else if (!previousItem
&& item
->GetParent()->GetChildCount() > 1
282 // Insert at the beginning
283 item
->SetTreeItem(treeControl
->InsertItem(item
->GetParent()->GetTreeItemId(),
284 (size_t) 0, // Insert at first position
285 item
->GetName(), -1, -1, new ctTreeItemData(item
)));
289 item
->SetTreeItem(treeControl
->AppendItem(item
->GetParent()->GetTreeItemId(),
290 item
->GetName(), -1, -1, new ctTreeItemData(item
)));
295 if (item
->GetTreeItemId().IsOk())
297 treeControl
->SetItemText(item
->GetTreeItemId(), item
->GetName());
301 if (item
->GetType() == ctTypeGroup
)
303 iconId
= treeControl
->GetIconTable().GetIconId(wxT("Group"), 0, item
->IsActive());
305 else if (item
->GetType() == ctTypeCheckGroup
)
307 iconId
= treeControl
->GetIconTable().GetIconId(wxT("CheckGroup"), item
->IsEnabled() ? 0 : 1, item
->IsActive());
309 else if (item
->GetType() == ctTypeRadioGroup
)
311 iconId
= treeControl
->GetIconTable().GetIconId(wxT("RadioGroup"), item
->IsEnabled() ? 0 : 1, item
->IsActive());
313 else if (item
->GetType() == ctTypeBoolCheck
)
315 iconId
= treeControl
->GetIconTable().GetIconId(wxT("Checkbox"), item
->IsEnabled() ? 0 : 1, item
->IsActive());
317 else if (item
->GetType() == ctTypeBoolRadio
)
319 iconId
= treeControl
->GetIconTable().GetIconId(wxT("Radiobutton"), item
->IsEnabled() ? 0 : 1, item
->IsActive());
321 treeControl
->SetItemImage(item
->GetTreeItemId(), iconId
, wxTreeItemIcon_Normal
);
322 treeControl
->SetItemImage(item
->GetTreeItemId(), iconId
, wxTreeItemIcon_Selected
);
324 if (treeControl
->GetSelection() == item
->GetTreeItemId())
326 if (wxGetApp().GetMainFrame()->GetPropertyEditor()->GetItem())
327 wxGetApp().GetMainFrame()->GetPropertyEditor()->UpdateTitle();
333 void ctConfigToolView::OnIconLeftDown(ctConfigTreeCtrl
* treeControl
, ctConfigItem
* item
)
335 if (!item
->IsActive())
338 if (item
->GetType() == ctTypeCheckGroup
||
339 item
->GetType() == ctTypeBoolCheck
||
340 item
->GetType() == ctTypeBoolRadio
||
341 item
->GetType() == ctTypeRadioGroup
344 // Don't toggle a radio button that's already
346 if ((item
->GetType() == ctTypeBoolRadio
|| item
->GetType() == ctTypeRadioGroup
)
347 && item
->IsEnabled())
350 item
->Enable(!item
->IsEnabled());
352 GetDocument()->Modify(TRUE
);
355 SyncItem(treeControl
, item
);
358 if ((item
->GetType() == ctTypeBoolRadio
|| item
->GetType() == ctTypeRadioGroup
) && item
->IsEnabled())
360 item
->PropagateRadioButton(considered
);
362 item
->PropagateChange(considered
);
364 // Update the setup.h and configure text
365 if (wxGetApp().GetMainFrame()->GetMainNotebook()->GetSelection() > 0)
372 /// Returns the selected config item, if any.
373 ctConfigItem
* ctConfigToolView::GetSelection()
375 wxTreeCtrl
* treeCtrl
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl();
379 wxTreeItemId sel
= treeCtrl
->GetSelection();
382 ctTreeItemData
* data
= (ctTreeItemData
*) treeCtrl
->GetItemData(sel
);
384 return data
->GetConfigItem() ;
389 /// Add a checkbox item
390 void ctConfigToolView::OnAddCheckBoxItem(wxCommandEvent
& WXUNUSED(event
))
392 AddItem(ctTypeBoolCheck
, _("New checkbox item"));
395 /// Add a radiobutton item
396 void ctConfigToolView::OnAddRadioButtonItem(wxCommandEvent
& WXUNUSED(event
))
398 AddItem(ctTypeBoolRadio
, _("New radio button item"));
402 void ctConfigToolView::OnAddGroupItem(wxCommandEvent
& WXUNUSED(event
))
404 AddItem(ctTypeGroup
, _("New group item"));
407 /// Add a group option item
408 void ctConfigToolView::OnAddCheckGroupItem(wxCommandEvent
& WXUNUSED(event
))
410 AddItem(ctTypeCheckGroup
, _("New check group item"));
413 /// Add a group option item
414 void ctConfigToolView::OnAddRadioGroupItem(wxCommandEvent
& WXUNUSED(event
))
416 AddItem(ctTypeRadioGroup
, _("New radio group item"));
419 /// Add a string item
420 void ctConfigToolView::OnAddStringItem(wxCommandEvent
& WXUNUSED(event
))
422 AddItem(ctTypeString
, _("New string item"));
426 void ctConfigToolView::AddItem(ctConfigType type
, const wxString
& msg
)
428 ctConfigItem
* sel
= GetSelection();
431 wxString name
= wxGetTextFromUser(_("Please enter a name for the new item."),
435 ctConfigItem
* parent
;
436 ctConfigItem
* insertBefore
;
437 if (sel
->CanHaveChildren())
444 parent
= sel
->GetParent();
445 insertBefore
= sel
->FindNextSibling();
448 ctConfigItem
* newItem
= new ctConfigItem(NULL
, type
, name
);
449 newItem
->InitProperties();
451 newItem
->GetDocument()->GetCommandProcessor()->Submit(
452 new ctConfigCommand(msg
, ctCMD_NEW_ELEMENT
, NULL
, newItem
,
453 parent
, insertBefore
));
459 void ctConfigToolView::OnDeleteItem(wxCommandEvent
& WXUNUSED(event
))
461 ctConfigItem
* sel
= GetSelection();
464 wxString
name(sel
->GetName());
466 msg
.Printf(_("Delete %s?"), (const wxChar
*) name
);
467 if (wxYES
== wxMessageBox(msg
, _("Delete item"), wxICON_QUESTION
|wxYES_NO
))
469 wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->Delete(sel
->GetTreeItemId());
475 void ctConfigToolView::OnRenameItem(wxCommandEvent
& WXUNUSED(event
))
477 ctConfigItem
* sel
= GetSelection();
480 wxString name
= wxGetTextFromUser(_("Please enter a new name for the item."),
481 _("Rename item"), sel
->GetName());
485 SyncItem(wxGetApp().GetMainFrame()->GetConfigTreeCtrl(), sel
);
487 ctConfigToolHint
hint(NULL
, ctSelChanged
);
488 GetDocument()->UpdateAllViews (NULL
, & hint
);
493 /// Copy an item to the clipboard
494 void ctConfigToolView::OnCopy(wxCommandEvent
& WXUNUSED(event
))
496 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
497 ctConfigItem
* sel
= GetSelection();
500 doc
->SetClipboardItem(sel
->DeepClone());
504 /// Copy an item to the clipboard and cut the item
505 void ctConfigToolView::OnCut(wxCommandEvent
& WXUNUSED(event
))
507 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
508 ctConfigItem
* sel
= GetSelection();
512 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Cut Config Item"), ctCMD_CUT
,
513 sel
, (ctConfigItem
*) NULL
);
514 doc
->GetCommandProcessor()->Submit(cmd
);
519 /// Paste an item from the clipboard to the tree
520 void ctConfigToolView::OnPaste(wxCommandEvent
& WXUNUSED(event
))
522 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
523 ctConfigItem
* sel
= GetSelection();
524 if (sel
&& doc
->GetClipboardItem())
526 ctConfigItem
* parent
;
527 ctConfigItem
* insertBefore
;
528 if (sel
->CanHaveChildren())
535 parent
= sel
->GetParent();
536 insertBefore
= sel
->FindNextSibling();
539 ctConfigItem
* newItem
= doc
->GetClipboardItem()->DeepClone();
540 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE
,
541 NULL
, newItem
, parent
, insertBefore
);
542 doc
->GetCommandProcessor()->Submit(cmd
);
546 /// Update for copy command
547 void ctConfigToolView::OnUpdateCopy(wxUpdateUIEvent
& event
)
549 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
550 event
.Enable( doc
&& GetSelection() && GetSelection()->GetParent() );
554 void ctConfigToolView::OnUpdateCut(wxUpdateUIEvent
& event
)
556 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
557 event
.Enable( doc
&& GetSelection() && GetSelection()->GetParent() );
561 void ctConfigToolView::OnUpdatePaste(wxUpdateUIEvent
& event
)
563 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
564 event
.Enable( doc
&& doc
->GetClipboardItem() && GetSelection() );
567 /// Copy an item to the clipboard
568 void ctConfigToolView::OnContextCopy(wxCommandEvent
& WXUNUSED(event
))
570 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
571 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
574 doc
->SetClipboardItem(sel
->DeepClone());
578 /// Copy an item to the clipboard and cut the item
579 void ctConfigToolView::OnContextCut(wxCommandEvent
& WXUNUSED(event
))
581 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
582 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
586 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Cut Config Item"), ctCMD_CUT
,
587 sel
, (ctConfigItem
*) NULL
);
588 doc
->GetCommandProcessor()->Submit(cmd
);
593 /// Paste an item from the clipboard to the tree
594 void ctConfigToolView::OnContextPasteBefore(wxCommandEvent
& WXUNUSED(event
))
596 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
597 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
598 if (sel
&& doc
->GetClipboardItem())
600 ctConfigItem
* parent
= sel
->GetParent();
601 ctConfigItem
* insertBefore
= sel
;
603 ctConfigItem
* newItem
= doc
->GetClipboardItem()->DeepClone();
604 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE
,
605 NULL
, newItem
, parent
, insertBefore
);
606 doc
->GetCommandProcessor()->Submit(cmd
);
610 /// Paste an item from the clipboard to the tree
611 void ctConfigToolView::OnContextPasteAfter(wxCommandEvent
& WXUNUSED(event
))
613 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
614 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
615 if (sel
&& doc
->GetClipboardItem())
617 ctConfigItem
* parent
= sel
->GetParent();
618 ctConfigItem
* insertBefore
= sel
->FindNextSibling();
620 ctConfigItem
* newItem
= doc
->GetClipboardItem()->DeepClone();
621 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE
,
622 NULL
, newItem
, parent
, insertBefore
);
623 doc
->GetCommandProcessor()->Submit(cmd
);
627 /// Paste an item from the clipboard to the tree
628 void ctConfigToolView::OnContextPasteAsChild(wxCommandEvent
& WXUNUSED(event
))
630 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
631 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
632 if (sel
&& doc
->GetClipboardItem())
634 if (sel
->CanHaveChildren())
636 ctConfigItem
* parent
= sel
;
637 ctConfigItem
* insertBefore
= NULL
;
639 ctConfigItem
* newItem
= doc
->GetClipboardItem()->DeepClone();
640 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE
,
641 NULL
, newItem
, parent
, insertBefore
);
642 doc
->GetCommandProcessor()->Submit(cmd
);
647 /// Copy an item to the clipboard
648 void ctConfigToolView::OnUpdateContextCopy(wxUpdateUIEvent
& event
)
650 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
651 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
652 event
.Enable( doc
&& sel
&& sel
->GetParent() );
655 /// Copy an item to the clipboard and cut the item
656 void ctConfigToolView::OnUpdateContextCut(wxUpdateUIEvent
& event
)
658 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
659 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
660 event
.Enable( doc
&& sel
&& sel
->GetParent() );
663 /// Paste an item from the clipboard to the tree
664 void ctConfigToolView::OnUpdateContextPasteBefore(wxUpdateUIEvent
& event
)
666 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
667 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
668 event
.Enable( doc
&& sel
&& sel
->GetParent() && doc
->GetClipboardItem() );
671 /// Paste an item from the clipboard to the tree
672 void ctConfigToolView::OnUpdateContextPasteAfter(wxUpdateUIEvent
& event
)
674 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
675 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
676 event
.Enable( doc
&& sel
&& sel
->GetParent() && doc
->GetClipboardItem() );
679 /// Paste an item from the clipboard to the tree
680 void ctConfigToolView::OnUpdateContextPasteAsChild(wxUpdateUIEvent
& event
)
682 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
683 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
684 event
.Enable( doc
&& sel
&& sel
->CanHaveChildren() && doc
->GetClipboardItem() );
688 void ctConfigToolView::OnItemHelp(wxCommandEvent
& WXUNUSED(event
))
690 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
691 if ( doc
&& GetSelection() )
693 wxString helpTopic
= GetSelection()->GetPropertyString(wxT("help-topic"));
694 if (!helpTopic
.IsEmpty())
696 wxGetApp().GetReferenceHelpController().DisplaySection(helpTopic
);
702 void ctConfigToolView::OnUpdateItemHelp(wxUpdateUIEvent
& event
)
704 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
705 event
.Enable( doc
&& GetSelection() );
708 /// Add a custom property
709 void ctConfigToolView::OnAddCustomProperty(wxCommandEvent
& WXUNUSED(event
))
711 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
712 ctConfigItem
* sel
= GetSelection();
713 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
714 if (doc
&& sel
&& editor
)
716 ctCustomPropertyDialog
dialog(wxGetApp().GetMainFrame(),
717 -1, _("Add a custom property"));
718 if (dialog
.ShowModal() == wxID_OK
)
720 wxString name
= dialog
.GetPropertyName();
721 wxString type
= dialog
.GetPropertyType();
722 wxString descr
= dialog
.GetPropertyDescription();
723 wxString editorType
= dialog
.GetEditorType();
724 wxArrayString choices
= dialog
.GetChoices();
726 if (sel
->GetProperties().FindProperty(name
))
728 wxMessageBox(_("Sorry, this name already exists."), _T("Add custom property"),
729 wxOK
|wxICON_INFORMATION
);
732 ctProperty
* property
= new ctProperty
;
733 if (type
== wxT("bool"))
734 property
->GetVariant() = wxVariant((bool) FALSE
, name
);
735 else if (type
== wxT("double"))
736 property
->GetVariant() = wxVariant((double) 0.0, name
);
737 else if (type
== wxT("long"))
738 property
->GetVariant() = wxVariant((long) 0, name
);
740 property
->GetVariant() = wxVariant(wxT(""), name
);
741 property
->SetCustom(TRUE
);
742 property
->SetDescription(descr
);
743 property
->SetChoices(choices
);
744 property
->SetEditorType(editorType
);
746 sel
->GetProperties().AddProperty(property
);
747 editor
->ShowItem(sel
);
753 /// Edit a custom property
754 void ctConfigToolView::OnEditCustomProperty(wxCommandEvent
& WXUNUSED(event
))
756 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
757 ctConfigItem
* sel
= GetSelection();
758 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
759 if (doc
&& sel
&& editor
)
762 ctProperty
* property
= editor
->FindSelectedProperty(row
) ;
763 if (property
&& property
->IsCustom())
765 wxString oldName
= property
->GetName();
766 wxString oldDescription
= property
->GetDescription();
767 wxString oldType
= property
->GetVariant().GetType();
768 wxString oldEditorType
= property
->GetEditorType();
769 wxArrayString oldChoices
= property
->GetChoices();
771 ctCustomPropertyDialog
dialog(wxGetApp().GetMainFrame(),
772 -1, _("Edit custom property"));
773 dialog
.SetPropertyName(oldName
);
774 dialog
.SetPropertyType(oldType
);
775 dialog
.SetPropertyDescription(oldDescription
);
776 if (dialog
.ShowModal() == wxID_OK
)
778 wxString name
= dialog
.GetPropertyName();
779 wxString type
= dialog
.GetPropertyType();
780 wxString editorType
= dialog
.GetEditorType();
781 wxArrayString choices
= dialog
.GetChoices();
782 wxString descr
= dialog
.GetPropertyDescription();
784 if (name
!= oldName
&& sel
->GetProperties().FindProperty(name
))
786 wxMessageBox(_("Sorry, this name already exists."), _T("Add custom property"),
787 wxOK
|wxICON_INFORMATION
);
792 if (type
== wxT("bool"))
793 property
->GetVariant() = wxVariant((bool) FALSE
, name
);
794 else if (type
== wxT("double"))
795 property
->GetVariant() = wxVariant((double) 0.0, name
);
796 else if (type
== wxT("long"))
797 property
->GetVariant() = wxVariant((long) 0, name
);
799 property
->GetVariant() = wxVariant(wxT(""), name
);
802 property
->GetVariant().SetName(name
);
804 if (choices
!= oldChoices
)
805 property
->SetChoices(choices
);
807 if (editorType
!= oldEditorType
)
808 property
->SetEditorType(editorType
);
811 property
->GetVariant().SetName(name
);
813 property
->SetCustom(TRUE
);
815 if (descr
!= oldDescription
)
816 property
->SetDescription(descr
);
818 editor
->ShowItem(sel
);
825 /// Delete a custom property
826 void ctConfigToolView::OnDeleteCustomProperty(wxCommandEvent
& WXUNUSED(event
))
828 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
829 ctConfigItem
* sel
= GetSelection();
830 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
831 if (doc
&& sel
&& editor
)
834 ctProperty
* property
= editor
->FindSelectedProperty(row
) ;
835 if (property
&& property
->IsCustom())
837 wxString
name(property
->GetName());
839 msg
.Printf(_("Delete custom property '%s'?"), (const wxChar
*) name
);
840 if (wxYES
== wxMessageBox(msg
, _("Delete property"), wxICON_EXCLAMATION
|wxYES_NO
))
842 sel
->GetProperties().RemoveProperty(property
);
843 editor
->ShowItem(sel
);
851 /// Add a custom property: update event
852 void ctConfigToolView::OnUpdateAddCustomProperty(wxUpdateUIEvent
& event
)
854 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
855 event
.Enable( doc
&& GetSelection() && GetSelection()->GetParent() );
858 /// Edit a custom property: update event
859 void ctConfigToolView::OnUpdateEditCustomProperty(wxUpdateUIEvent
& event
)
861 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
862 ctConfigItem
* sel
= GetSelection();
863 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
865 event
.Enable( doc
&& sel
&& sel
->GetParent() && editor
&&
866 editor
->FindSelectedProperty(row
) &&
867 editor
->FindSelectedProperty(row
)->IsCustom() );
870 /// Delete a custom property: update event
871 void ctConfigToolView::OnUpdateDeleteCustomProperty(wxUpdateUIEvent
& event
)
873 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
874 ctConfigItem
* sel
= GetSelection();
875 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
877 event
.Enable( doc
&& sel
&& sel
->GetParent() && editor
&&
878 editor
->FindSelectedProperty(row
) &&
879 editor
->FindSelectedProperty(row
)->IsCustom() );
882 /// Regenerate setup.h and configure command
883 void ctConfigToolView::RegenerateSetup()
885 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
886 ctOutputWindow
* setupPage
= wxGetApp().GetMainFrame()->GetSetupPage() ;
887 ctOutputWindow
* configurePage
= wxGetApp().GetMainFrame()->GetConfigurePage() ;
889 wxString setupStr
= doc
->GenerateSetup();
890 wxString configureStr
= doc
->GenerateConfigureCommand();
892 setupPage
->SetText(setupStr
);
893 configurePage
->SetText(configureStr
);
896 /// Regenerate if selected a tab
897 void ctConfigToolView::OnTabSelect(wxNotebookEvent
& event
)
899 if (wxGetApp().GetMainFrame()->GetMainNotebook() != event
.GetEventObject())
905 if (event
.GetSelection() > 0)
911 void ctConfigToolView::OnSaveSetupFile(wxCommandEvent
& WXUNUSED(event
))
913 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
914 wxString setupStr
= doc
->GenerateSetup();
916 wxString filename
= _T("setup.h");
917 wxString path
= wxGetApp().GetSettings().m_lastSetupSaveDir
;
919 path
= doc
->GetFrameworkDir(FALSE
);
920 wxString wildcard
= _T("Header files (*.h)|*.h|All files (*.*)|*.*");
922 wxFileDialog
dialog(wxTheApp
->GetTopWindow(),
923 _("Save Setup File As"),
925 wildcard
, wxSAVE
|wxOVERWRITE_PROMPT
);
927 if (dialog
.ShowModal() == wxID_OK
)
929 wxString fullPath
= dialog
.GetPath();
930 wxGetApp().GetSettings().m_lastSetupSaveDir
= wxPathOnly(fullPath
);
932 wxFileOutputStream
stream(fullPath
);
935 wxMessageBox(_("Sorry, could not save this file."), _("Save Setup File"), wxICON_EXCLAMATION
|wxOK
);
943 void ctConfigToolView::OnSaveConfigureCommand(wxCommandEvent
& WXUNUSED(event
))
945 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
946 wxString configureStr
= doc
->GenerateConfigureCommand();
948 wxString filename
= _T("configurewx.sh");
949 wxString path
= wxGetApp().GetSettings().m_lastSetupSaveDir
;
951 path
= doc
->GetFrameworkDir(FALSE
);
952 wxString wildcard
= _T("Shell script files (*.sh)|*.sh|All files (*.*)|*.*");
954 wxFileDialog
dialog(wxTheApp
->GetTopWindow(),
955 _("Save Configure Command File As"),
957 wildcard
, wxSAVE
|wxOVERWRITE_PROMPT
);
959 if (dialog
.ShowModal() == wxID_OK
)
961 wxString fullPath
= dialog
.GetPath();
962 wxGetApp().GetSettings().m_lastSetupSaveDir
= wxPathOnly(fullPath
);
964 wxFileOutputStream
stream(fullPath
);
967 wxMessageBox(_("Sorry, could not save this file."), _("Save Configure Command File"), wxICON_EXCLAMATION
|wxOK
);
971 stream
<< configureStr
;
975 void ctConfigToolView::OnUpdateSaveSetupFile(wxUpdateUIEvent
& event
)
980 void ctConfigToolView::OnUpdateSaveConfigureCommand(wxUpdateUIEvent
& event
)
986 void ctConfigToolView::OnFind(wxCommandEvent
& WXUNUSED(event
))
988 ctFindReplaceDialog
* dialog
= wxGetApp().GetMainFrame()->GetFindDialog();
996 int style
= wxFR_NOUPDOWN
;
997 wxString
caption(wxT("Find text in settings"));
998 int flags
= wxFR_DOWN
;
999 if (wxGetApp().GetSettings().m_matchCase
)
1000 flags
|=wxFR_MATCHCASE
;
1001 if (wxGetApp().GetSettings().m_matchWholeWord
)
1002 flags
|=wxFR_WHOLEWORD
;
1004 ctFindReplaceDialog::sm_findData
.SetFlags(flags
);
1006 dialog
= new ctFindReplaceDialog(wxGetApp().GetMainFrame(), caption
, style
);
1011 /// Update find text
1012 void ctConfigToolView::OnUpdateFind(wxUpdateUIEvent
& event
)
1017 /// Save default file type
1018 void ctConfigToolView::OnGo(wxCommandEvent
& WXUNUSED(event
))
1020 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
1021 wxString path
= wxGetApp().GetSettings().m_lastSetupSaveDir
;
1022 if (!path
.IsEmpty())
1024 if (wxGetApp().GetSettings().m_defaultFileKind
== wxT("Setup file"))
1027 wxString setupStr
= doc
->GenerateSetup();
1029 wxString fullPath
= path
+ wxFILE_SEP_PATH
+ wxT("setup.h");
1030 if (wxFileExists(fullPath
))
1033 msg
.Printf(wxT("Overwrite existing file %s?"), (const wxChar
*) fullPath
);
1034 int ans
= wxMessageBox(msg
, _("Save Setup File"), wxICON_QUESTION
|wxYES_NO
|wxCANCEL
);
1035 if (ans
== wxCANCEL
)
1040 wxFileOutputStream
stream(fullPath
);
1043 wxMessageBox(_("Sorry, could not save this file."), _("Save Setup File"), wxICON_EXCLAMATION
|wxOK
);
1048 else if (wxGetApp().GetSettings().m_defaultFileKind
== wxT("Configure script"))
1051 wxString configureStr
= doc
->GenerateConfigureCommand();
1053 wxString fullPath
= path
+ wxFILE_SEP_PATH
+ wxT("configurewx.sh");
1054 if (wxFileExists(fullPath
))
1057 msg
.Printf(wxT("Overwrite existing file %s?"), (const wxChar
*) fullPath
);
1058 int ans
= wxMessageBox(msg
, _("Save Configure Script"), wxICON_QUESTION
|wxYES_NO
|wxCANCEL
);
1059 if (ans
== wxCANCEL
)
1064 wxFileOutputStream
stream(fullPath
);
1067 wxMessageBox(_("Sorry, could not save this file."), _("Save Configure Script"), wxICON_EXCLAMATION
|wxOK
);
1070 stream
<< configureStr
;
1074 wxMessageBox(wxT("Unrecognised default file type."));
1080 void ctConfigToolView::OnUpdateGo(wxUpdateUIEvent
& event
)
1082 wxString path
= wxGetApp().GetSettings().m_lastSetupSaveDir
;
1083 event
.Enable(!path
.IsEmpty());
1086 //----------------------------------------------------------------------------
1087 // ctFindReplaceDialog
1088 //----------------------------------------------------------------------------
1090 BEGIN_EVENT_TABLE(ctFindReplaceDialog
, wxFindReplaceDialog
)
1091 EVT_FIND(-1, ctFindReplaceDialog::OnFind
)
1092 EVT_FIND_NEXT(-1, ctFindReplaceDialog::OnFind
)
1093 EVT_FIND_CLOSE(-1, ctFindReplaceDialog::OnClose
)
1096 wxFindReplaceData
ctFindReplaceDialog::sm_findData
;
1097 wxString
ctFindReplaceDialog::sm_currentItem
= wxEmptyString
;
1099 ctFindReplaceDialog::ctFindReplaceDialog( wxWindow
*parent
, const wxString
& title
,
1101 wxFindReplaceDialog( parent
, & sm_findData
, title
, style
)
1103 sm_currentItem
= wxEmptyString
;
1106 ((ctMainFrame
*) parent
)->SetFindDialog(this);
1109 void ctFindReplaceDialog::OnFind(wxFindDialogEvent
& event
)
1111 wxString textToFind
= event
.GetFindString();
1112 bool matchCase
= ((event
.GetFlags() & wxFR_MATCHCASE
) != 0);
1113 bool wholeWord
= ((event
.GetFlags() & wxFR_WHOLEWORD
) != 0);
1115 wxGetApp().GetSettings().m_matchCase
= matchCase
;
1116 wxGetApp().GetSettings().m_matchWholeWord
= wholeWord
;
1118 if (!DoFind(textToFind
, matchCase
, wholeWord
))
1120 wxMessageBox(wxT("No more matches."), wxT("Search"), wxOK
|wxICON_INFORMATION
, this);
1124 bool ctFindReplaceDialog::DoFind(const wxString
& textToFind
, bool matchCase
, bool wholeWord
, bool wrap
)
1126 ctConfigToolDoc
* doc
= wxGetApp().GetMainFrame()->GetDocument();
1129 ctConfigToolView
* view
= (ctConfigToolView
*) doc
->GetFirstView();
1131 ctConfigItem
* currentItem
= NULL
;
1132 ctConfigItem
* focusItem
= view
->GetSelection();
1135 focusItem
= doc
->GetTopItem();
1140 if (!sm_currentItem
.IsEmpty())
1142 currentItem
= doc
->GetTopItem()->FindItem(sm_currentItem
);
1145 // If we were at this item last time, skip the first one.
1146 bool skipFirstItem
= (currentItem
== focusItem
);
1147 currentItem
= FindNextItem(doc
, currentItem
, textToFind
, matchCase
, wholeWord
, wrap
,
1152 sm_currentItem
= currentItem
->GetName();
1153 wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->SelectItem(currentItem
->GetTreeItemId());
1158 sm_currentItem
= wxEmptyString
;
1164 ctConfigItem
* ctFindReplaceDialog::FindNextItem(ctConfigToolDoc
* doc
,
1166 const wxString
& text
,
1172 ctConfigItem
* firstInDoc
= NULL
;
1174 wxString
text2(text
);
1178 ctConfigItem
* found
= NULL
;
1179 ctConfigItem
* next
= item
;
1184 // If starting the search from beginning, we can now
1185 // set the value of 'item' in the 2nd iteration without immediately
1186 // dropping out of the while loop because card == next
1187 if (!item
&& (i
> 0))
1190 // We might want to start from this item if skipFirst is false.
1191 if ((i
== 0) && !skipFirst
&& next
)
1195 next
= doc
->FindNextItem(next
, wrap
);
1197 // Save to be used in iteration 2
1198 if ((i
== 0) && !item
)
1203 wxString
str(next
->GetName());
1204 wxString
description(next
->GetPropertyString(wxT("description")));
1205 wxString
notes(next
->GetPropertyString(wxT("notes")));
1209 description
.MakeLower();
1212 if (ctMatchString(str
, text2
, matchWordOnly
) ||
1213 ctMatchString(description
, text2
, matchWordOnly
) ||
1214 ctMatchString(notes
, text2
, matchWordOnly
))
1220 break; // Didn't find an item at all
1224 while (!found
&& item
!= next
);
1226 if (item
== found
&& !firstInDoc
)
1232 void ctFindReplaceDialog::OnClose(wxFindDialogEvent
& event
)
1234 bool matchCase
= ((event
.GetFlags() & wxFR_MATCHCASE
) != 0);
1235 bool wholeWord
= ((event
.GetFlags() & wxFR_WHOLEWORD
) != 0);
1236 wxGetApp().GetSettings().m_matchCase
= matchCase
;
1237 wxGetApp().GetSettings().m_matchWholeWord
= wholeWord
;
1240 ((ctMainFrame
*) GetParent())->SetFindDialog(NULL
);