~ubuntu-branches/ubuntu/karmic/codelite/karmic

« back to all changes in this revision

Viewing changes to Plugin/project.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-08-15 17:42:43 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090815174243-nlb9ikgigbiybz12
Tags: 1.0.2893+dfsg-0ubuntu1
* debian/rules:
  + Tidy up get-orig-source rule
* debian/control:
  + Bump Standards-Version
  + Change Maintainer email address to @ubuntu.com
  + Drop cdbs build-dependency
* debian/copyright:
  + Update to DEP-5 format
* debian/patches/00_add-fPIC.patch:
  + Dropped, fix upstream
* Closes LP: #413992

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
//////////////////////////////////////////////////////////////////////////////
24
24
//////////////////////////////////////////////////////////////////////////////
25
25
#include "project.h"
 
26
#include "fileextmanager.h"
26
27
#include "xmlutils.h"
27
28
#include <wx/tokenzr.h>
28
29
#include "wx/arrstr.h"
29
30
#include "dirsaver.h"
 
31
#include "globals.h"
30
32
 
31
33
const wxString Project::STATIC_LIBRARY = wxT("Static Library");
32
34
const wxString Project::DYNAMIC_LIBRARY = wxT("Dynamic Library");
73
75
        wxXmlNode *depNode = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Dependencies"));
74
76
        root->AddChild(depNode);
75
77
 
76
 
        m_doc.Save(m_fileName.GetFullPath());
 
78
        SaveXmlFile();
77
79
        //create build settings
78
80
        SetSettings(new ProjectSettings(NULL));
79
81
        ProjectSettingsPtr settings = GetSettings();
94
96
        m_fileName = path;
95
97
        m_fileName.MakeAbsolute();
96
98
        SetModified(true);
 
99
        SetProjectLastModifiedTime(GetFileLastModifiedTime());
 
100
 
97
101
        return true;
98
102
}
99
103
 
156
160
 
157
161
        //if not in transaction save the changes
158
162
        if (!InTransaction()) {
159
 
                m_doc.Save(m_fileName.GetFullPath());
 
163
                SaveXmlFile();
160
164
        }
161
165
 
162
166
        // cache the result
211
215
        node->AddProperty(wxT("Name"), tmp.GetFullPath());
212
216
        vd->AddChild(node);
213
217
        if (!InTransaction()) {
214
 
                m_doc.Save(m_fileName.GetFullPath());
 
218
                SaveXmlFile();
215
219
        }
216
220
        SetModified(true);
217
221
        return true;
239
243
 
240
244
                delete vd;
241
245
                SetModified(true);
242
 
                return m_doc.Save(m_fileName.GetFullPath());
 
246
                return SaveXmlFile();
243
247
        }
244
248
        return false;
245
249
}
265
269
                delete node;
266
270
        }
267
271
        SetModified(true);
268
 
        return m_doc.Save(m_fileName.GetFullPath());;
 
272
        return SaveXmlFile();
269
273
}
270
274
 
271
275
wxString Project::GetName() const
335
339
        SetModified(true);
336
340
}
337
341
 
 
342
bool Project::SaveXmlFile()
 
343
{
 
344
        bool ok = m_doc.Save(m_fileName.GetFullPath());
 
345
        SetProjectLastModifiedTime(GetFileLastModifiedTime());
 
346
 
 
347
        return ok;
 
348
}
 
349
 
338
350
void Project::Save()
339
351
{
340
352
        m_tranActive = false;
341
353
        if ( m_doc.IsOk() )
342
 
                m_doc.Save(m_fileName.GetFullPath());
 
354
                SaveXmlFile();
343
355
}
344
356
 
345
357
void Project::GetFilesByVirtualDir(const wxString &vdFullPath, wxArrayString &files)
408
420
                delete oldSettings;
409
421
        }
410
422
        m_doc.GetRoot()->AddChild(settings->ToXml());
411
 
        m_doc.Save(m_fileName.GetFullPath());
 
423
        SaveXmlFile();
412
424
}
413
425
 
414
426
void Project::SetGlobalSettings(BuildConfigCommonPtr globalSettings)
420
432
                delete oldSettings;
421
433
        }
422
434
        settings->AddChild(globalSettings->ToXml());
423
 
        m_doc.Save(m_fileName.GetFullPath());
 
435
        SaveXmlFile();
424
436
}
425
437
 
426
438
wxArrayString Project::GetDependencies() const
506
518
                }
507
519
        }
508
520
 
509
 
//      wxXmlNode *deps = XmlUtils::FindFirstByTagName(doc.GetRoot(), wxT("Dependencies"));
510
 
//      if (deps) {
511
 
//              doc.GetRoot()->RemoveChild(deps);
512
 
//              delete deps;
513
 
//      }
514
 
 
515
521
        // add an empty deps node
516
522
        deps = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Dependencies"));
517
523
        doc.GetRoot()->AddChild(deps);
537
543
                wxFileName fn = files.at(i);
538
544
                wxCopyFile(fn.GetFullPath(), new_path + wxT("/") + fn.GetFullName());
539
545
 
540
 
                // add source file under the 'src' while headers are added under 'include'
541
 
                wxString e(fn.GetExt());
542
 
                e = e.MakeLower();
543
 
 
544
546
                wxXmlNode *file_node = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("File"));
545
547
                file_node->AddProperty(wxT("Name"), fn.GetFullName());
546
548
 
547
 
                if ( e == wxT("cpp") || e == wxT("cxx") || e == wxT("c") || e == wxT("c++") || e == wxT("cc") ) {
 
549
                switch ( FileExtManager::GetType( fn.GetFullName() ) ) {
 
550
                case FileExtManager::TypeSource:
 
551
 
548
552
                        // source file
549
553
                        if ( !srcNode ) {
550
554
                                srcNode = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("VirtualDirectory"));
552
556
                                doc.GetRoot()->AddChild(srcNode);
553
557
                        }
554
558
                        srcNode->AddChild(file_node);
 
559
                        break;
555
560
 
556
 
                } else if ( e == wxT("h") || e == wxT("hpp") || e == wxT("h++") || e == wxT("hxx")|| e == wxT("hh")  || e == wxT("inc") || e == wxT("inl") ) {
 
561
                case FileExtManager::TypeHeader:
557
562
                        // header file
558
563
                        if (!headNode) {
559
564
                                headNode = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("VirtualDirectory"));
561
566
                                doc.GetRoot()->AddChild(headNode);
562
567
                        }
563
568
                        headNode->AddChild(file_node);
 
569
                        break;
564
570
 
565
 
                } else {
 
571
                default:
566
572
                        // resource file
567
573
                        if ( !rcNode ) {
568
574
                                rcNode = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("VirtualDirectory"));
570
576
                                doc.GetRoot()->AddChild(rcNode);
571
577
                        }
572
578
                        rcNode->AddChild(file_node);
 
579
                        break;
573
580
                }
574
581
        }
 
582
 
575
583
        doc.Save(newFile);
576
584
}
577
585
 
596
604
                }
597
605
                child = child->GetNext();
598
606
        }
599
 
        m_doc.Save(m_fileName.GetFullPath());
 
607
        SaveXmlFile();
600
608
}
601
609
 
602
610
bool Project::RenameFile(const wxString& oldName, const wxString& virtualDir, const wxString& newName)
622
630
        }
623
631
 
624
632
        SetModified(true);
625
 
        return m_doc.Save(m_fileName.GetFullPath());;
 
633
        return SaveXmlFile();
626
634
}
627
635
 
628
636
wxString Project::GetVDByFileName(const wxString& file)
681
689
        wxXmlNode *vdNode = GetVirtualDir(oldVdPath);
682
690
        if (vdNode) {
683
691
                XmlUtils::UpdateProperty(vdNode, wxT("Name"), newName);
684
 
                return m_doc.Save(m_fileName.GetFullPath());
 
692
                return SaveXmlFile();
685
693
        }
686
694
        return false;
687
695
}
739
747
        }
740
748
 
741
749
        //save changes
742
 
        m_doc.Save(m_fileName.GetFullPath());
 
750
        SaveXmlFile();
743
751
        SetModified(true);
744
752
}
745
753
 
795
803
        node->AddProperty(wxT("Name"), tmp.GetFullPath());
796
804
        vd->AddChild(node);
797
805
        if (!InTransaction()) {
798
 
                m_doc.Save(m_fileName.GetFullPath());
 
806
                SaveXmlFile();
799
807
        }
800
808
        SetModified(true);
801
809
        return true;
883
891
        // serialize the data
884
892
        arch.SetXmlNode(dataNode);
885
893
        obj->Serialize(arch);
886
 
        return m_doc.Save(m_fileName.GetFullPath());
 
894
        return SaveXmlFile();
887
895
}
888
896
 
889
897
void Project::SetProjectInternalType(const wxString& internalType)
895
903
{
896
904
        return m_doc.GetRoot()->GetPropVal(wxT("InternalType"), wxEmptyString);
897
905
}
 
906
 
 
907
void Project::GetAllPluginsData(std::map<wxString, wxString>& pluginsDataMap)
 
908
{
 
909
        if(!m_doc.IsOk()){
 
910
                return;
 
911
        }
 
912
 
 
913
        // locate the 'Plugins' node
 
914
        wxXmlNode *plugins = XmlUtils::FindFirstByTagName(m_doc.GetRoot(), wxT("Plugins"));
 
915
        if( !plugins ) {
 
916
                return;
 
917
        }
 
918
 
 
919
        wxXmlNode *child = plugins->GetChildren();
 
920
        while( child ) {
 
921
                if( child->GetName() == wxT("Plugin") ) {
 
922
                        // get the content
 
923
                        pluginsDataMap[child->GetPropVal(wxT("Name"), wxEmptyString)] = child->GetNodeContent();
 
924
                }
 
925
                child = child->GetNext();
 
926
        }
 
927
}
 
928
 
 
929
wxString Project::GetPluginData(const wxString& pluginName)
 
930
{
 
931
        if(!m_doc.IsOk()){
 
932
                return wxEmptyString;
 
933
        }
 
934
 
 
935
        // locate the 'Plugins' node
 
936
        wxXmlNode *plugins = XmlUtils::FindFirstByTagName(m_doc.GetRoot(), wxT("Plugins"));
 
937
        if( !plugins ) {
 
938
                return wxEmptyString;
 
939
        }
 
940
 
 
941
        // find the node and return its content
 
942
        wxXmlNode *dataNode = XmlUtils::FindNodeByName(plugins, wxT("Plugin"), pluginName);
 
943
        if( dataNode ){
 
944
                return dataNode->GetNodeContent();
 
945
        }
 
946
        return wxEmptyString;
 
947
}
 
948
 
 
949
void Project::SetPluginData(const wxString& pluginName, const wxString& data)
 
950
{
 
951
        if(!m_doc.IsOk()){
 
952
                return ;
 
953
        }
 
954
 
 
955
        // locate the 'Plugins' node
 
956
        wxXmlNode *plugins = XmlUtils::FindFirstByTagName(m_doc.GetRoot(), wxT("Plugins"));
 
957
        if( !plugins ) {
 
958
                plugins = new wxXmlNode(m_doc.GetRoot(), wxXML_ELEMENT_NODE, wxT("Plugins"));
 
959
        }
 
960
 
 
961
        wxXmlNode *plugin = XmlUtils::FindNodeByName(plugins, wxT("Plugin"), pluginName);
 
962
        if( !plugin ) {
 
963
                plugin = new wxXmlNode(plugins, wxXML_ELEMENT_NODE, wxT("Plugin"));
 
964
                plugin->AddProperty(wxT("Name"), pluginName);
 
965
        }
 
966
 
 
967
        XmlUtils::SetCDATANodeContent(plugin, data);
 
968
        SaveXmlFile();
 
969
}
 
970
 
 
971
 
 
972
void Project::SetAllPluginsData(const std::map<wxString, wxString>& pluginsDataMap)
 
973
{
 
974
        if(!m_doc.IsOk()){
 
975
                return;
 
976
        }
 
977
 
 
978
        // locate the 'Plugins' node
 
979
        wxXmlNode *plugins = XmlUtils::FindFirstByTagName(m_doc.GetRoot(), wxT("Plugins"));
 
980
        if( plugins ) {
 
981
                m_doc.GetRoot()->RemoveChild( plugins );
 
982
                delete plugins;
 
983
        }
 
984
 
 
985
        std::map<wxString, wxString>::const_iterator iter = pluginsDataMap.begin();
 
986
        for(; iter != pluginsDataMap.end(); iter ++) {
 
987
                SetPluginData( iter->first, iter->second );
 
988
        }
 
989
        SaveXmlFile();
 
990
}
 
991
 
 
992
time_t Project::GetFileLastModifiedTime() const
 
993
{
 
994
        return GetFileModificationTime(GetFileName());
 
995
}