#include "import_from_xrc.h" #include "allocator_mgr.h" #include "file_logger.h" #include "import_dlg.h" #include "notebook_base_wrapper.h" #include "notebook_page_wrapper.h" #include "wxc_project_metadata.h" #include "wxgui_helpers.h" #include "xmlutils.h" #include #include #include #include ImportFromXrc::ImportFromXrc(wxWindow* parent) : m_Parent(parent) { } ImportFromXrc::~ImportFromXrc() {} bool ImportFromXrc::ImportProject(ImportDlg::ImportFileData& data) const { ImportDlg dlg(ImportDlg::IPD_XRC, m_Parent); if(dlg.ShowModal() != wxID_OK) { return false; } wxString filepath = dlg.GetFilepath(); if(filepath.empty() || !wxFileExists(filepath)) { return false; } wxXmlDocument doc(filepath); if(!doc.IsOk()) { wxMessageBox(_("Failed to load the file to import"), _("CodeLite"), wxICON_ERROR | wxOK, m_Parent); return false; } wxcWidget::List_t toplevels; if(ParseFile(doc, toplevels) && !toplevels.empty()) { wxcProjectMetadata::Get().Serialize(toplevels, wxFileName(dlg.GetOutputFilepath())); data = dlg.GetData(); return true; } return false; } bool ImportFromXrc::ParseFile(wxXmlDocument& doc, wxcWidget::List_t& toplevels) const { wxXmlNode* toplevelnode = doc.GetRoot()->GetChildren(); while(toplevelnode) { wxString tag = toplevelnode->GetName(); if(tag != wxT("object")) { wxMessageBox(_("This doesn't seem to be a valid XRC file. Aborting."), _("CodeLite"), wxICON_ERROR | wxOK, m_Parent); return false; } bool alreadyParented(false); wxcWidget* wrapper = ParseNode(toplevelnode, NULL, alreadyParented); if(wrapper) { toplevels.push_back(wrapper); } toplevelnode = toplevelnode->GetNext(); } return true; } wxcWidget* ImportFromXrc::ParseNode(wxXmlNode* node, wxcWidget* parentwrapper, bool& alreadyParented) const { wxcWidget* wrapper = NULL; // XRC for some reason treats sizeritems as an object! We'll deal with that below, but cache node first // BTW, wxSpacer is an exception: it's called but looks like a sizeritem with no contained object // BTW2, the buttons in a wxStdButtonSizer are also an exception: each is wrapped in a