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
13
#include <wx/dynarray.h>
14
#include <wx/filename.h>
16
#include <wx/treectrl.h>
18
#include "blockallocated.h"
21
class ProjectBuildTarget;
24
WX_DECLARE_HASH_MAP(ProjectBuildTarget*, pfDetails*, wxPointerHash, wxPointerEqual, PFDMap);
28
pfCustomBuild() : useCustomBuildCommand(false) {}
29
wxString buildCommand;
30
bool useCustomBuildCommand;
32
WX_DECLARE_HASH_MAP(wxString, pfCustomBuild, wxStringHash, wxStringEqual, pfCustomBuildMap);
35
typedef std::vector<ProjectFile*> ProjectFilesVector;
37
/** Represents a file in a Code::Blocks project. */
38
class ProjectFile : public BlockAllocated<ProjectFile, 1000>
42
ProjectFile(cbProject* prj);
46
/** Change filename of the file. Note that this does only update
47
* the internal variables. It does NOT rename the file on disk...
48
* It updates @c file, @c relativeFilename, @c relativeToCommonTopLevelPath
49
* and finally marks the parent project as modified.
50
* @note This allows renaming only the LAST part of the filename (the name and extension)
52
void Rename(const wxString& new_name);
54
/** Make this file belong to an additional build target.
55
* @param targetName The build target to add this file to. */
56
void AddBuildTarget(const wxString& targetName);
58
/** Rename a build target this file belongs in.
59
* @param oldTargetName The build target's old name.
60
* @param newTargetName The build target's new name.
61
* @note This does *not* change the build target's name, just the reference in the project file.
62
* This is actually used by cbProject::RenameBuildTarget(). */
63
void RenameBuildTarget(const wxString& oldTargetName, const wxString& newTargetName);
65
/** Remove this file from the specified build target.
66
* @param targetName The build target's name to remove this file from. */
67
void RemoveBuildTarget(const wxString& targetName);
69
/** Show the file properties dialog.
70
* @param parent The parent window for the dialog (can be NULL).
71
* @return True if the user closed the dialog with "OK", false if closed it with "Cancel".
73
bool ShowOptions(wxWindow* parent);
75
// take as example the relative file sdk/cbProject.cpp
76
/** @return The relative (to the project) filename without extension. */
77
wxString GetBaseName() const; // returns sdk/cbProject
79
/** @return The generated object filename. */
80
const wxString& GetObjName(); // returns sdk/cbProject.o
82
/** Set the generated object filename.
83
* @param name The filename for the generated object. */
84
void SetObjName(const wxString& name);
86
/** @return The parent project. */
87
cbProject* GetParentProject(){ return project; }
89
/** This is called automatically when adding/removing build targets.
90
* @param target A pointer to the build target whose file details should be updated. */
91
void UpdateFileDetails(ProjectBuildTarget* target = 0);
93
/** Access the file details for this project file for the specified target.
94
* @param target A pointer to the build target whose file details should be updated.
95
* @return The details for this project file for the specified build target. */
96
const pfDetails& GetFileDetails(ProjectBuildTarget* target);
98
/** Set the visual state (modified, read-only, etc).
99
* @param state The new visual state. */
100
void SetFileState(FileVisualState state);
102
/** @return The visual state (modified, read-only, etc). */
103
FileVisualState GetFileState() const;
105
/** Modify 'Use custom command to build this file' for a compilerId. */
106
void SetUseCustomBuildCommand(const wxString& compilerId, bool useCustomBuildCommand);
108
/** Modify customBuild command for a compilerId. */
109
void SetCustomBuildCommand(const wxString& compilerId, const wxString& newBuildCommand);
111
/** Read 'Use custom command to build this file' for a compilerId. */
112
bool GetUseCustomBuildCommand(const wxString& compilerId);
114
/** Read customBuild command for a compilerId. */
115
wxString GetCustomBuildCommand(const wxString& compilerId);
117
/** The full filename of this file. Usually you need to read from it and never write to it.
118
* @note Use Rename() if you want to change this or else bad things will happen
122
/** The relative (to the project) filename of this file. Usually you need to read from it and never write to it.
123
* @note Use Rename() if you want to change this or else bad things will happen
125
wxString relativeFilename;
127
/** The relative filename to the common top-level path.
128
* This is used mainly for the tree, as this is guaranteed to not contain '..' */
129
wxString relativeToCommonTopLevelPath;
131
/** Compile flag. If it's true, the file is compiled (generates object file) else it is not. */
134
/** Link flag. If it's true, the (generated object) file is linked else it is not. */
137
/** The weight. This is a number between 0 and 100 (defaults to 50).
138
* Files with smaller weights are compiled earlier than those with larger weights. */
139
unsigned short int weight;
141
/** If true, the file is open inside an editor. */
142
bool editorOpen; // layout info
144
/** The last known caret position in an editor for this file. */
145
int editorPos; // layout info
147
/** The last known caret line in an editor for this file. */
148
int editorTopLine; // layout info
150
/** The position of the editor-tab for this file. */
151
int editorTabPos; // layout info
153
/** A map for custom builds. Key is compiler ID, value is pfCustomBuild struct. */
154
pfCustomBuildMap customBuild;
156
/** The compiler variable used for this file (e.g CPP, CC, etc). */
157
wxString compilerVar;
159
/** An array of strings, containing the names of all the build targets this file belongs to. */
160
wxArrayString buildTargets;
162
/** A string that represents the virtual folder this file will appear in.
163
* This is a relative path which doesn't have to exist in the filesystem
165
wxString virtual_path;
167
/** If this is an auto-generated file, which file is generating it? */
168
ProjectFile* autoGeneratedBy;
170
/** Auto-generated files when compiling this file */
171
ProjectFilesVector generatedFiles;
173
friend class cbProject;
175
void DoUpdateFileDetails(ProjectBuildTarget* target);
177
FileVisualState m_VisualState;
178
wxTreeItemId m_TreeItemId; // set by the project when building the tree
182
WX_DECLARE_LIST(ProjectFile, FilesList);
184
/** This is a helper class that caches various filenames for one ProjectFile.
185
* These include the source filename, the generated object filename,
186
* relative and absolute versions of the above, etc.
187
* Mainly used by the compiler...
189
class pfDetails : public BlockAllocated<pfDetails, 1000>
192
pfDetails(ProjectBuildTarget* target, ProjectFile* pf);
193
void Update(ProjectBuildTarget* target, ProjectFile* pf);
194
// all the members below, are set in the constructor
195
wxString source_file;
196
wxString object_file;
200
wxString object_file_flat;
201
// those below, have no UnixFilename() applied, nor QuoteStringIfNeeded()
202
wxString source_file_native;
203
wxString object_file_native;
204
wxString dep_file_native;
205
wxString object_dir_native;
206
wxString dep_dir_native;
207
wxString source_file_absolute_native;
208
wxString object_file_absolute_native;
209
wxString object_file_flat_absolute_native;
210
wxString dep_file_absolute_native;
211
wxString object_file_flat_native;
214
#endif // PROJECTFILE_H