1 /////////////////////////////////////////////////////////////////////////////
2 // Author: Vaclav Slavik
5 // Copyright: (c) 2000 Vaclav Slavik
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 #pragma implementation "editor.h"
11 #pragma implementation "treedt.h"
14 // For compilers that support precompilation, includes "wx/wx.h".
15 #include "wx/wxprec.h"
22 #include "wx/xml/xml.h"
23 #include "wx/xml/xmlres.h"
24 #include "wx/splitter.h"
25 #include "wx/config.h"
35 class EditorTreeCtrl
: public wxTreeCtrl
38 EditorTreeCtrl(wxWindow
*parent
, int id
, EditorFrame
*frame
)
39 : wxTreeCtrl(parent
, id
), m_EdFrame(frame
) {}
42 EditorFrame
*m_EdFrame
;
44 void OnRightClick(wxMouseEvent
&event
)
47 m_EdFrame
->m_TreeCtrl
->HitTest(event
.GetPosition());
50 m_EdFrame
->m_TreeCtrl
->SelectItem(item
);
51 m_EdFrame
->OnRightClickTree(event
.GetPosition());
57 BEGIN_EVENT_TABLE(EditorTreeCtrl
, wxTreeCtrl
)
58 EVT_RIGHT_DOWN(EditorTreeCtrl::OnRightClick
)
64 ID_PREVIEW
= wxID_HIGHEST
+ 100,
84 ID_NEWNODE
= wxID_HIGHEST
+ 1000,
85 ID_NEWSYBNODE
= ID_NEWNODE
+ 2000
94 BEGIN_EVENT_TABLE(EditorFrame
, wxFrame
)
95 EVT_TREE_SEL_CHANGED(ID_TREE
, EditorFrame::OnTreeSel
)
96 EVT_TOOL_RANGE(ID_PREVIEW
, ID_EXIT
, EditorFrame::OnToolbar
)
97 EVT_MENU_RANGE(ID_NEWDIALOG
, ID_NEWSYBNODE
+ 1000, EditorFrame::OnNewNode
)
98 EVT_TEXT(ID_XMLIDEDIT
, EditorFrame::OnXMLIDEdit
)
99 EVT_BUTTON(ID_XMLIDPICK
, EditorFrame::OnXMLIDPick
)
100 EVT_BUTTON(ID_EDITCODE
, EditorFrame::OnEditCode
)
101 EVT_BUTTON(ID_CLEARPROP
, EditorFrame::OnClearProp
)
102 EVT_LIST_ITEM_SELECTED(ID_PROPSLIST
, EditorFrame::OnPropSel
)
107 #if defined(__UNIX__) || wxUSE_XPM_IN_MSW
108 #include "bitmaps/preview.xpm"
109 #include "bitmaps/close.xpm"
110 #include "bitmaps/save.xpm"
111 #include "bitmaps/open.xpm"
113 #include "bitmaps/control.xpm"
114 #include "bitmaps/vsizer.xpm"
115 #include "bitmaps/hsizer.xpm"
116 #include "bitmaps/panel.xpm"
118 #include "bitmaps/unused.xpm"
119 #include "bitmaps/used.xpm"
122 #if defined(__WXMSW__) && defined(wxUSE_XPM_IN_MSW)
124 #define wxBITMAP(arg) wxBitmap(arg##_xpm)
126 #define wxICON(arg) wxIcon(arg##_xpm)
130 EditorFrame
*EditorFrame::ms_Instance
= NULL
;
132 EditorFrame::EditorFrame(wxFrame
*parent
, const wxString
& filename
)
133 : wxFrame(parent
, -1, filename
+ _("- wxWindows resources editor"))
137 wxConfigBase
*cfg
= wxConfigBase::Get();
139 SetSize(wxRect(wxPoint(cfg
->Read("editor_x", -1), cfg
->Read("editor_y", -1)),
140 wxSize(cfg
->Read("editor_w", 400), cfg
->Read("editor_h", 400))));
142 m_SelectedNode
= NULL
;
144 m_FileName
= wxEmptyString
;
148 wxMenu
*menuFile
= new wxMenu
;
149 menuFile
->Append(ID_NEW
, "&New");
150 menuFile
->Append(ID_OPEN
, "&Open\tCtrl-O");
151 menuFile
->Append(ID_SAVE
, "&Save\tCtrl-S");
152 menuFile
->Append(ID_SAVEAS
, "Save &as...");
153 menuFile
->AppendSeparator();
154 menuFile
->Append(ID_EXIT
, "E&xit\tAlt-X");
156 wxMenuBar
*menuBar
= new wxMenuBar();
157 menuBar
->Append(menuFile
, "&File");
161 m_Handlers
.DeleteContents(TRUE
);
162 RegisterHandlers(".");
163 RegisterHandlers("./df");
164 m_Handlers
.Append(new NodeHandlerUnknown(this));
167 RegisterHandlers(wxGetHomeDir() + "/.wxrcedit");
168 //FIXME - add $(prefix)/share/wx/wxrcedit
172 wxToolBar
*toolBar
= CreateToolBar(wxNO_BORDER
| wxTB_HORIZONTAL
| wxTB_FLAT
);
174 toolBar
->SetToolBitmapSize(wxSize(24, 24));
176 toolBar
->SetMargins(2, 2);
177 toolBar
-> AddTool(ID_EXIT
, wxBITMAP(close
), wxNullBitmap
,
178 FALSE
, -1, -1, (wxObject
*) NULL
,
179 _("Quit the editor"));
180 toolBar
-> AddTool(ID_OPEN
, wxBITMAP(open
), wxNullBitmap
,
181 FALSE
, -1, -1, (wxObject
*) NULL
,
182 _("Open XML resource file"));
183 toolBar
-> AddTool(ID_SAVE
, wxBITMAP(save
), wxNullBitmap
,
184 FALSE
, -1, -1, (wxObject
*) NULL
,
186 toolBar
-> AddTool(ID_PREVIEW
, wxBITMAP(preview
), wxNullBitmap
,
187 FALSE
, -1, -1, (wxObject
*) NULL
,
189 toolBar
-> Realize();
192 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
193 wxPanel
*p
= new wxPanel(this);
194 sizer
->Add(p
, 1, wxEXPAND
);
195 wxSizer
*sizer2
= new wxBoxSizer(wxVERTICAL
);
197 m_Splitter
= new wxSplitterWindow(p
);
198 sizer2
->Add(m_Splitter
, 1, wxEXPAND
);
201 // Create tree control:
202 m_TreeCtrl
= new EditorTreeCtrl(m_Splitter
, ID_TREE
, this);
203 m_ImgList
= new wxImageList(16, 16);
204 m_ImgList
->Add(wxICON(control
));
205 m_ImgList
->Add(wxICON(panel
));
206 m_ImgList
->Add(wxICON(vsizer
));
207 m_ImgList
->Add(wxICON(hsizer
));
209 m_TreeCtrl
->SetImageList(m_ImgList
);
212 // Create properties panel:
213 m_Splitter2
= new wxSplitterWindow(m_Splitter
);
214 m_PropsPanel
= new wxPanel(m_Splitter2
, -1, wxDefaultPosition
,
215 wxDefaultSize
, wxTAB_TRAVERSAL
);
217 wxSizer
*sizer3
= new wxBoxSizer(wxVERTICAL
);
219 wxSizer
*sz
= new wxBoxSizer(wxHORIZONTAL
);
221 sizer3
->Add(new wxButton(m_PropsPanel
, ID_EDITCODE
, "Edit XML code"),
222 0, wxALL
| wxEXPAND
, 2);
223 sz
->Add(new wxStaticText(m_PropsPanel
, -1, _("XMLID name:")),
224 0, wxLEFT
| wxALIGN_CENTER_VERTICAL
, 2);
225 m_XMLIDCtrl
= new wxTextCtrl(m_PropsPanel
, ID_XMLIDEDIT
, "");
226 sz
->Add(m_XMLIDCtrl
, 1, wxLEFT
|wxRIGHT
, 2);
227 sz
->Add(new wxButton(m_PropsPanel
, ID_XMLIDPICK
, "...", wxDefaultPosition
, wxSize(16,-1)),
229 sizer3
->Add(sz
, 0, wxTOP
|wxEXPAND
, 2);
231 m_PropsList
= new wxListCtrl(m_PropsPanel
, ID_PROPSLIST
, wxDefaultPosition
, wxDefaultSize
, wxLC_REPORT
| wxLC_SINGLE_SEL
);
233 m_ImgListProp
= new wxImageList(16, 16);
234 m_ImgListProp
->Add(wxICON(unused
));
235 m_ImgListProp
->Add(wxICON(used
));
236 m_PropsList
->SetImageList(m_ImgListProp
, wxIMAGE_LIST_SMALL
);
238 m_PropsList
->InsertColumn(0, _("Property"));
239 m_PropsList
->InsertColumn(1, _("Value"));
240 m_PropsList
->SetColumnWidth(0, cfg
->Read("editor_col0", wxLIST_AUTOSIZE_USEHEADER
));
241 m_PropsList
->SetColumnWidth(1, cfg
->Read("editor_col1", wxLIST_AUTOSIZE_USEHEADER
));
243 sizer3
->Add(m_PropsList
, 1, wxALL
| wxEXPAND
, 2);
245 m_PropsPanel
->SetAutoLayout(TRUE
);
246 m_PropsPanel
->SetSizer(sizer3
);
247 m_PropsPanel
->Layout();
249 m_PropsEditPanel
= new wxScrolledWindow(m_Splitter2
, -1, wxDefaultPosition
,
250 wxDefaultSize
, wxTAB_TRAVERSAL
);
252 m_Splitter
->SplitVertically(m_TreeCtrl
, m_Splitter2
);
253 m_Splitter
->SetSashPosition(cfg
->Read("editor_sash", 140));
255 m_Splitter2
->SplitHorizontally(m_PropsPanel
, m_PropsEditPanel
);
256 m_Splitter2
->SetSashPosition(cfg
->Read("editor_sash2", 100));
258 p
->SetAutoLayout(TRUE
);
275 EditorFrame::~EditorFrame()
277 wxConfigBase
*cfg
= wxConfigBase::Get();
279 cfg
->Write("editor_x", (long)GetPosition().x
);
280 cfg
->Write("editor_y", (long)GetPosition().y
);
281 cfg
->Write("editor_w", (long)GetSize().x
);
282 cfg
->Write("editor_h", (long)GetSize().y
);
283 cfg
->Write("editor_sash", (long)m_Splitter
->GetSashPosition());
284 cfg
->Write("editor_sash2", (long)m_Splitter2
->GetSashPosition());
285 cfg
->Write("editor_col0", (long)m_PropsList
->GetColumnWidth(0));
286 cfg
->Write("editor_col1", (long)m_PropsList
->GetColumnWidth(1));
289 delete m_ImgListProp
;
295 NodeHandler
*EditorFrame::FindHandler(wxXmlNode
*node
)
297 wxNode
*n
= m_Handlers
.GetFirst();
300 NodeHandler
*h
= (NodeHandler
*) n
->GetData();
301 if (h
->CanHandle(node
))
310 void EditorFrame::RegisterHandlers(const wxString
& dirname
)
312 if (!wxDirExists(dirname
)) return;
319 cont
= dir
.GetFirst(&filename
, "*.df");
322 hnd
= NodeHandler::CreateFromFile(filename
, this);
323 if (hnd
) m_Handlers
.Append(hnd
);
324 cont
= dir
.GetNext(&filename
);
331 void EditorFrame::LoadFile(const wxString
& filename
)
336 m_Resource
= new wxXmlDocument
;
338 if (!m_Resource
->Load(filename
))
343 wxLogError("Error parsing " + filename
);
347 m_FileName
= filename
;
349 SetTitle(m_FileName
);
355 void EditorFrame::SaveFile(const wxString
& filename
)
357 m_FileName
= filename
;
360 if (!m_Resource
->Save(filename
, wxXML_IO_LIBXML
))
361 wxLogError("Error saving " + filename
);
366 void EditorFrame::NewFile()
371 m_Resource
= new wxXmlDocument
;
372 m_Resource
->SetRoot(new wxXmlNode(wxXML_ELEMENT_NODE
, "resource"));
380 void EditorFrame::RefreshPreview(wxXmlNode
*node
)
383 wxXmlResource
*res
= new wxXmlResource
;
385 wxPoint pos
= wxDefaultPosition
;
387 while (node
->GetParent() != m_Resource
->GetRoot())
388 node
= node
->GetParent();
390 if (m_Preview
) pos
= m_Preview
->GetPosition();
392 res
->InitAllHandlers();
394 wxGetTempFileName("xmleditor", tempfile
);
395 m_Resource
->Save(tempfile
, wxXML_IO_BIN
);
396 res
->Load(tempfile
, wxXML_BINARY
);
398 if (node
->GetName() == "dialog")
400 wxDialog
*dlg
= new wxDialog
;
401 if (res
->LoadDialog(dlg
, this, node
->GetPropVal("name", "-1")))
403 if (pos
.x
!= -1) dlg
->Move(pos
);
405 if (m_Preview
) m_Preview
->Close(TRUE
);
411 wxLogError(_("Cannot preview the dialog -- XML resource corrupted."));
415 wxRemoveFile(tempfile
);
420 void EditorFrame::RefreshTree()
422 wxXmlNode
*sel
= m_SelectedNode
;
424 m_TreeCtrl
->DeleteAllItems();
425 wxTreeItemId root
= m_TreeCtrl
->AddRoot("Resource: " + m_FileName
);
427 wxXmlNode
*n
= m_Resource
->GetRoot()->GetChildren();
430 if (n
->GetType() == wxXML_ELEMENT_NODE
)
431 CreateTreeNode(m_TreeCtrl
, root
, n
);
435 m_TreeCtrl
->Expand(root
);
440 void EditorFrame::RefreshProps(wxXmlNode
*node
)
444 for (int i
= 0; i
< m_PropsList
->GetItemCount(); i
++)
445 delete (wxObject
*)(m_PropsList
->GetItemData(i
));
447 m_PropsList
->DeleteAllItems();
449 if (node
== NULL
) return;
451 m_XMLIDCtrl
->SetValue(FindHandler(node
)->GetRealNode(node
)->
452 GetPropVal("name", "-1"));
453 CreatePropsList(m_PropsList
, node
);
460 void EditorFrame::RefreshPropsEdit()
462 m_PropsEditPanel
->DestroyChildren();
463 m_PropsEditPanel
->SetSizer(NULL
);
465 if (!m_SelectedNode
|| m_SelectedProp
== -1 ||
466 m_PropsList
->GetItemData(m_SelectedProp
) == 0) return;
468 wxBoxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
470 sizer
->Add(new wxButton(m_PropsEditPanel
, ID_CLEARPROP
, _("Clear")),
474 FindHandler(m_SelectedNode
)->CreatePropEditPanel(m_PropsEditPanel
, m_PropsList
, m_SelectedProp
),
477 m_PropsEditPanel
->SetAutoLayout(TRUE
);
478 m_PropsEditPanel
->SetSizer(sizer
);
479 m_PropsEditPanel
->Layout();
481 wxSize winsz
= m_PropsEditPanel
->GetSize();
482 sizer
->SetMinSize(winsz
.x
, winsz
.y
);
484 wxSize minsz
= sizer
->GetMinSize();
486 m_PropsEditPanel
->SetScrollbars(8, 8, 1/*minsz.x/8*/, minsz
.y
/8);
491 bool EditorFrame::SelectNode(wxXmlNode
*node
, wxTreeItemId
*root
)
495 wxTreeItemId rootitem
= m_TreeCtrl
->GetRootItem();
496 return SelectNode(node
, &rootitem
);
504 item
= m_TreeCtrl
->GetFirstChild(*root
, cookie
);
507 dt
= (XmlTreeData
*)(m_TreeCtrl
->GetItemData(item
));
508 nd
= (dt
) ? dt
->Node
: NULL
;
511 m_TreeCtrl
->SelectItem(item
);
512 m_TreeCtrl
->EnsureVisible(item
);
515 if (m_TreeCtrl
->ItemHasChildren(item
) && SelectNode(node
, &item
))
517 item
= m_TreeCtrl
->GetNextChild(*root
, cookie
);
524 wxTreeItemId
EditorFrame::CreateTreeNode(wxTreeCtrl
*treectrl
, wxTreeItemId parent
, wxXmlNode
*node
)
528 wxTreeItemId invalid
;
532 return FindHandler(node
)->CreateTreeNode(treectrl
, parent
, node
);
537 void EditorFrame::CreatePropsList(wxListCtrl
*treectrl
, wxXmlNode
*node
)
541 FindHandler(node
)->CreatePropsList(treectrl
, node
);
546 void EditorFrame::NotifyChanged(int change_type
)
548 if (change_type
& CHANGED_TREE
)
551 if (change_type
& CHANGED_TREE_SELECTED
)
553 wxTreeItemId sel
= m_TreeCtrl
->GetSelection();
554 m_TreeCtrl
->SetItemText(sel
,
555 FindHandler(m_SelectedNode
)->GetTreeString(m_SelectedNode
));
558 if (change_type
& CHANGED_TREE_SELECTED_ICON
)
560 wxTreeItemId sel
= m_TreeCtrl
->GetSelection();
561 int icon
= FindHandler(m_SelectedNode
)->GetTreeIcon(m_SelectedNode
);
562 m_TreeCtrl
->SetItemImage(sel
, icon
);
565 if (change_type
& CHANGED_PROPS_PANEL
)
566 RefreshProps(m_SelectedNode
);
571 void EditorFrame::OnTreeSel(wxTreeEvent
& event
)
573 XmlTreeData
*dt
= (XmlTreeData
*)(m_TreeCtrl
->GetItemData(event
.GetItem()));
574 wxXmlNode
*node
= (dt
) ? dt
->Node
: NULL
;
576 m_SelectedNode
= node
;
582 void EditorFrame::OnXMLIDEdit(wxCommandEvent
& event
)
584 if (!m_SelectedNode
) return;
585 wxXmlNode
*node
= FindHandler(m_SelectedNode
)->GetRealNode(m_SelectedNode
);
587 node
->DeleteProperty("name");
588 wxString s
= m_XMLIDCtrl
->GetValue();
589 if (!(s
== "-1")) node
->AddProperty("name", s
);
590 NotifyChanged(CHANGED_TREE_SELECTED
);
595 void EditorFrame::OnXMLIDPick(wxCommandEvent
& event
)
597 if (!m_SelectedNode
) return;
598 wxXmlNode
*node
= FindHandler(m_SelectedNode
)->GetRealNode(m_SelectedNode
);
600 wxString choices
[] = {wxString("-1")
601 #define stdID(id) , wxString(#id)
602 stdID(wxID_OK
) stdID(wxID_CANCEL
)
603 stdID(wxID_YES
) stdID(wxID_NO
)
604 stdID(wxID_APPLY
) stdID(wxID_HELP
)
605 stdID(wxID_HELP_CONTEXT
)
607 stdID(wxID_OPEN
) stdID(wxID_CLOSE
) stdID(wxID_NEW
)
608 stdID(wxID_SAVE
) stdID(wxID_SAVEAS
) stdID(wxID_REVERT
)
609 stdID(wxID_EXIT
) stdID(wxID_UNDO
) stdID(wxID_REDO
)
610 stdID(wxID_PRINT
) stdID(wxID_PRINT_SETUP
)
611 stdID(wxID_PREVIEW
) stdID(wxID_ABOUT
) stdID(wxID_HELP_CONTENTS
)
612 stdID(wxID_HELP_COMMANDS
) stdID(wxID_HELP_PROCEDURES
)
613 stdID(wxID_CUT
) stdID(wxID_COPY
) stdID(wxID_PASTE
)
614 stdID(wxID_CLEAR
) stdID(wxID_FIND
) stdID(wxID_DUPLICATE
)
615 stdID(wxID_SELECTALL
)
616 stdID(wxID_STATIC
) stdID(wxID_FORWARD
) stdID(wxID_BACKWARD
)
617 stdID(wxID_DEFAULT
) stdID(wxID_MORE
) stdID(wxID_SETUP
)
623 wxGetSingleChoice(_("Choose from predefined IDs:"), _("XMLID"),
624 38/*sizeof choices*/, choices
);
627 m_XMLIDCtrl
->SetValue(s
);
628 node
->DeleteProperty("name");
629 if (!(s
== "-1")) node
->AddProperty("name", s
);
630 NotifyChanged(CHANGED_TREE_SELECTED
);
635 void EditorFrame::OnEditCode(wxCommandEvent
& event
)
637 if (!m_SelectedNode
) return;
640 wxDialog
dlg(this, -1, _("XML code editor"), wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
);
641 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
642 wxTextCtrl
*tc
= new wxTextCtrl(&dlg
, -1, "", wxDefaultPosition
,
643 wxDefaultSize
, wxTE_MULTILINE
);
644 sizer
->Add(tc
, 1, wxEXPAND
| wxALL
, 10);
646 wxSizer
*sz2
= new wxBoxSizer(wxHORIZONTAL
);
648 sz2
->Add(new wxButton(&dlg
, wxID_OK
, _("Save")), 0);
649 sz2
->Add(new wxButton(&dlg
, wxID_CANCEL
, _("Cancel")), 0, wxLEFT
, 10);
651 sizer
->Add(sz2
, 0, wxALIGN_RIGHT
| wxRIGHT
|wxBOTTOM
, 10);
653 dlg
.SetAutoLayout(TRUE
);
656 wxConfigBase
*cfg
= wxConfigBase::Get();
658 dlg
.SetSize(wxRect(wxPoint(cfg
->Read("xmleditor_x", -1), cfg
->Read("xmleditor_y", -1)),
659 wxSize(cfg
->Read("xmleditor_w", 400), cfg
->Read("xmleditor_h", 400))));
662 wxGetTempFileName("xmleditor", tempfile
);
666 doc
.SetRoot(new wxXmlNode(*m_SelectedNode
));
667 doc
.Save(tempfile
, wxXML_IO_LIBXML
);
669 tc
->LoadFile(tempfile
);
671 if (dlg
.ShowModal() == wxID_OK
)
673 tc
->SaveFile(tempfile
);
675 if (doc
.Load(tempfile
))
677 (*m_SelectedNode
) = *doc
.GetRoot();
678 NotifyChanged(CHANGED_TREE
);
679 //FIXME-instead, regenerate only children
681 else wxLogError(_("Illegal XML file, canceled."));
683 wxRemoveFile(tempfile
);
685 cfg
->Write("xmleditor_x", (long)dlg
.GetPosition().x
);
686 cfg
->Write("xmleditor_y", (long)dlg
.GetPosition().y
);
687 cfg
->Write("xmleditor_w", (long)dlg
.GetSize().x
);
688 cfg
->Write("xmleditor_h", (long)dlg
.GetSize().y
);
693 void EditorFrame::OnClearProp(wxCommandEvent
& event
)
695 m_PropsList
->SetItemImage(m_SelectedProp
, 0, 0);
696 m_PropsList
->SetItem(m_SelectedProp
, 1, "");
698 PropsListInfo
*pli
= (PropsListInfo
*)m_PropsList
->GetItemData(m_SelectedProp
);
700 wxXmlNode
*nd
= XmlFindNode(pli
->m_Node
, pli
->m_PropInfo
->Name
);
702 if (nd
== NULL
) return;
703 nd
->GetParent()->RemoveChild(nd
);
710 void EditorFrame::OnPropSel(wxListEvent
& event
)
712 m_SelectedProp
= event
.GetIndex();
718 void EditorFrame::OnToolbar(wxCommandEvent
& event
)
720 switch (event
.GetId())
724 XmlTreeData
* dt
= (XmlTreeData
*)m_TreeCtrl
->GetItemData(m_TreeCtrl
->GetSelection());;
725 if (dt
!= NULL
&& dt
->Node
!= NULL
)
726 RefreshPreview(dt
->Node
);
740 wxString name
= wxFileSelector("Open XML resource", "", "", "", "XML resources|*.xml", wxOPEN
| wxFILE_MUST_EXIST
);
747 if (m_FileName
!= "") { SaveFile(m_FileName
); break;}
752 wxString name
= wxFileSelector("Save as", "", m_FileName
, "", "XML resources|*.xml", wxSAVE
| wxOVERWRITE_PROMPT
);
754 SaveFile((m_FileName
= name
));
758 case ID_DELETE_NODE
:
760 XmlTreeData
*dt
= (XmlTreeData
*)
761 (m_TreeCtrl
->GetItemData(m_TreeCtrl
->GetParent(m_TreeCtrl
->GetSelection())));
762 wxXmlNode
*n
= (dt
) ? dt
->Node
: NULL
;
764 m_SelectedNode
->GetParent()->RemoveChild(m_SelectedNode
);
765 NotifyChanged(CHANGED_TREE
);
774 void EditorFrame::OnNewNode(wxCommandEvent
& event
)
776 if (event
.GetId() >= ID_NEWSYBNODE
)
779 (XmlTreeData
*)(m_TreeCtrl
->GetItemData(
780 m_TreeCtrl
->GetParent(m_TreeCtrl
->GetSelection())));
782 if (pardt
&& pardt
->Node
&& pardt
->Node
!= m_Resource
->GetRoot())
784 wxXmlNode
*nd
= pardt
->Node
;
786 wxXmlNode
*realnode
= FindHandler(nd
)->GetRealNode(nd
);
787 NodeHandler
*hnd
= FindHandler(realnode
);
788 wxString name
= hnd
->GetChildTypes()[event
.GetId()-ID_NEWSYBNODE
];
790 wxXmlNode
*node
= new wxXmlNode(wxXML_ELEMENT_NODE
, name
);
791 hnd
->InsertNode(realnode
, node
, m_SelectedNode
);
792 wxTreeItemId root
= m_TreeCtrl
->GetSelection();
793 SelectNode(node
, &root
);
798 else if (event
.GetId() >= ID_NEWNODE
)
800 wxXmlNode
*realnode
= FindHandler(m_SelectedNode
)->GetRealNode(m_SelectedNode
);
801 NodeHandler
*hnd
= FindHandler(realnode
);
802 wxString name
= hnd
->GetChildTypes()[event
.GetId()-ID_NEWNODE
];
804 wxXmlNode
*node
= new wxXmlNode(wxXML_ELEMENT_NODE
, name
);
805 hnd
->InsertNode(realnode
, node
);
806 wxTreeItemId root
= m_TreeCtrl
->GetSelection();
807 SelectNode(node
, &root
);
813 switch (event
.GetId())
815 case ID_NEWDIALOG
: name
= "dialog"; break;
816 case ID_NEWPANEL
: name
= "panel"; break;
817 case ID_NEWMENU
: name
= "menu"; break;
818 case ID_NEWMENUBAR
: name
= "menubar"; break;
819 case ID_NEWTOOLBAR
: name
= "toolbar"; break;
820 default : return; // never occurs
823 wxXmlNode
*node
= new wxXmlNode(wxXML_ELEMENT_NODE
, name
);
824 m_Resource
->GetRoot()->AddChild(node
);
825 NotifyChanged(CHANGED_TREE
);
832 void EditorFrame::OnRightClickTree(wxPoint pos
)
834 wxMenu
*popup
= new wxMenu
;
836 if (m_SelectedNode
== NULL
|| m_SelectedNode
== m_Resource
->GetRoot())
838 popup
->Append(ID_NEWDIALOG
, _("New dialog"));
839 popup
->Append(ID_NEWPANEL
, _("New panel"));
840 popup
->Append(ID_NEWMENU
, _("New menu"));
841 popup
->Append(ID_NEWMENUBAR
, _("New menubar"));
842 popup
->Append(ID_NEWTOOLBAR
, _("New toolbar"));
849 FindHandler(FindHandler(m_SelectedNode
)->GetRealNode(m_SelectedNode
))->
854 wxMenu
*news
= new wxMenu
;
855 for (size_t i
= 0; i
< arr
.GetCount(); i
++)
857 news
->Append(i
+ ID_NEWNODE
, arr
[i
]);
858 if (i
% 16 == 15) news
->Break();
860 popup
->Append(ID_NEWNODE
-1, _("New child"), news
);
866 (XmlTreeData
*)(m_TreeCtrl
->GetItemData(
867 m_TreeCtrl
->GetParent(m_TreeCtrl
->GetSelection())));
868 if (pardt
&& pardt
->Node
&& pardt
->Node
!= m_Resource
->GetRoot())
870 wxXmlNode
*nd
= pardt
->Node
;
872 FindHandler(FindHandler(nd
)->GetRealNode(nd
))->
877 wxMenu
*news
= new wxMenu
;
878 for (size_t i
= 0; i
< arr
.GetCount(); i
++)
880 news
->Append(i
+ ID_NEWSYBNODE
, arr
[i
]);
881 if (i
% 16 == 15) news
->Break();
883 popup
->Append(ID_NEWSYBNODE
-1, _("New sybling"), news
);
888 popup
->AppendSeparator();
889 popup
->Append(ID_DELETE_NODE
, _("Delete"));
892 m_TreeCtrl
->PopupMenu(popup
, pos
);