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
)
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();
451 wxString
name(sel
->GetName());
453 msg
.Printf(_("Delete %s?"), (const wxChar
*) name
);
454 if (wxYES
== wxMessageBox(msg
, _("Delete item"), wxICON_QUESTION
|wxYES_NO
))
456 wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->Delete(sel
->GetTreeItemId());
462 void ctConfigToolView::OnRenameItem(wxCommandEvent
& event
)
464 ctConfigItem
* sel
= GetSelection();
467 wxString name
= wxGetTextFromUser(_("Please enter a new name for the item."),
468 _("Rename item"), sel
->GetName());
472 SyncItem(wxGetApp().GetMainFrame()->GetConfigTreeCtrl(), sel
);
474 ctConfigToolHint
hint(NULL
, ctSelChanged
);
475 GetDocument()->UpdateAllViews (NULL
, & hint
);
480 /// Copy an item to the clipboard
481 void ctConfigToolView::OnCopy(wxCommandEvent
& event
)
483 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
484 ctConfigItem
* sel
= GetSelection();
487 doc
->SetClipboardItem(sel
->DeepClone());
491 /// Copy an item to the clipboard and cut the item
492 void ctConfigToolView::OnCut(wxCommandEvent
& event
)
494 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
495 ctConfigItem
* sel
= GetSelection();
499 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Cut Config Item"), ctCMD_CUT
,
500 sel
, (ctConfigItem
*) NULL
);
501 doc
->GetCommandProcessor()->Submit(cmd
);
506 /// Paste an item from the clipboard to the tree
507 void ctConfigToolView::OnPaste(wxCommandEvent
& event
)
509 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
510 ctConfigItem
* sel
= GetSelection();
511 if (sel
&& doc
->GetClipboardItem())
513 ctConfigItem
* parent
;
514 ctConfigItem
* insertBefore
;
515 if (sel
->CanHaveChildren())
522 parent
= sel
->GetParent();
523 insertBefore
= sel
->FindNextSibling();
526 ctConfigItem
* newItem
= doc
->GetClipboardItem()->DeepClone();
527 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE
,
528 NULL
, newItem
, parent
, insertBefore
);
529 doc
->GetCommandProcessor()->Submit(cmd
);
533 /// Update for copy command
534 void ctConfigToolView::OnUpdateCopy(wxUpdateUIEvent
& event
)
536 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
537 event
.Enable( doc
&& GetSelection() && GetSelection()->GetParent() );
541 void ctConfigToolView::OnUpdateCut(wxUpdateUIEvent
& event
)
543 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
544 event
.Enable( doc
&& GetSelection() && GetSelection()->GetParent() );
548 void ctConfigToolView::OnUpdatePaste(wxUpdateUIEvent
& event
)
550 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
551 event
.Enable( doc
&& doc
->GetClipboardItem() && GetSelection() );
554 /// Copy an item to the clipboard
555 void ctConfigToolView::OnContextCopy(wxCommandEvent
& event
)
557 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
558 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
561 doc
->SetClipboardItem(sel
->DeepClone());
565 /// Copy an item to the clipboard and cut the item
566 void ctConfigToolView::OnContextCut(wxCommandEvent
& event
)
568 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
569 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
573 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Cut Config Item"), ctCMD_CUT
,
574 sel
, (ctConfigItem
*) NULL
);
575 doc
->GetCommandProcessor()->Submit(cmd
);
580 /// Paste an item from the clipboard to the tree
581 void ctConfigToolView::OnContextPasteBefore(wxCommandEvent
& event
)
583 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
584 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
585 if (sel
&& doc
->GetClipboardItem())
587 ctConfigItem
* parent
= sel
->GetParent();
588 ctConfigItem
* insertBefore
= sel
;
590 ctConfigItem
* newItem
= doc
->GetClipboardItem()->DeepClone();
591 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE
,
592 NULL
, newItem
, parent
, insertBefore
);
593 doc
->GetCommandProcessor()->Submit(cmd
);
597 /// Paste an item from the clipboard to the tree
598 void ctConfigToolView::OnContextPasteAfter(wxCommandEvent
& event
)
600 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
601 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
602 if (sel
&& doc
->GetClipboardItem())
604 ctConfigItem
* parent
= sel
->GetParent();
605 ctConfigItem
* insertBefore
= sel
->FindNextSibling();
607 ctConfigItem
* newItem
= doc
->GetClipboardItem()->DeepClone();
608 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE
,
609 NULL
, newItem
, parent
, insertBefore
);
610 doc
->GetCommandProcessor()->Submit(cmd
);
614 /// Paste an item from the clipboard to the tree
615 void ctConfigToolView::OnContextPasteAsChild(wxCommandEvent
& event
)
617 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
618 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
619 if (sel
&& doc
->GetClipboardItem())
621 if (sel
->CanHaveChildren())
623 ctConfigItem
* parent
= sel
;
624 ctConfigItem
* insertBefore
= NULL
;
626 ctConfigItem
* newItem
= doc
->GetClipboardItem()->DeepClone();
627 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE
,
628 NULL
, newItem
, parent
, insertBefore
);
629 doc
->GetCommandProcessor()->Submit(cmd
);
634 /// Copy an item to the clipboard
635 void ctConfigToolView::OnUpdateContextCopy(wxUpdateUIEvent
& event
)
637 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
638 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
639 event
.Enable( doc
&& sel
&& sel
->GetParent() );
642 /// Copy an item to the clipboard and cut the item
643 void ctConfigToolView::OnUpdateContextCut(wxUpdateUIEvent
& event
)
645 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
646 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
647 event
.Enable( doc
&& sel
&& sel
->GetParent() );
650 /// Paste an item from the clipboard to the tree
651 void ctConfigToolView::OnUpdateContextPasteBefore(wxUpdateUIEvent
& event
)
653 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
654 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
655 event
.Enable( doc
&& sel
&& sel
->GetParent() && doc
->GetClipboardItem() );
658 /// Paste an item from the clipboard to the tree
659 void ctConfigToolView::OnUpdateContextPasteAfter(wxUpdateUIEvent
& event
)
661 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
662 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
663 event
.Enable( doc
&& sel
&& sel
->GetParent() && doc
->GetClipboardItem() );
666 /// Paste an item from the clipboard to the tree
667 void ctConfigToolView::OnUpdateContextPasteAsChild(wxUpdateUIEvent
& event
)
669 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
670 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
671 event
.Enable( doc
&& sel
&& sel
->CanHaveChildren() && doc
->GetClipboardItem() );
675 void ctConfigToolView::OnItemHelp(wxCommandEvent
& event
)
677 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
678 if ( doc
&& GetSelection() )
680 wxString helpTopic
= GetSelection()->GetPropertyString(wxT("help-topic"));
681 if (!helpTopic
.IsEmpty())
683 wxGetApp().GetReferenceHelpController().DisplaySection(helpTopic
);
689 void ctConfigToolView::OnUpdateItemHelp(wxUpdateUIEvent
& event
)
691 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
692 event
.Enable( doc
&& GetSelection() );
695 /// Add a custom property
696 void ctConfigToolView::OnAddCustomProperty(wxCommandEvent
& event
)
698 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
699 ctConfigItem
* sel
= GetSelection();
700 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
701 if (doc
&& sel
&& editor
)
703 ctCustomPropertyDialog
dialog(wxGetApp().GetMainFrame(),
704 -1, _("Add a custom property"));
705 if (dialog
.ShowModal() == wxID_OK
)
707 wxString name
= dialog
.GetPropertyName();
708 wxString type
= dialog
.GetPropertyType();
709 wxString descr
= dialog
.GetPropertyDescription();
710 wxString editorType
= dialog
.GetEditorType();
711 wxArrayString choices
= dialog
.GetChoices();
713 if (sel
->GetProperties().FindProperty(name
))
715 wxMessageBox(_("Sorry, this name already exists."), _T("Add custom property"),
716 wxOK
|wxICON_INFORMATION
);
719 ctProperty
* property
= new ctProperty
;
720 if (type
== wxT("bool"))
721 property
->GetVariant() = wxVariant((bool) FALSE
, name
);
722 else if (type
== wxT("double"))
723 property
->GetVariant() = wxVariant((double) 0.0, name
);
724 else if (type
== wxT("long"))
725 property
->GetVariant() = wxVariant((long) 0, name
);
727 property
->GetVariant() = wxVariant(wxT(""), name
);
728 property
->SetCustom(TRUE
);
729 property
->SetDescription(descr
);
730 property
->SetChoices(choices
);
731 property
->SetEditorType(editorType
);
733 sel
->GetProperties().AddProperty(property
);
734 editor
->ShowItem(sel
);
740 /// Edit a custom property
741 void ctConfigToolView::OnEditCustomProperty(wxCommandEvent
& event
)
743 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
744 ctConfigItem
* sel
= GetSelection();
745 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
746 if (doc
&& sel
&& editor
)
749 ctProperty
* property
= editor
->FindSelectedProperty(row
) ;
750 if (property
&& property
->IsCustom())
752 wxString oldName
= property
->GetName();
753 wxString oldDescription
= property
->GetDescription();
754 wxString oldType
= property
->GetVariant().GetType();
755 wxString oldEditorType
= property
->GetEditorType();
756 wxArrayString oldChoices
= property
->GetChoices();
758 ctCustomPropertyDialog
dialog(wxGetApp().GetMainFrame(),
759 -1, _("Edit custom property"));
760 dialog
.SetPropertyName(oldName
);
761 dialog
.SetPropertyType(oldType
);
762 dialog
.SetPropertyDescription(oldDescription
);
763 if (dialog
.ShowModal() == wxID_OK
)
765 wxString name
= dialog
.GetPropertyName();
766 wxString type
= dialog
.GetPropertyType();
767 wxString editorType
= dialog
.GetEditorType();
768 wxArrayString choices
= dialog
.GetChoices();
769 wxString descr
= dialog
.GetPropertyDescription();
771 if (name
!= oldName
&& sel
->GetProperties().FindProperty(name
))
773 wxMessageBox(_("Sorry, this name already exists."), _T("Add custom property"),
774 wxOK
|wxICON_INFORMATION
);
779 if (type
== wxT("bool"))
780 property
->GetVariant() = wxVariant((bool) FALSE
, name
);
781 else if (type
== wxT("double"))
782 property
->GetVariant() = wxVariant((double) 0.0, name
);
783 else if (type
== wxT("long"))
784 property
->GetVariant() = wxVariant((long) 0, name
);
786 property
->GetVariant() = wxVariant(wxT(""), name
);
789 property
->GetVariant().SetName(name
);
791 if (choices
!= oldChoices
)
792 property
->SetChoices(choices
);
794 if (editorType
!= oldEditorType
)
795 property
->SetEditorType(editorType
);
798 property
->GetVariant().SetName(name
);
800 property
->SetCustom(TRUE
);
802 if (descr
!= oldDescription
)
803 property
->SetDescription(descr
);
805 editor
->ShowItem(sel
);
812 /// Delete a custom property
813 void ctConfigToolView::OnDeleteCustomProperty(wxCommandEvent
& event
)
815 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
816 ctConfigItem
* sel
= GetSelection();
817 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
818 if (doc
&& sel
&& editor
)
821 ctProperty
* property
= editor
->FindSelectedProperty(row
) ;
822 if (property
&& property
->IsCustom())
824 wxString
name(property
->GetName());
826 msg
.Printf(_("Delete custom property '%s'?"), (const wxChar
*) name
);
827 if (wxYES
== wxMessageBox(msg
, _("Delete property"), wxICON_EXCLAMATION
|wxYES_NO
))
829 sel
->GetProperties().RemoveProperty(property
);
830 editor
->ShowItem(sel
);
838 /// Add a custom property: update event
839 void ctConfigToolView::OnUpdateAddCustomProperty(wxUpdateUIEvent
& event
)
841 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
842 event
.Enable( doc
&& GetSelection() && GetSelection()->GetParent() );
845 /// Edit a custom property: update event
846 void ctConfigToolView::OnUpdateEditCustomProperty(wxUpdateUIEvent
& event
)
848 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
849 ctConfigItem
* sel
= GetSelection();
850 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
852 event
.Enable( doc
&& sel
&& sel
->GetParent() && editor
&&
853 editor
->FindSelectedProperty(row
) &&
854 editor
->FindSelectedProperty(row
)->IsCustom() );
857 /// Delete a custom property: update event
858 void ctConfigToolView::OnUpdateDeleteCustomProperty(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 /// Regenerate setup.h and configure command
870 void ctConfigToolView::RegenerateSetup()
872 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
873 ctOutputWindow
* setupPage
= wxGetApp().GetMainFrame()->GetSetupPage() ;
874 ctOutputWindow
* configurePage
= wxGetApp().GetMainFrame()->GetConfigurePage() ;
876 wxString setupStr
= doc
->GenerateSetup();
877 wxString configureStr
= doc
->GenerateConfigureCommand();
879 setupPage
->SetText(setupStr
);
880 configurePage
->SetText(configureStr
);
883 /// Regenerate if selected a tab
884 void ctConfigToolView::OnTabSelect(wxNotebookEvent
& event
)
886 if (wxGetApp().GetMainFrame()->GetMainNotebook() != event
.GetEventObject())
892 if (event
.GetSelection() > 0)
898 void ctConfigToolView::OnSaveSetupFile(wxCommandEvent
& event
)
900 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
901 wxString setupStr
= doc
->GenerateSetup();
903 wxString filename
= _T("setup.h");
904 wxString path
= doc
->GetFrameworkDir(FALSE
);
905 wxString wildcard
= _T("Header files (*.h)|*.h|All files (*.*)|*.*");
907 wxFileDialog
dialog(wxTheApp
->GetTopWindow(),
908 _("Save Setup File As"),
910 wildcard
, wxSAVE
|wxOVERWRITE_PROMPT
);
912 if (dialog
.ShowModal() == wxID_OK
)
914 wxString fullPath
= dialog
.GetPath();
916 // TODO: save last saved path in settings.
918 wxFileOutputStream
stream(fullPath
);
921 wxMessageBox(_("Sorry, could not save this file."), _("Save Setup File"), wxICON_EXCLAMATION
|wxOK
);
929 void ctConfigToolView::OnSaveConfigureCommand(wxCommandEvent
& event
)
931 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
932 wxString configureStr
= doc
->GenerateConfigureCommand();
934 wxString filename
= _T("configurewx.sh");
935 wxString path
= doc
->GetFrameworkDir(FALSE
);
936 wxString wildcard
= _T("Shell script files (*.sh)|*.sh|All files (*.*)|*.*");
938 wxFileDialog
dialog(wxTheApp
->GetTopWindow(),
939 _("Save Configure Command File As"),
941 wildcard
, wxSAVE
|wxOVERWRITE_PROMPT
);
943 if (dialog
.ShowModal() == wxID_OK
)
945 wxString fullPath
= dialog
.GetPath();
947 // TODO: save last saved path in settings.
949 wxFileOutputStream
stream(fullPath
);
952 wxMessageBox(_("Sorry, could not save this file."), _("Save Configure Command File"), wxICON_EXCLAMATION
|wxOK
);
956 stream
<< configureStr
;
960 void ctConfigToolView::OnUpdateSaveSetupFile(wxUpdateUIEvent
& event
)
965 void ctConfigToolView::OnUpdateSaveConfigureCommand(wxUpdateUIEvent
& event
)