1 /////////////////////////////////////////////////////////////////////////////
2 // Name: configtoolview.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
19 #include "wx/wfstream.h"
20 #include "wx/txtstrm.h"
21 #include "configtoolview.h"
22 #include "configtooldoc.h"
23 #include "configtree.h"
24 #include "wxconfigtool.h"
25 #include "mainframe.h"
26 #include "propeditor.h"
28 #include "custompropertydialog.h"
30 IMPLEMENT_DYNAMIC_CLASS(ctConfigToolView
, wxView
)
32 BEGIN_EVENT_TABLE(ctConfigToolView
, wxView
)
33 EVT_MENU(ctID_ADD_ITEM_CHECKBOX
, ctConfigToolView::OnAddCheckBoxItem
)
34 EVT_MENU(ctID_ADD_ITEM_RADIOBUTTON
, ctConfigToolView::OnAddRadioButtonItem
)
35 EVT_MENU(ctID_ADD_ITEM_GROUP
, ctConfigToolView::OnAddGroupItem
)
36 EVT_MENU(ctID_ADD_ITEM_CHECK_GROUP
, ctConfigToolView::OnAddCheckGroupItem
)
37 EVT_MENU(ctID_ADD_ITEM_RADIO_GROUP
, ctConfigToolView::OnAddRadioGroupItem
)
38 EVT_MENU(ctID_ADD_ITEM_STRING
, ctConfigToolView::OnAddStringItem
)
39 EVT_MENU(ctID_RENAME_ITEM
, ctConfigToolView::OnRenameItem
)
40 EVT_MENU(ctID_DELETE_ITEM
, ctConfigToolView::OnDeleteItem
)
42 EVT_MENU(wxID_COPY
, ctConfigToolView::OnCopy
)
43 EVT_MENU(wxID_CUT
, ctConfigToolView::OnCut
)
44 EVT_MENU(wxID_PASTE
, ctConfigToolView::OnPaste
)
46 EVT_UPDATE_UI(wxID_COPY
, ctConfigToolView::OnUpdateCopy
)
47 EVT_UPDATE_UI(wxID_CUT
, ctConfigToolView::OnUpdateCut
)
48 EVT_UPDATE_UI(wxID_PASTE
, ctConfigToolView::OnUpdatePaste
)
50 EVT_MENU(ctID_ITEM_HELP
, ctConfigToolView::OnItemHelp
)
52 EVT_UPDATE_UI(ctID_ADD_ITEM_CHECKBOX
, ctConfigToolView::OnUpdateAddItem
)
53 EVT_UPDATE_UI(ctID_ADD_ITEM_RADIOBUTTON
, ctConfigToolView::OnUpdateAddItem
)
54 EVT_UPDATE_UI(ctID_ADD_ITEM_GROUP
, ctConfigToolView::OnUpdateAddItem
)
55 EVT_UPDATE_UI(ctID_ADD_ITEM_CHECK_GROUP
, ctConfigToolView::OnUpdateAddItem
)
56 EVT_UPDATE_UI(ctID_ADD_ITEM_RADIO_GROUP
, ctConfigToolView::OnUpdateAddItem
)
57 EVT_UPDATE_UI(ctID_ADD_ITEM_STRING
, ctConfigToolView::OnUpdateAddItem
)
58 EVT_UPDATE_UI(ctID_RENAME_ITEM
, ctConfigToolView::OnUpdateCut
)
59 EVT_UPDATE_UI(ctID_DELETE_ITEM
, ctConfigToolView::OnUpdateCut
)
60 EVT_UPDATE_UI(ctID_ITEM_HELP
, ctConfigToolView::OnUpdateItemHelp
)
62 EVT_MENU(ctID_TREE_COPY
, ctConfigToolView::OnContextCopy
)
63 EVT_MENU(ctID_TREE_CUT
, ctConfigToolView::OnContextCut
)
64 EVT_MENU(ctID_TREE_PASTE_BEFORE
, ctConfigToolView::OnContextPasteBefore
)
65 EVT_MENU(ctID_TREE_PASTE_AFTER
, ctConfigToolView::OnContextPasteAfter
)
66 EVT_MENU(ctID_TREE_PASTE_AS_CHILD
, ctConfigToolView::OnContextPasteAsChild
)
67 EVT_UPDATE_UI(ctID_TREE_COPY
, ctConfigToolView::OnUpdateContextCopy
)
68 EVT_UPDATE_UI(ctID_TREE_CUT
, ctConfigToolView::OnUpdateContextCut
)
69 EVT_UPDATE_UI(ctID_TREE_PASTE_BEFORE
, ctConfigToolView::OnUpdateContextPasteBefore
)
70 EVT_UPDATE_UI(ctID_TREE_PASTE_AFTER
, ctConfigToolView::OnUpdateContextPasteAfter
)
71 EVT_UPDATE_UI(ctID_TREE_PASTE_AS_CHILD
, ctConfigToolView::OnUpdateContextPasteAsChild
)
73 EVT_MENU(ctID_ADD_CUSTOM_PROPERTY
, ctConfigToolView::OnAddCustomProperty
)
74 EVT_MENU(ctID_EDIT_CUSTOM_PROPERTY
, ctConfigToolView::OnEditCustomProperty
)
75 EVT_MENU(ctID_DELETE_CUSTOM_PROPERTY
, ctConfigToolView::OnDeleteCustomProperty
)
76 EVT_UPDATE_UI(ctID_ADD_CUSTOM_PROPERTY
, ctConfigToolView::OnUpdateAddCustomProperty
)
77 EVT_UPDATE_UI(ctID_EDIT_CUSTOM_PROPERTY
, ctConfigToolView::OnUpdateEditCustomProperty
)
78 EVT_UPDATE_UI(ctID_DELETE_CUSTOM_PROPERTY
, ctConfigToolView::OnUpdateDeleteCustomProperty
)
80 EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY
, ctConfigToolView::OnTabSelect
)
82 EVT_MENU(ctID_SAVE_SETUP_FILE
, ctConfigToolView::OnSaveSetupFile
)
83 EVT_MENU(ctID_SAVE_CONFIGURE_COMMAND
, ctConfigToolView::OnSaveConfigureCommand
)
84 EVT_UPDATE_UI(ctID_SAVE_SETUP_FILE
, ctConfigToolView::OnUpdateSaveSetupFile
)
85 EVT_UPDATE_UI(ctID_SAVE_CONFIGURE_COMMAND
, ctConfigToolView::OnUpdateSaveConfigureCommand
)
87 EVT_MENU(wxID_FIND
, ctConfigToolView::OnFind
)
88 EVT_UPDATE_UI(wxID_FIND
, ctConfigToolView::OnUpdateFind
)
90 EVT_MENU(ctID_GO
, ctConfigToolView::OnGo
)
91 EVT_UPDATE_UI(ctID_GO
, ctConfigToolView::OnUpdateGo
)
95 // What to do when a view is created. Creates actual
96 // windows for displaying the view.
97 bool ctConfigToolView::OnCreate(wxDocument
*doc
, long WXUNUSED(flags
) )
99 wxGetApp().GetDocManager()->ActivateView(this, true);
100 wxGetApp().GetMainFrame()->SetDocument((ctConfigToolDoc
*) doc
);
101 wxGetApp().GetMainFrame()->GetSetupPage()->SetDocument((ctConfigToolDoc
*) doc
) ;
102 wxGetApp().GetMainFrame()->GetConfigurePage()->SetDocument((ctConfigToolDoc
*) doc
) ;
107 void ctConfigToolView::OnDraw(wxDC
*WXUNUSED(dc
))
111 void ctConfigToolView::OnUpdate(wxView
*WXUNUSED(sender
), wxObject
*hintObj
)
113 ctConfigToolDoc
* doc
= wxDynamicCast(GetDocument(), ctConfigToolDoc
);
114 ctConfigTreeCtrl
* treeCtrl
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl();
118 wxASSERT (doc
!= NULL
);
120 ctConfigItem
* selItem
= NULL
;
122 wxTreeItemId sel
= treeCtrl
->GetSelection();
125 ctTreeItemData
* data
= (ctTreeItemData
*) treeCtrl
->GetItemData(sel
);
127 selItem
= data
->GetConfigItem() ;
130 ctConfigToolHint
* hint
= (ctConfigToolHint
*) hintObj
;
131 int hintOp
= ctNoHint
;
137 case ctInitialUpdate
:
139 if (doc
&& doc
->GetTopItem())
141 wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->DeleteAllItems();
142 AddItems(wxGetApp().GetMainFrame()->GetConfigTreeCtrl(), doc
->GetTopItem());
143 wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->Expand(doc
->GetTopItem()->GetTreeItemId());
151 wxGetApp().GetMainFrame()->GetPropertyEditor()->ShowItem(selItem
);
157 // TODO: update windows and frame title
160 case ctFilenameChanged
:
162 wxGetApp().GetMainFrame()->UpdateFrameTitle();
167 // TODO: update windows
168 treeCtrl
->DeleteAllItems();
169 wxGetApp().GetMainFrame()->GetPropertyEditor()->ShowItem(NULL
);
174 // ctConfigItem& ti = *(ctConfigItem *)hint->m_item;
175 wxGetApp().GetMainFrame()->GetPropertyEditor()->ShowItem(selItem
);
184 // Clean up windows used for displaying the view.
185 bool ctConfigToolView::OnClose(bool WXUNUSED(deleteWindow
))
187 if (!GetDocument()->Close())
190 ctConfigToolHint
hint(NULL
, ctClear
);
191 GetDocument()->UpdateAllViews (NULL
, & hint
);
193 wxGetApp().GetDocManager()->ActivateView(this, false);
197 wxGetApp().GetMainFrame()->SetDocument(NULL
);
198 wxGetApp().GetMainFrame()->GetSetupPage()->SetDocument(NULL
) ;
199 wxGetApp().GetMainFrame()->GetConfigurePage()->SetDocument(NULL
) ;
204 void ctConfigToolView::OnChangeFilename()
206 if (wxGetApp().GetTopWindow() && GetDocument())
208 wxString
docTitle(wxFileNameFromPath(GetDocument()->GetFilename()));
209 wxStripExtension(docTitle
);
210 GetDocument()->SetTitle(docTitle
);
212 wxString
name(GetDocument()->GetFilename());
213 wxStripExtension(name
);
217 wxString modifiedMarker
;
218 if (GetDocument()->IsModified())
219 modifiedMarker
= wxT("*");
221 title
= docTitle
+ modifiedMarker
+ wxString(wxT(" - ")) + wxGetApp().GetSettings().GetAppName() ;
223 ((wxFrame
*) wxGetApp().GetTopWindow())->SetTitle(title
);
228 void ctConfigToolView::OnUpdateDisable(wxUpdateUIEvent
& event
)
230 event
.Enable( false );
233 void ctConfigToolView::OnUpdateAddItem(wxUpdateUIEvent
& event
)
235 event
.Enable( true );
238 /// Add item and its children to the tree
239 void ctConfigToolView::AddItems(ctConfigTreeCtrl
* treeControl
, ctConfigItem
* item
)
241 SyncItem(treeControl
, item
);
243 int count
= item
->GetChildCount();
245 for (i
= 0; i
< count
; i
++)
247 ctConfigItem
* child
= item
->GetChild(i
);
248 AddItems(treeControl
, child
);
252 /// Gets the tree item in sync with the item
253 void ctConfigToolView::SyncItem(ctConfigTreeCtrl
* treeControl
, ctConfigItem
* item
)
255 if (!item
->GetTreeItemId().IsOk())
257 if (!item
->GetParent())
259 item
->SetTreeItem(treeControl
->AddRoot(wxEmptyString
, -1, -1, new ctTreeItemData(item
)));
263 // Find the item to insert the new item after.
264 ctConfigItem
* previousItem
= item
->FindPreviousSibling();
265 if (previousItem
&& previousItem
->GetTreeItemId().IsOk())
267 item
->SetTreeItem(treeControl
->InsertItem(item
->GetParent()->GetTreeItemId(),
268 previousItem
->GetTreeItemId(),
269 item
->GetName(), -1, -1, new ctTreeItemData(item
)));
271 else if (!previousItem
&& item
->GetParent()->GetChildCount() > 1
274 // Insert at the beginning
275 item
->SetTreeItem(treeControl
->InsertItem(item
->GetParent()->GetTreeItemId(),
276 (size_t) 0, // Insert at first position
277 item
->GetName(), -1, -1, new ctTreeItemData(item
)));
281 item
->SetTreeItem(treeControl
->AppendItem(item
->GetParent()->GetTreeItemId(),
282 item
->GetName(), -1, -1, new ctTreeItemData(item
)));
287 if (item
->GetTreeItemId().IsOk())
289 treeControl
->SetItemText(item
->GetTreeItemId(), item
->GetName());
293 if (item
->GetType() == ctTypeGroup
)
295 iconId
= treeControl
->GetIconTable().GetIconId(wxT("Group"), 0, item
->IsActive());
297 else if (item
->GetType() == ctTypeCheckGroup
)
299 iconId
= treeControl
->GetIconTable().GetIconId(wxT("CheckGroup"), item
->IsEnabled() ? 0 : 1, item
->IsActive());
301 else if (item
->GetType() == ctTypeRadioGroup
)
303 iconId
= treeControl
->GetIconTable().GetIconId(wxT("RadioGroup"), item
->IsEnabled() ? 0 : 1, item
->IsActive());
305 else if (item
->GetType() == ctTypeBoolCheck
)
307 iconId
= treeControl
->GetIconTable().GetIconId(wxT("Checkbox"), item
->IsEnabled() ? 0 : 1, item
->IsActive());
309 else if (item
->GetType() == ctTypeBoolRadio
)
311 iconId
= treeControl
->GetIconTable().GetIconId(wxT("Radiobutton"), item
->IsEnabled() ? 0 : 1, item
->IsActive());
313 treeControl
->SetItemImage(item
->GetTreeItemId(), iconId
, wxTreeItemIcon_Normal
);
314 treeControl
->SetItemImage(item
->GetTreeItemId(), iconId
, wxTreeItemIcon_Selected
);
316 if (treeControl
->GetSelection() == item
->GetTreeItemId())
318 if (wxGetApp().GetMainFrame()->GetPropertyEditor()->GetItem())
319 wxGetApp().GetMainFrame()->GetPropertyEditor()->UpdateTitle();
325 void ctConfigToolView::OnIconLeftDown(ctConfigTreeCtrl
* treeControl
, ctConfigItem
* item
)
327 if (!item
->IsActive())
330 if (item
->GetType() == ctTypeCheckGroup
||
331 item
->GetType() == ctTypeBoolCheck
||
332 item
->GetType() == ctTypeBoolRadio
||
333 item
->GetType() == ctTypeRadioGroup
336 // Don't toggle a radio button that's already
338 if ((item
->GetType() == ctTypeBoolRadio
|| item
->GetType() == ctTypeRadioGroup
)
339 && item
->IsEnabled())
342 item
->Enable(!item
->IsEnabled());
344 GetDocument()->Modify(true);
347 SyncItem(treeControl
, item
);
350 if ((item
->GetType() == ctTypeBoolRadio
|| item
->GetType() == ctTypeRadioGroup
) && item
->IsEnabled())
352 item
->PropagateRadioButton(considered
);
354 item
->PropagateChange(considered
);
356 // Update the setup.h and configure text
357 if (wxGetApp().GetMainFrame()->GetMainNotebook()->GetSelection() > 0)
364 /// Returns the selected config item, if any.
365 ctConfigItem
* ctConfigToolView::GetSelection()
367 wxTreeCtrl
* treeCtrl
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl();
371 wxTreeItemId sel
= treeCtrl
->GetSelection();
374 ctTreeItemData
* data
= (ctTreeItemData
*) treeCtrl
->GetItemData(sel
);
376 return data
->GetConfigItem() ;
381 /// Add a checkbox item
382 void ctConfigToolView::OnAddCheckBoxItem(wxCommandEvent
& WXUNUSED(event
))
384 AddItem(ctTypeBoolCheck
, _("New checkbox item"));
387 /// Add a radiobutton item
388 void ctConfigToolView::OnAddRadioButtonItem(wxCommandEvent
& WXUNUSED(event
))
390 AddItem(ctTypeBoolRadio
, _("New radio button item"));
394 void ctConfigToolView::OnAddGroupItem(wxCommandEvent
& WXUNUSED(event
))
396 AddItem(ctTypeGroup
, _("New group item"));
399 /// Add a group option item
400 void ctConfigToolView::OnAddCheckGroupItem(wxCommandEvent
& WXUNUSED(event
))
402 AddItem(ctTypeCheckGroup
, _("New check group item"));
405 /// Add a group option item
406 void ctConfigToolView::OnAddRadioGroupItem(wxCommandEvent
& WXUNUSED(event
))
408 AddItem(ctTypeRadioGroup
, _("New radio group item"));
411 /// Add a string item
412 void ctConfigToolView::OnAddStringItem(wxCommandEvent
& WXUNUSED(event
))
414 AddItem(ctTypeString
, _("New string item"));
418 void ctConfigToolView::AddItem(ctConfigType type
, const wxString
& msg
)
420 ctConfigItem
* sel
= GetSelection();
423 wxString name
= wxGetTextFromUser(_("Please enter a name for the new item."), msg
);
426 ctConfigItem
* parent
;
427 ctConfigItem
* insertBefore
;
428 if (sel
->CanHaveChildren())
435 parent
= sel
->GetParent();
436 insertBefore
= sel
->FindNextSibling();
439 ctConfigItem
* newItem
= new ctConfigItem(NULL
, type
, name
);
440 newItem
->InitProperties();
442 newItem
->GetDocument()->GetCommandProcessor()->Submit(
443 new ctConfigCommand(msg
, ctCMD_NEW_ELEMENT
, NULL
, newItem
,
444 parent
, insertBefore
));
450 void ctConfigToolView::OnDeleteItem(wxCommandEvent
& WXUNUSED(event
))
452 ctConfigItem
* sel
= GetSelection();
455 wxString
name(sel
->GetName());
457 msg
.Printf(_("Delete %s?"), (const wxChar
*) name
);
458 if (wxYES
== wxMessageBox(msg
, _("Delete item"), wxICON_QUESTION
|wxYES_NO
))
460 wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->Delete(sel
->GetTreeItemId());
466 void ctConfigToolView::OnRenameItem(wxCommandEvent
& WXUNUSED(event
))
468 ctConfigItem
* sel
= GetSelection();
471 wxString name
= wxGetTextFromUser(_("Please enter a new name for the item."),
472 _("Rename item"), sel
->GetName());
476 SyncItem(wxGetApp().GetMainFrame()->GetConfigTreeCtrl(), sel
);
478 ctConfigToolHint
hint(NULL
, ctSelChanged
);
479 GetDocument()->UpdateAllViews (NULL
, & hint
);
484 /// Copy an item to the clipboard
485 void ctConfigToolView::OnCopy(wxCommandEvent
& WXUNUSED(event
))
487 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
488 ctConfigItem
* sel
= GetSelection();
491 doc
->SetClipboardItem(sel
->DeepClone());
495 /// Copy an item to the clipboard and cut the item
496 void ctConfigToolView::OnCut(wxCommandEvent
& WXUNUSED(event
))
498 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
499 ctConfigItem
* sel
= GetSelection();
503 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Cut Config Item"), ctCMD_CUT
,
504 sel
, (ctConfigItem
*) NULL
);
505 doc
->GetCommandProcessor()->Submit(cmd
);
510 /// Paste an item from the clipboard to the tree
511 void ctConfigToolView::OnPaste(wxCommandEvent
& WXUNUSED(event
))
513 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
514 ctConfigItem
* sel
= GetSelection();
515 if (sel
&& doc
->GetClipboardItem())
517 ctConfigItem
* parent
;
518 ctConfigItem
* insertBefore
;
519 if (sel
->CanHaveChildren())
526 parent
= sel
->GetParent();
527 insertBefore
= sel
->FindNextSibling();
530 ctConfigItem
* newItem
= doc
->GetClipboardItem()->DeepClone();
531 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE
,
532 NULL
, newItem
, parent
, insertBefore
);
533 doc
->GetCommandProcessor()->Submit(cmd
);
537 /// Update for copy command
538 void ctConfigToolView::OnUpdateCopy(wxUpdateUIEvent
& event
)
540 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
541 event
.Enable( doc
&& GetSelection() && GetSelection()->GetParent() );
545 void ctConfigToolView::OnUpdateCut(wxUpdateUIEvent
& event
)
547 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
548 event
.Enable( doc
&& GetSelection() && GetSelection()->GetParent() );
552 void ctConfigToolView::OnUpdatePaste(wxUpdateUIEvent
& event
)
554 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
555 event
.Enable( doc
&& doc
->GetClipboardItem() && GetSelection() );
558 /// Copy an item to the clipboard
559 void ctConfigToolView::OnContextCopy(wxCommandEvent
& WXUNUSED(event
))
561 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
562 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
565 doc
->SetClipboardItem(sel
->DeepClone());
569 /// Copy an item to the clipboard and cut the item
570 void ctConfigToolView::OnContextCut(wxCommandEvent
& WXUNUSED(event
))
572 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
573 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
577 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Cut Config Item"), ctCMD_CUT
,
578 sel
, (ctConfigItem
*) NULL
);
579 doc
->GetCommandProcessor()->Submit(cmd
);
584 /// Paste an item from the clipboard to the tree
585 void ctConfigToolView::OnContextPasteBefore(wxCommandEvent
& WXUNUSED(event
))
587 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
588 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
589 if (sel
&& doc
->GetClipboardItem())
591 ctConfigItem
* parent
= sel
->GetParent();
592 ctConfigItem
* insertBefore
= sel
;
594 ctConfigItem
* newItem
= doc
->GetClipboardItem()->DeepClone();
595 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE
,
596 NULL
, newItem
, parent
, insertBefore
);
597 doc
->GetCommandProcessor()->Submit(cmd
);
601 /// Paste an item from the clipboard to the tree
602 void ctConfigToolView::OnContextPasteAfter(wxCommandEvent
& WXUNUSED(event
))
604 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
605 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
606 if (sel
&& doc
->GetClipboardItem())
608 ctConfigItem
* parent
= sel
->GetParent();
609 ctConfigItem
* insertBefore
= sel
->FindNextSibling();
611 ctConfigItem
* newItem
= doc
->GetClipboardItem()->DeepClone();
612 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE
,
613 NULL
, newItem
, parent
, insertBefore
);
614 doc
->GetCommandProcessor()->Submit(cmd
);
618 /// Paste an item from the clipboard to the tree
619 void ctConfigToolView::OnContextPasteAsChild(wxCommandEvent
& WXUNUSED(event
))
621 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
622 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
623 if (sel
&& doc
->GetClipboardItem())
625 if (sel
->CanHaveChildren())
627 ctConfigItem
* parent
= sel
;
628 ctConfigItem
* insertBefore
= NULL
;
630 ctConfigItem
* newItem
= doc
->GetClipboardItem()->DeepClone();
631 ctConfigCommand
* cmd
= new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE
,
632 NULL
, newItem
, parent
, insertBefore
);
633 doc
->GetCommandProcessor()->Submit(cmd
);
638 /// Copy an item to the clipboard
639 void ctConfigToolView::OnUpdateContextCopy(wxUpdateUIEvent
& event
)
641 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
642 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
643 event
.Enable( doc
&& sel
&& sel
->GetParent() );
646 /// Copy an item to the clipboard and cut the item
647 void ctConfigToolView::OnUpdateContextCut(wxUpdateUIEvent
& event
)
649 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
650 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
651 event
.Enable( doc
&& sel
&& sel
->GetParent() );
654 /// Paste an item from the clipboard to the tree
655 void ctConfigToolView::OnUpdateContextPasteBefore(wxUpdateUIEvent
& event
)
657 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
658 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
659 event
.Enable( doc
&& sel
&& sel
->GetParent() && doc
->GetClipboardItem() );
662 /// Paste an item from the clipboard to the tree
663 void ctConfigToolView::OnUpdateContextPasteAfter(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::OnUpdateContextPasteAsChild(wxUpdateUIEvent
& event
)
673 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
674 ctConfigItem
* sel
= wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
675 event
.Enable( doc
&& sel
&& sel
->CanHaveChildren() && doc
->GetClipboardItem() );
679 void ctConfigToolView::OnItemHelp(wxCommandEvent
& WXUNUSED(event
))
681 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
682 if ( doc
&& GetSelection() )
684 wxString helpTopic
= GetSelection()->GetPropertyString(wxT("help-topic"));
685 if (!helpTopic
.empty())
687 wxGetApp().GetReferenceHelpController().DisplaySection(helpTopic
);
693 void ctConfigToolView::OnUpdateItemHelp(wxUpdateUIEvent
& event
)
695 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
696 event
.Enable( doc
&& GetSelection() );
699 /// Add a custom property
700 void ctConfigToolView::OnAddCustomProperty(wxCommandEvent
& WXUNUSED(event
))
702 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
703 ctConfigItem
* sel
= GetSelection();
704 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
705 if (doc
&& sel
&& editor
)
707 ctCustomPropertyDialog
dialog(wxGetApp().GetMainFrame(),
708 wxID_ANY
, _("Add a custom property"));
709 if (dialog
.ShowModal() == wxID_OK
)
711 wxString name
= dialog
.GetPropertyName();
712 wxString type
= dialog
.GetPropertyType();
713 wxString descr
= dialog
.GetPropertyDescription();
714 wxString editorType
= dialog
.GetEditorType();
715 wxArrayString choices
= dialog
.GetChoices();
717 if (sel
->GetProperties().FindProperty(name
))
719 wxMessageBox(_("Sorry, this name already exists."), _T("Add custom property"),
720 wxOK
|wxICON_INFORMATION
);
723 ctProperty
* property
= new ctProperty
;
724 if (type
== wxT("bool"))
725 property
->GetVariant() = wxVariant(false, name
);
726 else if (type
== wxT("double"))
727 property
->GetVariant() = wxVariant((double) 0.0, name
);
728 else if (type
== wxT("long"))
729 property
->GetVariant() = wxVariant((long) 0, name
);
731 property
->GetVariant() = wxVariant(wxEmptyString
, name
);
732 property
->SetCustom(true);
733 property
->SetDescription(descr
);
734 property
->SetChoices(choices
);
735 property
->SetEditorType(editorType
);
737 sel
->GetProperties().AddProperty(property
);
738 editor
->ShowItem(sel
);
744 /// Edit a custom property
745 void ctConfigToolView::OnEditCustomProperty(wxCommandEvent
& WXUNUSED(event
))
747 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
748 ctConfigItem
* sel
= GetSelection();
749 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
750 if (doc
&& sel
&& editor
)
753 ctProperty
* property
= editor
->FindSelectedProperty(row
) ;
754 if (property
&& property
->IsCustom())
756 wxString oldName
= property
->GetName();
757 wxString oldDescription
= property
->GetDescription();
758 wxString oldType
= property
->GetVariant().GetType();
759 wxString oldEditorType
= property
->GetEditorType();
760 wxArrayString oldChoices
= property
->GetChoices();
762 ctCustomPropertyDialog
dialog(wxGetApp().GetMainFrame(),
763 wxID_ANY
, _("Edit custom property"));
764 dialog
.SetPropertyName(oldName
);
765 dialog
.SetPropertyType(oldType
);
766 dialog
.SetPropertyDescription(oldDescription
);
767 if (dialog
.ShowModal() == wxID_OK
)
769 wxString name
= dialog
.GetPropertyName();
770 wxString type
= dialog
.GetPropertyType();
771 wxString editorType
= dialog
.GetEditorType();
772 wxArrayString choices
= dialog
.GetChoices();
773 wxString descr
= dialog
.GetPropertyDescription();
775 if (name
!= oldName
&& sel
->GetProperties().FindProperty(name
))
777 wxMessageBox(_("Sorry, this name already exists."), _T("Add custom property"),
778 wxOK
|wxICON_INFORMATION
);
783 if (type
== wxT("bool"))
784 property
->GetVariant() = wxVariant(false, name
);
785 else if (type
== wxT("double"))
786 property
->GetVariant() = wxVariant((double) 0.0, name
);
787 else if (type
== wxT("long"))
788 property
->GetVariant() = wxVariant((long) 0, name
);
790 property
->GetVariant() = wxVariant(wxEmptyString
, name
);
793 property
->GetVariant().SetName(name
);
795 if (choices
!= oldChoices
)
796 property
->SetChoices(choices
);
798 if (editorType
!= oldEditorType
)
799 property
->SetEditorType(editorType
);
802 property
->GetVariant().SetName(name
);
804 property
->SetCustom(true);
806 if (descr
!= oldDescription
)
807 property
->SetDescription(descr
);
809 editor
->ShowItem(sel
);
816 /// Delete a custom property
817 void ctConfigToolView::OnDeleteCustomProperty(wxCommandEvent
& WXUNUSED(event
))
819 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
820 ctConfigItem
* sel
= GetSelection();
821 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
822 if (doc
&& sel
&& editor
)
825 ctProperty
* property
= editor
->FindSelectedProperty(row
) ;
826 if (property
&& property
->IsCustom())
828 wxString
name(property
->GetName());
830 msg
.Printf(_("Delete custom property '%s'?"), (const wxChar
*) name
);
831 if (wxYES
== wxMessageBox(msg
, _("Delete property"), wxICON_EXCLAMATION
|wxYES_NO
))
833 sel
->GetProperties().RemoveProperty(property
);
834 editor
->ShowItem(sel
);
842 /// Add a custom property: update event
843 void ctConfigToolView::OnUpdateAddCustomProperty(wxUpdateUIEvent
& event
)
845 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
846 event
.Enable( doc
&& GetSelection() && GetSelection()->GetParent() );
849 /// Edit a custom property: update event
850 void ctConfigToolView::OnUpdateEditCustomProperty(wxUpdateUIEvent
& event
)
852 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
853 ctConfigItem
* sel
= GetSelection();
854 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
856 event
.Enable( doc
&& sel
&& sel
->GetParent() && editor
&&
857 editor
->FindSelectedProperty(row
) &&
858 editor
->FindSelectedProperty(row
)->IsCustom() );
861 /// Delete a custom property: update event
862 void ctConfigToolView::OnUpdateDeleteCustomProperty(wxUpdateUIEvent
& event
)
864 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
865 ctConfigItem
* sel
= GetSelection();
866 ctPropertyEditor
* editor
= wxGetApp().GetMainFrame()->GetPropertyEditor();
868 event
.Enable( doc
&& sel
&& sel
->GetParent() && editor
&&
869 editor
->FindSelectedProperty(row
) &&
870 editor
->FindSelectedProperty(row
)->IsCustom() );
873 /// Regenerate setup.h and configure command
874 void ctConfigToolView::RegenerateSetup()
876 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
877 ctOutputWindow
* setupPage
= wxGetApp().GetMainFrame()->GetSetupPage() ;
878 ctOutputWindow
* configurePage
= wxGetApp().GetMainFrame()->GetConfigurePage() ;
880 wxString setupStr
= doc
->GenerateSetup();
881 wxString configureStr
= doc
->GenerateConfigureCommand();
883 setupPage
->SetText(setupStr
);
884 configurePage
->SetText(configureStr
);
887 /// Regenerate if selected a tab
888 void ctConfigToolView::OnTabSelect(wxNotebookEvent
& event
)
890 if (wxGetApp().GetMainFrame()->GetMainNotebook() != event
.GetEventObject())
896 if (event
.GetSelection() > 0)
902 void ctConfigToolView::OnSaveSetupFile(wxCommandEvent
& WXUNUSED(event
))
904 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
905 wxString setupStr
= doc
->GenerateSetup();
907 wxString filename
= _T("setup.h");
908 wxString path
= wxGetApp().GetSettings().m_lastSetupSaveDir
;
910 path
= doc
->GetFrameworkDir(false);
911 wxString wildcard
= _T("Header files (*.h)|*.h|All files (*.*)|*.*");
913 wxFileDialog
dialog(wxTheApp
->GetTopWindow(),
914 _("Save Setup File As"),
916 wildcard
, wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
918 if (dialog
.ShowModal() == wxID_OK
)
920 wxString fullPath
= dialog
.GetPath();
921 wxGetApp().GetSettings().m_lastSetupSaveDir
= wxPathOnly(fullPath
);
923 wxFileOutputStream
osFile(fullPath
);
926 wxMessageBox(_("Sorry, could not save this file."), _("Save Setup File"), wxICON_EXCLAMATION
|wxOK
);
930 wxTextOutputStream
stream(osFile
);
935 void ctConfigToolView::OnSaveConfigureCommand(wxCommandEvent
& WXUNUSED(event
))
937 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
938 wxString configureStr
= doc
->GenerateConfigureCommand();
940 wxString filename
= _T("configurewx.sh");
941 wxString path
= wxGetApp().GetSettings().m_lastSetupSaveDir
;
943 path
= doc
->GetFrameworkDir(false);
944 wxString wildcard
= _T("Shell script files (*.sh)|*.sh|All files (*.*)|*.*");
946 wxFileDialog
dialog(wxTheApp
->GetTopWindow(),
947 _("Save Configure Command File As"),
949 wildcard
, wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
951 if (dialog
.ShowModal() == wxID_OK
)
953 wxString fullPath
= dialog
.GetPath();
954 wxGetApp().GetSettings().m_lastSetupSaveDir
= wxPathOnly(fullPath
);
956 wxFileOutputStream
osFile(fullPath
);
959 wxMessageBox(_("Sorry, could not save this file."), _("Save Configure Command File"), wxICON_EXCLAMATION
|wxOK
);
963 wxTextOutputStream
stream(osFile
);
964 stream
<< configureStr
;
968 void ctConfigToolView::OnUpdateSaveSetupFile(wxUpdateUIEvent
& event
)
973 void ctConfigToolView::OnUpdateSaveConfigureCommand(wxUpdateUIEvent
& event
)
979 void ctConfigToolView::OnFind(wxCommandEvent
& WXUNUSED(event
))
981 ctFindReplaceDialog
* dialog
= wxGetApp().GetMainFrame()->GetFindDialog();
989 int style
= wxFR_NOUPDOWN
;
990 wxString
caption(wxT("Find text in settings"));
991 int flags
= wxFR_DOWN
;
992 if (wxGetApp().GetSettings().m_matchCase
)
993 flags
|=wxFR_MATCHCASE
;
994 if (wxGetApp().GetSettings().m_matchWholeWord
)
995 flags
|=wxFR_WHOLEWORD
;
997 ctFindReplaceDialog::sm_findData
.SetFlags(flags
);
999 dialog
= new ctFindReplaceDialog(wxGetApp().GetMainFrame(), caption
, style
);
1004 /// Update find text
1005 void ctConfigToolView::OnUpdateFind(wxUpdateUIEvent
& event
)
1010 /// Save default file type
1011 void ctConfigToolView::OnGo(wxCommandEvent
& WXUNUSED(event
))
1013 ctConfigToolDoc
* doc
= (ctConfigToolDoc
*) GetDocument();
1014 wxString path
= wxGetApp().GetSettings().m_lastSetupSaveDir
;
1017 if (wxGetApp().GetSettings().m_defaultFileKind
== wxT("Setup file"))
1020 wxString setupStr
= doc
->GenerateSetup();
1022 wxString fullPath
= path
+ wxFILE_SEP_PATH
+ wxT("setup.h");
1023 if (wxFileExists(fullPath
))
1026 msg
.Printf(wxT("Overwrite existing file %s?"), (const wxChar
*) fullPath
);
1027 int ans
= wxMessageBox(msg
, _("Save Setup File"), wxICON_QUESTION
|wxYES_NO
|wxCANCEL
);
1028 if (ans
== wxCANCEL
)
1033 wxFileOutputStream
stream(fullPath
);
1036 wxMessageBox(_("Sorry, could not save this file."), _("Save Setup File"), wxICON_EXCLAMATION
|wxOK
);
1041 else if (wxGetApp().GetSettings().m_defaultFileKind
== wxT("Configure script"))
1044 wxString configureStr
= doc
->GenerateConfigureCommand();
1046 wxString fullPath
= path
+ wxFILE_SEP_PATH
+ wxT("configurewx.sh");
1047 if (wxFileExists(fullPath
))
1050 msg
.Printf(wxT("Overwrite existing file %s?"), (const wxChar
*) fullPath
);
1051 int ans
= wxMessageBox(msg
, _("Save Configure Script"), wxICON_QUESTION
|wxYES_NO
|wxCANCEL
);
1052 if (ans
== wxCANCEL
)
1057 wxFileOutputStream
stream(fullPath
);
1060 wxMessageBox(_("Sorry, could not save this file."), _("Save Configure Script"), wxICON_EXCLAMATION
|wxOK
);
1063 stream
<< configureStr
;
1067 wxMessageBox(wxT("Unrecognised default file type."));
1073 void ctConfigToolView::OnUpdateGo(wxUpdateUIEvent
& event
)
1075 wxString path
= wxGetApp().GetSettings().m_lastSetupSaveDir
;
1076 event
.Enable(!path
.empty());
1079 //----------------------------------------------------------------------------
1080 // ctFindReplaceDialog
1081 //----------------------------------------------------------------------------
1083 BEGIN_EVENT_TABLE(ctFindReplaceDialog
, wxFindReplaceDialog
)
1084 EVT_FIND(wxID_ANY
, ctFindReplaceDialog::OnFind
)
1085 EVT_FIND_NEXT(wxID_ANY
, ctFindReplaceDialog::OnFind
)
1086 EVT_FIND_CLOSE(wxID_ANY
, ctFindReplaceDialog::OnClose
)
1089 wxFindReplaceData
ctFindReplaceDialog::sm_findData
;
1090 wxString
ctFindReplaceDialog::sm_currentItem
= wxEmptyString
;
1092 ctFindReplaceDialog::ctFindReplaceDialog( wxWindow
*parent
, const wxString
& title
,
1094 wxFindReplaceDialog( parent
, & sm_findData
, title
, style
)
1096 sm_currentItem
= wxEmptyString
;
1099 ((ctMainFrame
*) parent
)->SetFindDialog(this);
1102 void ctFindReplaceDialog::OnFind(wxFindDialogEvent
& event
)
1104 wxString textToFind
= event
.GetFindString();
1105 bool matchCase
= ((event
.GetFlags() & wxFR_MATCHCASE
) != 0);
1106 bool wholeWord
= ((event
.GetFlags() & wxFR_WHOLEWORD
) != 0);
1108 wxGetApp().GetSettings().m_matchCase
= matchCase
;
1109 wxGetApp().GetSettings().m_matchWholeWord
= wholeWord
;
1111 if (!DoFind(textToFind
, matchCase
, wholeWord
))
1113 wxMessageBox(wxT("No more matches."), wxT("Search"), wxOK
|wxICON_INFORMATION
, this);
1117 bool ctFindReplaceDialog::DoFind(const wxString
& textToFind
, bool matchCase
, bool wholeWord
, bool wrap
)
1119 ctConfigToolDoc
* doc
= wxGetApp().GetMainFrame()->GetDocument();
1122 ctConfigToolView
* view
= (ctConfigToolView
*) doc
->GetFirstView();
1124 ctConfigItem
* currentItem
= NULL
;
1125 ctConfigItem
* focusItem
= view
->GetSelection();
1128 focusItem
= doc
->GetTopItem();
1133 if (!sm_currentItem
.empty())
1135 currentItem
= doc
->GetTopItem()->FindItem(sm_currentItem
);
1138 // If we were at this item last time, skip the first one.
1139 bool skipFirstItem
= (currentItem
== focusItem
);
1140 currentItem
= FindNextItem(doc
, currentItem
, textToFind
, matchCase
, wholeWord
, wrap
,
1145 sm_currentItem
= currentItem
->GetName();
1146 wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->SelectItem(currentItem
->GetTreeItemId());
1151 sm_currentItem
= wxEmptyString
;
1157 ctConfigItem
* ctFindReplaceDialog::FindNextItem(ctConfigToolDoc
* doc
,
1159 const wxString
& text
,
1165 ctConfigItem
* firstInDoc
= NULL
;
1167 wxString
text2(text
);
1171 ctConfigItem
* found
= NULL
;
1172 ctConfigItem
* next
= item
;
1177 // If starting the search from beginning, we can now
1178 // set the value of 'item' in the 2nd iteration without immediately
1179 // dropping out of the while loop because card == next
1180 if (!item
&& (i
> 0))
1183 // We might want to start from this item if skipFirst is false.
1184 if ((i
== 0) && !skipFirst
&& next
)
1188 next
= doc
->FindNextItem(next
, wrap
);
1190 // Save to be used in iteration 2
1191 if ((i
== 0) && !item
)
1196 wxString
str(next
->GetName());
1197 wxString
description(next
->GetPropertyString(wxT("description")));
1198 wxString
notes(next
->GetPropertyString(wxT("notes")));
1202 description
.MakeLower();
1205 if (ctMatchString(str
, text2
, matchWordOnly
) ||
1206 ctMatchString(description
, text2
, matchWordOnly
) ||
1207 ctMatchString(notes
, text2
, matchWordOnly
))
1213 break; // Didn't find an item at all
1217 while (!found
&& item
!= next
);
1219 if (item
== found
&& !firstInDoc
)
1225 void ctFindReplaceDialog::OnClose(wxFindDialogEvent
& event
)
1227 bool matchCase
= ((event
.GetFlags() & wxFR_MATCHCASE
) != 0);
1228 bool wholeWord
= ((event
.GetFlags() & wxFR_WHOLEWORD
) != 0);
1229 wxGetApp().GetSettings().m_matchCase
= matchCase
;
1230 wxGetApp().GetSettings().m_matchWholeWord
= wholeWord
;
1233 ((ctMainFrame
*) GetParent())->SetFindDialog(NULL
);