applied patch #427244 (wxrcedit improvements: XRC version upgrade)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10375 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -35,6 +35,66 @@
|
|||||||
#include "propframe.h"
|
#include "propframe.h"
|
||||||
|
|
||||||
|
|
||||||
|
void wxXmlRcEditDocument::UpgradeNodeValue(wxXmlNode *node)
|
||||||
|
{
|
||||||
|
wxXmlNode *n = node;
|
||||||
|
if (n == NULL) return;
|
||||||
|
n = n->GetChildren();
|
||||||
|
|
||||||
|
while (n)
|
||||||
|
{
|
||||||
|
if (n->GetType() == wxXML_TEXT_NODE ||
|
||||||
|
n->GetType() == wxXML_CDATA_SECTION_NODE)
|
||||||
|
{
|
||||||
|
wxString str1 = n->GetContent();
|
||||||
|
const wxChar *dt;
|
||||||
|
|
||||||
|
for (dt = str1.c_str(); *dt; dt++)
|
||||||
|
{
|
||||||
|
// Remap amp_char to &, map double amp_char to amp_char (for things
|
||||||
|
// like "&File..." -- this is illegal in XML, so we use "_File..."):
|
||||||
|
if (*dt == '$')
|
||||||
|
{
|
||||||
|
if ( *(++dt) != '$' )
|
||||||
|
str1[size_t(dt-str1.c_str()-1)] = '_';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
n->SetContent(str1);
|
||||||
|
}
|
||||||
|
n = n->GetNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxXmlRcEditDocument::UpgradeNode(wxXmlNode *node)
|
||||||
|
{
|
||||||
|
if (node)
|
||||||
|
{
|
||||||
|
UpgradeNodeValue(node);
|
||||||
|
UpgradeNode(node->GetNext());
|
||||||
|
UpgradeNode(node->GetChildren());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxXmlRcEditDocument::Upgrade()
|
||||||
|
{
|
||||||
|
int v1,v2,v3,v4;
|
||||||
|
long version;
|
||||||
|
wxXmlNode *node = GetRoot();
|
||||||
|
wxString verstr = wxT("0.0.0.0");
|
||||||
|
node->GetPropVal(wxT("version"),verstr);
|
||||||
|
if (wxSscanf(verstr.c_str(), wxT("%i.%i.%i.%i"),
|
||||||
|
&v1, &v2, &v3, &v4) == 4)
|
||||||
|
version = v1*256*256*256+v2*256*256+v3*256+v4;
|
||||||
|
else
|
||||||
|
version = 0;
|
||||||
|
if (!version)
|
||||||
|
{
|
||||||
|
UpgradeNode(node);
|
||||||
|
}
|
||||||
|
node->DeleteProperty(wxT("version"));
|
||||||
|
node->AddProperty(wxT("version"), wxT(WX_XMLRES_CURRENT_VERSION_STRING));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class EditorTreeCtrl : public wxTreeCtrl
|
class EditorTreeCtrl : public wxTreeCtrl
|
||||||
{
|
{
|
||||||
@@ -230,8 +290,11 @@ void EditorFrame::LoadFile(const wxString& filename)
|
|||||||
|
|
||||||
delete m_Resource;
|
delete m_Resource;
|
||||||
|
|
||||||
|
// create new resource in order to handle version differences properly
|
||||||
|
PreviewFrame::Get()->ResetResource();
|
||||||
|
|
||||||
m_FileName = "";
|
m_FileName = "";
|
||||||
m_Resource = new wxXmlDocument;
|
m_Resource = new wxXmlRcEditDocument;
|
||||||
m_Modified = FALSE;
|
m_Modified = FALSE;
|
||||||
|
|
||||||
if (!m_Resource->Load(filename))
|
if (!m_Resource->Load(filename))
|
||||||
@@ -244,6 +307,9 @@ void EditorFrame::LoadFile(const wxString& filename)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_FileName = filename;
|
m_FileName = filename;
|
||||||
|
|
||||||
|
// Upgrades old versions
|
||||||
|
m_Resource->Upgrade();
|
||||||
RefreshTree();
|
RefreshTree();
|
||||||
}
|
}
|
||||||
RefreshTitle();
|
RefreshTitle();
|
||||||
@@ -255,11 +321,6 @@ void EditorFrame::SaveFile(const wxString& filename)
|
|||||||
{
|
{
|
||||||
m_FileName = filename;
|
m_FileName = filename;
|
||||||
|
|
||||||
// change version:
|
|
||||||
wxXmlNode *root = m_Resource->GetRoot();
|
|
||||||
root->DeleteProperty(wxT("version"));
|
|
||||||
root->AddProperty(wxT("version"), wxT(WX_XMLRES_CURRENT_VERSION_STRING));
|
|
||||||
|
|
||||||
// save it:
|
// save it:
|
||||||
if (!m_Resource->Save(filename))
|
if (!m_Resource->Save(filename))
|
||||||
wxLogError(_("Error saving ") + filename);
|
wxLogError(_("Error saving ") + filename);
|
||||||
@@ -278,7 +339,7 @@ void EditorFrame::NewFile()
|
|||||||
delete m_Resource;
|
delete m_Resource;
|
||||||
|
|
||||||
m_FileName = "";
|
m_FileName = "";
|
||||||
m_Resource = new wxXmlDocument;
|
m_Resource = new wxXmlRcEditDocument;
|
||||||
m_Resource->SetRoot(new wxXmlNode(wxXML_ELEMENT_NODE, _("resource")));
|
m_Resource->SetRoot(new wxXmlNode(wxXML_ELEMENT_NODE, _("resource")));
|
||||||
|
|
||||||
m_Modified = FALSE;
|
m_Modified = FALSE;
|
||||||
@@ -433,7 +494,8 @@ void EditorFrame::OnTreeSel(wxTreeEvent& event)
|
|||||||
}
|
}
|
||||||
RecursivelyExpand(m_TreeCtrl, event.GetItem());
|
RecursivelyExpand(m_TreeCtrl, event.GetItem());
|
||||||
|
|
||||||
PreviewFrame::Get()->Preview(node);
|
PreviewFrame::Get()->Preview(node,m_Resource->GetRoot()->GetPropVal(
|
||||||
|
wxT("version"), wxT("0.0.0.0")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -447,7 +509,8 @@ void EditorFrame::OnToolbar(wxCommandEvent& event)
|
|||||||
{
|
{
|
||||||
XmlTreeData* dt = (XmlTreeData*)m_TreeCtrl->GetItemData(m_TreeCtrl->GetSelection());;
|
XmlTreeData* dt = (XmlTreeData*)m_TreeCtrl->GetItemData(m_TreeCtrl->GetSelection());;
|
||||||
if (dt != NULL && dt->Node != NULL)
|
if (dt != NULL && dt->Node != NULL)
|
||||||
PreviewFrame::Get()->Preview(dt->Node);
|
PreviewFrame::Get()->Preview(dt->Node,m_Resource->GetRoot()->GetPropVal(
|
||||||
|
wxT("version"), wxT("0.0.0.0")));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -47,6 +47,18 @@ enum ChangeType
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class wxXmlRcEditDocument : public wxXmlDocument
|
||||||
|
{
|
||||||
|
// Helper functions for Upgrade()
|
||||||
|
void UpgradeNodeValue(wxXmlNode *node);
|
||||||
|
void UpgradeNode(wxXmlNode *node);
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Upgrades older versions
|
||||||
|
void Upgrade();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
class EditorFrame : public wxFrame
|
class EditorFrame : public wxFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -80,7 +92,7 @@ class EditorFrame : public wxFrame
|
|||||||
wxXmlNode *m_Clipboard;
|
wxXmlNode *m_Clipboard;
|
||||||
|
|
||||||
wxString m_FileName;
|
wxString m_FileName;
|
||||||
wxXmlDocument *m_Resource;
|
wxXmlRcEditDocument *m_Resource;
|
||||||
|
|
||||||
bool m_Modified;
|
bool m_Modified;
|
||||||
|
|
||||||
|
@@ -69,7 +69,9 @@ void PropEditCtrlTxt::WriteValue()
|
|||||||
wxWindow *PropEditCtrlInt::CreateEditCtrl()
|
wxWindow *PropEditCtrlInt::CreateEditCtrl()
|
||||||
{
|
{
|
||||||
PropEditCtrlTxt::CreateEditCtrl();
|
PropEditCtrlTxt::CreateEditCtrl();
|
||||||
|
#if wxUSE_VALIDATORS
|
||||||
m_TextCtrl->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
|
m_TextCtrl->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
|
||||||
|
#endif
|
||||||
return m_TextCtrl;
|
return m_TextCtrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -75,13 +75,9 @@ PreviewFrame::PreviewFrame()
|
|||||||
|
|
||||||
SetMenuBar(new wxMenuBar());
|
SetMenuBar(new wxMenuBar());
|
||||||
|
|
||||||
m_RC = new wxXmlResource;
|
m_RC = NULL;
|
||||||
// these handlers take precedence over std. ones:
|
|
||||||
m_RC->AddHandler(new MyMenubarHandler(GetMenuBar()));
|
|
||||||
// std handlers:
|
|
||||||
m_RC->InitAllHandlers();
|
|
||||||
m_TmpFile = wxGetTempFileName(_T("wxrcedit"));
|
m_TmpFile = wxGetTempFileName(_T("wxrcedit"));
|
||||||
m_RC->Load(m_TmpFile);
|
ResetResource();
|
||||||
|
|
||||||
wxConfigBase *cfg = wxConfigBase::Get();
|
wxConfigBase *cfg = wxConfigBase::Get();
|
||||||
SetSize(wxRect(wxPoint(cfg->Read(_T("previewframe_x"), -1), cfg->Read(_T("previewframe_y"), -1)),
|
SetSize(wxRect(wxPoint(cfg->Read(_T("previewframe_x"), -1), cfg->Read(_T("previewframe_y"), -1)),
|
||||||
@@ -103,6 +99,18 @@ PreviewFrame::PreviewFrame()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void PreviewFrame::ResetResource()
|
||||||
|
{
|
||||||
|
delete m_RC;
|
||||||
|
m_RC = new wxXmlResource;
|
||||||
|
// these handlers take precedence over std. ones:
|
||||||
|
m_RC->AddHandler(new MyMenubarHandler(GetMenuBar()));
|
||||||
|
// std handlers:
|
||||||
|
m_RC->InitAllHandlers();
|
||||||
|
wxRemoveFile(m_TmpFile);
|
||||||
|
m_RC->Load(m_TmpFile);
|
||||||
|
}
|
||||||
|
|
||||||
PreviewFrame::~PreviewFrame()
|
PreviewFrame::~PreviewFrame()
|
||||||
{
|
{
|
||||||
wxConfigBase *cfg = wxConfigBase::Get();
|
wxConfigBase *cfg = wxConfigBase::Get();
|
||||||
@@ -132,13 +140,15 @@ void PreviewFrame::MakeDirty()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PreviewFrame::Preview(wxXmlNode *node)
|
void PreviewFrame::Preview(wxXmlNode *node,const wxString &version)
|
||||||
{
|
{
|
||||||
while (node->GetParent()->GetParent() != NULL) node = node->GetParent();
|
while (node->GetParent()->GetParent() != NULL) node = node->GetParent();
|
||||||
|
|
||||||
{
|
{
|
||||||
wxXmlDocument doc;
|
wxXmlDocument doc;
|
||||||
doc.SetRoot(new wxXmlNode(wxXML_ELEMENT_NODE, _T("resource")));
|
wxXmlNode *root = new wxXmlNode(wxXML_ELEMENT_NODE, _T("resource"));
|
||||||
|
root->AddProperty(new wxXmlProperty(wxT("version"),version,NULL));
|
||||||
|
doc.SetRoot(root);
|
||||||
doc.GetRoot()->AddChild(new wxXmlNode(*node));
|
doc.GetRoot()->AddChild(new wxXmlNode(*node));
|
||||||
|
|
||||||
if (XmlGetClass(doc.GetRoot()->GetChildren()) == _T("wxDialog"))
|
if (XmlGetClass(doc.GetRoot()->GetChildren()) == _T("wxDialog"))
|
||||||
@@ -158,6 +168,7 @@ void PreviewFrame::Preview(wxXmlNode *node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_Node = node;
|
m_Node = node;
|
||||||
|
m_Version = version;
|
||||||
|
|
||||||
m_LogCtrl->Clear();
|
m_LogCtrl->Clear();
|
||||||
wxLogTextCtrl mylog(m_LogCtrl);
|
wxLogTextCtrl mylog(m_LogCtrl);
|
||||||
@@ -220,21 +231,11 @@ void PreviewFrame::PreviewPanel()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
|
||||||
// avoid Problems with setting the focus to a no longer existing child
|
|
||||||
void PreviewFrame::OnActivate(wxActivateEvent &event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(PreviewFrame, wxFrame)
|
BEGIN_EVENT_TABLE(PreviewFrame, wxFrame)
|
||||||
EVT_ENTER_WINDOW(PreviewFrame::OnMouseEnter)
|
EVT_ENTER_WINDOW(PreviewFrame::OnMouseEnter)
|
||||||
#ifdef __WXMSW__
|
|
||||||
EVT_ACTIVATE(PreviewFrame::OnActivate)
|
|
||||||
#endif
|
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
void PreviewFrame::OnMouseEnter(wxMouseEvent& event)
|
void PreviewFrame::OnMouseEnter(wxMouseEvent& event)
|
||||||
{
|
{
|
||||||
if (m_Dirty) Preview(m_Node);
|
if (m_Dirty) Preview(m_Node,m_Version);
|
||||||
}
|
}
|
||||||
|
@@ -31,12 +31,13 @@ class PreviewFrame : public wxFrame
|
|||||||
PreviewFrame();
|
PreviewFrame();
|
||||||
~PreviewFrame();
|
~PreviewFrame();
|
||||||
|
|
||||||
void Preview(wxXmlNode *node);
|
void Preview(wxXmlNode *node,const wxString &version);
|
||||||
void MakeDirty();
|
void MakeDirty();
|
||||||
// current node updated, needs preview refresh
|
// current node updated, needs preview refresh
|
||||||
// (will be done once mouse enters preview win)
|
// (will be done once mouse enters preview win)
|
||||||
|
|
||||||
static PreviewFrame *Get();
|
static PreviewFrame *Get();
|
||||||
|
void ResetResource();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void PreviewMenu();
|
void PreviewMenu();
|
||||||
@@ -46,6 +47,7 @@ class PreviewFrame : public wxFrame
|
|||||||
private:
|
private:
|
||||||
static PreviewFrame *ms_Instance;
|
static PreviewFrame *ms_Instance;
|
||||||
wxXmlNode *m_Node;
|
wxXmlNode *m_Node;
|
||||||
|
wxString m_Version;
|
||||||
wxScrolledWindow *m_ScrollWin;
|
wxScrolledWindow *m_ScrollWin;
|
||||||
wxTextCtrl *m_LogCtrl;
|
wxTextCtrl *m_LogCtrl;
|
||||||
wxSplitterWindow *m_Splitter;
|
wxSplitterWindow *m_Splitter;
|
||||||
@@ -57,9 +59,6 @@ class PreviewFrame : public wxFrame
|
|||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
void OnMouseEnter(wxMouseEvent& event);
|
void OnMouseEnter(wxMouseEvent& event);
|
||||||
#ifdef __WXMSW__
|
|
||||||
void OnActivate(wxActivateEvent &event);
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -37,6 +37,11 @@
|
|||||||
|
|
||||||
#include "wx/generic/treectlg.h"
|
#include "wx/generic/treectlg.h"
|
||||||
|
|
||||||
|
#ifdef __WXMSW__
|
||||||
|
#include "windows.h"
|
||||||
|
#include "wx/msw/winundef.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "splittree.h"
|
#include "splittree.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user