📄 configtoolview.cpp
字号:
{
AddItem(ctTypeString, _("New string item"));
}
/// Add an item
void ctConfigToolView::AddItem(ctConfigType type, const wxString& msg)
{
ctConfigItem* sel = GetSelection();
if (sel)
{
wxString name = wxGetTextFromUser(_("Please enter a name for the new item."), msg);
if (!name.empty())
{
ctConfigItem* parent ;
ctConfigItem* insertBefore ;
if (sel->CanHaveChildren())
{
parent = sel;
insertBefore = NULL;
}
else
{
parent = sel->GetParent();
insertBefore = sel->FindNextSibling();
}
ctConfigItem* newItem = new ctConfigItem(NULL, type, name);
newItem->InitProperties();
newItem->GetDocument()->GetCommandProcessor()->Submit(
new ctConfigCommand(msg, ctCMD_NEW_ELEMENT, NULL, newItem,
parent, insertBefore));
}
}
}
/// Delete an item
void ctConfigToolView::OnDeleteItem(wxCommandEvent& WXUNUSED(event))
{
ctConfigItem* sel = GetSelection();
if (sel)
{
wxString name(sel->GetName());
wxString msg;
msg.Printf(_("Delete %s?"), (const wxChar*) name);
if (wxYES == wxMessageBox(msg, _("Delete item"), wxICON_QUESTION|wxYES_NO))
{
wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->Delete(sel->GetTreeItemId());
}
}
}
/// Rename an item
void ctConfigToolView::OnRenameItem(wxCommandEvent& WXUNUSED(event))
{
ctConfigItem* sel = GetSelection();
if (sel)
{
wxString name = wxGetTextFromUser(_("Please enter a new name for the item."),
_("Rename item"), sel->GetName());
if (!name.empty())
{
sel->SetName(name);
SyncItem(wxGetApp().GetMainFrame()->GetConfigTreeCtrl(), sel);
ctConfigToolHint hint(NULL, ctSelChanged);
GetDocument()->UpdateAllViews (NULL, & hint);
}
}
}
/// Copy an item to the clipboard
void ctConfigToolView::OnCopy(wxCommandEvent& WXUNUSED(event))
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
ctConfigItem* sel = GetSelection();
if (sel)
{
doc->SetClipboardItem(sel->DeepClone());
}
}
/// Copy an item to the clipboard and cut the item
void ctConfigToolView::OnCut(wxCommandEvent& WXUNUSED(event))
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
ctConfigItem* sel = GetSelection();
if (sel)
{
{
ctConfigCommand* cmd = new ctConfigCommand(wxT("Cut Config Item"), ctCMD_CUT,
sel, (ctConfigItem*) NULL);
doc->GetCommandProcessor()->Submit(cmd);
}
}
}
/// Paste an item from the clipboard to the tree
void ctConfigToolView::OnPaste(wxCommandEvent& WXUNUSED(event))
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
ctConfigItem* sel = GetSelection();
if (sel && doc->GetClipboardItem())
{
ctConfigItem* parent ;
ctConfigItem* insertBefore ;
if (sel->CanHaveChildren())
{
parent = sel;
insertBefore = NULL;
}
else
{
parent = sel->GetParent();
insertBefore = sel->FindNextSibling();
}
ctConfigItem* newItem = doc->GetClipboardItem()->DeepClone();
ctConfigCommand* cmd = new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE,
NULL, newItem, parent, insertBefore);
doc->GetCommandProcessor()->Submit(cmd);
}
}
/// Update for copy command
void ctConfigToolView::OnUpdateCopy(wxUpdateUIEvent& event)
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
event.Enable( doc && GetSelection() && GetSelection()->GetParent() );
}
/// Update for cut
void ctConfigToolView::OnUpdateCut(wxUpdateUIEvent& event)
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
event.Enable( doc && GetSelection() && GetSelection()->GetParent() );
}
/// Update for paste
void ctConfigToolView::OnUpdatePaste(wxUpdateUIEvent& event)
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
event.Enable( doc && doc->GetClipboardItem() && GetSelection() );
}
/// Copy an item to the clipboard
void ctConfigToolView::OnContextCopy(wxCommandEvent& WXUNUSED(event))
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
ctConfigItem* sel = wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
if (doc && sel)
{
doc->SetClipboardItem(sel->DeepClone());
}
}
/// Copy an item to the clipboard and cut the item
void ctConfigToolView::OnContextCut(wxCommandEvent& WXUNUSED(event))
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
ctConfigItem* sel = wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
if (sel)
{
{
ctConfigCommand* cmd = new ctConfigCommand(wxT("Cut Config Item"), ctCMD_CUT,
sel, (ctConfigItem*) NULL);
doc->GetCommandProcessor()->Submit(cmd);
}
}
}
/// Paste an item from the clipboard to the tree
void ctConfigToolView::OnContextPasteBefore(wxCommandEvent& WXUNUSED(event))
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
ctConfigItem* sel = wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
if (sel && doc->GetClipboardItem())
{
ctConfigItem* parent = sel->GetParent();
ctConfigItem* insertBefore = sel;
ctConfigItem* newItem = doc->GetClipboardItem()->DeepClone();
ctConfigCommand* cmd = new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE,
NULL, newItem, parent, insertBefore);
doc->GetCommandProcessor()->Submit(cmd);
}
}
/// Paste an item from the clipboard to the tree
void ctConfigToolView::OnContextPasteAfter(wxCommandEvent& WXUNUSED(event))
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
ctConfigItem* sel = wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
if (sel && doc->GetClipboardItem())
{
ctConfigItem* parent = sel->GetParent();
ctConfigItem* insertBefore = sel->FindNextSibling();
ctConfigItem* newItem = doc->GetClipboardItem()->DeepClone();
ctConfigCommand* cmd = new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE,
NULL, newItem, parent, insertBefore);
doc->GetCommandProcessor()->Submit(cmd);
}
}
/// Paste an item from the clipboard to the tree
void ctConfigToolView::OnContextPasteAsChild(wxCommandEvent& WXUNUSED(event))
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
ctConfigItem* sel = wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
if (sel && doc->GetClipboardItem())
{
if (sel->CanHaveChildren())
{
ctConfigItem* parent = sel;
ctConfigItem* insertBefore = NULL;
ctConfigItem* newItem = doc->GetClipboardItem()->DeepClone();
ctConfigCommand* cmd = new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE,
NULL, newItem, parent, insertBefore);
doc->GetCommandProcessor()->Submit(cmd);
}
}
}
/// Copy an item to the clipboard
void ctConfigToolView::OnUpdateContextCopy(wxUpdateUIEvent& event)
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
ctConfigItem* sel = wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
event.Enable( doc && sel && sel->GetParent() );
}
/// Copy an item to the clipboard and cut the item
void ctConfigToolView::OnUpdateContextCut(wxUpdateUIEvent& event)
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
ctConfigItem* sel = wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
event.Enable( doc && sel && sel->GetParent() );
}
/// Paste an item from the clipboard to the tree
void ctConfigToolView::OnUpdateContextPasteBefore(wxUpdateUIEvent& event)
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
ctConfigItem* sel = wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
event.Enable( doc && sel && sel->GetParent() && doc->GetClipboardItem() );
}
/// Paste an item from the clipboard to the tree
void ctConfigToolView::OnUpdateContextPasteAfter(wxUpdateUIEvent& event)
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
ctConfigItem* sel = wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
event.Enable( doc && sel && sel->GetParent() && doc->GetClipboardItem() );
}
/// Paste an item from the clipboard to the tree
void ctConfigToolView::OnUpdateContextPasteAsChild(wxUpdateUIEvent& event)
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
ctConfigItem* sel = wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem();
event.Enable( doc && sel && sel->CanHaveChildren() && doc->GetClipboardItem() );
}
/// Item help
void ctConfigToolView::OnItemHelp(wxCommandEvent& WXUNUSED(event))
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
if ( doc && GetSelection() )
{
wxString helpTopic = GetSelection()->GetPropertyString(wxT("help-topic"));
if (!helpTopic.empty())
{
wxGetApp().GetReferenceHelpController().DisplaySection(helpTopic);
}
}
}
/// Item help update
void ctConfigToolView::OnUpdateItemHelp(wxUpdateUIEvent& event)
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
event.Enable( doc && GetSelection() );
}
/// Add a custom property
void ctConfigToolView::OnAddCustomProperty(wxCommandEvent& WXUNUSED(event))
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
ctConfigItem* sel = GetSelection();
ctPropertyEditor* editor = wxGetApp().GetMainFrame()->GetPropertyEditor();
if (doc && sel && editor)
{
ctCustomPropertyDialog dialog(wxGetApp().GetMainFrame(),
wxID_ANY, _("Add a custom property"));
if (dialog.ShowModal() == wxID_OK)
{
wxString name = dialog.GetPropertyName();
wxString type = dialog.GetPropertyType();
wxString descr = dialog.GetPropertyDescription();
wxString editorType = dialog.GetEditorType();
wxArrayString choices = dialog.GetChoices();
if (sel->GetProperties().FindProperty(name))
{
wxMessageBox(_("Sorry, this name already exists."), _T("Add custom property"),
wxOK|wxICON_INFORMATION);
return;
}
ctProperty* property = new ctProperty;
if (type == wxT("bool"))
property->GetVariant() = wxVariant(false, name);
else if (type == wxT("double"))
property->GetVariant() = wxVariant((double) 0.0, name);
else if (type == wxT("long"))
property->GetVariant() = wxVariant((long) 0, name);
else
property->GetVariant() = wxVariant(wxEmptyString, name);
property->SetCustom(true);
property->SetDescription(descr);
property->SetChoices(choices);
property->SetEditorType(editorType);
sel->GetProperties().AddProperty(property);
editor->ShowItem(sel);
OnChangeFilename();
}
}
}
/// Edit a custom property
void ctConfigToolView::OnEditCustomProperty(wxCommandEvent& WXUNUSED(event))
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
ctConfigItem* sel = GetSelection();
ctPropertyEditor* editor = wxGetApp().GetMainFrame()->GetPropertyEditor();
if (doc && sel && editor)
{
int row;
ctProperty* property = editor->FindSelectedProperty(row) ;
if (property && property->IsCustom())
{
wxString oldName = property->GetName();
wxString oldDescription = property->GetDescription();
wxString oldType = property->GetVariant().GetType();
wxString oldEditorType = property->GetEditorType();
wxArrayString oldChoices = property->GetChoices();
ctCustomPropertyDialog dialog(wxGetApp().GetMainFrame(),
wxID_ANY, _("Edit custom property"));
dialog.SetPropertyName(oldName);
dialog.SetPropertyType(oldType);
dialog.SetPropertyDescription(oldDescription);
if (dialog.ShowModal() == wxID_OK)
{
wxString name = dialog.GetPropertyName();
wxString type = dialog.GetPropertyType();
wxString editorType = dialog.GetEditorType();
wxArrayString choices = dialog.GetChoices();
wxString descr = dialog.GetPropertyDescription();
if (name != oldName && sel->GetProperties().FindProperty(name))
{
wxMessageBox(_("Sorry, this name already exists."), _T("Add custom property"),
wxOK|wxICON_INFORMATION);
return;
}
if (type != oldType)
{
if (type == wxT("bool"))
property->GetVariant() = wxVariant(false, name);
else if (type == wxT("double"))
property->GetVariant() = wxVariant((double) 0.0, name);
else if (type == wxT("long"))
property->GetVariant() = wxVariant((long) 0, name);
else
property->GetVariant() = wxVariant(wxEmptyString, name);
}
if (name != oldName)
property->GetVariant().SetName(name);
if (choices != oldChoices)
property->SetChoices(choices);
if (editorType != oldEditorType)
property->SetEditorType(editorType);
if (name != oldName)
property->GetVariant().SetName(name);
property->SetCustom(true);
if (descr != oldDescription)
property->SetDescription(descr);
editor->ShowItem(sel);
OnChangeFilename();
}
}
}
}
/// Delete a custom property
void ctConfigToolView::OnDeleteCustomProperty(wxCommandEvent& WXUNUSED(event))
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
ctConfigItem* sel = GetSelection();
ctPropertyEditor* editor = wxGetApp().GetMainFrame()->GetPropertyEditor();
if (doc && sel && editor)
{
int row;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -