Code::Blocks  SVN r11506
cbproject.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
3  * http://www.gnu.org/licenses/lgpl-3.0.html
4  */
5 
6 #ifndef CBPROJECT_H
7 #define CBPROJECT_H
8 
9 #include <wx/datetime.h>
10 #include <wx/dynarray.h>
11 #include <wx/hashmap.h>
12 #include <wx/treectrl.h>
13 
14 #include "settings.h"
15 #include "misctreeitemdata.h"
16 #include "compiletargetbase.h"
17 #include "cbplugin.h"
18 #include "projectbuildtarget.h"
19 #include "projectmanager.h"
20 
21 #include <map>
22 #include <vector>
23 
24 // forward decl
25 class cbProject;
26 class ProjectBuildTarget;
27 class ProjectFile;
29 class TiXmlNode;
30 class TiXmlElement;
31 
32 // hashmap for fast searches in cbProject::GetFileByFilename()
34 
35 typedef std::map<wxString, wxArrayString> VirtualBuildTargetsMap;
36 
38 {
39  public:
42  {
43  ftdkUndefined = 0,
47  ftdkVirtualGroup, // wilcard matching
48  ftdkVirtualFolder
49  };
50 
51  FileTreeData(cbProject* project, FileTreeDataKind kind = ftdkUndefined)
52  : m_Index(-1),
53  m_Project(project),
54  m_file(nullptr),
55  m_kind(kind)
56  {}
57 
58  FileTreeDataKind GetKind() const { return m_kind; }
59  cbProject* GetProject() const { return m_Project; }
60  int GetFileIndex() const { return m_Index; }
61  ProjectFile* GetProjectFile() const { return m_file; }
62  const wxString& GetFolder() const { return m_folder; }
63 
64  void SetKind(FileTreeDataKind kind){ m_kind = kind; }
65  void SetProject(cbProject* project){ m_Project = project; }
66  // only valid for file selections
67  void SetFileIndex(int index){ m_Index = index; }
68  void SetProjectFile(ProjectFile* file){ m_file = file; }
69  // only valid for folder selections
70  void SetFolder(const wxString& folder){ m_folder = folder; }
71  private:
72  int m_Index;
77 };
78 
83 enum PCHMode
84 {
88 };
89 
97 {
98  public:
100  cbProject(const wxString& filename = wxEmptyString);
102  ~cbProject() override;
103 
105  bool IsLoaded() const { return m_Loaded; }
106 
108  void ClearAllProperties();
109 
114  void CalculateCommonTopLevelPath();
115 
117  wxString GetCommonTopLevelPath() const;
118 
120  bool GetModified() const override;
121 
125  void SetModified(bool modified = true) override;
126 
131  ProjectFile* GetFile(int index);
132 
139  ProjectFile* GetFileByFilename(const wxString& filename, bool isRelative = true, bool isUnixFilename = false);
140 
142  int GetFilesCount(){ return m_Files.size(); }
143 
148  void SetMakefile(const wxString& makefile){ m_Makefile = makefile; SetModified(true); }
149 
151  const wxString& GetMakefile();
152 
156  void SetMakefileCustom(bool custom);
157 
159  bool IsMakefileCustom(){ return m_CustomMakefile; }
160 
165  void SetMakefileExecutionDir(const wxString& dir);
166 
170  wxString GetMakefileExecutionDir();
171 
177  wxString GetExecutionDir();
178 
184  bool BuildTargetValid(const wxString& name, bool virtuals_too = true) const;
185 
187  wxString GetFirstValidBuildTargetName(bool virtuals_too = true) const;
188 
191  const wxString& GetDefaultExecuteTarget() const;
192 
197  void SetDefaultExecuteTarget(const wxString& name);
198 
200  int GetBuildTargetsCount() { return m_Targets.GetCount(); }
201 
206  ProjectBuildTarget* GetBuildTarget(int index);
207 
212  ProjectBuildTarget* GetBuildTarget(const wxString& targetName);
213 
218  ProjectBuildTarget* AddBuildTarget(const wxString& targetName);
219 
225  bool RenameBuildTarget(int index, const wxString& targetName);
226 
232  bool RenameBuildTarget(const wxString& oldTargetName, const wxString& newTargetName);
233 
239  ProjectBuildTarget* DuplicateBuildTarget(int index, const wxString& newName = wxEmptyString);
240 
246  ProjectBuildTarget* DuplicateBuildTarget(const wxString& targetName, const wxString& newName = wxEmptyString);
247 
258  bool ExportTargetAsProject(int index);
259 
267  bool ExportTargetAsProject(const wxString& targetName);
268 
273  bool RemoveBuildTarget(int index);
274 
279  bool RemoveBuildTarget(const wxString& targetName);
280 
287  void ReOrderTargets(const wxArrayString& nameOrder);
288 
295  bool SetActiveBuildTarget(const wxString& name);
296 
298  const wxString& GetActiveBuildTarget() const;
299 
301  PCHMode GetModeForPCH() const { return m_PCHMode; }
302 
306  void SetModeForPCH(PCHMode mode){ m_PCHMode = mode; SetModified(true); }
307 
308  void SetCompilerID(const wxString& id) override; // overriden
309 
311  wxTreeItemId GetProjectNode(){ return m_ProjectNode; }
312 
314  void SetProjectNode(wxTreeItemId node) { m_ProjectNode = node; }
315 
320  bool QueryCloseAllFiles();
321 
327  bool CloseAllFiles(bool dontsave=false);
328 
332  bool SaveAllFiles();
333 
337  bool Save();
338 
343  bool SaveAs();
344 
350  bool SaveLayout();
351 
356  bool LoadLayout();
357 
366  void BeginAddFiles();
367 
375  void EndAddFiles();
376 
385  void BeginRemoveFiles();
386 
394  void EndRemoveFiles();
395 
405  ProjectFile* AddFile(const wxString& targetName, const wxString& filename, bool compile = true, bool link = true, unsigned short int weight = 50);
406 
416  ProjectFile* AddFile(int targetIndex, const wxString& filename, bool compile = true, bool link = true, unsigned short int weight = 50);
417 
422  bool RemoveFile(ProjectFile* pf);
423 
424  struct Glob
425  {
429  Glob(const wxString& path, const wxString& wildCard, bool recursive) : m_Path(path), m_WildCard(wildCard), m_Recursive(recursive) {}
430  };
431 
435  void SetGlobs(const std::vector<Glob>& globs);
436 
440  std::vector<Glob> GetGlobs() const;
441 
445  const wxArrayString& ExpandedNodes() { return m_ExpandedNodes; }
446 
451  void AddExpandedNode(const wxString& path) { m_ExpandedNodes.Add(path); }
452 
456  void SaveTreeState(wxTreeCtrl* tree);
457 
461  void RestoreTreeState(wxTreeCtrl* tree);
462 
472  int SelectTarget(int initial = -1, bool evenIfOne = false);
473 
478  ProjectBuildTarget* GetCurrentlyCompilingTarget() { return m_CurrentlyCompilingTarget; }
479 
485  void SetCurrentlyCompilingTarget(ProjectBuildTarget* bt);
486 
503  bool DefineVirtualBuildTarget(const wxString& alias, const wxArrayString& targets);
504 
510  bool HasVirtualBuildTarget(const wxString& alias) const;
511 
517  bool RemoveVirtualBuildTarget(const wxString& alias);
518 
523  wxArrayString GetVirtualBuildTargets() const;
524 
530  const wxArrayString& GetVirtualBuildTargetGroup(const wxString& alias) const;
531 
540  wxArrayString GetExpandedVirtualBuildTargetGroup(const wxString& alias) const;
541 
549  bool CanAddToVirtualBuildTarget(const wxString& alias, const wxString& target);
550 
552  const wxArrayString& GetVirtualFolders() const;
553 
555  void SetVirtualFolders(const wxArrayString& folders);
556 
559  bool AppendUniqueVirtualFolder(const wxString &folder);
560 
562  void RemoveVirtualFolders(const wxString &folder);
563 
566  void ReplaceVirtualFolder(const wxString &oldFolder, const wxString &newFolder);
567 
569  wxDateTime GetLastModificationTime() const { return m_LastModified; }
570 
572  void Touch();
573 
586  void SetExtendedObjectNamesGeneration(bool ext);
587 
592  bool GetExtendedObjectNamesGeneration() const;
593 
598  void SetNotes(const wxString& notes);
599 
604  const wxString& GetNotes() const;
605 
610  void SetShowNotesOnLoad(bool show);
611 
616  bool GetShowNotesOnLoad() const;
617 
622  void SetCheckForExternallyModifiedFiles(bool check);
623 
628  bool GetCheckForExternallyModifiedFiles() const;
629 
637  void ShowNotes(bool nonEmptyOnly, bool editable = false);
638 
645  void SetTitle(const wxString& title) override;
646 
655  virtual TiXmlNode* GetExtensionsNode();
656 
675  virtual void AddToExtensions(const wxString& stringDesc);
676 
680  virtual void ProjectFileRenamed(ProjectFile* pf);
681 
685  virtual FilesList& GetFilesList(){ return m_Files; }
686 
687  private:
688  void Open();
689  void ExpandVirtualBuildTargetGroup(const wxString& alias, wxArrayString& result) const;
690  ProjectBuildTarget* AddDefaultBuildTarget();
691  int IndexOfBuildTargetName(const wxString& targetName) const;
692  wxString CreateUniqueFilename();
693  void NotifyPlugins(wxEventType type, const wxString& targetName = wxEmptyString, const wxString& oldTargetName = wxEmptyString);
694 
695  // properties
697  BuildTargets m_Targets;
704 
705  std::vector<Glob> m_Globs;
706  FilesList m_Files;
707  ProjectFileArray m_FileArray;
710  bool m_Loaded;
712 
713  wxArrayString m_VirtualFolders; // not saved, just used throughout cbProject's lifetime
714 
718 
720 
721  // hashmap for fast searches in cbProject::GetFileByFilename()
722  ProjectFiles m_ProjectFilesMap; // keeps UnixFilename(ProjectFile::relativeFilename)
724 
726 
731 
732  // copy of <Extensions> element, in case certain plugins are disabled
733  // so that the contents are not lost
734  TiXmlElement* m_pExtensionsElement;
735 };
736 
740 DLLIMPORT wxString cbMergeLibPaths(const wxString &oldPath, const wxString &newPath);
741 
742 #endif // CBPROJECT_H
743 
744 
wxTreeItemId GetProjectNode()
Definition: cbproject.h:311
wxArrayString m_ExpandedNodes
Definition: cbproject.h:708
FileTreeData(cbProject *project, FileTreeDataKind kind=ftdkUndefined)
Definition: cbproject.h:51
bool m_CurrentlyLoading
Definition: cbproject.h:715
const wxString & GetFolder() const
Definition: cbproject.h:62
FilesList m_Files
Definition: cbproject.h:706
void SetModeForPCH(PCHMode mode)
Set the mode to handle precompiled headers.
Definition: cbproject.h:306
ProjectBuildTarget * m_CurrentlyCompilingTarget
Definition: cbproject.h:723
std::vector< Glob > m_Globs
Definition: cbproject.h:705
FileTreeDataKind
The kind of tree node.
Definition: cbproject.h:41
virtual FilesList & GetFilesList()
Provides an easy way to iterate all the files belonging in this target.
Definition: cbproject.h:685
void SetProjectNode(wxTreeItemId node)
Sets the root item of this item, should not be called by user&#39;s code!
Definition: cbproject.h:314
bool m_AutoShowNotesOnLoad
Definition: cbproject.h:729
PCHMode GetModeForPCH() const
Definition: cbproject.h:301
wxArrayString m_VirtualFolders
Definition: cbproject.h:713
PCHMode
Precompiled headers mode.
Definition: cbproject.h:83
void SetProject(cbProject *project)
Definition: cbproject.h:65
cbProject * m_Project
Definition: cbproject.h:73
ProjectFile * GetProjectFile() const
Definition: cbproject.h:61
wxString m_BasePath
Definition: cbproject.h:717
ProjectFiles m_ProjectFilesMap
Definition: cbproject.h:722
Represents a file in a Code::Blocks project.
Definition: projectfile.h:39
ProjectBuildTarget * GetCurrentlyCompilingTarget()
Get a pointer to the currently compiling target.
Definition: cbproject.h:478
ProjectFile * m_file
Definition: cbproject.h:74
bool m_CustomMakefile
Definition: cbproject.h:702
In the objects output dir, along with other object files.
Definition: cbproject.h:87
virtual void SetCompilerID(const wxString &id)
! Set the flag if the host app should be run in terminal
Glob(const wxString &path, const wxString &wildCard, bool recursive)
Definition: cbproject.h:429
void SetFolder(const wxString &folder)
Definition: cbproject.h:70
wxString m_WildCard
Definition: cbproject.h:427
#define DLLIMPORT
Definition: settings.h:16
int GetFileIndex() const
Definition: cbproject.h:60
wxString m_Notes
Definition: cbproject.h:728
Represents a Code::Blocks project.
Definition: cbproject.h:96
DLLIMPORT wxString cbGetDynamicLinkerPathForTarget(cbProject *project, ProjectBuildTarget *target)
Returns a string valid to be used as LD_LIBRARY_PATH (or equivalent).
Definition: cbproject.cpp:1755
const wxArrayString & ExpandedNodes()
Convenience function for remembering the project&#39;s tree state when refreshing it. ...
Definition: cbproject.h:445
TiXmlElement * m_pExtensionsElement
Definition: cbproject.h:734
null_pointer_t nullptr
Definition: nullptr.cpp:16
virtual void SetModified(bool modified)
WX_DECLARE_STRING_HASH_MAP(ProjectFile *, ProjectFiles)
VirtualBuildTargetsMap m_VirtualTargets
Definition: cbproject.h:696
wxTreeItemId m_ProjectNode
Definition: cbproject.h:711
friend class cbProject
std::map< wxString, wxArrayString > VirtualBuildTargetsMap
Definition: cbproject.h:35
wxDateTime GetLastModificationTime() const
Returns the last modification time for the file.
Definition: cbproject.h:569
wxString wxEmptyString
wxString m_LastSavedActiveTarget
Definition: cbproject.h:699
FileTreeDataKind m_kind
Definition: cbproject.h:76
int GetFilesCount()
Definition: cbproject.h:142
bool IsMakefileCustom()
Definition: cbproject.h:159
bool m_CheckForExternallyModifiedFiles
Definition: cbproject.h:730
int GetBuildTargetsCount()
Definition: cbproject.h:200
void SetMakefile(const wxString &makefile)
Set the Makefile filename used when exporting a Makefile for the project, or when using a custom Make...
Definition: cbproject.h:148
bool m_ExtendedObjectNamesGeneration
Definition: cbproject.h:727
In a dir (named by the PCH) on the same level as the source header (default).
Definition: cbproject.h:86
DLLIMPORT void SaveTreeState(wxTreeCtrl *tree, const wxTreeItemId &parent, wxArrayString &nodePaths, wxArrayString &selectedItemPaths)
Definition: globals.cpp:575
wxString m_MakefileExecutionDir
Definition: cbproject.h:703
wxArrayString m_SelectedNodes
Definition: cbproject.h:709
cbProject * GetProject() const
Definition: cbproject.h:59
wxString m_CommonTopLevelPath
Definition: cbproject.h:716
FileTreeDataKind GetKind() const
Definition: cbproject.h:58
BuildTargets m_Targets
Definition: cbproject.h:697
bool RemoveFile(const wxString &src)
Definition: sc_io.cpp:134
ProjectFileArray m_FileArray
Definition: cbproject.h:707
void AddExpandedNode(const wxString &path)
Convenience function for remembering the project&#39;s tree state when refreshing it. ...
Definition: cbproject.h:451
void SetKind(FileTreeDataKind kind)
Definition: cbproject.h:64
Represents a Code::Blocks project build target.
wxString m_DefaultExecuteTarget
Definition: cbproject.h:700
PCHMode m_PCHMode
Definition: cbproject.h:719
void SetProjectFile(ProjectFile *file)
Definition: cbproject.h:68
int wxEventType
wxString m_ActiveTarget
Definition: cbproject.h:698
wxString m_Path
Definition: cbproject.h:426
wxDateTime m_LastModified
Definition: cbproject.h:725
bool IsLoaded() const
Definition: cbproject.h:105
wxString m_folder
Definition: cbproject.h:75
DLLIMPORT void RestoreTreeState(wxTreeCtrl *tree, const wxTreeItemId &parent, wxArrayString &nodePaths, wxArrayString &selectedItemPaths)
Definition: globals.cpp:589
bool m_Loaded
Definition: cbproject.h:710
virtual bool GetModified() const
DLLIMPORT wxString cbMergeLibPaths(const wxString &oldPath, const wxString &newPath)
Merges to LD_LIBRARY_PATH/PATH strings together to form a new valid string.
Definition: cbproject.cpp:1777
void SetFileIndex(int index)
Definition: cbproject.h:67
Base class for build target classes Each Code::Blocks project consists of at least one target...
wxString m_Makefile
Definition: cbproject.h:701