X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/56d2f75071fc2a29ec10abe97c5a908bb35f30f4..7fb357a795b41c4c7fd5bcbfcac2a1faffb4f19c:/contrib/utils/wxrcedit/xmlhelpr.cpp?ds=inline diff --git a/contrib/utils/wxrcedit/xmlhelpr.cpp b/contrib/utils/wxrcedit/xmlhelpr.cpp index c4c0f2ff17..55b5ade824 100644 --- a/contrib/utils/wxrcedit/xmlhelpr.cpp +++ b/contrib/utils/wxrcedit/xmlhelpr.cpp @@ -17,14 +17,17 @@ #pragma hdrstop #endif -#include "wx/xml/xml.h" +#include "wx/xrc/xml.h" #include "wx/wx.h" +#include "wx/tokenzr.h" #include "xmlhelpr.h" -wxXmlNode *XmlFindNode(wxXmlNode *parent, const wxString& param) +wxXmlNode *XmlFindNodeSimple(wxXmlNode *parent, const wxString& param) { + if (param.IsEmpty()) return parent; + wxXmlNode *n = parent->GetChildren(); while (n) @@ -37,15 +40,51 @@ wxXmlNode *XmlFindNode(wxXmlNode *parent, const wxString& param) } -void XmlWriteValue(wxXmlNode *parent, const wxString& name, const wxString& value) + +wxXmlNode *XmlFindNode(wxXmlNode *parent, const wxString& path) { - wxXmlNode *n = XmlFindNode(parent, name); - if (n == NULL) + wxXmlNode *n = parent; + wxStringTokenizer tkn(path, _T("/")); + while (tkn.HasMoreTokens()) + { + n = XmlFindNodeSimple(n, tkn.GetNextToken()); + if (n == NULL) break; + } + return n; +} + + + +wxXmlNode *XmlCreateNode(wxXmlNode *parent, const wxString& name) +{ + wxXmlNode *n; + wxString nm; + + wxStringTokenizer tkn(name, _T("/")); + n = parent; + while (tkn.HasMoreTokens()) { - n = new wxXmlNode(wxXML_ELEMENT_NODE, name); - parent->AddChild(n); - n->AddChild(new wxXmlNode(wxXML_TEXT_NODE, "")); + parent = n; + nm = tkn.GetNextToken(); + n = XmlFindNodeSimple(parent, nm); + if (n) continue; + + // n == NULL: + n = new wxXmlNode(wxXML_ELEMENT_NODE, nm); + parent->AddChild(n); } + n->AddChild(new wxXmlNode(wxXML_TEXT_NODE, wxEmptyString)); + + return n; +} + + + +void XmlWriteValue(wxXmlNode *parent, const wxString& name, const wxString& value) +{ + wxXmlNode *n = XmlFindNode(parent, name); + if (n == NULL) + n = XmlCreateNode(parent, name); n = n->GetChildren(); @@ -81,4 +120,20 @@ wxString XmlReadValue(wxXmlNode *parent, const wxString& name) +wxString XmlGetClass(wxXmlNode *parent) +{ + return parent->GetPropVal(_T("class"), wxEmptyString); +} + + + +void XmlSetClass(wxXmlNode *parent, const wxString& classname) +{ + parent->DeleteProperty(_T("class")); + parent->AddProperty(_T("class"), classname); +} + + + +