コード例 #1
0
ファイル: xmlutils.cpp プロジェクト: 05storm26/codelite
bool XmlUtils::StaticWriteObject(wxXmlNode* root, const wxString& name, SerializedObject* obj)
{
	if(!root)
		return false;

	Archive arch;
	wxXmlNode *child = XmlUtils::FindNodeByName(root, wxT("ArchiveObject"), name);
	if (child) {
		wxXmlNode *n = root;
		n->RemoveChild(child);
		delete child;
	}

	//create new xml node for this object
	child = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("ArchiveObject"));
	root->AddChild(child);
	
	wxString objectVersion = obj->GetVersion();
	if(objectVersion.IsEmpty() == false)
		child->AddProperty(wxT("Version"), objectVersion);
		
	child->AddProperty(wxT("Name"), name);

	arch.SetXmlNode(child);
	//serialize the object into the archive
	obj->Serialize(arch);
	return true;
}
コード例 #2
0
ファイル: sessionmanager.cpp プロジェクト: stahta01/codelite
bool SessionManager::Save(const wxString& name,
                          SessionEntry& session,
                          const wxString& suffix /*=wxT("")*/,
                          const wxChar* Tag /*=sessionTag*/)
{
    if(!m_doc.GetRoot()) {
        return false;
    }

    if(name.empty()) return false;

    wxXmlNode* child = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, Tag);
    child->AddProperty(wxT("Name"), name);

    Archive arch;
    arch.SetXmlNode(child);
    session.Serialize(arch);

    wxXmlDocument doc;
    doc.SetRoot(child);

    // If we're saving a tabgroup, suffix will be ".tabgroup", not the default ".session"
    const wxFileName& sessionFileName = GetSessionFileName(name, suffix);
    return doc.Save(sessionFileName.GetFullPath());
}
コード例 #3
0
ファイル: sessionmanager.cpp プロジェクト: stahta01/codelite
bool SessionManager::GetSession(const wxString& workspaceFile,
                                SessionEntry& session,
                                const wxString& suffix,
                                const wxChar* Tag)
{
    if(!m_doc.GetRoot()) {
        return false;
    }

    wxFileName sessionFileName = GetSessionFileName(workspaceFile, suffix);
    wxXmlDocument doc;
    
    if(sessionFileName.FileExists()) {
        if(!doc.Load(sessionFileName.GetFullPath()) || !doc.IsOk()) return false;
    } else {
        doc.SetRoot(new wxXmlNode(NULL, wxXML_ELEMENT_NODE, Tag));
    }

    wxXmlNode* const node = doc.GetRoot();
    if(!node || node->GetName() != Tag) return false;

    Archive arch;
    arch.SetXmlNode(node);
    session.DeSerialize(arch);

    return true;
}
コード例 #4
0
ファイル: project.cpp プロジェクト: Hmaal/codelite
bool Project::SetUserData(const wxString& name, SerializedObject* obj)
{
    if(!m_doc.IsOk()) {
        return false;
    }

    Archive arch;

    // locate the 'UserData' node
    wxXmlNode *userData = XmlUtils::FindFirstByTagName(m_doc.GetRoot(), wxT("UserData"));
    if( !userData ) {
        userData = new wxXmlNode(m_doc.GetRoot(), wxXML_ELEMENT_NODE, wxT("UserData"));
    }

    // try to find a previous data stored under the same name, if we succeed - remove it
    wxXmlNode *dataNode = XmlUtils::FindNodeByName(userData, wxT("Data"), name);
    if(dataNode) {
        // remove old node
        userData->RemoveChild(dataNode);
        delete dataNode;
    }

    // create a new node and set the userData node as the parent
    dataNode = new wxXmlNode(userData, wxXML_ELEMENT_NODE, wxT("Data"));
    dataNode->AddProperty(wxT("Name"), name);

    // serialize the data
    arch.SetXmlNode(dataNode);
    obj->Serialize(arch);
    return SaveXmlFile();
}
コード例 #5
0
bool EditorConfig::ReadObject(const wxString &name, SerializedObject *obj)
{
	//find the object node in the xml file
	wxXmlNode *node = XmlUtils::FindNodeByName(m_doc->GetRoot(), wxT("ArchiveObject"), name);
	if(node){
		Archive arch;
		arch.SetXmlNode(node);
		obj->DeSerialize(arch);
		return true;
	}
	return false;
}
コード例 #6
0
ファイル: project.cpp プロジェクト: Hmaal/codelite
bool Project::GetUserData(const wxString& name, SerializedObject* obj)
{
    if(!m_doc.IsOk()) {
        return false;
    }

    Archive arch;
    wxXmlNode *userData = XmlUtils::FindFirstByTagName(m_doc.GetRoot(), wxT("UserData"));
    if(userData) {
        wxXmlNode *dataNode = XmlUtils::FindNodeByName(userData, wxT("Data"), name);
        if(dataNode) {
            arch.SetXmlNode(dataNode);
            obj->DeSerialize(arch);
            return true;
        }
    }
    return false;
}
コード例 #7
0
bool EditorConfig::WriteObject(const wxString &name, SerializedObject *obj)
{
	Archive arch;
	
	wxXmlNode *child = XmlUtils::FindNodeByName(m_doc->GetRoot(), wxT("ArchiveObject"), name);
	if(child){
		wxXmlNode *n = m_doc->GetRoot();
		n->RemoveChild(child);
		delete child;
	} // if(child)

	//create new xml node for this object
	child = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("ArchiveObject"));
	m_doc->GetRoot()->AddChild(child);
	child->AddProperty(wxT("Name"), name);

	arch.SetXmlNode(child);
	//serialize the object into the archive
	obj->Serialize(arch);
	//save the archive
	return m_doc->Save(m_fileName.GetFullPath());
}
コード例 #8
0
ファイル: xmlutils.cpp プロジェクト: 05storm26/codelite
bool XmlUtils::StaticReadObject(wxXmlNode* root, const wxString& name, SerializedObject* obj)
{
	//find the object node in the xml file
	
	wxXmlNode *node = XmlUtils::FindNodeByName(root, wxT("ArchiveObject"), name);
	if (node) {
		
		// Check to see if we need a version check
		wxString objectVersion = obj->GetVersion();
		if(objectVersion.IsEmpty() == false) {
			if(node->GetPropVal(wxT("Version"), wxT("")) != objectVersion) {
				return false;
			}
		}
		
		Archive arch;
		arch.SetXmlNode(node);
		obj->DeSerialize(arch);
		return true;
	}
	return false;
}