📄 configtoolview.cpp
字号:
/////////////////////////////////////////////////////////////////////////////
// Name: configtoolview.cpp
// Purpose: View class
// Author: Julian Smart
// Modified by:
// Created: 2003-06-04
// RCS-ID: $Id: configtoolview.cpp,v 1.13 2006/05/28 23:31:17 VZ Exp $
// Copyright: (c) Julian Smart
// Licence:
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/wfstream.h"
#include "wx/txtstrm.h"
#include "configtoolview.h"
#include "configtooldoc.h"
#include "configtree.h"
#include "wxconfigtool.h"
#include "mainframe.h"
#include "propeditor.h"
#include "utils.h"
#include "custompropertydialog.h"
IMPLEMENT_DYNAMIC_CLASS(ctConfigToolView, wxView)
BEGIN_EVENT_TABLE(ctConfigToolView, wxView)
EVT_MENU(ctID_ADD_ITEM_CHECKBOX, ctConfigToolView::OnAddCheckBoxItem)
EVT_MENU(ctID_ADD_ITEM_RADIOBUTTON, ctConfigToolView::OnAddRadioButtonItem)
EVT_MENU(ctID_ADD_ITEM_GROUP, ctConfigToolView::OnAddGroupItem)
EVT_MENU(ctID_ADD_ITEM_CHECK_GROUP, ctConfigToolView::OnAddCheckGroupItem)
EVT_MENU(ctID_ADD_ITEM_RADIO_GROUP, ctConfigToolView::OnAddRadioGroupItem)
EVT_MENU(ctID_ADD_ITEM_STRING, ctConfigToolView::OnAddStringItem)
EVT_MENU(ctID_RENAME_ITEM, ctConfigToolView::OnRenameItem)
EVT_MENU(ctID_DELETE_ITEM, ctConfigToolView::OnDeleteItem)
EVT_MENU(wxID_COPY, ctConfigToolView::OnCopy)
EVT_MENU(wxID_CUT, ctConfigToolView::OnCut)
EVT_MENU(wxID_PASTE, ctConfigToolView::OnPaste)
EVT_UPDATE_UI(wxID_COPY, ctConfigToolView::OnUpdateCopy)
EVT_UPDATE_UI(wxID_CUT, ctConfigToolView::OnUpdateCut)
EVT_UPDATE_UI(wxID_PASTE, ctConfigToolView::OnUpdatePaste)
EVT_MENU(ctID_ITEM_HELP, ctConfigToolView::OnItemHelp)
EVT_UPDATE_UI(ctID_ADD_ITEM_CHECKBOX, ctConfigToolView::OnUpdateAddItem)
EVT_UPDATE_UI(ctID_ADD_ITEM_RADIOBUTTON, ctConfigToolView::OnUpdateAddItem)
EVT_UPDATE_UI(ctID_ADD_ITEM_GROUP, ctConfigToolView::OnUpdateAddItem)
EVT_UPDATE_UI(ctID_ADD_ITEM_CHECK_GROUP, ctConfigToolView::OnUpdateAddItem)
EVT_UPDATE_UI(ctID_ADD_ITEM_RADIO_GROUP, ctConfigToolView::OnUpdateAddItem)
EVT_UPDATE_UI(ctID_ADD_ITEM_STRING, ctConfigToolView::OnUpdateAddItem)
EVT_UPDATE_UI(ctID_RENAME_ITEM, ctConfigToolView::OnUpdateCut)
EVT_UPDATE_UI(ctID_DELETE_ITEM, ctConfigToolView::OnUpdateCut)
EVT_UPDATE_UI(ctID_ITEM_HELP, ctConfigToolView::OnUpdateItemHelp)
EVT_MENU(ctID_TREE_COPY, ctConfigToolView::OnContextCopy)
EVT_MENU(ctID_TREE_CUT, ctConfigToolView::OnContextCut)
EVT_MENU(ctID_TREE_PASTE_BEFORE, ctConfigToolView::OnContextPasteBefore)
EVT_MENU(ctID_TREE_PASTE_AFTER, ctConfigToolView::OnContextPasteAfter)
EVT_MENU(ctID_TREE_PASTE_AS_CHILD, ctConfigToolView::OnContextPasteAsChild)
EVT_UPDATE_UI(ctID_TREE_COPY, ctConfigToolView::OnUpdateContextCopy)
EVT_UPDATE_UI(ctID_TREE_CUT, ctConfigToolView::OnUpdateContextCut)
EVT_UPDATE_UI(ctID_TREE_PASTE_BEFORE, ctConfigToolView::OnUpdateContextPasteBefore)
EVT_UPDATE_UI(ctID_TREE_PASTE_AFTER, ctConfigToolView::OnUpdateContextPasteAfter)
EVT_UPDATE_UI(ctID_TREE_PASTE_AS_CHILD, ctConfigToolView::OnUpdateContextPasteAsChild)
EVT_MENU(ctID_ADD_CUSTOM_PROPERTY, ctConfigToolView::OnAddCustomProperty)
EVT_MENU(ctID_EDIT_CUSTOM_PROPERTY, ctConfigToolView::OnEditCustomProperty)
EVT_MENU(ctID_DELETE_CUSTOM_PROPERTY, ctConfigToolView::OnDeleteCustomProperty)
EVT_UPDATE_UI(ctID_ADD_CUSTOM_PROPERTY, ctConfigToolView::OnUpdateAddCustomProperty)
EVT_UPDATE_UI(ctID_EDIT_CUSTOM_PROPERTY, ctConfigToolView::OnUpdateEditCustomProperty)
EVT_UPDATE_UI(ctID_DELETE_CUSTOM_PROPERTY, ctConfigToolView::OnUpdateDeleteCustomProperty)
EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, ctConfigToolView::OnTabSelect)
EVT_MENU(ctID_SAVE_SETUP_FILE, ctConfigToolView::OnSaveSetupFile)
EVT_MENU(ctID_SAVE_CONFIGURE_COMMAND, ctConfigToolView::OnSaveConfigureCommand)
EVT_UPDATE_UI(ctID_SAVE_SETUP_FILE, ctConfigToolView::OnUpdateSaveSetupFile)
EVT_UPDATE_UI(ctID_SAVE_CONFIGURE_COMMAND, ctConfigToolView::OnUpdateSaveConfigureCommand)
EVT_MENU(wxID_FIND, ctConfigToolView::OnFind)
EVT_UPDATE_UI(wxID_FIND, ctConfigToolView::OnUpdateFind)
EVT_MENU(ctID_GO, ctConfigToolView::OnGo)
EVT_UPDATE_UI(ctID_GO, ctConfigToolView::OnUpdateGo)
END_EVENT_TABLE()
// What to do when a view is created. Creates actual
// windows for displaying the view.
bool ctConfigToolView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
{
wxGetApp().GetDocManager()->ActivateView(this, true);
wxGetApp().GetMainFrame()->SetDocument((ctConfigToolDoc*) doc);
wxGetApp().GetMainFrame()->GetSetupPage()->SetDocument((ctConfigToolDoc*) doc) ;
wxGetApp().GetMainFrame()->GetConfigurePage()->SetDocument((ctConfigToolDoc*) doc) ;
return true;
}
void ctConfigToolView::OnDraw(wxDC *WXUNUSED(dc))
{
}
void ctConfigToolView::OnUpdate(wxView *WXUNUSED(sender), wxObject *hintObj)
{
ctConfigToolDoc* doc = wxDynamicCast(GetDocument(), ctConfigToolDoc);
ctConfigTreeCtrl* treeCtrl = wxGetApp().GetMainFrame()->GetConfigTreeCtrl();
if (!treeCtrl)
return;
wxASSERT (doc != NULL);
ctConfigItem* selItem = NULL;
wxTreeItemId sel = treeCtrl->GetSelection();
if (sel.IsOk())
{
ctTreeItemData* data = (ctTreeItemData*) treeCtrl->GetItemData(sel);
if (data)
selItem = data->GetConfigItem() ;
}
ctConfigToolHint* hint = (ctConfigToolHint*) hintObj;
int hintOp = ctNoHint;
if (hint)
hintOp = hint->m_op;
switch (hintOp)
{
case ctInitialUpdate:
{
if (doc && doc->GetTopItem())
{
wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->DeleteAllItems();
AddItems(wxGetApp().GetMainFrame()->GetConfigTreeCtrl(), doc->GetTopItem());
wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->Expand(doc->GetTopItem()->GetTreeItemId());
}
}
break;
case ctSelChanged:
{
if (selItem)
{
wxGetApp().GetMainFrame()->GetPropertyEditor()->ShowItem(selItem);
}
}
break;
case ctAllSaved:
{
// TODO: update windows and frame title
}
break;
case ctFilenameChanged:
{
wxGetApp().GetMainFrame()->UpdateFrameTitle();
}
break;
case ctClear:
{
// TODO: update windows
treeCtrl->DeleteAllItems();
wxGetApp().GetMainFrame()->GetPropertyEditor()->ShowItem(NULL);
break;
}
case ctValueChanged:
{
// ctConfigItem& ti = *(ctConfigItem *)hint->m_item;
wxGetApp().GetMainFrame()->GetPropertyEditor()->ShowItem(selItem);
}
break;
default:
break;
}
}
// Clean up windows used for displaying the view.
bool ctConfigToolView::OnClose(bool WXUNUSED(deleteWindow))
{
if (!GetDocument()->Close())
return false;
ctConfigToolHint hint(NULL, ctClear);
GetDocument()->UpdateAllViews (NULL, & hint);
wxGetApp().GetDocManager()->ActivateView(this, false);
Activate(false);
wxGetApp().GetMainFrame()->SetDocument(NULL);
wxGetApp().GetMainFrame()->GetSetupPage()->SetDocument(NULL) ;
wxGetApp().GetMainFrame()->GetConfigurePage()->SetDocument(NULL) ;
return true;
}
void ctConfigToolView::OnChangeFilename()
{
if (wxGetApp().GetTopWindow() && GetDocument())
{
wxString docTitle(wxFileNameFromPath(GetDocument()->GetFilename()));
wxStripExtension(docTitle);
GetDocument()->SetTitle(docTitle);
wxString name(GetDocument()->GetFilename());
wxStripExtension(name);
wxString title;
wxString modifiedMarker;
if (GetDocument()->IsModified())
modifiedMarker = wxT("*");
title = docTitle + modifiedMarker + wxString(wxT(" - ")) + wxGetApp().GetSettings().GetAppName() ;
((wxFrame*) wxGetApp().GetTopWindow())->SetTitle(title);
}
}
// General disabler
void ctConfigToolView::OnUpdateDisable(wxUpdateUIEvent& event)
{
event.Enable( false );
}
void ctConfigToolView::OnUpdateAddItem(wxUpdateUIEvent& event)
{
event.Enable( true );
}
/// Add item and its children to the tree
void ctConfigToolView::AddItems(ctConfigTreeCtrl* treeControl, ctConfigItem* item)
{
SyncItem(treeControl, item);
int count = item->GetChildCount();
int i;
for (i = 0; i < count; i++)
{
ctConfigItem* child = item->GetChild(i);
AddItems(treeControl, child);
}
}
/// Gets the tree item in sync with the item
void ctConfigToolView::SyncItem(ctConfigTreeCtrl* treeControl, ctConfigItem* item)
{
if (!item->GetTreeItemId().IsOk())
{
if (!item->GetParent())
{
item->SetTreeItem(treeControl->AddRoot(wxEmptyString, -1, -1, new ctTreeItemData(item)));
}
else
{
// Find the item to insert the new item after.
ctConfigItem* previousItem = item->FindPreviousSibling();
if (previousItem && previousItem->GetTreeItemId().IsOk())
{
item->SetTreeItem(treeControl->InsertItem(item->GetParent()->GetTreeItemId(),
previousItem->GetTreeItemId(),
item->GetName(), -1, -1, new ctTreeItemData(item)));
}
else if (!previousItem && item->GetParent()->GetChildCount() > 1
)
{
// Insert at the beginning
item->SetTreeItem(treeControl->InsertItem(item->GetParent()->GetTreeItemId(),
(size_t) 0, // Insert at first position
item->GetName(), -1, -1, new ctTreeItemData(item)));
}
else
{
item->SetTreeItem(treeControl->AppendItem(item->GetParent()->GetTreeItemId(),
item->GetName(), -1, -1, new ctTreeItemData(item)));
}
}
}
if (item->GetTreeItemId().IsOk())
{
treeControl->SetItemText(item->GetTreeItemId(), item->GetName());
int iconId = 0;
if (item->GetType() == ctTypeGroup)
{
iconId = treeControl->GetIconTable().GetIconId(wxT("Group"), 0, item->IsActive());
}
else if (item->GetType() == ctTypeCheckGroup)
{
iconId = treeControl->GetIconTable().GetIconId(wxT("CheckGroup"), item->IsEnabled() ? 0 : 1, item->IsActive());
}
else if (item->GetType() == ctTypeRadioGroup)
{
iconId = treeControl->GetIconTable().GetIconId(wxT("RadioGroup"), item->IsEnabled() ? 0 : 1, item->IsActive());
}
else if (item->GetType() == ctTypeBoolCheck)
{
iconId = treeControl->GetIconTable().GetIconId(wxT("Checkbox"), item->IsEnabled() ? 0 : 1, item->IsActive());
}
else if (item->GetType() == ctTypeBoolRadio)
{
iconId = treeControl->GetIconTable().GetIconId(wxT("Radiobutton"), item->IsEnabled() ? 0 : 1, item->IsActive());
}
treeControl->SetItemImage(item->GetTreeItemId(), iconId, wxTreeItemIcon_Normal);
treeControl->SetItemImage(item->GetTreeItemId(), iconId, wxTreeItemIcon_Selected);
if (treeControl->GetSelection() == item->GetTreeItemId())
{
if (wxGetApp().GetMainFrame()->GetPropertyEditor()->GetItem())
wxGetApp().GetMainFrame()->GetPropertyEditor()->UpdateTitle();
}
}
}
/// Clicked an icon
void ctConfigToolView::OnIconLeftDown(ctConfigTreeCtrl* treeControl, ctConfigItem* item)
{
if (!item->IsActive())
return;
if (item->GetType() == ctTypeCheckGroup ||
item->GetType() == ctTypeBoolCheck ||
item->GetType() == ctTypeBoolRadio ||
item->GetType() == ctTypeRadioGroup
)
{
// Don't toggle a radio button that's already
// enabled.
if ((item->GetType() == ctTypeBoolRadio || item->GetType() == ctTypeRadioGroup)
&& item->IsEnabled())
return;
item->Enable(!item->IsEnabled());
GetDocument()->Modify(true);
OnChangeFilename();
SyncItem(treeControl, item);
wxList considered;
if ((item->GetType() == ctTypeBoolRadio || item->GetType() == ctTypeRadioGroup) && item->IsEnabled())
{
item->PropagateRadioButton(considered);
}
item->PropagateChange(considered);
// Update the setup.h and configure text
if (wxGetApp().GetMainFrame()->GetMainNotebook()->GetSelection() > 0)
{
RegenerateSetup();
}
}
}
/// Returns the selected config item, if any.
ctConfigItem* ctConfigToolView::GetSelection()
{
wxTreeCtrl* treeCtrl = wxGetApp().GetMainFrame()->GetConfigTreeCtrl();
if (!treeCtrl)
return NULL;
wxTreeItemId sel = treeCtrl->GetSelection();
if (sel.IsOk())
{
ctTreeItemData* data = (ctTreeItemData*) treeCtrl->GetItemData(sel);
if (data)
return data->GetConfigItem() ;
}
return NULL;
}
/// Add a checkbox item
void ctConfigToolView::OnAddCheckBoxItem(wxCommandEvent& WXUNUSED(event))
{
AddItem(ctTypeBoolCheck, _("New checkbox item"));
}
/// Add a radiobutton item
void ctConfigToolView::OnAddRadioButtonItem(wxCommandEvent& WXUNUSED(event))
{
AddItem(ctTypeBoolRadio, _("New radio button item"));
}
/// Add a group item
void ctConfigToolView::OnAddGroupItem(wxCommandEvent& WXUNUSED(event))
{
AddItem(ctTypeGroup, _("New group item"));
}
/// Add a group option item
void ctConfigToolView::OnAddCheckGroupItem(wxCommandEvent& WXUNUSED(event))
{
AddItem(ctTypeCheckGroup, _("New check group item"));
}
/// Add a group option item
void ctConfigToolView::OnAddRadioGroupItem(wxCommandEvent& WXUNUSED(event))
{
AddItem(ctTypeRadioGroup, _("New radio group item"));
}
/// Add a string item
void ctConfigToolView::OnAddStringItem(wxCommandEvent& WXUNUSED(event))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -