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;
28 class FilesGroupsAndMasks;
29 class TiXmlNode;
30 class TiXmlElement;
31 
32 // hashmap for fast searches in cbProject::GetFileByFilename()
33 WX_DECLARE_STRING_HASH_MAP(ProjectFile*, ProjectFiles);
34 
35 typedef std::map<wxString, wxArrayString> VirtualBuildTargetsMap;
36 
37 class DLLIMPORT FileTreeData : public MiscTreeItemData
38 {
39     public:
40         /// The kind of tree node
41         enum FileTreeDataKind
42         {
43             ftdkUndefined = 0,
44             ftdkProject,
45             ftdkFolder,
46             ftdkFile,
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 
GetKind()58         FileTreeDataKind GetKind() const { return m_kind; }
GetProject()59         cbProject* GetProject() const { return m_Project; }
GetFileIndex()60         int GetFileIndex() const { return m_Index; }
GetProjectFile()61         ProjectFile* GetProjectFile() const { return m_file; }
GetFolder()62         const wxString& GetFolder() const { return m_folder; }
63 
SetKind(FileTreeDataKind kind)64         void SetKind(FileTreeDataKind kind){ m_kind = kind; }
SetProject(cbProject * project)65         void SetProject(cbProject* project){ m_Project = project; }
66         // only valid for file selections
SetFileIndex(int index)67         void SetFileIndex(int index){ m_Index = index; }
SetProjectFile(ProjectFile * file)68         void SetProjectFile(ProjectFile* file){ m_file = file; }
69         // only valid for folder selections
SetFolder(const wxString & folder)70         void SetFolder(const wxString& folder){ m_folder = folder; }
71     private:
72         int m_Index;
73         cbProject* m_Project;
74         ProjectFile* m_file;
75         wxString m_folder;
76         FileTreeDataKind m_kind;
77 };
78 
79 /** Precompiled headers mode.
80   * Defines where and how are the project's precompiled headers generated.
81   * Currently implemented only for GCC (3.4 and above).
82   */
83 enum PCHMode
84 {
85     pchSourceDir = 0, /// In a dir (named by the PCH) on the same level as the source header (default).
86     pchObjectDir,     /// In the objects output dir, along with other object files.
87     pchSourceFile     /// In a file alongside the source header (with .gch appended).
88 };
89 
90 /** @brief Represents a Code::Blocks project.
91   *
92   * A project is a collection of build targets and files.
93   * Each project can contain any number of build targets and files.
94   * @see ProjectBuildTarget, ProjectFile.
95   */
96 class DLLIMPORT cbProject : public CompileTargetBase
97 {
98      public:
99         /// Constructor
100         cbProject(const wxString& filename = wxEmptyString);
101         /// Destructor
102         ~cbProject() override;
103 
104         cbProject& operator=(const cbProject &p);
105 
106         /** @return True if the project fully loaded, false if not. */
IsLoaded()107         bool IsLoaded() const { return m_Loaded; }
108 
109         /** This resets the project to a clear state. Like it's just been new'ed. */
110         void ClearAllProperties();
111 
112         /** Calculates the top-level path common to all project files.
113           * This is called automatically (no need for you to call it) and is used
114           * to find the top-level folder for building the tree.
115           */
116         void CalculateCommonTopLevelPath();
117 
118         /** @return the top-level path common to all project files. */
119         wxString GetCommonTopLevelPath() const;
120 
121         /** @return True if the project is modified in any way. */
122         bool GetModified() const override;
123 
124         /** Mark the project as modified or not.
125           * @param modified If true, the project is marked as modified. If false, as not-modified.
126           */
127         void SetModified(bool modified = true) override;
128 
129         /** Access a file of the project.
130           * @param index The index of the file. Must be greater or equal than zero and less than GetFilesCount().
131           * @return A pointer to the file or NULL if not found.
132           */
133         ProjectFile* GetFile(int index);
134 
135         /** Access a file of the project.
136           * @param filename The filename of the file.
137           * @param isRelative True if @c filename is a relative filename, false if not.
138           * @param isUnixFilename True if @c filename is already normalized with UnixFilename(), false if not.
139           * @return A pointer to the file or NULL if not found.
140           */
141         ProjectFile* GetFileByFilename(const wxString& filename, bool isRelative = true, bool isUnixFilename = false);
142 
143         /** @return The number of files in the project. */
GetFilesCount()144         int GetFilesCount(){ return m_Files.size(); }
145 
146         /** Set the Makefile filename used when exporting a Makefile for the project,
147           * or when using a custom Makefile to build the project.
148           * @param makefile The filename for the Makefile.
149           */
SetMakefile(const wxString & makefile)150         void SetMakefile(const wxString& makefile){ m_Makefile = makefile; SetModified(true); }
151 
152         /** @return The filename for the Makefile. */
153         const wxString& GetMakefile() const;
154 
155         /** Mark if the project should use a custom Makefile for compilation.
156           * @param custom If true, use a custom Makefile for compilation. If false, use direct C::B build mode.
157           */
158         void SetMakefileCustom(bool custom);
159 
160         /** @return True if the project is using a custom Makefile for compilation, false if not. */
IsMakefileCustom()161         bool IsMakefileCustom(){ return m_CustomMakefile; }
162 
163         /** Allow the specification of specific execution directory if the project use a custom Makefile.
164           * Defaults to the projects base path, if no custom makefile is used.
165           * @param dir The directory the custom Makefile should be executed from.
166           */
167         void SetMakefileExecutionDir(const wxString& dir);
168 
169         /** @return The execution directory for the custom Makefile.
170           * Defaults to the projects base path, if no custom makefile is used.
171           */
172         wxString GetMakefileExecutionDir();
173 
174         /** @return Either the execution directory for the custom Makefile or
175           * the projects base path.
176           * Defaults to the projects base path, if no custom makefile is used.
177           * Used to unify the call to the function.
178           */
179         wxString GetExecutionDir();
180 
181         /** Is there a build target (virtual or real) by @c name?
182           * @param name The build target's name.
183           * @param virtuals_too Include virtual build targets in query.
184           * @return True if exists a build target (virtual or real) by that name, false if not.
185           */
186         bool BuildTargetValid(const wxString& name, bool virtuals_too = true) const;
187 
188         /** @return The first valid (virtual or real) build target. */
189         wxString GetFirstValidBuildTargetName(bool virtuals_too = true) const;
190 
191         /** @return The build target index which will be pre-selected when the "Select target"
192           * dialog appears when running the project. Valid only for multi-target projects. */
193         const wxString& GetDefaultExecuteTarget() const;
194 
195         /** Set the build target index which will be pre-selected when the "Select target"
196           * dialog appears when running the project.
197           * @param name The build target's name.
198           */
199         void SetDefaultExecuteTarget(const wxString& name);
200 
201         /** @return The number of build targets this project contains. */
GetBuildTargetsCount()202         int GetBuildTargetsCount() const { return m_Targets.GetCount(); }
203 
204         /** Access a build target.
205           * @param index The build target index. Must be greater or equal to zero and less than GetBuildTargetsCount().
206           * @return The build target or NULL if not found.
207           */
208         ProjectBuildTarget* GetBuildTarget(int index);
209 
210         /** Access a build target.
211           * @param index The build target index. Must be greater or equal to zero and less than GetBuildTargetsCount().
212           * @return The build target or NULL if not found.
213           */
214         const ProjectBuildTarget* GetBuildTarget(int index) const;
215 
216         /** Access a build target.
217           * @param targetName The build target name.
218           * @return The build target or NULL if not found.
219           */
220         ProjectBuildTarget* GetBuildTarget(const wxString& targetName);
221 
222         /** Access a build target.
223           * @param targetName The build target name.
224           * @return The build target or NULL if not found.
225           */
226         const ProjectBuildTarget* GetBuildTarget(const wxString& targetName) const;
227 
228         /** Add a new build target.
229           * @param targetName The build target name.
230           * @return The build target that was just created.
231           */
232         ProjectBuildTarget* AddBuildTarget(const wxString& targetName);
233 
234         /** Rename a build target.
235           * @param index The build target's index to rename.
236           * @param targetName The new name for the build target.
237           * @return True if @c index was valid, false if not.
238           */
239         bool RenameBuildTarget(int index, const wxString& targetName);
240 
241         /** Rename a build target.
242           * @param oldTargetName The build target's old name.
243           * @param newTargetName The new name for the build target.
244           * @return True if @c oldTargetName was valid, false if not.
245           */
246         bool RenameBuildTarget(const wxString& oldTargetName, const wxString& newTargetName);
247 
248         /** Duplicate a build target.
249           * @param index The index of the build target to duplicate.
250           * @param newName The name for the new build target. If empty, it will be named like "Copy of <base_target_name>".
251           * @return The new build target if @c index was valid, NULL if not (or something went wrong).
252           */
253         ProjectBuildTarget* DuplicateBuildTarget(int index, const wxString& newName = wxEmptyString);
254 
255         /** Duplicate a build target.
256           * @param targetName The name of the build target to duplicate.
257           * @param newName The name for the new build target. If empty, it will be named like "Copy of <base_target_name>".
258           * @return The new build target if @c index was valid, NULL if not (or something went wrong).
259           */
260         ProjectBuildTarget* DuplicateBuildTarget(const wxString& targetName, const wxString& newName = wxEmptyString);
261 
262         /** Export a target as a new project.
263           * In other words, save a copy of the project containing only the specified target.
264           * The user will be prompted with a dialog to select the new project name.
265           * @param index The index of the build target to export.
266           * @return True on success, false on failure (or dialog cancellation).
267           * @note The dialog to select the new project name is not a file dialog because
268           * the user is not allowed to save anywhere. The new project must remain "operational"
269           * (assuming the target to export, was "operational") so the new project must be saved
270           * in the same directory as the original to preserve relative paths.
271           */
272         bool ExportTargetAsProject(int index);
273 
274         /** Export a target as a new project.
275           * In other words, save a copy of the project containing only the specified target.
276           * The user will be prompted with a dialog to select the new project name.
277           * @param targetName The name of the build target to export.
278           * @return True on success, false on failure (or dialog cancellation).
279           * @see ExportTargetAsProject(int).
280           */
281         bool ExportTargetAsProject(const wxString& targetName);
282 
283         /** Remove a build target.
284           * @param index The index of the build target to remove.
285           * @return True if @c index was valid, false if not.
286           */
287         bool RemoveBuildTarget(int index);
288 
289         /** Remove a build target.
290           * @param targetName The build target name.
291           * @return True if the @c targetName was valid, false if not.
292           */
293         bool RemoveBuildTarget(const wxString& targetName);
294 
295         /** Reorder the list of build targets.
296           * This is useful, so that when the special build target "All" is being built
297           * targets are built in the desired order.
298           * @param nameOrder An array of strings containing build target names in the order you desire.
299           * The number of array elements must be equal to GetBuildTargetsCount().
300           */
301         void ReOrderTargets(const wxArrayString& nameOrder);
302 
303         /** Set the active build target.
304           * @param name The build target name to set as active. If @c name does
305           *             not exist, then the first virtual target is set
306           *             or the first real target, depending which is valid.
307           * @return True if @c name was valid, false if not.
308           */
309         bool SetActiveBuildTarget(const wxString& name);
310 
311         /** @return The active build target name. Note that this might be a virtual target. */
312         const wxString& GetActiveBuildTarget() const;
313 
314         /** @return The mode precompiled headers are handled. */
GetModeForPCH()315         PCHMode GetModeForPCH() const { return m_PCHMode; }
316 
317         /** Set the mode to handle precompiled headers.
318           * @param mode The desired PCH mode.
319           */
SetModeForPCH(PCHMode mode)320         void SetModeForPCH(PCHMode mode){ m_PCHMode = mode; SetModified(true); }
321 
322         void SetCompilerID(const wxString& id) override; // overriden
323 
324         /** @return The root item of this project in the project manager's tree. */
GetProjectNode()325         wxTreeItemId GetProjectNode(){ return m_ProjectNode; }
326 
327         /** Sets the root item of this item, should not be called by user's code! */
SetProjectNode(wxTreeItemId node)328         void SetProjectNode(wxTreeItemId node) { m_ProjectNode = node; }
329 
330         /** Act like closing all project files, but don't do it.
331           * Used to check if any of the project files need saving.
332           * @return True if even one project file needs to be saved, false if not.
333           */
334         bool QueryCloseAllFiles();
335 
336         /** Close all project files.
337           * @param dontsave If true, no project file will be saved even if modified.
338           * If false, any modified file will be saved (default).
339           * @return True if successful, false otherwise.
340           */
341         bool CloseAllFiles(bool dontsave=false);
342 
343         /** Save all project files.
344           * @return True if successful, false otherwise.
345           */
346         bool SaveAllFiles();
347 
348         /** Save the project.
349           * @return True if successful, false otherwise.
350           */
351         bool Save();
352 
353         /** Save the project under a different name.
354           * A dialog pops up for the user to choose a new filename for the project.
355           * @return True if successful, false otherwise.
356           */
357         bool SaveAs();
358 
359         /** Save the project's layout.
360           * Layout is the list of open project files, which one is active,
361           * where the cursor is located on each one of those, etc.
362           * @return True if successful, false otherwise.
363           */
364         bool SaveLayout();
365 
366         /** Load the project's layout.
367           * @see SaveLayout() for info.
368           * @return True if successful, false otherwise.
369           */
370         bool LoadLayout();
371 
372         /** Notify that file(s) will be added shortly.
373           * This function should be called before calling AddFile().
374           * When done calling AddFile() as many times as needed, call
375           * EndAddFiles().
376           *
377           * This sequence of function calls ensures proper events dispatching.
378           * This function broadcasts the cbEVT_PROJECT_BEGIN_ADD_FILES event.
379           */
380         void BeginAddFiles();
381 
382         /** Notify that file(s) addition finished.
383           * This function should be called when done calling AddFile() as many times as needed.
384           *
385           * This sequence of function calls ensures proper events dispatching.
386           * This function broadcasts the cbEVT_PROJECT_END_ADD_FILES event.
387           * @see BeginAddFiles().
388           */
389         void EndAddFiles();
390 
391         /** Notify that file(s) will be removed shortly.
392           * This function should be called before calling RemoveFile().
393           * When done calling RemoveFile() as many times as needed, call
394           * EndRemoveFiles().
395           *
396           * This sequence of function calls ensures proper events dispatching.
397           * This function broadcasts the cbEVT_PROJECT_BEGIN_REMOVE_FILES event.
398           */
399         void BeginRemoveFiles();
400 
401         /** Notify that file(s) removal finished.
402           * This function should be called when done calling RemoveFile() as many times as needed.
403           *
404           * This sequence of function calls ensures proper events dispatching.
405           * This function broadcasts the cbEVT_PROJECT_END_REMOVE_FILES event.
406           * @see BeginRemoveFiles().
407           */
408         void EndRemoveFiles();
409 
410         /** Add a file to the project.
411           * This variation, takes a target name as first parameter.
412           * @param targetName The name of the build target to add this file to.
413           * @param filename The file's filename. This *must* be a filename relative to the project's path.
414           * @param compile If true this file is compiled when building the project.
415           * @param link If true this file is linked when building the project.
416           * @param weight A value between zero and 100 (defaults to 50). Smaller weight, makes the file compile earlier than those with larger weight.
417           * @return The newly added file or NULL if something went wrong.
418           */
419         ProjectFile* AddFile(const wxString& targetName, const wxString& filename, bool compile = true, bool link = true, unsigned short int weight = 50);
420 
421         /** Add a file to the project.
422           * This variation, takes a target index as first parameter.
423           * @param targetIndex The index of the build target to add this file to.
424           * @param filename The file's filename. This *must* be a filename relative to the project's path.
425           * @param compile If true this file is compiled when building the project.
426           * @param link If true this file is linked when building the project.
427           * @param weight A value between zero and 100 (defaults to 50). Smaller weight, makes the file compile earlier than those with larger weight.
428           * @return The newly added file or NULL if something went wrong.
429           */
430         ProjectFile* AddFile(int targetIndex, const wxString& filename, bool compile = true, bool link = true, unsigned short int weight = 50);
431 
432         /** Remove a file from the project.
433           * @param pf The pointer to ProjectFile.
434           * @return True if @c pf was a valid project file, false if not.
435           */
436         bool RemoveFile(ProjectFile* pf);
437 
438         struct Glob
439         {
440             wxString m_Path;
441             wxString m_WildCard;
442             bool m_Recursive;
GlobGlob443             Glob(const wxString& path, const wxString& wildCard, bool recursive) : m_Path(path), m_WildCard(wildCard), m_Recursive(recursive) {}
444         };
445 
446         /** Set the globs to the project, this are directory paths do retrieve files from to be added to the project, the path can be searched recursively
447           * @param globs the globs to add to the project.
448           */
449         void SetGlobs(const std::vector<Glob>& globs);
450 
451         /** Retrieve the current globs from the project
452           * @return globs the globs to add to the project.
453           */
454         std::vector<Glob> GetGlobs() const;
455 
456         /** Convenience function for remembering the project's tree state when refreshing it.
457           * @return An array of strings containing the tree-path names of expanded nodes.
458           */
ExpandedNodes()459         const wxArrayString& ExpandedNodes() { return m_ExpandedNodes; }
460 
461         /** Convenience function for remembering the project's tree state when refreshing it.
462           * Adds an expanded node in this internal list.
463           * @param path The tree-path to add.
464           */
AddExpandedNode(const wxString & path)465         void AddExpandedNode(const wxString& path) { m_ExpandedNodes.Add(path); }
466 
467         /** Convenience function for remembering the project's tree state when refreshing it.
468           * @param tree The tree control to save its expanded state.
469           */
470         void SaveTreeState(wxTreeCtrl* tree);
471 
472         /** Convenience function for remembering the project's tree state when refreshing it.
473           * @param tree The tree control to restore its expanded state to a previously saved.
474           */
475         void RestoreTreeState(wxTreeCtrl* tree);
476 
477         /** Displays a target selection dialog.
478           * When invoked, a selection dialog is presented to the user so that he/she
479           * can select one target from the list of this project's targets.
480           * @param initial The index of the pre-selected target when the dialog is displayed.
481           * Defaults to none (-1).
482           * @param evenIfOne If true, the dialog is still shown even if the project contains only one target.
483           * The default behaviour is to not show the dialog if the project has only one target.
484           * @return The target's index that the user selected or -1 if the dialog was cancelled.
485           */
486         int SelectTarget(int initial = -1, bool evenIfOne = false);
487 
488         /** Get a pointer to the currently compiling target.
489           * @return While the project is being built, this function returns the currently building
490           * target. For all other times, NULL is returned.
491           */
GetCurrentlyCompilingTarget()492         ProjectBuildTarget* GetCurrentlyCompilingTarget() { return m_CurrentlyCompilingTarget; }
493 
494         /** Get a pointer to the currently compiling target.
495           * @return While the project is being built, this function returns the currently building
496           * target. For all other times, NULL is returned.
497           */
GetCurrentlyCompilingTarget()498         const ProjectBuildTarget* GetCurrentlyCompilingTarget() const
499         {
500             return m_CurrentlyCompilingTarget;
501         }
502 
503         /** Set the currently compiling target.
504           * @note This function is for internal use by compilers only.
505           * Using this function in any other place results in undefined behaviour!
506           * @param bt The build target that is currently building.
507           */
508         void SetCurrentlyCompilingTarget(ProjectBuildTarget* bt);
509 
510         /** Define a new virtual build target.
511           *
512           * A virtual build target is not really a build target itself but it is an alias
513           * for a group of other build targets, real or virtual.
514           * An example is the "All" virtual build target which means "all build targets".
515           *
516           * @param alias The virtual build target's name.
517           * @param targets A list of build target names to include in this virtual build target.
518           *                They can be real or other virtual build targets.
519           * @return True for success, false for failure. The only reason for this function
520           *         to return false is if a *real* build target exists with the same name as @c alias
521           *         (or if you pass an empty @c targets array).
522           * @note Every time you call this function with the same @c alias parameter, the virtual
523           *       build target is re-defined. In other words, it's not an error if @c alias is already
524           *       defined.
525           */
526         bool DefineVirtualBuildTarget(const wxString& alias, const wxArrayString& targets);
527 
528         /** Does a virtual build target exist?
529           *
530           * @param alias The virtual build target's name.
531           * @return True if the virtual build target exists, false if not.
532           */
533         bool HasVirtualBuildTarget(const wxString& alias) const;
534 
535         /** Remove a virtual build target.
536           *
537           * @param alias The virtual build target's name.
538           * @return True if the virtual build target was removed, false if not.
539           */
540         bool RemoveVirtualBuildTarget(const wxString& alias);
541 
542         /** Get a list of all defined virtual build targets.
543           *
544           * @return A list of all defined virtual build targets.
545           */
546         wxArrayString GetVirtualBuildTargets() const;
547 
548         /** Access a virtual build target's group of build targets.
549           *
550           * @param alias The virtual build target's name.
551           * @return The list of all build targets under the alias @c alias.
552           */
553         const wxArrayString& GetVirtualBuildTargetGroup(const wxString& alias) const;
554 
555         /** Access a virtual build target's expanded group of build targets.
556           *
557           * The difference from GetVirtualBuildTargetGroup() lies in that this function
558           * returns the full list of real build targets in this group (by recursively
559           * expanding virtual build targets in the group).
560           * @param alias The virtual build target's name.
561           * @return The expanded list of all real build targets under the alias @c alias.
562           */
563         wxArrayString GetExpandedVirtualBuildTargetGroup(const wxString& alias) const;
564 
565         /** Checks if a build target (virtual or real) can be added to a virtual build target,
566           * without causing a circular-reference.
567           *
568           * @param alias The "parent" virtual build target to add the build target in.
569           * @param target The build target to add in the @c alias virtual build target.
570           * @return True if a circular reference is not detected, false if it is.
571           */
572         bool CanAddToVirtualBuildTarget(const wxString& alias, const wxString& target);
573 
574         /** Get a list of the virtual folders. Normally used by the project loader only.*/
575         const wxArrayString& GetVirtualFolders() const;
576 
577         /** Set the virtual folders list. Normally used by the project loader only. */
578         void SetVirtualFolders(const wxArrayString& folders);
579 
580         /** Appends a new virtual folder to the end of the list only if it doesn't exists.
581           * @return True if folder has been appended, false if not. */
582         bool AppendUniqueVirtualFolder(const wxString &folder);
583 
584         /** Remove all virtual folders starting with folder. */
585         void RemoveVirtualFolders(const wxString &folder);
586 
587         /** Replaced the oldFolder with newFolder or appends newFolder to the end of the list
588           * if oldFolder is not found.*/
589         void ReplaceVirtualFolder(const wxString &oldFolder, const wxString &newFolder);
590 
591         /** Returns the last modification time for the file. Used to detect modifications outside the Program. */
GetLastModificationTime()592         wxDateTime GetLastModificationTime() const { return m_LastModified; }
593 
594         /** Sets the last modification time for the project to 'now'. Used to detect modifications outside the Program. */
595         void Touch();
596 
597         /** Sets object names generation to extended/normal mode.
598           *
599           * In normal mode (the default), the file @c foo.cpp generates the @c foo.o object file.
600           * In extended mode, the file @c foo.cpp generates the @c foo.cpp.o object file.
601           *
602           * This option is useful for large projects containing similarly named files
603           * (in the same directory) differing only on their extensions. Using the
604           * extended mode with said projects guarantees that each object name will
605           * be unique.
606           *
607           * @param ext Set to true to switch to extended mode, false for normal mode.
608           */
609         void SetExtendedObjectNamesGeneration(bool ext);
610 
611         /** Gets object names generation mode (extended/normal).
612           * @return True for extended mode, false for normal mode.
613           * @see SetExtendedObjectNamesGeneration.
614           */
615         bool GetExtendedObjectNamesGeneration() const;
616 
617         /** Set notes on the project.
618           *
619           * @param notes Simple text notes about the project.
620           */
621         void SetNotes(const wxString& notes);
622 
623         /** Get notes on the project.
624           *
625           * @return Simple text notes about the project.
626           */
627         const wxString& GetNotes() const;
628 
629         /** Set show project notes on load automatically.
630           *
631           * @param show If true show project notes on load.
632           */
633         void SetShowNotesOnLoad(bool show);
634 
635         /** Get show project notes on load automatically.
636           *
637           * @return True if show project notes on load is set, false if not.
638           */
639         bool GetShowNotesOnLoad() const;
640 
641         /** Set check for externally modified files.
642           *
643           * @param True if check for externally modified files is set, false if not.
644           */
645         void SetCheckForExternallyModifiedFiles(bool check);
646 
647         /** Get check for externally modified files.
648           *
649           * @return True if check for externally modified files is set, false if not.
650           */
651         bool GetCheckForExternallyModifiedFiles() const;
652 
653         /** Show project notes now.
654           *
655           * @param nonEmptyOnly If true, show notes only if non-empty.
656           * @param editable If true, the notes will be editable.
657           *
658           * @note If @c editable is true, the @c nonEmptyOnly parameter is ignored...
659           */
660         void ShowNotes(bool nonEmptyOnly, bool editable = false);
661 
662         /** Changes project title
663           *
664           * This function overrides CompileTargetBase::SetTitle.
665           * It sends additional notification event to plugins
666           * and than calls base function.
667           */
668         void SetTitle(const wxString& title) override;
669 
670         /** Access the \<Extensions\> XML node of this project
671           *
672           * This function is for advanced users only. Use at your own risk
673           * (and respect other plugins authors work under this node).
674           *
675           * @return The \<Extensions\> XML node.
676           * @note This function will never return NULL.
677           */
678         virtual TiXmlNode* GetExtensionsNode();
679 
680         /** Access the \<Extensions\> XML node of this project
681           *
682           * This function is for advanced users only. Use at your own risk
683           * (and respect other plugins authors work under this node).
684           *
685           * @return The \<Extensions\> XML node.
686           * @note This function will return NULL if the object is not created.
687           */
688         virtual const TiXmlNode* GetExtensionsNode() const;
689 
690         /** Convenience function (mainly for scripts) to add nodes/attributes
691           * under the \<Extensions\> node.
692           *
693           * It is mainly useful for scripts that can't otherwise access the XML node.
694           * For C++ code, using GetExtensionsNode() is recommended instead (which is much faster).
695           *
696           * @param stringDesc A string representation of the nodes/attributes to add/edit
697           * under \<Extensions\>.
698           * @c stringDesc is a string of the form:
699           * "node/subnode/.../+subnode:attr=val"
700           *
701           * The ":attr=val" part is optional.
702           * The node/subnode structure will be created if not there.
703           * To set more than one attribute, call this function more than once,
704           * using the same node/subnode structure.
705           * If a node begins with the "plus" sign (+), then this forces adding a new node
706           * instead of re-using the existing one (if any).
707           */
708         virtual void AddToExtensions(const wxString& stringDesc);
709 
710         /** Internal use only.
711           * Updates the internal hashmap of project files.
712           */
713         virtual void ProjectFileRenamed(ProjectFile* pf);
714 
715         /** Provides an easy way to iterate all the files belonging in this target.
716           * @return A list of files belonging in this target.
717           */
GetFilesList()718         virtual FilesList& GetFilesList() { return m_Files; }
719 
720         /** Provides an easy way to iterate all the files belonging in this target.
721           * @return A list of files belonging in this target.
722           */
GetFilesList()723         virtual const FilesList& GetFilesList() const { return m_Files; }
724 
725     private:
726         void Open();
727         void ExpandVirtualBuildTargetGroup(const wxString& alias, wxArrayString& result) const;
728         ProjectBuildTarget* AddDefaultBuildTarget();
729         int IndexOfBuildTargetName(const wxString& targetName) const;
730         wxString CreateUniqueFilename();
731         void NotifyPlugins(wxEventType type, const wxString& targetName = wxEmptyString, const wxString& oldTargetName = wxEmptyString);
732 
733         // properties
734         VirtualBuildTargetsMap m_VirtualTargets;
735         BuildTargets           m_Targets;
736         wxString               m_ActiveTarget;
737         wxString               m_LastSavedActiveTarget;
738         wxString               m_DefaultExecuteTarget;
739         mutable wxString       m_Makefile;
740         bool                   m_CustomMakefile;
741         mutable wxString       m_MakefileExecutionDir;
742 
743         std::vector<Glob> m_Globs;
744         FilesList         m_Files;
745         ProjectFileArray  m_FileArray;
746         wxArrayString     m_ExpandedNodes;
747         wxArrayString     m_SelectedNodes;
748         bool              m_Loaded;
749         wxTreeItemId      m_ProjectNode;
750 
751         wxArrayString m_VirtualFolders; // not saved, just used throughout cbProject's lifetime
752 
753         bool     m_CurrentlyLoading;
754         wxString m_CommonTopLevelPath;
755         wxString m_BasePath;
756 
757         PCHMode m_PCHMode;
758 
759         // hashmap for fast searches in cbProject::GetFileByFilename()
760         ProjectFiles        m_ProjectFilesMap; // keeps UnixFilename(ProjectFile::relativeFilename)
761         ProjectBuildTarget* m_CurrentlyCompilingTarget;
762 
763         wxDateTime m_LastModified;
764 
765         bool     m_ExtendedObjectNamesGeneration;
766         wxString m_Notes;
767         bool     m_AutoShowNotesOnLoad;
768         bool     m_CheckForExternallyModifiedFiles;
769 
770         // copy of <Extensions> element, in case certain plugins are disabled
771         // so that the contents are not lost
772         TiXmlElement* m_pExtensionsElement;
773 };
774 
775 /// Returns a string valid to be used as LD_LIBRARY_PATH (or equivalent).
776 DLLIMPORT wxString cbGetDynamicLinkerPathForTarget(cbProject *project, ProjectBuildTarget* target);
777 /// Merges to LD_LIBRARY_PATH/PATH strings together to form a new valid string.
778 DLLIMPORT wxString cbMergeLibPaths(const wxString &oldPath, const wxString &newPath);
779 
780 #endif // CBPROJECT_H
781 
782 
783