bool MANFrame::SearchManPage(const wxString &dirs, const wxString &keyword) { SetDirs(dirs); if (keyword.IsEmpty()) { if (m_dirsVect.empty()) { SetPage(NoSearchDirsSet); } return false; } std::vector<wxString> files_found; GetMatches(keyword, &files_found); m_entry->SetValue(keyword); if (files_found.empty()) { SetPage(ManPageNotFound); return false; } if (files_found.size() == 1) { wxString filename = files_found.front(); wxString man_page = GetManPage(filename); if (man_page.IsEmpty()) { SetPage(ManPageNotFound); return false; } SetPage(cbC2U(man2html_buffer(cbU2C(man_page)))); return true; } SetPage(CreateLinksPage(files_found)); return true; }
bool ConfigManager::Read(const wxString& name, wxColour* ret) { wxString key(name); TiXmlElement* e = AssertPath(key); TiXmlHandle parentHandle(e); TiXmlElement *c = (TiXmlElement *) parentHandle.FirstChild(cbU2C(key)).FirstChild("colour").Element(); if (c) { int r, g, b; if (c->QueryIntAttribute("r", &r) == TIXML_SUCCESS && c->QueryIntAttribute("g", &g) == TIXML_SUCCESS && c->QueryIntAttribute("b", &b) == TIXML_SUCCESS) ret->Set(r, g, b); return true; } return false; }
wxWizardPage* WizPageBase::GetPrev() const { try { wxString sig = _T("OnGetPrevPage_") + m_PageName; SqPlus::SquirrelFunction<wxString&> cb(cbU2C(sig)); if (cb.func.IsNull()) return wxWizardPageSimple::GetPrev(); wxString prev = cb(); if (prev.IsEmpty()) return 0; return s_PagesByName[prev]; } catch (SquirrelError& e) { Manager::Get()->GetScriptingManager()->DisplayErrors(&e); } return wxWizardPageSimple::GetPrev(); }
bool xmlFile::Open(wxString& _src) { if( _src.Contains(_T("#zip:"))) { wxString contents; wxFileSystem* fs = new wxFileSystem; wxFSFile* f = fs->OpenFile(_src); if (!f) { delete fs; return false; } { wxInputStream* is = f->GetStream(); while (!is->Eof() && is->CanRead()) { char tmp[1024]; memset(tmp, 0, sizeof(tmp)); is->Read(tmp, sizeof(tmp) - 1); contents << cbC2U((const char*)tmp); } } delete f; delete fs; m_doc.Parse(cbU2C(contents)); m_pWorkingElement = m_doc.RootElement(); return true; } else { if(TinyXML::LoadDocument(_src, &m_doc)) { m_pWorkingElement = (TiXmlElement*)&m_doc; return true; } } return false; }
void XrcDialog::OnButton(wxCommandEvent& event) { // VERY important, or else the dialog will not be dismissed with // standard event IDs like wxID_OK/wxID_CANCEL/etc. event.Skip(true); try { // Manager::Get()->GetLogManager()->DebugLog(F(_T("Script dialog event: %d"), event.GetId())); SqPlus::SquirrelFunction<void> cb(cbU2C(m_CallBack)); if (cb.func.IsNull()) return; cb(event.GetId()); } catch (SquirrelError& e) { Manager::Get()->GetScriptingManager()->DisplayErrors(&e); } }
void ConfigManager::Read(const wxString& name, ConfigManagerContainer::IntToStringMap* map) { wxString key(name); TiXmlElement* e = AssertPath(key); TiXmlHandle parentHandle(e); TiXmlNode *mNode = parentHandle.FirstChild(cbU2C(key)).FirstChild("ismap").Node(); TiXmlNode *curr = nullptr; long tmp; if (mNode) { while ((curr = mNode->IterateChildren(curr))) { cbC2U(curr->Value()).Mid(1).ToLong(&tmp); (*map)[tmp] = cbC2U(curr->FirstChild()->ToText()->Value()); } } }
void MANFrame::OnLinkClicked(wxHtmlLinkEvent &event) { wxString link = event.GetLinkInfo().GetHref(); if (link.StartsWith(_T("man:"), &link)) { if (link.Last() == _T(')')) { link.RemoveLast(); wxString name = link.BeforeLast(_T('(')); if (name.IsEmpty()) { return; } wxString section = link.AfterLast(_T('(')); if (!section.IsEmpty()) { name += _T(".") + section; } SearchManPage(name); } } else if (link.StartsWith(_T("fman:"), &link)) { wxString man_page = GetManPage(link); if (man_page.IsEmpty()) { SetPage(ManPageNotFound); return; } SetPage(cbC2U(man2html_buffer(cbU2C(man_page)))); } else if (wxFileName(link).GetExt().Mid(0, 3).CmpNoCase(_T("htm")) == 0) { m_htmlWindow->LoadPage(link); } }
void WizPageBase::OnPageChanging(wxWizardEvent& event) { Manager::Get()->GetConfigManager(_T("scripts"))->Write(_T("/generic_wizard/") + m_PageName + _T("/skip"), (bool)m_SkipPage); try { wxString sig = _T("OnLeave_") + m_PageName; SqPlus::SquirrelFunction<bool> cb(cbU2C(sig)); if (cb.func.IsNull()) return; bool allow = cb(event.GetDirection() != 0); // !=0 forward, ==0 backward if (!allow) event.Veto(); } catch (SquirrelError& e) { Manager::Get()->GetScriptingManager()->DisplayErrors(&e); } }
void ProjectConfiguration::XmlWrite(TiXmlElement* Node,cbProject* Project) { TiXmlElement* LibFinder = Node->FirstChildElement("lib_finder"); if ( !LibFinder ) LibFinder = Node->InsertEndChild(TiXmlElement("lib_finder"))->ToElement(); LibFinder->Clear(); if ( m_DisableAuto ) { LibFinder->SetAttribute("disable_auto","1"); } for ( size_t i=0; i<m_GlobalUsedLibs.Count(); i++ ) { LibFinder->InsertEndChild(TiXmlElement("lib"))->ToElement()->SetAttribute("name",cbU2C(m_GlobalUsedLibs[i])); } for ( wxMultiStringMap::iterator i=m_TargetsUsedLibs.begin(); i!=m_TargetsUsedLibs.end(); ++i ) { if ( !Project->GetBuildTarget(i->first) ) continue; wxArrayString& Libs = i->second; if ( Libs.Count() ) { TiXmlElement* TargetElem = LibFinder->InsertEndChild(TiXmlElement("target"))->ToElement(); TargetElem->SetAttribute("name",cbU2C(i->first)); for ( size_t i=0; i<Libs.Count(); i++ ) { TargetElem->InsertEndChild(TiXmlElement("lib"))->ToElement()->SetAttribute("name",cbU2C(Libs[i])); } } } if ( !LibFinder->FirstAttribute() && !LibFinder->FirstChild() ) { // LibFinder is empty, let's delete it so it doesn't trash here Node->RemoveChild(LibFinder); } }
//------------------------------------------------------------------------------ void WizPage::OnButton(wxCommandEvent& event) { wxWindow* win = FindWindowById(event.GetId(), this); if (!win) { Manager::Get()->GetLogManager()->DebugLog(F(_T("Can't locate window with id %d"), event.GetId())); return; } try { wxString sig = _T("OnClick_") + win->GetName(); SqPlus::SquirrelFunction<void> cb(cbU2C(sig)); if (cb.func.IsNull()) return; cb(); } catch (SquirrelError& e) { Manager::Get()->GetScriptingManager()->DisplayErrors(&e); } }
bool xmlFile::CWElement(wxString& filename) { if(!m_pWorkingElement) return false; TiXmlElement* curElement = m_pWorkingElement; wxArrayString elements = GetArrayFromString(filename, _T('/')); for(size_t i=0; i < elements.GetCount(); i++) { if(elements[i] == _T(".")) continue; if(elements[i] == _T("..")) { if(!CWElementToParent()) { m_pWorkingElement = curElement; return false; } } else { TiXmlElement* tmp = m_pWorkingElement->FirstChildElement(cbU2C(elements[i])); if(tmp) { m_pWorkingElement = tmp; } else { m_pWorkingElement = curElement; return false; } } } return ( curElement == m_pWorkingElement ? false :true); }
void ConfigManager::Write(const wxString& name, const ConfigManagerContainer::StringSet& set) { wxString key(name); TiXmlElement* e = AssertPath(key); TiXmlElement *leaf = GetUniqElement(e, key); TiXmlElement *mNode; mNode = GetUniqElement(leaf, _T("sset")); leaf->RemoveChild(mNode); mNode = GetUniqElement(leaf, _T("sset")); for (ConfigManagerContainer::StringSet::const_iterator it = set.begin(); it != set.end(); ++it) { TiXmlElement s("s"); TiXmlText t(cbU2C(*it)); t.SetCDATA(true); s.InsertEndChild(t); mNode->InsertEndChild(s); } }
void EnvVars::OnProjectLoadingHook(cbProject* project, TiXmlElement* elem, bool loading) { #if TRACE_ENVVARS Manager::Get()->GetLogManager()->DebugLog(F(_T("OnProjectLoadingHook"))); #endif if (loading) { TiXmlElement* node = elem->FirstChildElement("envvars"); if (node) { m_ProjectSets[project] = cbC2U(node->Attribute("set")); if (m_ProjectSets[project].IsEmpty()) // no envvar set to apply setup return; if (!nsEnvVars::EnvvarSetExists(m_ProjectSets[project])) EnvvarSetWarning(m_ProjectSets[project]); } } else { // Hook called when saving project file. // since rev4332, the project keeps a copy of the <Extensions> element // and re-uses it when saving the project (so to avoid losing entries in it // if plugins that use that element are not loaded atm). // so, instead of blindly inserting the element, we must first check it's // not already there (and if it is, clear its contents) TiXmlElement* node = elem->FirstChildElement("envvars"); if (!node) node = elem->InsertEndChild(TiXmlElement("envvars"))->ToElement(); node->Clear(); if (!m_ProjectSets[project].IsEmpty()) node->SetAttribute("set", cbU2C(m_ProjectSets[project])); } }// OnProjectLoadingHook
int LibraryDetectionManager::StoreNewSettingsFile( const wxString& shortcut, const std::vector< char >& content ) { // Try to parse file's content TiXmlDocument doc; if ( !doc.Parse( &content[0] ) ) return -1; // Ensure that this file contains required shortcut if ( !doc.RootElement() ) return -1; if ( !doc.RootElement()->Attribute("short_code") ) return -1; if ( strcmp( doc.RootElement()->Attribute("short_code"), cbU2C(shortcut) ) ) return -1; // Finally load new data - this will make sure that we have valid xml structure int AddedConfigs = LoadXmlDoc( doc ); if ( !AddedConfigs ) return -1; // Search for not-yet existing file name int i=0; wxString BaseName = ConfigManager::GetFolder(sdDataUser) + wxFileName::GetPathSeparator() + _T("lib_finder") + wxFileName::GetPathSeparator(); if ( !wxFileName::Mkdir( BaseName, 0777, wxPATH_MKDIR_FULL ) ) return -2; wxString FileName = BaseName + shortcut + _T(".xml"); while ( wxFileName::FileExists( FileName ) || wxFileName::DirExists( FileName ) ) FileName = BaseName + shortcut + wxString::Format(_T("%d.xml"),i++); // Store data wxFile fl( FileName, wxFile::write_excl ); if ( !fl.IsOpened() ) return -2; const char* ptr = &content[0]; size_t len = strlen(ptr); if ( fl.Write( ptr, len ) != len ) return -2; return AddedConfigs; }
bool QuerySvn(const wxString& workingDir, wxString& revision, wxString& date) { revision = _T("0"); date = _T("unknown date"); wxString svncmd = _T("svn info --xml --non-interactive "); svncmd.Append(_T("\"") + workingDir + _T("\"")); wxArrayString xmlOutput; if (wxExecute(svncmd, xmlOutput) != -1) { wxString buf = _T(""); for(unsigned int i=0; i<xmlOutput.GetCount(); ++i){ buf << xmlOutput[i]; } TiXmlDocument doc; doc.Parse(cbU2C(buf)); if (doc.Error()) return 0; TiXmlHandle hCommit(&doc); hCommit = hCommit.FirstChildElement("info").FirstChildElement("entry").FirstChildElement("commit"); if(const TiXmlElement* e = hCommit.ToElement()) { revision = e->Attribute("revision") ? cbC2U(e->Attribute("revision")) : _T(""); const TiXmlElement* d = e->FirstChildElement("date"); if(d && d->GetText()) date = cbC2U(d->GetText()); return 1; } } return 0; }
bool wxsStringProperty::XmlWrite(wxsPropertyContainer* Object,TiXmlElement* Element) { if ( XmlStoreEmpty || (VALUE != Default) ) { wxString Base = VALUE; wxString Result; for ( const wxChar* Ch = Base.c_str(); *Ch; Ch++ ) { switch ( *Ch ) { case _T('_'): Result << _T("__"); break; // TODO: This is NOT compatible with xrc file when there's no version entry or version is less than 2.3.0.1 //case _T('&'): Result << _T('_'); break; // We could leave this to be translated into & but this looks nicer ;) case _T('\\'): Result << _T("\\\\"); break; // We could handle \n and \r here too but this is not necessary since XRC loading // routines also handle \n and \r chars default: Result << *Ch; } } // TODO: Use proper encoding Element->InsertEndChild(TiXmlText(cbU2C(Result))); return true; } return false; }
// ---------------------------------------------------------------------------- bool BrowseTrackerLayout::Save(const wxString& filename, FileBrowse_MarksHash& m_FileBrowse_MarksArchive) // ---------------------------------------------------------------------------- { //DumpBrowse_Marks(wxT("BookMarks"), m_FileBrowse_MarksArchive, m_EdBook_MarksArchive); const char* ROOT_TAG = "BrowseTracker_layout_file"; TiXmlDocument doc; doc.SetCondenseWhiteSpace(false); doc.InsertEndChild(TiXmlDeclaration("1.0", "UTF-8", "yes")); TiXmlElement* rootnode = static_cast<TiXmlElement*>(doc.InsertEndChild(TiXmlElement(ROOT_TAG))); if (!rootnode) return false; TiXmlElement* tgtidx = static_cast<TiXmlElement*>(rootnode->InsertEndChild(TiXmlElement("ActiveTarget"))); tgtidx->SetAttribute("name", cbU2C(m_pProject->GetActiveBuildTarget())); ProjectFile* active = 0L; cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor(); if (ed) active = ed->GetProjectFile(); for (FilesList::iterator it = m_pProject->GetFilesList().begin(); it != m_pProject->GetFilesList().end(); ++it) { ProjectFile* f = *it; if (f->editorOpen || f->editorPos || f->editorTopLine || f->editorTabPos) { TiXmlElement* node = static_cast<TiXmlElement*>(rootnode->InsertEndChild(TiXmlElement("File"))); node->SetAttribute("name", cbU2C(f->relativeFilename)); node->SetAttribute("open", f->editorOpen); node->SetAttribute("top", (f == active)); node->SetAttribute("tabpos", f->editorTabPos); TiXmlElement* cursor = static_cast<TiXmlElement*>(node->InsertEndChild(TiXmlElement("Cursor"))); cursor->SetAttribute("position", f->editorPos); cursor->SetAttribute("topLine", f->editorTopLine); // Save the BrowseMarks FileBrowse_MarksHash::iterator it2 = m_FileBrowse_MarksArchive.find(f->file.GetFullPath()); if (it2 != m_FileBrowse_MarksArchive.end() ) do { const BrowseMarks* pBrowse_Marks = it2->second; if (not pBrowse_Marks) break; wxString browseMarks = pBrowse_Marks->GetStringOfBrowse_Marks(); #if defined(LOGGING) //LOGIT( _T("Layout writing BROWSEMarkString [%p]is[%s]"), pBrowse_Marks, browseMarks.c_str()); #endif TiXmlElement* btMarks = static_cast<TiXmlElement*>(node->InsertEndChild(TiXmlElement("BrowseMarks"))); btMarks->SetAttribute("positions", cbU2C(browseMarks)); }while(0); } }//for const wxArrayString& en = m_pProject->ExpandedNodes(); for (unsigned int i = 0; i < en.GetCount(); ++i) { if (!en[i].IsEmpty()) { TiXmlElement* node = static_cast<TiXmlElement*>(rootnode->InsertEndChild(TiXmlElement("Expand"))); node->SetAttribute("folder", cbU2C(en[i])); } } return cbSaveTinyXMLDocument(&doc, filename); }
void ConfigManager::DeleteSubPath(const wxString& thePath) { if (doc->ErrorId()) { cbMessageBox(wxString(_T("### TinyXML error:\n")) << cbC2U(doc->ErrorDesc())); doc->ClearError(); } wxString path(thePath); to_lower(path); Collapse(path); wxString illegal(_T(" :.,;!\"\'$%&()[]<>{}?*+-|#")); size_t i; while ((i = path.find_first_of(illegal)) != wxString::npos) path[i] = _T('_'); if (path.Last() == _T('/')) path.RemoveLast(); if (path.IsSameAs(_T("/"))) // this function will refuse to remove root! return; TiXmlElement* parent = pathNode ? pathNode : root; if (path.find(_T('/')) != wxString::npos) { wxString sub; do { sub = path.BeforeFirst(_T('/')); path = path.AfterFirst(_T('/')); if (sub.IsEmpty()) parent = root; else if (sub.IsSameAs(_T("."))) ; else if (parent != root && sub.IsSameAs(_T(".."))) parent = parent->Parent()->ToElement(); else { TiXmlElement* n = parent->FirstChildElement(cbU2C(sub)); if (n) parent = n; else return; } } while (path.find(_T('/')) != wxString::npos); } if (!path.IsEmpty()) { if (TiXmlNode *toRemove = parent->FirstChild(cbU2C(path))) { toRemove->Clear(); parent->RemoveChild(toRemove); } } }
// ---------------------------------------------------------------------------- bool BrowseTrackerLayout::Save(const wxString& filename, FileBrowse_MarksHash& m_FileBrowse_MarksArchive, FileBrowse_MarksHash& m_EdBook_MarksArchive) // ---------------------------------------------------------------------------- { ////DumpBrowse_Marks(wxT("BookMarks"), m_FileBrowse_MarksArchive, m_EdBook_MarksArchive); const char* ROOT_TAG = "BrowseTracker_layout_file"; TiXmlDocument doc; doc.SetCondenseWhiteSpace(false); doc.InsertEndChild(TiXmlDeclaration("1.0", "UTF-8", "yes")); TiXmlElement* rootnode = static_cast<TiXmlElement*>(doc.InsertEndChild(TiXmlElement(ROOT_TAG))); if (!rootnode) return false; TiXmlElement* tgtidx = static_cast<TiXmlElement*>(rootnode->InsertEndChild(TiXmlElement("ActiveTarget"))); tgtidx->SetAttribute("name", cbU2C(m_pProject->GetActiveBuildTarget())); ProjectFile* active = 0L; cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor(); if (ed) active = ed->GetProjectFile(); int count = m_pProject->GetFilesCount(); for (int i = 0; i < count; ++i) { ProjectFile* f = m_pProject->GetFile(i); if (f->editorOpen || f->editorPos || f->editorTopLine || f->editorTabPos) { TiXmlElement* node = static_cast<TiXmlElement*>(rootnode->InsertEndChild(TiXmlElement("File"))); node->SetAttribute("name", cbU2C(f->relativeFilename)); node->SetAttribute("open", f->editorOpen); node->SetAttribute("top", (f == active)); node->SetAttribute("tabpos", f->editorTabPos); TiXmlElement* cursor = static_cast<TiXmlElement*>(node->InsertEndChild(TiXmlElement("Cursor"))); cursor->SetAttribute("position", f->editorPos); cursor->SetAttribute("topLine", f->editorTopLine); EditorBase* eb = 0; // write out a string of browse mark positions #if defined(LOGGING) ////LOGIT( _T("ProjectFilename[%s]"),f->file.GetFullPath().c_str() ); #endif eb = Manager::Get()->GetEditorManager()->GetEditor(f->file.GetFullPath()); #if defined(LOGGING) ////if (eb) LOGIT( _T("EditorBase Filename[%d][%s]"), i, eb->GetFilename().c_str() ); #endif ////if(eb) if (f->file.GetFullPath() != eb->GetFilename()) ////{ //// #if defined(LOGGING) //// LOGIT( _T("NAME MISSMATCH ProjectFile[%s]EditorBase[%s]"), f->file.GetFullPath().c_str(), eb->GetFilename().c_str() ); //// #endif ////} //// #if defined(LOGGING) //// if (m_FileBrowse_MarksArchive.find(eb) != m_FileBrowse_MarksArchive.end() ) //// LOGIT( _T("Found eb[%p][%s]"), eb, eb->GetShortName().c_str() ); //// else{ //// int i = 0; //// for (EbBrowse_MarksHash::iterator it = m_FileBrowse_MarksArchive.begin(); //// it != m_FileBrowse_MarksArchive.end(); ++it) //// { //// #if defined(LOGGING) //// LOGIT( _T("m_FileBrowse_MarksArchive[i][%d][%p]"), i, it->first ); //// #endif //// ++i; //// } //// } //// #endif #if defined(LOGGING) ////LOGIT( _T("Layout processing for[%s]"),/*f->relativeFilename.c_str(),*/ f->file.GetFullPath().c_str() ); #endif // Save the BrowseMarks FileBrowse_MarksHash::iterator it = m_FileBrowse_MarksArchive.find(f->file.GetFullPath()); if (it != m_FileBrowse_MarksArchive.end() ) do { BrowseMarks* pBrowse_Marks = it->second; if (not pBrowse_Marks) break; wxString browseMarks = pBrowse_Marks->GetStringOfBrowse_Marks(); #if defined(LOGGING) ////LOGIT( _T("Layout writing BROWSEMarkString [%p]is[%s]"), pBrowse_Marks, browseMarks.c_str()); #endif TiXmlElement* btMarks = static_cast<TiXmlElement*>(node->InsertEndChild(TiXmlElement("BrowseMarks"))); btMarks->SetAttribute("positions", cbU2C(browseMarks)); }while(0); ////else{ //// #if defined(LOGGING) //// LOGIT( _T("Browse_Marks failed find for[%s]"), f->file.GetFullPath().c_str() ); //// #endif ////} // Save the Book_Marks it = m_EdBook_MarksArchive.find(f->file.GetFullPath()); if (it != m_EdBook_MarksArchive.end() ) do { BrowseMarks* pBook_Marks = it->second; if (not pBook_Marks) break; wxString bookMarks = pBook_Marks->GetStringOfBrowse_Marks(); #if defined(LOGGING) ////LOGIT( _T("Layout writing BOOKMarkString [%p]is[%s]"), pBook_Marks, bookMarks.c_str()); #endif TiXmlElement* btMarks = static_cast<TiXmlElement*>(node->InsertEndChild(TiXmlElement("Book_Marks"))); btMarks->SetAttribute("positions", cbU2C(bookMarks)); }while(0); ////else{ //// #if defined(LOGGING) //// LOGIT( _T("Book_Marks failed find for[%s]"), f->file.GetFullPath().c_str() ); //// #endif ////} } }//for const wxArrayString& en = m_pProject->ExpandedNodes(); for (unsigned int i = 0; i < en.GetCount(); ++i) { if (!en[i].IsEmpty()) { TiXmlElement* node = static_cast<TiXmlElement*>(rootnode->InsertEndChild(TiXmlElement("Expand"))); node->SetAttribute("folder", cbU2C(en[i])); } } return cbSaveTinyXMLDocument(&doc, filename); }
TiXmlElement* wxsVersionConverter::ConvertFromOldConfig(TiXmlElement* ConfigNode,TiXmlDocument* Doc,wxsProject* Project) const { if ( cbMessageBox(_("This project uses old wxSmith configuration format\n" "Would you like me to convert to new one?\n"), _("wxSmith: Converting from old format"), wxYES_NO) != wxID_YES ) return 0; TiXmlElement* NewConfig = Doc->InsertEndChild(TiXmlElement("wxSmith"))->ToElement(); TiXmlElement* Resources = NewConfig->InsertEndChild(TiXmlElement("resources"))->ToElement(); NewConfig->SetAttribute("version",CurrentVersionStr); for ( TiXmlElement* Node = ConfigNode->FirstChildElement(); Node; Node = Node->NextSiblingElement() ) { wxString NodeName = cbC2U(Node->Value()); if ( NodeName == _T("configuration") ) { const char* AppSrc = Node->Attribute("app_src_file"); const char* Main = Node->Attribute("main_resource"); const char* InitAll = Node->Attribute("init_all_handlers"); if ( AppSrc ) { TiXmlElement* GUINode = NewConfig->InsertEndChild(TiXmlElement("gui"))->ToElement(); GUINode->SetAttribute("name","wxWidgets"); GUINode->SetAttribute("src",AppSrc); GUINode->SetAttribute("main",Main?Main:""); GUINode->SetAttribute("init_handlers",InitAll?InitAll:"necessary"); GUINode->SetAttribute("language","CPP"); } } else { if ( NodeName == _T("dialog") || NodeName == _T("frame") || NodeName == _T("panel") ) { const char* Wxs = Node->Attribute("wxs_file"); const char* Class = Node->Attribute("class"); const char* Src = Node->Attribute("src_file"); const char* Hdr = Node->Attribute("header_file"); const char* Xrc = Node->Attribute("xrc_file"); const char* Mode = Node->Attribute("edit_mode"); if ( Wxs && Class && Src && Hdr && Mode ) { if ( cbC2U(Mode) == _T("Source") ) Xrc = 0; TiXmlElement* Res = Resources->InsertEndChild(TiXmlElement( NodeName == _T("dialog") ? "wxDialog" : NodeName == _T("frame") ? "wxFrame" : "wxPanel" ))->ToElement(); Res->SetAttribute("wxs",cbU2C(_T("wxsmith/")+cbC2U(Wxs))); Res->SetAttribute("src",Src); Res->SetAttribute("hdr",Hdr); if ( Xrc ) Res->SetAttribute("xrc",Xrc); Res->SetAttribute("name",Class); Res->SetAttribute("language","CPP"); ConvertOldWxsFile(Project->GetProjectPath()+_T("wxsmith/")+cbC2U(Wxs),Xrc!=0); AdoptOldSourceFile(Project->GetProjectPath()+cbC2U(Src),cbC2U(Class)); } } } } return NewConfig; }
size_t wxsItemResDataObject::GetDataSize(cb_unused const wxDataFormat& format) const { wxString XmlData = GetXmlData(); const wxWX2MBbuf str = cbU2C(XmlData); return strlen(str)+1; }
/*! \brief Load / save project hook. When CodeBlocks loads and saves a file, we hook into the process here and load or save our parameters. \param project CodeBlocks project instance. \param elem XML element of root node. \param loading Flag set whether load / save, true = loading, false = saving. */ void OpenOCDDriver::OnProjectLoadingHook(cbProject* project, TiXmlElement* elem, bool loading) { if (loading) { TiXmlElement* node = elem->FirstChildElement("gdbremote"); if (node) { TiXmlElement *device = node->FirstChildElement("hardware"); m_Interface = cbC2U(device->Attribute("interface")); m_Option = cbC2U(device->Attribute("option")); m_JTAGSpeed = cbC2U(device->Attribute("jtagspeed")); m_GDBPort = atoi(device->Attribute("gdbport")); m_ConfigFile = cbC2U(device->Attribute("configfile")); wxString strAuto = cbC2U(device->Attribute("auto")); m_TelnetPort = atoi(device->Attribute("telnetport")); m_TCLPort = atoi(device->Attribute("tclport")); if (strAuto == _T("true")) m_Auto = true; else m_Auto = false; // Now get advanced options. TiXmlElement *advopts = node->FirstChildElement("advintopts"); if (advopts) { TiXmlAttribute *attr = advopts->FirstAttribute(); while (attr) { // Populate hash map with attributes. wxString key = cbC2U(attr->Name()); wxString value = cbC2U(attr->Value()); m_AdvOpts[key] = value; attr = attr->Next(); } } } else { m_Interface = _T("parport"); m_Option = _T("wiggler"); m_JTAGSpeed = _T("0"); m_ConfigFile = _T("openocd.cfg"); m_Auto = true; m_TelnetPort = 4444; m_GDBPort = 2000; m_TCLPort = 6666; m_AdvOpts.clear(); } } else { TiXmlElement* node = elem->FirstChildElement("gdbremote"); if (!node) node = elem->InsertEndChild(TiXmlElement("gdbremote"))->ToElement(); node->Clear(); TiXmlElement *device = node->InsertEndChild(TiXmlElement("hardware"))->ToElement(); device->SetAttribute("interface", cbU2C(m_Interface)); device->SetAttribute("option", cbU2C(m_Option)); device->SetAttribute("jtagspeed", cbU2C(m_JTAGSpeed)); device->SetAttribute("gdbport", m_GDBPort); device->SetAttribute("configfile", cbU2C(m_ConfigFile)); if (m_Auto == true) device->SetAttribute("auto", "true"); else device->SetAttribute("auto", "false"); device->SetAttribute("telnetport", m_TelnetPort); device->SetAttribute("tclport", m_TCLPort); // Write advanced options TiXmlElement *advopts = node->InsertEndChild(TiXmlElement("advintopts"))->ToElement(); AdvOptsHash::iterator it; for( it = m_AdvOpts.begin(); it != m_AdvOpts.end(); ++it ) { wxString key = it->first, value = it->second; // do something useful with key and value advopts->SetAttribute(cbU2C(key), cbU2C(value)); } } }
void PluginManager::ReadExtraFilesFromManifestFile(const wxString& pluginFilename, wxArrayString& extraFiles) { extraFiles.Clear(); // find and load plugin's resource file // (pluginFilename contains no path info) wxFileName fname(pluginFilename); fname.SetExt(_T("zip")); wxString actual = fname.GetFullName(); // remove 'lib' prefix from plugin name (if any) if (!platform::windows && actual.StartsWith(_T("lib"))) actual.Remove(0, 3); actual = ConfigManager::LocateDataFile(actual, sdPluginsUser | sdDataUser | sdPluginsGlobal | sdDataGlobal); if (actual.IsEmpty()) { Manager::Get()->GetLogManager()->LogError(_T("Plugin resource not found: ") + fname.GetFullName()); return; // not found } // load XML from ZIP wxString contents; wxFileSystem* fs = new wxFileSystem; wxFSFile* f = fs->OpenFile(actual + _T("#zip:manifest.xml")); if (f) { wxInputStream* is = f->GetStream(); char tmp[1024] = {}; while (!is->Eof() && is->CanRead()) { memset(tmp, 0, sizeof(tmp)); is->Read(tmp, sizeof(tmp) - 1); contents << cbC2U((const char*)tmp); } delete f; } else { Manager::Get()->GetLogManager()->LogError(_T("No plugin manifest file in resource: ") + actual); delete fs; return; } delete fs; // actually load XML document TiXmlDocument doc; if (!doc.Parse(cbU2C(contents))) return; TiXmlElement* root = doc.FirstChildElement("CodeBlocks_plugin_manifest_file"); if (!root) return; TiXmlElement* extra = root->FirstChildElement("Extra"); while (extra) { const char* file = extra->Attribute("file"); if (file && *file) { extraFiles.Add(cbC2U(file)); } extra = extra->NextSiblingElement("Extra"); } }
bool PluginManager::ReadManifestFile(const wxString& pluginFilename, const wxString& pluginName, PluginInfo* infoOut) { if (!m_pCurrentlyLoadingManifestDoc) { // find and load plugin's resource file // (pluginFilename contains no path info) wxFileName fname(pluginFilename); fname.SetExt(_T("zip")); wxString actual = fname.GetFullName(); // remove 'lib' prefix from plugin name (if any) if (!platform::windows && actual.StartsWith(_T("lib"))) actual.Remove(0, 3); actual = ConfigManager::LocateDataFile(actual, sdPluginsUser | sdDataUser | sdPluginsGlobal | sdDataGlobal); if (actual.IsEmpty()) { Manager::Get()->GetLogManager()->LogError(_T("Plugin resource not found: ") + fname.GetFullName()); return false; // not found } // load XML from ZIP wxString contents; wxFileSystem* fs = new wxFileSystem; wxFSFile* f = fs->OpenFile(actual + _T("#zip:manifest.xml")); if (f) { wxInputStream* is = f->GetStream(); char tmp[1024] = {}; while (!is->Eof() && is->CanRead()) { memset(tmp, 0, sizeof(tmp)); is->Read(tmp, sizeof(tmp) - 1); contents << cbC2U((const char*)tmp); } delete f; } else { Manager::Get()->GetLogManager()->LogError(_T("No plugin manifest file in resource: ") + actual); delete fs; return false; } delete fs; // actually load XML document m_pCurrentlyLoadingManifestDoc = new TiXmlDocument; if (!m_pCurrentlyLoadingManifestDoc->Parse(cbU2C(contents))) { Manager::Get()->GetLogManager()->LogError(_T("Plugin manifest could not be parsed: ") + actual); return false; } } TiXmlElement* root = m_pCurrentlyLoadingManifestDoc->FirstChildElement("CodeBlocks_plugin_manifest_file"); if (!root) { Manager::Get()->GetLogManager()->LogError(_T("Plugin resource file not valid (no root element found) for: ") + pluginFilename); return false; } TiXmlElement* version = root->FirstChildElement("SdkVersion"); if (!version) { Manager::Get()->GetLogManager()->LogError(_T("Plugin resource file not valid (no SdkVersion element found) for: ") + pluginFilename); return false; } // check version // int major; // int minor; // int release; // if (version->QueryIntAttribute("major", &major) != TIXML_SUCCESS) // major = 0; // if (version->QueryIntAttribute("minor", &minor) != TIXML_SUCCESS) // minor = 0; // if (version->QueryIntAttribute("release", &release) != TIXML_SUCCESS) // release = 0; // // if (major != PLUGIN_SDK_VERSION_MAJOR || // minor != PLUGIN_SDK_VERSION_MINOR || // release != PLUGIN_SDK_VERSION_RELEASE) // { // // wrong version: in this case, inform the user... // wxString fmt; // fmt.Printf(_("SDK version mismatch for %s (%d.%d.%d). Expecting %d.%d.%d"), // pluginName.c_str(), // major, // minor, // release, // PLUGIN_SDK_VERSION_MAJOR, // PLUGIN_SDK_VERSION_MINOR, // PLUGIN_SDK_VERSION_RELEASE); // Manager::Get()->GetLogManager()->LogError(fmt); // return false; // } // if no plugin name specified, we 're done here (successfully) if (pluginName.IsEmpty() || !infoOut) return true; TiXmlElement* plugin = root->FirstChildElement("Plugin"); while (plugin) { const char* name = plugin->Attribute("name"); if (name && cbC2U(name) == pluginName) { infoOut->name = pluginName; TiXmlElement* value = plugin->FirstChildElement("Value"); while (value) { if (value->Attribute("title")) infoOut->title = cbC2U(value->Attribute("title")); if (value->Attribute("version")) infoOut->version = cbC2U(value->Attribute("version")); if (value->Attribute("description")) infoOut->description = cbC2U(value->Attribute("description")); if (value->Attribute("author")) infoOut->author = cbC2U(value->Attribute("author")); if (value->Attribute("authorEmail")) infoOut->authorEmail = cbC2U(value->Attribute("authorEmail")); if (value->Attribute("authorWebsite")) infoOut->authorWebsite = cbC2U(value->Attribute("authorWebsite")); if (value->Attribute("thanksTo")) infoOut->thanksTo = cbC2U(value->Attribute("thanksTo")); if (value->Attribute("license")) infoOut->license = cbC2U(value->Attribute("license")); value = value->NextSiblingElement("Value"); } break; } plugin = plugin->NextSiblingElement("Plugin"); } return true; }
bool ProjectLayoutLoader::Save(const wxString& filename) { const char* ROOT_TAG = "CodeBlocks_layout_file"; TiXmlDocument doc; doc.SetCondenseWhiteSpace(false); doc.InsertEndChild(TiXmlDeclaration("1.0", "UTF-8", "yes")); TiXmlElement* rootnode = static_cast<TiXmlElement*>(doc.InsertEndChild(TiXmlElement(ROOT_TAG))); if (!rootnode) return false; rootnode->InsertEndChild(TiXmlElement("FileVersion")); rootnode->FirstChildElement("FileVersion")->SetAttribute("major", PROJECT_LAYOUT_FILE_VERSION_MAJOR); rootnode->FirstChildElement("FileVersion")->SetAttribute("minor", PROJECT_LAYOUT_FILE_VERSION_MINOR); TiXmlElement* tgtidx = static_cast<TiXmlElement*>(rootnode->InsertEndChild(TiXmlElement("ActiveTarget"))); tgtidx->SetAttribute("name", cbU2C(m_pProject->GetActiveBuildTarget())); ProjectFile* active = nullptr; cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor(); if (ed) active = ed->GetProjectFile(); for (FilesList::iterator it = m_pProject->GetFilesList().begin(); it != m_pProject->GetFilesList().end(); ++it) { ProjectFile* f = *it; if (f->editorOpen || f->editorPos || f->editorPos_2 || f->editorTopLine || f->editorTopLine_2 || f->editorTabPos) { TiXmlElement* node = static_cast<TiXmlElement*>(rootnode->InsertEndChild(TiXmlElement("File"))); node->SetAttribute("name", cbU2C(f->relativeFilename)); node->SetAttribute("open", f->editorOpen); node->SetAttribute("top", (f == active)); node->SetAttribute("tabpos", f->editorTabPos); node->SetAttribute("split", f->editorSplit); node->SetAttribute("active", f->editorSplitActive); node->SetAttribute("splitpos", f->editorSplitPos); node->SetAttribute("zoom_1", f->editorZoom); node->SetAttribute("zoom_2", f->editorZoom_2); TiXmlElement* cursor = static_cast<TiXmlElement*>(node->InsertEndChild(TiXmlElement("Cursor"))); TiXmlElement* cursor_1 = static_cast<TiXmlElement*>(cursor->InsertEndChild(TiXmlElement("Cursor1"))); cursor_1->SetAttribute("position", f->editorPos); cursor_1->SetAttribute("topLine", f->editorTopLine); if(f->editorSplit != cbEditor::stNoSplit) { TiXmlElement* cursor_2 = static_cast<TiXmlElement*>(cursor->InsertEndChild(TiXmlElement("Cursor2"))); cursor_2->SetAttribute("position", f->editorPos_2); cursor_2->SetAttribute("topLine", f->editorTopLine_2); } if (f->editorFoldLinesArray.GetCount() > 0) { TiXmlElement* folding = static_cast<TiXmlElement*>(node->InsertEndChild(TiXmlElement("Folding"))); for (unsigned int i = 0; i < f->editorFoldLinesArray.GetCount(); i++) { TiXmlElement* line = static_cast<TiXmlElement*>(folding->InsertEndChild(TiXmlElement("Collapse"))); line->SetAttribute("line", f->editorFoldLinesArray[i]); } } } } const wxArrayString& en = m_pProject->ExpandedNodes(); for (unsigned int i = 0; i < en.GetCount(); ++i) { if (!en[i].IsEmpty()) { TiXmlElement* node = static_cast<TiXmlElement*>(rootnode->InsertEndChild(TiXmlElement("Expand"))); node->SetAttribute("folder", cbU2C(en[i])); } } if (Manager::Get()->GetConfigManager(_T("app"))->ReadBool(_T("/environment/enable_editor_layout"), false)) { TiXmlElement *el = static_cast<TiXmlElement*>( rootnode->InsertEndChild( TiXmlElement("EditorTabsLayout") ) ); el->SetAttribute("layout", cbU2C( Manager::Get()->GetEditorManager()->GetNotebook()->SavePerspective(m_pProject->GetTitle()) )); } // else ?! return cbSaveTinyXMLDocument(&doc, filename); }
bool wxsSizerFlagsProperty::XmlWrite(wxsPropertyContainer* Object,TiXmlElement* Element) { Element->InsertEndChild(TiXmlText(cbU2C(GetString(FLAGS)))); return true; }