~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/include/projectfile.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 PROJECTFILE_H
 
7
#define PROJECTFILE_H
 
8
 
 
9
#include <vector>
 
10
 
 
11
#include "settings.h"
 
12
#include "globals.h"
 
13
#include <wx/dynarray.h>
 
14
#include <wx/filename.h>
 
15
#include <wx/list.h>
 
16
#include <wx/treectrl.h>
 
17
 
 
18
#include "blockallocated.h"
 
19
 
 
20
class cbProject;
 
21
class ProjectBuildTarget;
 
22
class pfDetails;
 
23
 
 
24
WX_DECLARE_HASH_MAP(ProjectBuildTarget*, pfDetails*, wxPointerHash, wxPointerEqual, PFDMap);
 
25
 
 
26
struct pfCustomBuild
 
27
{
 
28
    pfCustomBuild() : useCustomBuildCommand(false) {}
 
29
    wxString buildCommand;
 
30
    bool useCustomBuildCommand;
 
31
};
 
32
WX_DECLARE_HASH_MAP(wxString, pfCustomBuild, wxStringHash, wxStringEqual, pfCustomBuildMap);
 
33
 
 
34
class ProjectFile;
 
35
typedef std::vector<ProjectFile*> ProjectFilesVector;
 
36
 
 
37
/** Represents a file in a Code::Blocks project. */
 
38
class ProjectFile  : public BlockAllocated<ProjectFile, 1000>
 
39
{
 
40
    public:
 
41
        /// Constructor
 
42
        ProjectFile(cbProject* prj);
 
43
        /// Destructor
 
44
        ~ProjectFile();
 
45
        
 
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)
 
51
          */
 
52
                void Rename(const wxString& new_name);
 
53
 
 
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);
 
57
 
 
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);
 
64
 
 
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);
 
68
 
 
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".
 
72
          */
 
73
        bool ShowOptions(wxWindow* parent);
 
74
 
 
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
 
78
 
 
79
        /** @return The generated object filename. */
 
80
        const wxString& GetObjName(); // returns sdk/cbProject.o
 
81
 
 
82
        /** Set the generated object filename.
 
83
          * @param name The filename for the generated object. */
 
84
        void SetObjName(const wxString& name);
 
85
 
 
86
        /** @return The parent project. */
 
87
        cbProject* GetParentProject(){ return project; }
 
88
 
 
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);
 
92
 
 
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);
 
97
 
 
98
        /** Set the visual state (modified, read-only, etc).
 
99
          * @param state The new visual state. */
 
100
                void SetFileState(FileVisualState state);
 
101
 
 
102
        /** @return The visual state (modified, read-only, etc). */
 
103
                FileVisualState GetFileState() const;
 
104
 
 
105
        /** Modify 'Use custom command to build this file' for a compilerId. */
 
106
        void SetUseCustomBuildCommand(const wxString& compilerId, bool useCustomBuildCommand);
 
107
 
 
108
        /** Modify customBuild command for a compilerId. */
 
109
        void SetCustomBuildCommand(const wxString& compilerId, const wxString& newBuildCommand);
 
110
 
 
111
        /** Read 'Use custom command to build this file' for a compilerId. */
 
112
        bool GetUseCustomBuildCommand(const wxString& compilerId);
 
113
 
 
114
        /** Read customBuild command for a compilerId. */
 
115
        wxString GetCustomBuildCommand(const wxString& compilerId);
 
116
 
 
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
 
119
          */
 
120
        wxFileName file;
 
121
 
 
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
 
124
          */
 
125
        wxString relativeFilename;
 
126
 
 
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;
 
130
 
 
131
        /** Compile flag. If it's true, the file is compiled (generates object file) else it is not. */
 
132
        bool compile;
 
133
 
 
134
        /** Link flag. If it's true, the (generated object) file is linked else it is not. */
 
135
        bool link;
 
136
 
 
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;
 
140
 
 
141
        /** If true, the file is open inside an editor. */
 
142
        bool editorOpen; // layout info
 
143
 
 
144
        /** The last known caret position in an editor for this file. */
 
145
        int editorPos; // layout info
 
146
 
 
147
        /** The last known caret line in an editor for this file. */
 
148
        int editorTopLine; // layout info
 
149
 
 
150
                /** The position of the editor-tab for this file. */
 
151
                int editorTabPos; // layout info
 
152
 
 
153
        /** A map for custom builds. Key is compiler ID, value is pfCustomBuild struct. */
 
154
        pfCustomBuildMap customBuild;
 
155
 
 
156
        /** The compiler variable used for this file (e.g CPP, CC, etc). */
 
157
        wxString compilerVar;
 
158
 
 
159
        /** An array of strings, containing the names of all the build targets this file belongs to. */
 
160
        wxArrayString buildTargets;
 
161
 
 
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
 
164
          * hierarchy. */
 
165
        wxString virtual_path;
 
166
        
 
167
        /** If this is an auto-generated file, which file is generating it? */
 
168
        ProjectFile* autoGeneratedBy;
 
169
        
 
170
        /** Auto-generated files when compiling this file */
 
171
        ProjectFilesVector generatedFiles;
 
172
    protected:
 
173
        friend class cbProject;
 
174
 
 
175
        void DoUpdateFileDetails(ProjectBuildTarget* target);
 
176
        cbProject* project;
 
177
        FileVisualState m_VisualState;
 
178
        wxTreeItemId m_TreeItemId; // set by the project when building the tree
 
179
        wxString m_ObjName;
 
180
        PFDMap m_PFDMap;
 
181
};
 
182
WX_DECLARE_LIST(ProjectFile, FilesList);
 
183
 
 
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...
 
188
  */
 
189
class pfDetails : public BlockAllocated<pfDetails, 1000>
 
190
{
 
191
    public:
 
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;
 
197
        wxString dep_file;
 
198
        wxString object_dir;
 
199
        wxString dep_dir;
 
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;
 
212
};
 
213
 
 
214
#endif // PROJECTFILE_H