1 /////////////////////////////////////////////////////////////////////////////
2 // Name: configtoolview.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "configtoolview.cpp"
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
)
92 ctConfigToolView::ctConfigToolView()
96 // What to do when a view is created. Creates actual
97 // windows for displaying the view.
98 bool ctConfigToolView::OnCreate(wxDocument
*doc
, long WXUNUSED(flags
) )
100 wxGetApp().GetDocManager()->ActivateView(this, TRUE
);
101 wxGetApp().GetMainFrame()->SetDocument((ctConfigToolDoc
*) doc
);
102 wxGetApp().GetMainFrame()->GetSetupPage()->SetDocument((ctConfigToolDoc
*) doc
) ;
103 wxGetApp().GetMainFrame()->GetConfigurePage()->SetDocument((ctConfigToolDoc
*) doc
) ;
108 void ctConfigToolView::OnDraw(wxDC
*dc
)
112 void ctConfigToolView::OnUpdate(wxView
*WXUNUSED(sender
), wxObject
*hintObj
)
114 ctConfigToolDoc
* doc
= wxDynamicCast(GetDocument(), ctConfigToolDoc
);
115 ctConfigTreeCtrl
* treeCtrl
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl();
119 wxASSERT (doc
!= NULL
);
121 ctConfigItem
* selItem
= NULL
;
123 wxTreeItemId sel
= treeCtrl
->GetSelection();
126 ctTreeItemData
* data
= (ctTreeItemData
*) treeCtrl
->GetItemData(sel
);
128 selItem
= data
->GetConfigItem() ;
131 ctConfigToolHint
* hint
= (ctConfigToolHint
*) hintObj
;
132 int hintOp
= ctNoHint
;
138 case ctInitialUpdate
:
140 if (doc
&& doc
->GetTopItem())
142 wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->DeleteAllItems();
143 AddItems(wxGetApp().GetMainFrame()->GetConfigTreeCtrl(), doc
->GetTopItem());
144 wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->Expand(doc
->GetTopItem()->GetTreeItemId());
152 wxGetApp().GetMainFrame()->GetPropertyEditor()->ShowItem(selItem
);
158 // TODO: update windows and frame title
161 case ctFilenameChanged
:
163 wxGetApp().GetMainFrame()->UpdateFrameTitle();
168 // TODO: update windows
169 treeCtrl
->DeleteAllItems();
170 wxGetApp().GetMainFrame()->GetPropertyEditor()->ShowItem(NULL
);
175 // ctConfigItem& ti = *(ctConfigItem *)hint->m_item;
176 wxGetApp().GetMainFrame()->GetPropertyEditor()->ShowItem(selItem
);
185 // Clean up windows used for displaying the view.
186 bool ctConfigToolView::OnClose(bool deleteWindow
)
188 if (!GetDocument()->Close())
191 ctConfigToolHint
hint(NULL
, ctClear
);
192 GetDocument()->UpdateAllViews (NULL
, & hint
);
194 wxGetApp().GetDocManager()->ActivateView(this, FALSE
);
198 wxGetApp().GetMainFrame()->SetDocument(NULL
);
199 wxGetApp().GetMainFrame()->GetSetupPage()->SetDocument(NULL
) ;
200 wxGetApp().GetMainFrame()->GetConfigurePage()->SetDocument(NULL
) ;
205 void ctConfigToolView::OnChangeFilename()
207 if (wxGetApp().GetTopWindow() && GetDocument())
209 wxString
docTitle(wxFileNameFromPath(GetDocument()->GetFilename()));
210 wxStripExtension(docTitle
);
211 GetDocument()->SetTitle(docTitle
);
213 wxString
name(GetDocument()->GetFilename());
214 wxStripExtension(name
);
218 wxString modifiedMarker
;
219 if (GetDocument()->IsModified())
220 modifiedMarker
= wxT("*");
222 title
= docTitle
+ modifiedMarker
+ wxString(wxT(" - ")) + wxGetApp().GetSettings().GetAppName() ;
224 ((wxFrame
*) wxGetApp().GetTopWindow())->SetTitle(title
);
229 void ctConfigToolView::OnUpdateDisable(wxUpdateUIEvent
& event
)
231 event
.Enable( FALSE
);
234 void ctConfigToolView::OnUpdateAddItem(wxUpdateUIEvent
& event
)
236 event
.Enable( TRUE
);
239 /// Add item and its children to the tree
240 void ctConfigToolView::AddItems(ctConfigTreeCtrl
* treeControl
, ctConfigItem
* item
)
242 SyncItem(treeControl
, item
);
244 int count
= item
->GetChildCount();
246 for (i
= 0; i
< count
; i
++)
248 ctConfigItem
* child
= item
->GetChild(i
);
249 AddItems(treeControl
, child
);
253 /// Gets the tree item in sync with the item
254 void ctConfigToolView::SyncItem(ctConfigTreeCtrl
* treeControl
, ctConfigItem
* item
)
256 if (!item
->GetTreeItemId().IsOk())
258 if (!item
->GetParent())
260 item
->SetTreeItem(treeControl
->AddRoot(_(""), -1, -1, new ctTreeItemData(item
)));
264 // Find the item to insert the new item after.
265 ctConfigItem
* previousItem
= item
->FindPreviousSibling();
266 if (previousItem
&& previousItem
->GetTreeItemId().IsOk())
268 item
->SetTreeItem(treeControl
->InsertItem(item
->GetParent()->GetTreeItemId(),
269 previousItem
->GetTreeItemId(),
270 item
->GetName(), -1, -1, new ctTreeItemData(item
)));
272 else if (!previousItem
&& item
->GetParent()->GetChildCount() > 1
275 // Insert at the beginning
276 item
->SetTreeItem(treeControl
->InsertItem(item
->GetParent()->GetTreeItemId(),
277 (size_t) 0, // Insert at first position
278 item
->GetName(), -1, -1, new ctTreeItemData(item
)));
282 item
->SetTreeItem(treeControl
->AppendItem(item
->GetParent()->GetTreeItemId(),
283 item
->GetName(), -1, -1, new ctTreeItemData(item
)));
288 if (item
->GetTreeItemId().IsOk())
290 treeControl
->SetItemText(item
->GetTreeItemId(), item
->GetName());
294 if (item
->GetType() == ctTypeGroup
)
296 iconId
= treeControl
->GetIconTable().GetIconId(wxT("Group"), 0, item
->IsActive());
298 else if (item
->GetType() == ctTypeCheckGroup
)
300 iconId
= treeControl
->GetIconTable().GetIconId(wxT("CheckGroup"), item
->IsEnabled() ? 0 : 1, item
->IsActive());
302 else if (item
->GetType() == ctTypeRadioGroup
)
304 iconId
= treeControl
->GetIconTable().GetIconId(wxT("RadioGroup"), item
->IsEnabled() ? 0 : 1, item
->IsActive());
306 else if (item
->GetType() == ctTypeBoolCheck
)
308 iconId
= treeControl
->GetIconTable().GetIconId(wxT("Checkbox"), item
->IsEnabled() ? 0 : 1, item
->IsActive());
310 else if (item
->GetType() == ctTypeBoolRadio
)
312 iconId
= treeControl
->GetIconTable().GetIconId(wxT("Radiobutton"), item
->IsEnabled() ? 0 : 1, item
->IsActive());
314 treeControl
->SetItemImage(item
->GetTreeItemId(), iconId
, wxTreeItemIcon_Normal
);
315 treeControl
->SetItemImage(item
->GetTreeItemId(), iconId
, wxTreeItemIcon_Selected
);
317 if (treeControl
->GetSelection() == item
->GetTreeItemId())
319 if (wxGetApp().GetMainFrame()->GetPropertyEditor()->GetItem())
320 wxGetApp().GetMainFrame()->GetPropertyEditor()->UpdateTitle();
326 void ctConfigToolView::OnIconLeftDown(ctConfigTreeCtrl
* treeControl
, ctConfigItem
* item
)
328 if (!item
->IsActive())
331 if (item
->GetType() == ctTypeCheckGroup
||
332 item
->GetType() == ctTypeBoolCheck
||
333 item
->GetType() == ctTypeBoolRadio
||
334 item
->GetType() == ctTypeRadioGroup
337 // Don't toggle a radio button that's already
339 if ((item
->GetType() == ctTypeBoolRadio
|| item
->GetType() == ctTypeRadioGroup
)
340 && item
->IsEnabled())
343 item
->Enable(!item
->IsEnabled());
345 GetDocument()->Modify(TRUE
);
348 SyncItem(treeControl
, item
);
351 item
->PropagateChange(considered
);
352 if ((item
->GetType() == ctTypeBoolRadio
|| item
->GetType() == ctTypeRadioGroup
) && item
->IsEnabled())
354 item
->PropagateRadioButton(considered
);
359 /// Returns the selected config item, if any.
360 ctConfigItem
* ctConfigToolView::GetSelection()
362 wxTreeCtrl
* treeCtrl
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl();
366 wxTreeItemId sel
= treeCtrl
->GetSelection();
369 ctTreeItemData
* data
= (ctTreeItemData
*) treeCtrl
->GetItemData(sel
);
371 return data
->GetConfigItem() ;
376 /// Add a checkbox item
377 void ctConfigToolView::OnAddCheckBoxItem(wxCommandEvent
& event
)
379 AddItem(ctTypeBoolCheck
, _("New checkbox item"));
382 /// Add a radiobutton item
383 void ctConfigToolView::OnAddRadioButtonItem(wxCommandEvent
& event
)
385 AddItem(ctTypeBoolRadio
, _("New radio button item"));
389 void ctConfigToolView::OnAddGroupItem(wxCommandEvent
& event
)
391 AddItem(ctTypeGroup
, _("New group item"));
394 /// Add a group option item
395 void ctConfigToolView::OnAddCheckGroupItem(wxCommandEvent
& event
)
397 AddItem(ctTypeCheckGroup
, _("New check group item"));
400 /// Add a group option item
401 void ctConfigToolView::OnAddRadioGroupItem(wxCommandEvent
& event
)
403 AddItem(ctTypeRadioGroup
, _("New radio group item"));
406 /// Add a string item
407 void ctConfigToolView::OnAddStringItem(wxCommandEvent
& event
)
409 AddItem(ctTypeString
, _("New string item"));
413 void ctConfigToolView::AddItem(ctConfigType type
, const wxString
& msg
)
415 ctConfigItem
* sel
= GetSelection();
418 wxString name
= wxGetTextFromUser(_("Please enter a name for the new item."),
422 ctConfigItem
* parent
;
423 ctConfigItem
* insertBefore
;
424 if (sel
->CanHaveChildren())
431 parent
= sel
->GetParent();
432 insertBefore
= sel
->FindNextSibling();
435 ctConfigItem
* newItem
= new ctConfigItem(NULL
, type
, name
);
436 newItem
->InitProperties();
438 newItem
->GetDocument()->GetCommandProcessor()->Submit(
439 new ctConfigCommand(msg
, ctCMD_NEW_ELEMENT
, NULL
, newItem
,
440 parent
, insertBefore
));
446 void ctConfigToolView::OnDeleteItem(wxCommandEvent
& event
)
448 ctConfigItem
* sel
= GetSelection();
452 msg
.Printf(_("Delete %s?"), sel
->GetName());
453 if (wxYES
== wxMessageBox(msg
, _("Delete item"), wxICON_QUESTION
|wxYES_NO
))
455 wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->Delete(sel
->GetTreeItemId());
461 void ctConfigToolView::OnRenameItem(wxCommandEvent
& event
)
463 ctConfigItem
* sel
= GetSelection();
466 wxString name
= wxGetTextFromUser(_("Please enter a new name for the item."),
467 _("Rename item"), sel
->GetName());
471 SyncItem(wxGetApp().GetMainFrame()->GetConfigTreeCtrl(), sel
);
473 ctConfigToolHint
hint(NULL
, ctSelChanged
);
474 GetDocument()->UpdateAllViews (NULL
, & hint
);
479 /// Copy an item to the clipboard
480 void ctConfigToolView::OnCopy(wxCommandEvent
& event
)
482 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
483 ctConfigItem
* sel
= GetSelection();
486 doc
->SetClipboardItem(sel
->DeepClone());
490 /// Copy an item to the clipboard and cut the item
491 void ctConfigToolView::OnCut(wxCommandEvent
& event
)
493 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
494 ctConfigItem
* sel
= GetSelection();
498 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Cut Config Item"), ctCMD_CUT
,
499 sel
, (ctConfigItem
*) NULL
);
500 doc
->GetCommandProcessor()->Submit(cmd
);
505 /// Paste an item from the clipboard to the tree
506 void ctConfigToolView::OnPaste(wxCommandEvent
& event
)
508 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
509 ctConfigItem
* sel
= GetSelection();
510 if (sel
&& doc
->GetClipboardItem())
512 ctConfigItem
* parent
;
513 ctConfigItem
* insertBefore
;
514 if (sel
->CanHaveChildren())
521 parent
= sel
->GetParent();
522 insertBefore
= sel
->FindNextSibling();
525 ctConfigItem
* newItem
= doc
->GetClipboardItem()->DeepClone();
526 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE
,
527 NULL
, newItem
, parent
, insertBefore
);
528 doc
->GetCommandProcessor()->Submit(cmd
);
532 /// Update for copy command
533 void ctConfigToolView::OnUpdateCopy(wxUpdateUIEvent
& event
)
535 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
536 event
.Enable( doc
&& GetSelection() && GetSelection()->GetParent() );
540 void ctConfigToolView::OnUpdateCut(wxUpdateUIEvent
& event
)
542 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
543 event
.Enable( doc
&& GetSelection() && GetSelection()->GetParent() );
547 void ctConfigToolView::OnUpdatePaste(wxUpdateUIEvent
& event
)
549 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
550 event
.Enable( doc
&& doc
->GetClipboardItem() && GetSelection() );
553 /// Copy an item to the clipboard
554 void ctConfigToolView::OnContextCopy(wxCommandEvent
& event
)
556 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
557 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
560 doc
->SetClipboardItem(sel
->DeepClone());
564 /// Copy an item to the clipboard and cut the item
565 void ctConfigToolView::OnContextCut(wxCommandEvent
& event
)
567 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
568 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
572 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Cut Config Item"), ctCMD_CUT
,
573 sel
, (ctConfigItem
*) NULL
);
574 doc
->GetCommandProcessor()->Submit(cmd
);
579 /// Paste an item from the clipboard to the tree
580 void ctConfigToolView::OnContextPasteBefore(wxCommandEvent
& event
)
582 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
583 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
584 if (sel
&& doc
->GetClipboardItem())
586 ctConfigItem
* parent
= sel
->GetParent();
587 ctConfigItem
* insertBefore
= sel
;
589 ctConfigItem
* newItem
= doc
->GetClipboardItem()->DeepClone();
590 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE
,
591 NULL
, newItem
, parent
, insertBefore
);
592 doc
->GetCommandProcessor()->Submit(cmd
);
596 /// Paste an item from the clipboard to the tree
597 void ctConfigToolView::OnContextPasteAfter(wxCommandEvent
& event
)
599 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
600 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
601 if (sel
&& doc
->GetClipboardItem())
603 ctConfigItem
* parent
= sel
->GetParent();
604 ctConfigItem
* insertBefore
= sel
->FindNextSibling();
606 ctConfigItem
* newItem
= doc
->GetClipboardItem()->DeepClone();
607 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE
,
608 NULL
, newItem
, parent
, insertBefore
);
609 doc
->GetCommandProcessor()->Submit(cmd
);
613 /// Paste an item from the clipboard to the tree
614 void ctConfigToolView::OnContextPasteAsChild(wxCommandEvent
& event
)
616 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
617 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
618 if (sel
&& doc
->GetClipboardItem())
620 if (sel
->CanHaveChildren())
622 ctConfigItem
* parent
= sel
;
623 ctConfigItem
* insertBefore
= NULL
;
625 ctConfigItem
* newItem
= doc
->GetClipboardItem()->DeepClone();
626 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE
,
627 NULL
, newItem
, parent
, insertBefore
);
628 doc
->GetCommandProcessor()->Submit(cmd
);
633 /// Copy an item to the clipboard
634 void ctConfigToolView::OnUpdateContextCopy(wxUpdateUIEvent
& event
)
636 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
637 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
638 event
.Enable( doc
&& sel
&& sel
->GetParent() );
641 /// Copy an item to the clipboard and cut the item
642 void ctConfigToolView::OnUpdateContextCut(wxUpdateUIEvent
& event
)
644 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
645 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
646 event
.Enable( doc
&& sel
&& sel
->GetParent() );
649 /// Paste an item from the clipboard to the tree
650 void ctConfigToolView::OnUpdateContextPasteBefore(wxUpdateUIEvent
& event
)
652 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
653 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
654 event
.Enable( doc
&& sel
&& sel
->GetParent() && doc
->GetClipboardItem() );
657 /// Paste an item from the clipboard to the tree
658 void ctConfigToolView::OnUpdateContextPasteAfter(wxUpdateUIEvent
& event
)
660 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
661 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
662 event
.Enable( doc
&& sel
&& sel
->GetParent() && doc
->GetClipboardItem() );
665 /// Paste an item from the clipboard to the tree
666 void ctConfigToolView::OnUpdateContextPasteAsChild(wxUpdateUIEvent
& event
)
668 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
669 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
670 event
.Enable( doc
&& sel
&& sel
->CanHaveChildren() && doc
->GetClipboardItem() );
674 void ctConfigToolView::OnItemHelp(wxCommandEvent
& event
)
676 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
677 if ( doc
&& GetSelection() )
679 wxString helpTopic
= GetSelection()->GetPropertyString(wxT("help-topic"));
680 if (!helpTopic
.IsEmpty())
682 wxGetApp().GetReferenceHelpController().DisplaySection(helpTopic
);
688 void ctConfigToolView::OnUpdateItemHelp(wxUpdateUIEvent
& event
)
690 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
691 event
.Enable( doc
&& GetSelection() );
694 /// Add a custom property
695 void ctConfigToolView::OnAddCustomProperty(wxCommandEvent
& event
)
697 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
698 ctConfigItem
* sel
= GetSelection();
699 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
700 if (doc
&& sel
&& editor
)
702 ctCustomPropertyDialog
dialog(wxGetApp().GetMainFrame(),
703 -1, _("Add a custom property"));
704 if (dialog
.ShowModal() == wxID_OK
)
706 wxString name
= dialog
.GetPropertyName();
707 wxString type
= dialog
.GetPropertyType();
708 wxString descr
= dialog
.GetPropertyDescription();
709 wxString editorType
= dialog
.GetEditorType();
710 wxArrayString choices
= dialog
.GetChoices();
712 if (sel
->GetProperties().FindProperty(name
))
714 wxMessageBox(_("Sorry, this name already exists."), _T("Add custom property"),
715 wxOK
|wxICON_INFORMATION
);
718 ctProperty
* property
= new ctProperty
;
719 if (type
== wxT("bool"))
720 property
->GetVariant() = wxVariant((bool) FALSE
, name
);
721 else if (type
== wxT("double"))
722 property
->GetVariant() = wxVariant((double) 0.0, name
);
723 else if (type
== wxT("long"))
724 property
->GetVariant() = wxVariant((long) 0, name
);
726 property
->GetVariant() = wxVariant(wxT(""), name
);
727 property
->SetCustom(TRUE
);
728 property
->SetDescription(descr
);
729 property
->SetChoices(choices
);
730 property
->SetEditorType(editorType
);
732 sel
->GetProperties().AddProperty(property
);
733 editor
->ShowItem(sel
);
739 /// Edit a custom property
740 void ctConfigToolView::OnEditCustomProperty(wxCommandEvent
& event
)
742 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
743 ctConfigItem
* sel
= GetSelection();
744 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
745 if (doc
&& sel
&& editor
)
748 ctProperty
* property
= editor
->FindSelectedProperty(row
) ;
749 if (property
&& property
->IsCustom())
751 wxString oldName
= property
->GetName();
752 wxString oldDescription
= property
->GetDescription();
753 wxString oldType
= property
->GetVariant().GetType();
754 wxString oldEditorType
= property
->GetEditorType();
755 wxArrayString oldChoices
= property
->GetChoices();
757 ctCustomPropertyDialog
dialog(wxGetApp().GetMainFrame(),
758 -1, _("Edit custom property"));
759 dialog
.SetPropertyName(oldName
);
760 dialog
.SetPropertyType(oldType
);
761 dialog
.SetPropertyDescription(oldDescription
);
762 if (dialog
.ShowModal() == wxID_OK
)
764 wxString name
= dialog
.GetPropertyName();
765 wxString type
= dialog
.GetPropertyType();
766 wxString editorType
= dialog
.GetEditorType();
767 wxArrayString choices
= dialog
.GetChoices();
768 wxString descr
= dialog
.GetPropertyDescription();
770 if (name
!= oldName
&& sel
->GetProperties().FindProperty(name
))
772 wxMessageBox(_("Sorry, this name already exists."), _T("Add custom property"),
773 wxOK
|wxICON_INFORMATION
);
778 if (type
== wxT("bool"))
779 property
->GetVariant() = wxVariant((bool) FALSE
, name
);
780 else if (type
== wxT("double"))
781 property
->GetVariant() = wxVariant((double) 0.0, name
);
782 else if (type
== wxT("long"))
783 property
->GetVariant() = wxVariant((long) 0, name
);
785 property
->GetVariant() = wxVariant(wxT(""), name
);
788 property
->GetVariant().SetName(name
);
790 if (choices
!= oldChoices
)
791 property
->SetChoices(choices
);
793 if (editorType
!= oldEditorType
)
794 property
->SetEditorType(editorType
);
797 property
->GetVariant().SetName(name
);
799 property
->SetCustom(TRUE
);
801 if (descr
!= oldDescription
)
802 property
->SetDescription(descr
);
804 editor
->ShowItem(sel
);
811 /// Delete a custom property
812 void ctConfigToolView::OnDeleteCustomProperty(wxCommandEvent
& event
)
814 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
815 ctConfigItem
* sel
= GetSelection();
816 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
817 if (doc
&& sel
&& editor
)
820 ctProperty
* property
= editor
->FindSelectedProperty(row
) ;
821 if (property
&& property
->IsCustom())
823 wxString
name(property
->GetName());
825 msg
.Printf(_("Delete custom property '%s'?"), (const wxChar
*) name
);
826 if (wxYES
== wxMessageBox(msg
, _("Delete property"), wxICON_EXCLAMATION
|wxYES_NO
))
828 sel
->GetProperties().RemoveProperty(property
);
829 editor
->ShowItem(sel
);
837 /// Add a custom property: update event
838 void ctConfigToolView::OnUpdateAddCustomProperty(wxUpdateUIEvent
& event
)
840 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
841 event
.Enable( doc
&& GetSelection() && GetSelection()->GetParent() );
844 /// Edit a custom property: update event
845 void ctConfigToolView::OnUpdateEditCustomProperty(wxUpdateUIEvent
& event
)
847 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
848 ctConfigItem
* sel
= GetSelection();
849 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
851 event
.Enable( doc
&& sel
&& sel
->GetParent() && editor
&&
852 editor
->FindSelectedProperty(row
) &&
853 editor
->FindSelectedProperty(row
)->IsCustom() );
856 /// Delete a custom property: update event
857 void ctConfigToolView::OnUpdateDeleteCustomProperty(wxUpdateUIEvent
& event
)
859 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
860 ctConfigItem
* sel
= GetSelection();
861 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
863 event
.Enable( doc
&& sel
&& sel
->GetParent() && editor
&&
864 editor
->FindSelectedProperty(row
) &&
865 editor
->FindSelectedProperty(row
)->IsCustom() );
868 /// Regenerate setup.h and configure command
869 void ctConfigToolView::RegenerateSetup()
871 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
872 ctOutputWindow
* setupPage
= wxGetApp().GetMainFrame()->GetSetupPage() ;
873 ctOutputWindow
* configurePage
= wxGetApp().GetMainFrame()->GetConfigurePage() ;
875 wxString setupStr
= doc
->GenerateSetup();
876 wxString configureStr
= doc
->GenerateConfigureCommand();
878 setupPage
->SetText(setupStr
);
879 configurePage
->SetText(configureStr
);
882 /// Regenerate if selected a tab
883 void ctConfigToolView::OnTabSelect(wxNotebookEvent
& event
)
885 if (wxGetApp().GetMainFrame()->GetMainNotebook() != event
.GetEventObject())
891 if (event
.GetSelection() > 0)
897 void ctConfigToolView::OnSaveSetupFile(wxCommandEvent
& event
)
899 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
900 wxString setupStr
= doc
->GenerateSetup();
902 wxString filename
= _T("setup.h");
903 wxString path
= doc
->GetFrameworkDir(FALSE
);
904 wxString wildcard
= _T("Header files (*.h)|*.h|All files (*.*)|*.*");
906 wxFileDialog
dialog(wxTheApp
->GetTopWindow(),
907 _("Save Setup File As"),
909 wildcard
, wxSAVE
|wxOVERWRITE_PROMPT
);
911 if (dialog
.ShowModal() == wxID_OK
)
913 wxString fullPath
= dialog
.GetPath();
915 // TODO: save last saved path in settings.
917 wxFileOutputStream
stream(fullPath
);
920 wxMessageBox(_("Sorry, could not save this file."), _("Save Setup File"), wxICON_EXCLAMATION
|wxOK
);
928 void ctConfigToolView::OnSaveConfigureCommand(wxCommandEvent
& event
)
930 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
931 wxString configureStr
= doc
->GenerateConfigureCommand();
933 wxString filename
= _T("configurewx.sh");
934 wxString path
= doc
->GetFrameworkDir(FALSE
);
935 wxString wildcard
= _T("Shell script files (*.sh)|*.sh|All files (*.*)|*.*");
937 wxFileDialog
dialog(wxTheApp
->GetTopWindow(),
938 _("Save Configure Command File As"),
940 wildcard
, wxSAVE
|wxOVERWRITE_PROMPT
);
942 if (dialog
.ShowModal() == wxID_OK
)
944 wxString fullPath
= dialog
.GetPath();
946 // TODO: save last saved path in settings.
948 wxFileOutputStream
stream(fullPath
);
951 wxMessageBox(_("Sorry, could not save this file."), _("Save Configure Command File"), wxICON_EXCLAMATION
|wxOK
);
955 stream
<< configureStr
;
959 void ctConfigToolView::OnUpdateSaveSetupFile(wxUpdateUIEvent
& event
)
964 void ctConfigToolView::OnUpdateSaveConfigureCommand(wxUpdateUIEvent
& event
)