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
)
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"
124 EditorFrame
*EditorFrame::ms_Instance
= NULL
;
126 EditorFrame::EditorFrame(wxFrame
*parent
, const wxString
& filename
)
127 : wxFrame(parent
, -1, filename
+ _("- wxWindows resources editor"))
131 wxConfigBase
*cfg
= wxConfigBase::Get();
133 SetSize(wxRect(wxPoint(cfg
->Read("editor_x", -1), cfg
->Read("editor_y", -1)),
134 wxSize(cfg
->Read("editor_w", 400), cfg
->Read("editor_h", 400))));
136 m_SelectedNode
= NULL
;
138 m_FileName
= wxEmptyString
;
142 wxMenu
*menuFile
= new wxMenu
;
143 menuFile
->Append(ID_NEW
, "&New");
144 menuFile
->Append(ID_OPEN
, "&Open\tCtrl-O");
145 menuFile
->Append(ID_SAVE
, "&Save\tCtrl-S");
146 menuFile
->Append(ID_SAVEAS
, "Save &as...");
147 menuFile
->AppendSeparator();
148 menuFile
->Append(ID_EXIT
, "E&xit\tAlt-X");
150 wxMenuBar
*menuBar
= new wxMenuBar();
151 menuBar
->Append(menuFile
, "&File");
155 m_Handlers
.DeleteContents(TRUE
);
156 RegisterHandlers(".");
157 RegisterHandlers("./df");
158 m_Handlers
.Append(new NodeHandlerUnknown(this));
161 RegisterHandlers(wxGetHomeDir() + "/.wxrcedit");
162 //FIXME - add $(prefix)/share/wx/wxrcedit
166 wxToolBar
*toolBar
= CreateToolBar(wxNO_BORDER
| wxTB_HORIZONTAL
| wxTB_FLAT
);
167 toolBar
->SetMargins(2, 2);
168 toolBar
-> AddTool(ID_EXIT
, wxBITMAP(close
), wxNullBitmap
,
169 FALSE
, -1, -1, (wxObject
*) NULL
,
170 _("Quit the editor"));
171 toolBar
-> AddTool(ID_OPEN
, wxBITMAP(open
), wxNullBitmap
,
172 FALSE
, -1, -1, (wxObject
*) NULL
,
173 _("Open XML resource file"));
174 toolBar
-> AddTool(ID_SAVE
, wxBITMAP(save
), wxNullBitmap
,
175 FALSE
, -1, -1, (wxObject
*) NULL
,
177 toolBar
-> AddTool(ID_PREVIEW
, wxBITMAP(preview
), wxNullBitmap
,
178 FALSE
, -1, -1, (wxObject
*) NULL
,
180 toolBar
-> Realize();
183 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
184 wxPanel
*p
= new wxPanel(this);
185 sizer
->Add(p
, 1, wxEXPAND
);
186 wxSizer
*sizer2
= new wxBoxSizer(wxVERTICAL
);
188 m_Splitter
= new wxSplitterWindow(p
);
189 sizer2
->Add(m_Splitter
, 1, wxEXPAND
);
192 // Create tree control:
193 m_TreeCtrl
= new EditorTreeCtrl(m_Splitter
, ID_TREE
, this);
194 m_ImgList
= new wxImageList(16, 16);
195 m_ImgList
->Add(wxICON(control
));
196 m_ImgList
->Add(wxICON(panel
));
197 m_ImgList
->Add(wxICON(vsizer
));
198 m_ImgList
->Add(wxICON(hsizer
));
200 m_TreeCtrl
->SetImageList(m_ImgList
);
203 // Create properties panel:
204 m_Splitter2
= new wxSplitterWindow(m_Splitter
);
205 m_PropsPanel
= new wxPanel(m_Splitter2
, -1, wxDefaultPosition
,
206 wxDefaultSize
, wxTAB_TRAVERSAL
);
208 wxSizer
*sizer3
= new wxBoxSizer(wxVERTICAL
);
210 wxSizer
*sz
= new wxBoxSizer(wxHORIZONTAL
);
212 sizer3
->Add(new wxButton(m_PropsPanel
, ID_EDITCODE
, "Edit XML code"),
213 0, wxALL
| wxEXPAND
, 2);
214 sz
->Add(new wxStaticText(m_PropsPanel
, -1, _("XMLID name:")),
215 0, wxLEFT
| wxALIGN_CENTER_VERTICAL
, 2);
216 m_XMLIDCtrl
= new wxTextCtrl(m_PropsPanel
, ID_XMLIDEDIT
, "");
217 sz
->Add(m_XMLIDCtrl
, 1, wxLEFT
|wxRIGHT
, 2);
218 sz
->Add(new wxButton(m_PropsPanel
, ID_XMLIDPICK
, "...", wxDefaultPosition
, wxSize(16,-1)),
220 sizer3
->Add(sz
, 0, wxTOP
|wxEXPAND
, 2);
222 m_PropsList
= new wxListCtrl(m_PropsPanel
, ID_PROPSLIST
, wxDefaultPosition
, wxDefaultSize
, wxLC_REPORT
| wxLC_SINGLE_SEL
);
224 m_ImgListProp
= new wxImageList(16, 16);
225 m_ImgListProp
->Add(wxICON(unused
));
226 m_ImgListProp
->Add(wxICON(used
));
227 m_PropsList
->SetImageList(m_ImgListProp
, wxIMAGE_LIST_SMALL
);
229 m_PropsList
->InsertColumn(0, _("Property"));
230 m_PropsList
->InsertColumn(1, _("Value"));
231 m_PropsList
->SetColumnWidth(0, cfg
->Read("editor_col0", wxLIST_AUTOSIZE_USEHEADER
));
232 m_PropsList
->SetColumnWidth(1, cfg
->Read("editor_col1", wxLIST_AUTOSIZE_USEHEADER
));
234 sizer3
->Add(m_PropsList
, 1, wxALL
| wxEXPAND
, 2);
236 m_PropsPanel
->SetAutoLayout(TRUE
);
237 m_PropsPanel
->SetSizer(sizer3
);
238 m_PropsPanel
->Layout();
240 m_PropsEditPanel
= new wxScrolledWindow(m_Splitter2
, -1, wxDefaultPosition
,
241 wxDefaultSize
, wxTAB_TRAVERSAL
);
243 m_Splitter
->SplitVertically(m_TreeCtrl
, m_Splitter2
);
244 m_Splitter
->SetSashPosition(cfg
->Read("editor_sash", 140));
246 m_Splitter2
->SplitHorizontally(m_PropsPanel
, m_PropsEditPanel
);
247 m_Splitter2
->SetSashPosition(cfg
->Read("editor_sash2", 100));
249 p
->SetAutoLayout(TRUE
);
266 EditorFrame::~EditorFrame()
268 wxConfigBase
*cfg
= wxConfigBase::Get();
270 cfg
->Write("editor_x", (long)GetPosition().x
);
271 cfg
->Write("editor_y", (long)GetPosition().y
);
272 cfg
->Write("editor_w", (long)GetSize().x
);
273 cfg
->Write("editor_h", (long)GetSize().y
);
274 cfg
->Write("editor_sash", (long)m_Splitter
->GetSashPosition());
275 cfg
->Write("editor_sash2", (long)m_Splitter2
->GetSashPosition());
276 cfg
->Write("editor_col0", (long)m_PropsList
->GetColumnWidth(0));
277 cfg
->Write("editor_col1", (long)m_PropsList
->GetColumnWidth(1));
280 delete m_ImgListProp
;
286 NodeHandler
*EditorFrame::FindHandler(wxXmlNode
*node
)
288 wxNode
*n
= m_Handlers
.GetFirst();
291 NodeHandler
*h
= (NodeHandler
*) n
->GetData();
292 if (h
->CanHandle(node
))
301 void EditorFrame::RegisterHandlers(const wxString
& dirname
)
303 if (!wxDirExists(dirname
)) return;
310 cont
= dir
.GetFirst(&filename
, "*.df");
313 hnd
= NodeHandler::CreateFromFile(filename
, this);
314 if (hnd
) m_Handlers
.Append(hnd
);
315 cont
= dir
.GetNext(&filename
);
322 void EditorFrame::LoadFile(const wxString
& filename
)
327 m_Resource
= new wxXmlDocument
;
329 if (!m_Resource
->Load(filename
))
334 wxLogError("Error parsing " + filename
);
338 m_FileName
= filename
;
340 SetTitle(m_FileName
);
346 void EditorFrame::SaveFile(const wxString
& filename
)
348 m_FileName
= filename
;
351 if (!m_Resource
->Save(filename
, wxXML_IO_LIBXML
))
352 wxLogError("Error saving " + filename
);
357 void EditorFrame::NewFile()
362 m_Resource
= new wxXmlDocument
;
363 m_Resource
->SetRoot(new wxXmlNode(wxXML_ELEMENT_NODE
, "resource"));
371 void EditorFrame::RefreshPreview(wxXmlNode
*node
)
374 wxXmlResource
*res
= new wxXmlResource
;
376 wxPoint pos
= wxDefaultPosition
;
378 while (node
->GetParent() != m_Resource
->GetRoot())
379 node
= node
->GetParent();
381 if (m_Preview
) pos
= m_Preview
->GetPosition();
383 res
->InitAllHandlers();
385 wxGetTempFileName("xmleditor", tempfile
);
386 m_Resource
->Save(tempfile
, wxXML_IO_BIN
);
387 res
->Load(tempfile
, wxXML_BINARY
);
389 if (node
->GetName() == "dialog")
391 wxDialog
*dlg
= new wxDialog
;
392 if (res
->LoadDialog(dlg
, this, node
->GetPropVal("name", "-1")))
394 if (pos
.x
!= -1) dlg
->Move(pos
);
396 if (m_Preview
) m_Preview
->Close(TRUE
);
402 wxLogError(_("Cannot preview the dialog -- XML resource corrupted."));
406 wxRemoveFile(tempfile
);
411 void EditorFrame::RefreshTree()
413 wxXmlNode
*sel
= m_SelectedNode
;
415 m_TreeCtrl
->DeleteAllItems();
416 wxTreeItemId root
= m_TreeCtrl
->AddRoot("Resource: " + m_FileName
);
418 wxXmlNode
*n
= m_Resource
->GetRoot()->GetChildren();
421 if (n
->GetType() == wxXML_ELEMENT_NODE
)
422 CreateTreeNode(m_TreeCtrl
, root
, n
);
426 m_TreeCtrl
->Expand(root
);
431 void EditorFrame::RefreshProps(wxXmlNode
*node
)
435 for (int i
= 0; i
< m_PropsList
->GetItemCount(); i
++)
436 delete (wxObject
*)(m_PropsList
->GetItemData(i
));
438 m_PropsList
->DeleteAllItems();
440 if (node
== NULL
) return;
442 m_XMLIDCtrl
->SetValue(FindHandler(node
)->GetRealNode(node
)->
443 GetPropVal("name", "-1"));
444 CreatePropsList(m_PropsList
, node
);
451 void EditorFrame::RefreshPropsEdit()
453 m_PropsEditPanel
->DestroyChildren();
454 m_PropsEditPanel
->SetSizer(NULL
);
456 if (!m_SelectedNode
|| m_SelectedProp
== -1 ||
457 m_PropsList
->GetItemData(m_SelectedProp
) == 0) return;
459 wxBoxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
461 sizer
->Add(new wxButton(m_PropsEditPanel
, ID_CLEARPROP
, _("Clear")),
465 FindHandler(m_SelectedNode
)->CreatePropEditPanel(m_PropsEditPanel
, m_PropsList
, m_SelectedProp
),
468 m_PropsEditPanel
->SetAutoLayout(TRUE
);
469 m_PropsEditPanel
->SetSizer(sizer
);
470 m_PropsEditPanel
->Layout();
472 wxSize winsz
= m_PropsEditPanel
->GetSize();
473 sizer
->SetMinSize(winsz
.x
, winsz
.y
);
475 wxSize minsz
= sizer
->GetMinSize();
477 m_PropsEditPanel
->SetScrollbars(8, 8, 1/*minsz.x/8*/, minsz
.y
/8);
482 bool EditorFrame::SelectNode(wxXmlNode
*node
, wxTreeItemId
*root
)
486 wxTreeItemId rootitem
= m_TreeCtrl
->GetRootItem();
487 return SelectNode(node
, &rootitem
);
495 item
= m_TreeCtrl
->GetFirstChild(*root
, cookie
);
498 dt
= (XmlTreeData
*)(m_TreeCtrl
->GetItemData(item
));
499 nd
= (dt
) ? dt
->Node
: NULL
;
502 m_TreeCtrl
->SelectItem(item
);
503 m_TreeCtrl
->EnsureVisible(item
);
506 if (m_TreeCtrl
->ItemHasChildren(item
) && SelectNode(node
, &item
))
508 item
= m_TreeCtrl
->GetNextChild(*root
, cookie
);
515 wxTreeItemId
EditorFrame::CreateTreeNode(wxTreeCtrl
*treectrl
, wxTreeItemId parent
, wxXmlNode
*node
)
519 wxTreeItemId invalid
;
523 return FindHandler(node
)->CreateTreeNode(treectrl
, parent
, node
);
528 void EditorFrame::CreatePropsList(wxListCtrl
*treectrl
, wxXmlNode
*node
)
532 FindHandler(node
)->CreatePropsList(treectrl
, node
);
537 void EditorFrame::NotifyChanged(int change_type
)
539 if (change_type
& CHANGED_TREE
)
542 if (change_type
& CHANGED_TREE_SELECTED
)
544 wxTreeItemId sel
= m_TreeCtrl
->GetSelection();
545 m_TreeCtrl
->SetItemText(sel
,
546 FindHandler(m_SelectedNode
)->GetTreeString(m_SelectedNode
));
549 if (change_type
& CHANGED_TREE_SELECTED_ICON
)
551 wxTreeItemId sel
= m_TreeCtrl
->GetSelection();
552 int icon
= FindHandler(m_SelectedNode
)->GetTreeIcon(m_SelectedNode
);
553 m_TreeCtrl
->SetItemImage(sel
, icon
);
556 if (change_type
& CHANGED_PROPS_PANEL
)
557 RefreshProps(m_SelectedNode
);
562 void EditorFrame::OnTreeSel(wxTreeEvent
& event
)
564 XmlTreeData
*dt
= (XmlTreeData
*)(m_TreeCtrl
->GetItemData(event
.GetItem()));
565 wxXmlNode
*node
= (dt
) ? dt
->Node
: NULL
;
567 m_SelectedNode
= node
;
573 void EditorFrame::OnXMLIDEdit(wxCommandEvent
& event
)
575 if (!m_SelectedNode
) return;
576 wxXmlNode
*node
= FindHandler(m_SelectedNode
)->GetRealNode(m_SelectedNode
);
578 node
->DeleteProperty("name");
579 wxString s
= m_XMLIDCtrl
->GetValue();
580 if (!(s
== "-1")) node
->AddProperty("name", s
);
581 NotifyChanged(CHANGED_TREE_SELECTED
);
586 void EditorFrame::OnXMLIDPick(wxCommandEvent
& event
)
588 if (!m_SelectedNode
) return;
589 wxXmlNode
*node
= FindHandler(m_SelectedNode
)->GetRealNode(m_SelectedNode
);
591 wxString choices
[] = {wxString("-1")
592 #define stdID(id) , wxString(#id)
593 stdID(wxID_OK
) stdID(wxID_CANCEL
)
594 stdID(wxID_YES
) stdID(wxID_NO
)
595 stdID(wxID_APPLY
) stdID(wxID_HELP
)
596 stdID(wxID_HELP_CONTEXT
)
598 stdID(wxID_OPEN
) stdID(wxID_CLOSE
) stdID(wxID_NEW
)
599 stdID(wxID_SAVE
) stdID(wxID_SAVEAS
) stdID(wxID_REVERT
)
600 stdID(wxID_EXIT
) stdID(wxID_UNDO
) stdID(wxID_REDO
)
601 stdID(wxID_PRINT
) stdID(wxID_PRINT_SETUP
)
602 stdID(wxID_PREVIEW
) stdID(wxID_ABOUT
) stdID(wxID_HELP_CONTENTS
)
603 stdID(wxID_HELP_COMMANDS
) stdID(wxID_HELP_PROCEDURES
)
604 stdID(wxID_CUT
) stdID(wxID_COPY
) stdID(wxID_PASTE
)
605 stdID(wxID_CLEAR
) stdID(wxID_FIND
) stdID(wxID_DUPLICATE
)
606 stdID(wxID_SELECTALL
)
607 stdID(wxID_STATIC
) stdID(wxID_FORWARD
) stdID(wxID_BACKWARD
)
608 stdID(wxID_DEFAULT
) stdID(wxID_MORE
) stdID(wxID_SETUP
)
614 wxGetSingleChoice(_("Choose from predefined IDs:"), _("XMLID"),
615 38/*sizeof choices*/, choices
);
618 m_XMLIDCtrl
->SetValue(s
);
619 node
->DeleteProperty("name");
620 if (!(s
== "-1")) node
->AddProperty("name", s
);
621 NotifyChanged(CHANGED_TREE_SELECTED
);
626 void EditorFrame::OnEditCode(wxCommandEvent
& event
)
628 if (!m_SelectedNode
) return;
631 wxDialog
dlg(this, -1, _("XML code editor"), wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
);
632 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
633 wxTextCtrl
*tc
= new wxTextCtrl(&dlg
, -1, "", wxDefaultPosition
,
634 wxDefaultSize
, wxTE_MULTILINE
);
635 sizer
->Add(tc
, 1, wxEXPAND
| wxALL
, 10);
637 wxSizer
*sz2
= new wxBoxSizer(wxHORIZONTAL
);
639 sz2
->Add(new wxButton(&dlg
, wxID_OK
, _("Save")), 0);
640 sz2
->Add(new wxButton(&dlg
, wxID_CANCEL
, _("Cancel")), 0, wxLEFT
, 10);
642 sizer
->Add(sz2
, 0, wxALIGN_RIGHT
| wxRIGHT
|wxBOTTOM
, 10);
644 dlg
.SetAutoLayout(TRUE
);
647 wxConfigBase
*cfg
= wxConfigBase::Get();
649 dlg
.SetSize(wxRect(wxPoint(cfg
->Read("xmleditor_x", -1), cfg
->Read("xmleditor_y", -1)),
650 wxSize(cfg
->Read("xmleditor_w", 400), cfg
->Read("xmleditor_h", 400))));
653 wxGetTempFileName("xmleditor", tempfile
);
657 doc
.SetRoot(new wxXmlNode(*m_SelectedNode
));
658 doc
.Save(tempfile
, wxXML_IO_LIBXML
);
660 tc
->LoadFile(tempfile
);
662 if (dlg
.ShowModal() == wxID_OK
)
664 tc
->SaveFile(tempfile
);
666 if (doc
.Load(tempfile
))
668 (*m_SelectedNode
) = *doc
.GetRoot();
669 NotifyChanged(CHANGED_TREE
);
670 //FIXME-instead, regenerate only children
672 else wxLogError(_("Illegal XML file, canceled."));
674 wxRemoveFile(tempfile
);
676 cfg
->Write("xmleditor_x", (long)dlg
.GetPosition().x
);
677 cfg
->Write("xmleditor_y", (long)dlg
.GetPosition().y
);
678 cfg
->Write("xmleditor_w", (long)dlg
.GetSize().x
);
679 cfg
->Write("xmleditor_h", (long)dlg
.GetSize().y
);
684 void EditorFrame::OnClearProp(wxCommandEvent
& event
)
686 m_PropsList
->SetItemImage(m_SelectedProp
, 0, 0);
687 m_PropsList
->SetItem(m_SelectedProp
, 1, "");
689 PropsListInfo
*pli
= (PropsListInfo
*)m_PropsList
->GetItemData(m_SelectedProp
);
691 wxXmlNode
*nd
= XmlFindNode(pli
->m_Node
, pli
->m_PropInfo
->Name
);
693 if (nd
== NULL
) return;
694 nd
->GetParent()->RemoveChild(nd
);
701 void EditorFrame::OnPropSel(wxListEvent
& event
)
703 m_SelectedProp
= event
.GetIndex();
709 void EditorFrame::OnToolbar(wxCommandEvent
& event
)
711 switch (event
.GetId())
715 XmlTreeData
* dt
= (XmlTreeData
*)m_TreeCtrl
->GetItemData(m_TreeCtrl
->GetSelection());;
716 if (dt
!= NULL
&& dt
->Node
!= NULL
)
717 RefreshPreview(dt
->Node
);
731 wxString name
= wxFileSelector("Open XML resource", "", "", "", "XML resources|*.xml", wxOPEN
| wxFILE_MUST_EXIST
);
738 if (m_FileName
!= "") { SaveFile(m_FileName
); break;}
743 wxString name
= wxFileSelector("Save as", "", m_FileName
, "", "XML resources|*.xml", wxSAVE
| wxOVERWRITE_PROMPT
);
745 SaveFile((m_FileName
= name
));
749 case ID_DELETE_NODE
:
751 XmlTreeData
*dt
= (XmlTreeData
*)
752 (m_TreeCtrl
->GetItemData(m_TreeCtrl
->GetParent(m_TreeCtrl
->GetSelection())));
753 wxXmlNode
*n
= (dt
) ? dt
->Node
: NULL
;
755 m_SelectedNode
->GetParent()->RemoveChild(m_SelectedNode
);
756 NotifyChanged(CHANGED_TREE
);
765 void EditorFrame::OnNewNode(wxCommandEvent
& event
)
767 if (event
.GetId() >= ID_NEWSYBNODE
)
770 (XmlTreeData
*)(m_TreeCtrl
->GetItemData(
771 m_TreeCtrl
->GetParent(m_TreeCtrl
->GetSelection())));
773 if (pardt
&& pardt
->Node
&& pardt
->Node
!= m_Resource
->GetRoot())
775 wxXmlNode
*nd
= pardt
->Node
;
777 wxXmlNode
*realnode
= FindHandler(nd
)->GetRealNode(nd
);
778 NodeHandler
*hnd
= FindHandler(realnode
);
779 wxString name
= hnd
->GetChildTypes()[event
.GetId()-ID_NEWSYBNODE
];
781 wxXmlNode
*node
= new wxXmlNode(wxXML_ELEMENT_NODE
, name
);
782 hnd
->InsertNode(realnode
, node
, m_SelectedNode
);
783 wxTreeItemId root
= m_TreeCtrl
->GetSelection();
784 SelectNode(node
, &root
);
789 else if (event
.GetId() >= ID_NEWNODE
)
791 wxXmlNode
*realnode
= FindHandler(m_SelectedNode
)->GetRealNode(m_SelectedNode
);
792 NodeHandler
*hnd
= FindHandler(realnode
);
793 wxString name
= hnd
->GetChildTypes()[event
.GetId()-ID_NEWNODE
];
795 wxXmlNode
*node
= new wxXmlNode(wxXML_ELEMENT_NODE
, name
);
796 hnd
->InsertNode(realnode
, node
);
797 wxTreeItemId root
= m_TreeCtrl
->GetSelection();
798 SelectNode(node
, &root
);
804 switch (event
.GetId())
806 case ID_NEWDIALOG
: name
= "dialog"; break;
807 case ID_NEWPANEL
: name
= "panel"; break;
808 case ID_NEWMENU
: name
= "menu"; break;
809 case ID_NEWMENUBAR
: name
= "menubar"; break;
810 case ID_NEWTOOLBAR
: name
= "toolbar"; break;
811 default : return; // never occurs
814 wxXmlNode
*node
= new wxXmlNode(wxXML_ELEMENT_NODE
, name
);
815 m_Resource
->GetRoot()->AddChild(node
);
816 NotifyChanged(CHANGED_TREE
);
823 void EditorFrame::OnRightClickTree(wxPoint pos
)
825 wxMenu
*popup
= new wxMenu
;
827 if (m_SelectedNode
== NULL
|| m_SelectedNode
== m_Resource
->GetRoot())
829 popup
->Append(ID_NEWDIALOG
, _("New dialog"));
830 popup
->Append(ID_NEWPANEL
, _("New panel"));
831 popup
->Append(ID_NEWMENU
, _("New menu"));
832 popup
->Append(ID_NEWMENUBAR
, _("New menubar"));
833 popup
->Append(ID_NEWTOOLBAR
, _("New toolbar"));
840 FindHandler(FindHandler(m_SelectedNode
)->GetRealNode(m_SelectedNode
))->
845 wxMenu
*news
= new wxMenu
;
846 for (size_t i
= 0; i
< arr
.GetCount(); i
++)
848 news
->Append(i
+ ID_NEWNODE
, arr
[i
]);
849 if (i
% 16 == 15) news
->Break();
851 popup
->Append(ID_NEWNODE
-1, _("New child"), news
);
857 (XmlTreeData
*)(m_TreeCtrl
->GetItemData(
858 m_TreeCtrl
->GetParent(m_TreeCtrl
->GetSelection())));
859 if (pardt
&& pardt
->Node
&& pardt
->Node
!= m_Resource
->GetRoot())
861 wxXmlNode
*nd
= pardt
->Node
;
863 FindHandler(FindHandler(nd
)->GetRealNode(nd
))->
868 wxMenu
*news
= new wxMenu
;
869 for (size_t i
= 0; i
< arr
.GetCount(); i
++)
871 news
->Append(i
+ ID_NEWSYBNODE
, arr
[i
]);
872 if (i
% 16 == 15) news
->Break();
874 popup
->Append(ID_NEWSYBNODE
-1, _("New sybling"), news
);
879 popup
->AppendSeparator();
880 popup
->Append(ID_DELETE_NODE
, _("Delete"));
883 m_TreeCtrl
->PopupMenu(popup
, pos
);