~ubuntu-branches/ubuntu/maverick/codelite/maverick

« back to all changes in this revision

Viewing changes to Plugin/project.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-04-30 02:46:27 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090430024627-7xp71gerfvw00xtt
Tags: 1.0.2822+dfsg-0ubuntu1
* New upstream release (LP: #369466)
* debian/copyright:
  + Added Files section for sdk/wxpropgrid
  + Made license text RFC compliant (add . for empty lines)
* debian/control:
  + Bump Standards-Version to 3.8.1
* debian/patches/02_fix-desktop.patch,
  + Refreshed to patch cleanly
* debian/*.install,
  debian/codelite.dirs,
  debian/codelite.links,
  debian/patches/03_fix-sh.patch,
  debian/patches/04_change-installpath.patch,
  + Updated for new upstream directory structure
  + Patches dropped, no longer needed.
* debian/patches/03_cstdio-include.patch,
  + Include cstdio for C++ and stdio.h for C, since it seems to be missing
* debian/codelite.menu,
  debian/*.1,
  debian/codelite.manpages:
  + Updated to reflect change in command names
    - CodeLite    => codelite
    - le_exec     => codelite_exec
    - le_dos2unix => codelite_fix_files
    - le_killproc => codelite_kill_children
* debian/README.source,
  debian/rules,
  debian/copyright:
  + Remove sdk/curl from the list of excluded files, since it doesn't exist
    any more

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//////////////////////////////////////////////////////////////////////////////
2
 
//////////////////////////////////////////////////////////////////////////////
3
 
//
4
 
// copyright            : (C) 2008 by Eran Ifrah
5
 
// file name            : project.cpp
6
 
//
7
 
// -------------------------------------------------------------------------
8
 
// A
9
 
//              _____           _      _     _ _
10
 
//             /  __ \         | |    | |   (_) |
11
 
//             | /  \/ ___   __| | ___| |    _| |_ ___
12
 
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
13
 
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
14
 
//              \____/\___/ \__,_|\___\_____/_|\__\___|
15
 
//
16
 
//                                                  F i l e
17
 
//
18
 
//    This program is free software; you can redistribute it and/or modify
19
 
//    it under the terms of the GNU General Public License as published by
20
 
//    the Free Software Foundation; either version 2 of the License, or
21
 
//    (at your option) any later version.
22
 
//
23
 
//////////////////////////////////////////////////////////////////////////////
24
 
//////////////////////////////////////////////////////////////////////////////
25
 
#include "project.h"
26
 
#include "xmlutils.h"
27
 
#include <wx/tokenzr.h>
28
 
#include "wx/arrstr.h"
29
 
#include "dirsaver.h"
30
 
 
31
 
const wxString Project::STATIC_LIBRARY = wxT("Static Library");
32
 
const wxString Project::DYNAMIC_LIBRARY = wxT("Dynamic Library");
33
 
const wxString Project::EXECUTABLE = wxT("Executable");
34
 
 
35
 
Project::Project()
36
 
                : m_tranActive(false)
37
 
                , m_isModified(false)
38
 
{
39
 
}
40
 
 
41
 
Project::~Project()
42
 
{
43
 
        m_vdCache.clear();
44
 
}
45
 
 
46
 
bool Project::Create(const wxString &name, const wxString &description, const wxString &path, const wxString &projType)
47
 
{
48
 
        m_vdCache.clear();
49
 
 
50
 
        m_fileName = path + wxFileName::GetPathSeparator() + name + wxT(".project");
51
 
        m_fileName.MakeAbsolute();
52
 
 
53
 
        wxXmlNode *root = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("CodeLite_Project"));
54
 
        m_doc.SetRoot(root);
55
 
        m_doc.GetRoot()->AddProperty(wxT("Name"), name);
56
 
 
57
 
        wxXmlNode *descNode = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Description"));
58
 
        XmlUtils::SetNodeContent(descNode, description);
59
 
        m_doc.GetRoot()->AddChild(descNode);
60
 
 
61
 
        // Create the default virtual directories
62
 
        wxXmlNode *srcNode = NULL, *headNode = NULL;
63
 
 
64
 
        srcNode = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("VirtualDirectory"));
65
 
        srcNode->AddProperty(wxT("Name"), wxT("src"));
66
 
        m_doc.GetRoot()->AddChild(srcNode);
67
 
 
68
 
        headNode = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("VirtualDirectory"));
69
 
        headNode->AddProperty(wxT("Name"), wxT("include"));
70
 
        m_doc.GetRoot()->AddChild(headNode);
71
 
 
72
 
        //creae dependencies node
73
 
        wxXmlNode *depNode = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Dependencies"));
74
 
        root->AddChild(depNode);
75
 
 
76
 
        m_doc.Save(m_fileName.GetFullPath());
77
 
        //create build settings
78
 
        SetSettings(new ProjectSettings(NULL));
79
 
        ProjectSettingsPtr settings = GetSettings();
80
 
        settings->SetProjectType(projType);
81
 
        SetSettings(settings);
82
 
        SetModified(true);
83
 
        return true;
84
 
}
85
 
 
86
 
bool Project::Load(const wxString &path)
87
 
{
88
 
        if ( !m_doc.Load(path) ) {
89
 
                return false;
90
 
        }
91
 
 
92
 
        m_vdCache.clear();
93
 
 
94
 
        m_fileName = path;
95
 
        m_fileName.MakeAbsolute();
 
1
//////////////////////////////////////////////////////////////////////////////
 
2
//////////////////////////////////////////////////////////////////////////////
 
3
//
 
4
// copyright            : (C) 2008 by Eran Ifrah
 
5
// file name            : project.cpp
 
6
//
 
7
// -------------------------------------------------------------------------
 
8
// A
 
9
//              _____           _      _     _ _
 
10
//             /  __ \         | |    | |   (_) |
 
11
//             | /  \/ ___   __| | ___| |    _| |_ ___
 
12
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
 
13
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
 
14
//              \____/\___/ \__,_|\___\_____/_|\__\___|
 
15
//
 
16
//                                                  F i l e
 
17
//
 
18
//    This program is free software; you can redistribute it and/or modify
 
19
//    it under the terms of the GNU General Public License as published by
 
20
//    the Free Software Foundation; either version 2 of the License, or
 
21
//    (at your option) any later version.
 
22
//
 
23
//////////////////////////////////////////////////////////////////////////////
 
24
//////////////////////////////////////////////////////////////////////////////
 
25
#include "project.h"
 
26
#include "xmlutils.h"
 
27
#include <wx/tokenzr.h>
 
28
#include "wx/arrstr.h"
 
29
#include "dirsaver.h"
 
30
 
 
31
const wxString Project::STATIC_LIBRARY = wxT("Static Library");
 
32
const wxString Project::DYNAMIC_LIBRARY = wxT("Dynamic Library");
 
33
const wxString Project::EXECUTABLE = wxT("Executable");
 
34
 
 
35
Project::Project()
 
36
                : m_tranActive(false)
 
37
                , m_isModified(false)
 
38
{
 
39
}
 
40
 
 
41
Project::~Project()
 
42
{
 
43
        m_vdCache.clear();
 
44
}
 
45
 
 
46
bool Project::Create(const wxString &name, const wxString &description, const wxString &path, const wxString &projType)
 
47
{
 
48
        m_vdCache.clear();
 
49
 
 
50
        m_fileName = path + wxFileName::GetPathSeparator() + name + wxT(".project");
 
51
        m_fileName.MakeAbsolute();
 
52
 
 
53
        wxXmlNode *root = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("CodeLite_Project"));
 
54
        m_doc.SetRoot(root);
 
55
        m_doc.GetRoot()->AddProperty(wxT("Name"), name);
 
56
 
 
57
        wxXmlNode *descNode = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Description"));
 
58
        XmlUtils::SetNodeContent(descNode, description);
 
59
        m_doc.GetRoot()->AddChild(descNode);
 
60
 
 
61
        // Create the default virtual directories
 
62
        wxXmlNode *srcNode = NULL, *headNode = NULL;
 
63
 
 
64
        srcNode = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("VirtualDirectory"));
 
65
        srcNode->AddProperty(wxT("Name"), wxT("src"));
 
66
        m_doc.GetRoot()->AddChild(srcNode);
 
67
 
 
68
        headNode = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("VirtualDirectory"));
 
69
        headNode->AddProperty(wxT("Name"), wxT("include"));
 
70
        m_doc.GetRoot()->AddChild(headNode);
 
71
 
 
72
        //creae dependencies node
 
73
        wxXmlNode *depNode = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Dependencies"));
 
74
        root->AddChild(depNode);
 
75
 
 
76
        m_doc.Save(m_fileName.GetFullPath());
 
77
        //create build settings
 
78
        SetSettings(new ProjectSettings(NULL));
 
79
        ProjectSettingsPtr settings = GetSettings();
 
80
        settings->SetProjectType(projType);
 
81
        SetSettings(settings);
 
82
        SetModified(true);
 
83
        return true;
 
84
}
 
85
 
 
86
bool Project::Load(const wxString &path)
 
87
{
 
88
        if ( !m_doc.Load(path) ) {
 
89
                return false;
 
90
        }
 
91
 
 
92
        m_vdCache.clear();
 
93
 
 
94
        m_fileName = path;
 
95
        m_fileName.MakeAbsolute();
96
96
        SetModified(true);
97
97
        return true;
98
98
}
99
99
 
100
100
wxXmlNode *Project::GetVirtualDir(const wxString &vdFullPath)
101
101
{
102
 
        wxStringTokenizer tkz(vdFullPath, wxT(":"));
103
 
 
 
102
        wxStringTokenizer tkz(vdFullPath, wxT(":"));
 
103
 
104
104
        // test the cache
105
 
        std::map<wxString, wxXmlNode*>::iterator iter = m_vdCache.find(vdFullPath);
106
 
        if(iter != m_vdCache.end()){
107
 
                return iter->second;
108
 
        }
 
105
        std::map<wxString, wxXmlNode*>::iterator iter = m_vdCache.find(vdFullPath);
 
106
        if(iter != m_vdCache.end()){
 
107
                return iter->second;
 
108
        }
109
109
 
110
110
        wxXmlNode *parent = m_doc.GetRoot();
111
111
        while ( tkz.HasMoreTokens() ) {
112
112
                parent = XmlUtils::FindNodeByName(parent, wxT("VirtualDirectory"), tkz.GetNextToken());
113
 
                if ( !parent ) {
 
113
                if ( !parent ) {
114
114
                        m_vdCache[vdFullPath] = NULL;
115
115
                        return NULL;
116
116
                }
117
 
        }
118
 
        // cache the result
 
117
        }
 
118
        // cache the result
119
119
        m_vdCache[vdFullPath] = parent;
120
120
        return parent;
121
121
}
157
157
        //if not in transaction save the changes
158
158
        if (!InTransaction()) {
159
159
                m_doc.Save(m_fileName.GetFullPath());
160
 
        }
161
 
 
162
 
        // cache the result
163
 
        m_vdCache[vdFullPath] = node;
 
160
        }
 
161
 
 
162
        // cache the result
 
163
        m_vdCache[vdFullPath] = node;
164
164
 
165
165
        return node;
166
166
}
230
230
                if ( parent ) {
231
231
                        parent->RemoveChild( vd );
232
232
                }
233
 
 
234
 
                // remove the entry from the cache
235
 
                std::map<wxString, wxXmlNode*>::iterator iter = m_vdCache.find(vdFullPath);
236
 
                if(iter != m_vdCache.end()){
237
 
                        m_vdCache.erase(iter);
238
 
                }
 
233
 
 
234
                // remove the entry from the cache
 
235
                std::map<wxString, wxXmlNode*>::iterator iter = m_vdCache.find(vdFullPath);
 
236
                if(iter != m_vdCache.end()){
 
237
                        m_vdCache.erase(iter);
 
238
                }
239
239
 
240
240
                delete vd;
241
241
                SetModified(true);
411
411
        m_doc.Save(m_fileName.GetFullPath());
412
412
}
413
413
 
 
414
void Project::SetGlobalSettings(BuildConfigCommonPtr globalSettings)
 
415
{
 
416
        wxXmlNode *settings = XmlUtils::FindFirstByTagName(m_doc.GetRoot(), wxT("Settings"));
 
417
        wxXmlNode *oldSettings = XmlUtils::FindFirstByTagName(settings, wxT("GlobalSettings"));
 
418
        if (oldSettings) {
 
419
                oldSettings->GetParent()->RemoveChild(oldSettings);
 
420
                delete oldSettings;
 
421
        }
 
422
        settings->AddChild(globalSettings->ToXml());
 
423
        m_doc.Save(m_fileName.GetFullPath());
 
424
}
 
425
 
414
426
wxArrayString Project::GetDependencies() const
415
427
{
416
428
        wxArrayString result;
478
490
        }
479
491
        XmlUtils::SetNodeContent(descNode, description);
480
492
 
481
 
        // Remove the 'Dependencies'
482
 
        wxXmlNode *deps = doc.GetRoot()->GetChildren();
483
 
        while(deps) {
484
 
                if(deps->GetName() == wxT("Dependencies")) {
485
 
                        doc.GetRoot()->RemoveChild(deps);
486
 
                        delete deps;
487
 
 
488
 
                        // restart the search from the begining
489
 
                        deps = doc.GetRoot()->GetChildren();
490
 
 
491
 
                } else {
492
 
                        // try next child
493
 
                        deps = deps->GetNext();
494
 
                }
495
 
        }
 
493
        // Remove the 'Dependencies'
 
494
        wxXmlNode *deps = doc.GetRoot()->GetChildren();
 
495
        while(deps) {
 
496
                if(deps->GetName() == wxT("Dependencies")) {
 
497
                        doc.GetRoot()->RemoveChild(deps);
 
498
                        delete deps;
 
499
 
 
500
                        // restart the search from the begining
 
501
                        deps = doc.GetRoot()->GetChildren();
 
502
 
 
503
                } else {
 
504
                        // try next child
 
505
                        deps = deps->GetNext();
 
506
                }
 
507
        }
496
508
 
497
509
//      wxXmlNode *deps = XmlUtils::FindFirstByTagName(doc.GetRoot(), wxT("Dependencies"));
498
510
//      if (deps) {
689
701
                                        result.Add(XmlUtils::ReadString(child, wxT("Name")));
690
702
                                }
691
703
                                child = child->GetNext();
692
 
                        }
 
704
                        }
693
705
                        return result;
694
706
                }
695
707
                node = node->GetNext();
696
708
        }
697
 
 
698
 
        // if we are here, it means no match for the given configuration
699
 
        // return the default dependencies
 
709
 
 
710
        // if we are here, it means no match for the given configuration
 
711
        // return the default dependencies
700
712
        return GetDependencies();
701
 
}
702
 
 
703
 
void Project::SetDependencies(wxArrayString& deps, const wxString& configuration)
704
 
{
705
 
        // first try to locate the old node
706
 
        wxXmlNode *node = m_doc.GetRoot()->GetChildren();
707
 
        while (node) {
708
 
                if ( node->GetName() == wxT("Dependencies") && node->GetPropVal(wxT("Name"), wxEmptyString) == configuration) {
709
 
                        // we have our match
710
 
                        node->GetParent()->RemoveChild(node);
711
 
                        delete node;
712
 
                        break;
713
 
                }
714
 
                node = node->GetNext();
715
 
        }
716
 
 
717
 
        // create new dependencies node
718
 
        node = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Dependencies"));
719
 
        node->AddProperty(wxT("Name"), configuration);
720
 
        m_doc.GetRoot()->AddChild(node);
721
 
 
722
 
        //create a node for each dependency in the array
723
 
        for (size_t i=0; i<deps.GetCount(); i++) {
724
 
                wxXmlNode *child = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Project"));
725
 
                child->AddProperty(wxT("Name"), deps.Item(i));
726
 
                node->AddChild(child);
727
 
        }
728
 
 
729
 
        //save changes
730
 
        m_doc.Save(m_fileName.GetFullPath());
731
 
        SetModified(true);
732
 
}
733
 
 
734
 
void Project::GetFiles(std::vector<wxFileName>& files, std::vector<wxFileName>& absFiles)
735
 
{
736
 
        DirSaver ds;
737
 
        ::wxSetWorkingDirectory(m_fileName.GetPath());
738
 
        GetFiles(m_doc.GetRoot(), files, absFiles);
739
 
}
740
 
 
741
 
void Project::GetFiles(wxXmlNode *parent, std::vector<wxFileName>& files, std::vector<wxFileName>& absFiles)
742
 
{
743
 
        if ( !parent ) {
744
 
                return;
745
 
        }
746
 
 
747
 
        wxXmlNode *child = parent->GetChildren();
748
 
        while (child) {
749
 
                if (child->GetName() == wxT("File")) {
750
 
                        wxString fileName = child->GetPropVal(wxT("Name"), wxEmptyString);
751
 
                        wxFileName tmp(fileName);
752
 
 
753
 
                        // append the file as it appears
754
 
                        files.push_back(tmp);
755
 
 
756
 
                        // convert to absolute path
757
 
                        tmp.MakeAbsolute();
758
 
                        absFiles.push_back(tmp);
759
 
 
760
 
                } else if (child->GetChildren()) {// we could also add a check for VirtualDirectory only
761
 
                        GetFiles(child, files, absFiles);
762
 
                }
763
 
                child = child->GetNext();
764
 
        }
765
 
}
766
 
 
767
 
bool Project::FastAddFile(const wxString& fileName, const wxString& virtualDir)
768
 
{
769
 
        wxXmlNode *vd = GetVirtualDir(virtualDir);
770
 
        if ( !vd ) {
771
 
                return false;
772
 
        }
773
 
 
774
 
        // Convert the file path to be relative to
775
 
        // the project path
776
 
        DirSaver ds;
777
 
 
778
 
        ::wxSetWorkingDirectory(m_fileName.GetPath());
779
 
        wxFileName tmp(fileName);
780
 
        tmp.MakeRelativeTo(m_fileName.GetPath());
781
 
 
782
 
        wxXmlNode *node = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("File"));
783
 
        node->AddProperty(wxT("Name"), tmp.GetFullPath());
784
 
        vd->AddChild(node);
785
 
        if (!InTransaction()) {
786
 
                m_doc.Save(m_fileName.GetFullPath());
787
 
        }
788
 
        SetModified(true);
789
 
        return true;
790
 
}
791
 
 
792
 
void Project::DoGetVirtualDirectories(wxXmlNode* parent, TreeNode<wxString, VisualWorkspaceNode>* tree)
793
 
{
794
 
        wxXmlNode *child = parent->GetChildren();
795
 
        while(child){
796
 
                if(child->GetName() == wxT("VirtualDirectory")){
797
 
 
798
 
                        VisualWorkspaceNode data;
799
 
                        data.name = XmlUtils::ReadString(child, wxT("Name"));
800
 
                        data.type = ProjectItem::TypeVirtualDirectory;
801
 
 
802
 
                        TreeNode<wxString, VisualWorkspaceNode>* node = new TreeNode<wxString, VisualWorkspaceNode>(data.name, data, tree);
803
 
                        tree->AddChild(node);
804
 
 
805
 
                        // test to see if it has children
806
 
                        if(child->GetChildren()){
807
 
                                DoGetVirtualDirectories(child, node);
808
 
                        }
809
 
                }
810
 
                child = child->GetNext();
811
 
        }
812
 
}
813
 
 
814
 
TreeNode<wxString, VisualWorkspaceNode>* Project::GetVirtualDirectories(TreeNode<wxString, VisualWorkspaceNode> *workspace)
815
 
{
816
 
        VisualWorkspaceNode data;
817
 
        data.name = GetName();
818
 
        data.type = ProjectItem::TypeProject;
819
 
 
820
 
        TreeNode<wxString, VisualWorkspaceNode> *parent = new TreeNode<wxString, VisualWorkspaceNode>(GetName(), data, workspace);
821
 
        DoGetVirtualDirectories(m_doc.GetRoot(), parent);
822
 
        workspace->AddChild(parent);
823
 
        return parent;
824
 
}
825
 
 
826
 
bool Project::GetUserData(const wxString& name, SerializedObject* obj)
827
 
{
828
 
        if(!m_doc.IsOk()){
829
 
                return false;
830
 
        }
831
 
 
832
 
        Archive arch;
833
 
        wxXmlNode *userData = XmlUtils::FindFirstByTagName(m_doc.GetRoot(), wxT("UserData"));
834
 
        if(userData){
835
 
                wxXmlNode *dataNode = XmlUtils::FindNodeByName(userData, wxT("Data"), name);
836
 
                if(dataNode){
837
 
                        arch.SetXmlNode(dataNode);
838
 
                        obj->DeSerialize(arch);
839
 
                        return true;
840
 
                }
841
 
        }
842
 
        return false;
843
 
}
844
 
 
845
 
bool Project::SetUserData(const wxString& name, SerializedObject* obj)
846
 
{
847
 
        if(!m_doc.IsOk()){
848
 
                return false;
849
 
        }
850
 
 
851
 
        Archive arch;
852
 
 
853
 
        // locate the 'UserData' node
854
 
        wxXmlNode *userData = XmlUtils::FindFirstByTagName(m_doc.GetRoot(), wxT("UserData"));
855
 
        if( !userData ) {
856
 
                userData = new wxXmlNode(m_doc.GetRoot(), wxXML_ELEMENT_NODE, wxT("UserData"));
857
 
        }
858
 
 
859
 
        // try to find a previous data stored under the same name, if we succeed - remove it
860
 
        wxXmlNode *dataNode = XmlUtils::FindNodeByName(userData, wxT("Data"), name);
861
 
        if(dataNode){
862
 
                // remove old node
863
 
                userData->RemoveChild(dataNode);
864
 
                delete dataNode;
865
 
        }
866
 
 
867
 
        // create a new node and set the userData node as the parent
868
 
        dataNode = new wxXmlNode(userData, wxXML_ELEMENT_NODE, wxT("Data"));
869
 
        dataNode->AddProperty(wxT("Name"), name);
870
 
 
871
 
        // serialize the data
872
 
        arch.SetXmlNode(dataNode);
873
 
        obj->Serialize(arch);
874
 
        return m_doc.Save(m_fileName.GetFullPath());
875
 
}
876
 
 
877
 
void Project::SetProjectInternalType(const wxString& internalType)
878
 
{
879
 
        XmlUtils::UpdateProperty(m_doc.GetRoot(), wxT("InternalType"), internalType);
880
 
}
881
 
 
882
 
wxString Project::GetProjectInternalType() const
883
 
{
884
 
        return m_doc.GetRoot()->GetPropVal(wxT("InternalType"), wxEmptyString);
885
 
}
 
713
}
 
714
 
 
715
void Project::SetDependencies(wxArrayString& deps, const wxString& configuration)
 
716
{
 
717
        // first try to locate the old node
 
718
        wxXmlNode *node = m_doc.GetRoot()->GetChildren();
 
719
        while (node) {
 
720
                if ( node->GetName() == wxT("Dependencies") && node->GetPropVal(wxT("Name"), wxEmptyString) == configuration) {
 
721
                        // we have our match
 
722
                        node->GetParent()->RemoveChild(node);
 
723
                        delete node;
 
724
                        break;
 
725
                }
 
726
                node = node->GetNext();
 
727
        }
 
728
 
 
729
        // create new dependencies node
 
730
        node = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Dependencies"));
 
731
        node->AddProperty(wxT("Name"), configuration);
 
732
        m_doc.GetRoot()->AddChild(node);
 
733
 
 
734
        //create a node for each dependency in the array
 
735
        for (size_t i=0; i<deps.GetCount(); i++) {
 
736
                wxXmlNode *child = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Project"));
 
737
                child->AddProperty(wxT("Name"), deps.Item(i));
 
738
                node->AddChild(child);
 
739
        }
 
740
 
 
741
        //save changes
 
742
        m_doc.Save(m_fileName.GetFullPath());
 
743
        SetModified(true);
 
744
}
 
745
 
 
746
void Project::GetFiles(std::vector<wxFileName>& files, std::vector<wxFileName>& absFiles)
 
747
{
 
748
        DirSaver ds;
 
749
        ::wxSetWorkingDirectory(m_fileName.GetPath());
 
750
        GetFiles(m_doc.GetRoot(), files, absFiles);
 
751
}
 
752
 
 
753
void Project::GetFiles(wxXmlNode *parent, std::vector<wxFileName>& files, std::vector<wxFileName>& absFiles)
 
754
{
 
755
        if ( !parent ) {
 
756
                return;
 
757
        }
 
758
 
 
759
        wxXmlNode *child = parent->GetChildren();
 
760
        while (child) {
 
761
                if (child->GetName() == wxT("File")) {
 
762
                        wxString fileName = child->GetPropVal(wxT("Name"), wxEmptyString);
 
763
                        wxFileName tmp(fileName);
 
764
 
 
765
                        // append the file as it appears
 
766
                        files.push_back(tmp);
 
767
 
 
768
                        // convert to absolute path
 
769
                        tmp.MakeAbsolute();
 
770
                        absFiles.push_back(tmp);
 
771
 
 
772
                } else if (child->GetChildren()) {// we could also add a check for VirtualDirectory only
 
773
                        GetFiles(child, files, absFiles);
 
774
                }
 
775
                child = child->GetNext();
 
776
        }
 
777
}
 
778
 
 
779
bool Project::FastAddFile(const wxString& fileName, const wxString& virtualDir)
 
780
{
 
781
        wxXmlNode *vd = GetVirtualDir(virtualDir);
 
782
        if ( !vd ) {
 
783
                return false;
 
784
        }
 
785
 
 
786
        // Convert the file path to be relative to
 
787
        // the project path
 
788
        DirSaver ds;
 
789
 
 
790
        ::wxSetWorkingDirectory(m_fileName.GetPath());
 
791
        wxFileName tmp(fileName);
 
792
        tmp.MakeRelativeTo(m_fileName.GetPath());
 
793
 
 
794
        wxXmlNode *node = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("File"));
 
795
        node->AddProperty(wxT("Name"), tmp.GetFullPath());
 
796
        vd->AddChild(node);
 
797
        if (!InTransaction()) {
 
798
                m_doc.Save(m_fileName.GetFullPath());
 
799
        }
 
800
        SetModified(true);
 
801
        return true;
 
802
}
 
803
 
 
804
void Project::DoGetVirtualDirectories(wxXmlNode* parent, TreeNode<wxString, VisualWorkspaceNode>* tree)
 
805
{
 
806
        wxXmlNode *child = parent->GetChildren();
 
807
        while(child){
 
808
                if(child->GetName() == wxT("VirtualDirectory")){
 
809
 
 
810
                        VisualWorkspaceNode data;
 
811
                        data.name = XmlUtils::ReadString(child, wxT("Name"));
 
812
                        data.type = ProjectItem::TypeVirtualDirectory;
 
813
 
 
814
                        TreeNode<wxString, VisualWorkspaceNode>* node = new TreeNode<wxString, VisualWorkspaceNode>(data.name, data, tree);
 
815
                        tree->AddChild(node);
 
816
 
 
817
                        // test to see if it has children
 
818
                        if(child->GetChildren()){
 
819
                                DoGetVirtualDirectories(child, node);
 
820
                        }
 
821
                }
 
822
                child = child->GetNext();
 
823
        }
 
824
}
 
825
 
 
826
TreeNode<wxString, VisualWorkspaceNode>* Project::GetVirtualDirectories(TreeNode<wxString, VisualWorkspaceNode> *workspace)
 
827
{
 
828
        VisualWorkspaceNode data;
 
829
        data.name = GetName();
 
830
        data.type = ProjectItem::TypeProject;
 
831
 
 
832
        TreeNode<wxString, VisualWorkspaceNode> *parent = new TreeNode<wxString, VisualWorkspaceNode>(GetName(), data, workspace);
 
833
        DoGetVirtualDirectories(m_doc.GetRoot(), parent);
 
834
        workspace->AddChild(parent);
 
835
        return parent;
 
836
}
 
837
 
 
838
bool Project::GetUserData(const wxString& name, SerializedObject* obj)
 
839
{
 
840
        if(!m_doc.IsOk()){
 
841
                return false;
 
842
        }
 
843
 
 
844
        Archive arch;
 
845
        wxXmlNode *userData = XmlUtils::FindFirstByTagName(m_doc.GetRoot(), wxT("UserData"));
 
846
        if(userData){
 
847
                wxXmlNode *dataNode = XmlUtils::FindNodeByName(userData, wxT("Data"), name);
 
848
                if(dataNode){
 
849
                        arch.SetXmlNode(dataNode);
 
850
                        obj->DeSerialize(arch);
 
851
                        return true;
 
852
                }
 
853
        }
 
854
        return false;
 
855
}
 
856
 
 
857
bool Project::SetUserData(const wxString& name, SerializedObject* obj)
 
858
{
 
859
        if(!m_doc.IsOk()){
 
860
                return false;
 
861
        }
 
862
 
 
863
        Archive arch;
 
864
 
 
865
        // locate the 'UserData' node
 
866
        wxXmlNode *userData = XmlUtils::FindFirstByTagName(m_doc.GetRoot(), wxT("UserData"));
 
867
        if( !userData ) {
 
868
                userData = new wxXmlNode(m_doc.GetRoot(), wxXML_ELEMENT_NODE, wxT("UserData"));
 
869
        }
 
870
 
 
871
        // try to find a previous data stored under the same name, if we succeed - remove it
 
872
        wxXmlNode *dataNode = XmlUtils::FindNodeByName(userData, wxT("Data"), name);
 
873
        if(dataNode){
 
874
                // remove old node
 
875
                userData->RemoveChild(dataNode);
 
876
                delete dataNode;
 
877
        }
 
878
 
 
879
        // create a new node and set the userData node as the parent
 
880
        dataNode = new wxXmlNode(userData, wxXML_ELEMENT_NODE, wxT("Data"));
 
881
        dataNode->AddProperty(wxT("Name"), name);
 
882
 
 
883
        // serialize the data
 
884
        arch.SetXmlNode(dataNode);
 
885
        obj->Serialize(arch);
 
886
        return m_doc.Save(m_fileName.GetFullPath());
 
887
}
 
888
 
 
889
void Project::SetProjectInternalType(const wxString& internalType)
 
890
{
 
891
        XmlUtils::UpdateProperty(m_doc.GetRoot(), wxT("InternalType"), internalType);
 
892
}
 
893
 
 
894
wxString Project::GetProjectInternalType() const
 
895
{
 
896
        return m_doc.GetRoot()->GetPropVal(wxT("InternalType"), wxEmptyString);
 
897
}