Code::Blocks  SVN r11506
projectmanager.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 PROJECTMANAGER_H
7 #define PROJECTMANAGER_H
8 
9 #ifndef CB_PRECOMP
10  #include "globals.h" // DEFAULT_WORKSPACE
11 #endif
12 
13 #include <wx/event.h>
14 #include <wx/dynarray.h>
15 #include <wx/hashmap.h>
16 #include <wx/treectrl.h>
17 
18 #include "cbexception.h"
19 #include "cbtreectrl.h"
20 #include "settings.h"
21 #include "manager.h"
22 
23 // forward decls
24 class cbProject;
25 class EditorBase;
26 class ProjectFile;
28 class cbWorkspace;
29 class cbAuiNotebook;
30 
31 WX_DEFINE_ARRAY(cbProject*, ProjectsArray);
32 WX_DECLARE_HASH_MAP(cbProject*, ProjectsArray*, wxPointerHash, wxPointerEqual, DepsMap); // for project dependencies
33 
34 
36 {
37  public:
38  virtual ~cbProjectManagerUI() {}
39 
40  virtual cbAuiNotebook* GetNotebook() = 0;
44  virtual cbTreeCtrl* GetTree() = 0;
46  virtual void RebuildTree() = 0;
52  virtual void FreezeTree() = 0;
60  virtual void UnfreezeTree(bool force = false) = 0;
71  virtual wxTreeItemId GetTreeSelection() = 0;
72 
73  virtual void ShowFileInTree(ProjectFile &projectFile) = 0;
74 
75  virtual void UpdateActiveProject(cbProject *oldProject, cbProject *newProject, bool refresh) = 0;
76  virtual void RemoveProject(cbProject *project) = 0;
77  virtual void BeginLoadingWorkspace() = 0;
78  virtual void CloseWorkspace() = 0;
79  virtual void FinishLoadingProject(cbProject *project, bool newAddition, FilesGroupsAndMasks* fileGroups) = 0;
80  virtual void FinishLoadingWorkspace(cbProject *activeProject, const wxString &workspaceTitle) = 0;
81 
87  virtual bool QueryCloseAllProjects() = 0;
88 
95  virtual bool QueryCloseProject(cbProject *proj, bool dontsavefiles = false) = 0;
96 
104  virtual bool QueryCloseWorkspace() = 0;
105 
111  virtual int AskForBuildTargetIndex(cbProject* project = nullptr) = 0;
118  virtual wxArrayInt AskForMultiBuildTargetIndex(cbProject* project = nullptr) = 0;
119 
124  virtual void ConfigureProjectDependencies(cbProject* base = nullptr) = 0;
125 
127  virtual void SwitchToProjectsPage() = 0;
128 };
129 
130 
142 class DLLIMPORT ProjectManager : public Mgr<ProjectManager>, public wxEvtHandler
143 {
144  static bool s_CanShutdown;
145  public:
146  friend class Mgr<ProjectManager>;
147  friend class Manager; // give Manager access to our private members
148 
149  // FIXME(obfuscated#): Extract these two in their own class
150  cbProjectManagerUI& GetUI() { return *m_ui; }
151  void SetUI(cbProjectManagerUI *ui);
152 
153  const FilesGroupsAndMasks* GetFilesGroupsAndMasks() const { return m_pFileGroups; }
154  FilesGroupsAndMasks* GetFilesGroupsAndMasks() { return m_pFileGroups; }
155 
157  static bool CanShutdown() { return s_CanShutdown; }
158 
163  wxString GetDefaultPath();
167  void SetDefaultPath(const wxString& path);
172  bool IsProjectStillOpen(cbProject* project);
177  cbProject* GetActiveProject(){ return m_pActiveProject; }
183  ProjectsArray* GetProjects(){ return m_pProjects; }
188  cbProject* IsOpen(const wxString& filename);
194  void SetProject(cbProject* project, bool refresh = true);
202  cbProject* LoadProject(const wxString& filename, bool activateIt = true);
203 
207  void ReloadProject(cbProject *project);
208 
213  bool SaveProject(cbProject* project);
220  bool SaveProjectAs(cbProject* project);
224  bool SaveActiveProject();
231  bool SaveActiveProjectAs();
235  bool SaveAllProjects();
242  bool CloseProject(cbProject* project, bool dontsave = false, bool refresh = true);
246  bool CloseActiveProject(bool dontsave = false);
250  bool CloseAllProjects(bool dontsave = false);
251 
259  cbProject* NewProject(const wxString& filename = wxEmptyString);
271  int AddFileToProject(const wxString& filename, cbProject* project = nullptr, int target = -1);
285  int AddFileToProject(const wxString& filename, cbProject* project, wxArrayInt& targets);
297  int AddMultipleFilesToProject(const wxArrayString& filelist, cbProject* project, int target = -1);
311  int AddMultipleFilesToProject(const wxArrayString& filelist, cbProject* project, wxArrayInt& targets);
316  void RemoveFileFromProject(ProjectFile* pfile, cbProject* project);
321  bool LoadWorkspace(const wxString& filename = DEFAULT_WORKSPACE);
325  bool SaveWorkspace();
330  bool SaveWorkspaceAs(const wxString& filename);
335  bool CloseWorkspace();
336 
340  bool IsLoadingProject();
344  bool IsLoadingWorkspace();
348  bool IsLoading();
352  bool IsClosingProject();
356  bool IsClosingWorkspace();
360  bool IsLoadingOrClosing();
365  static bool IsBusy();
369  cbWorkspace* GetWorkspace();
370 
379  bool AddProjectDependency(cbProject* base, cbProject* dependsOn);
385  void RemoveProjectDependency(cbProject* base, cbProject* doesNotDependOn);
390  void ClearProjectDependencies(cbProject* base);
395  void RemoveProjectFromAllDependencies(cbProject* base);
400  const ProjectsArray* GetDependenciesForProject(cbProject* base);
404  bool CausesCircularDependency(cbProject* base, cbProject* dependsOn);
405 
407  void WorkspaceChanged();
408 
413  bool BeginLoadingProject();
414 
419  void EndLoadingProject(cbProject* project);
420 
425  bool BeginLoadingWorkspace();
426 
430  void EndLoadingWorkspace();
431 
432  ProjectManager& operator=(cb_unused const ProjectManager& rhs) // prevent assignment operator
433  {
434  cbThrow(_T("Can't assign a ProjectManager* !!!"));
435  return *this;
436  }
437 
441  void SetIsRunning(cbPlugin *plugin);
442 
444  cbPlugin* GetIsRunning() const;
445 
447  cbProject* FindProjectForFile(const wxString& file, ProjectFile **resultFile,
448  bool isRelative, bool isUnixFilename);
449 
450  private:
451  ProjectManager(cb_unused const ProjectManager& rhs); // prevent copy construction
452 
453  ProjectManager();
454  ~ProjectManager() override;
455  void OnAppDoneStartup(CodeBlocksEvent& event);
456  int DoAddFileToProject(const wxString& filename, cbProject* project, wxArrayInt& targets);
457 
461  ProjectsArray* m_pProjects;
462  DepsMap m_ProjectDeps;
472 
473  DECLARE_EVENT_TABLE()
474 };
475 
476 #endif // PROJECTMANAGER_H
477 
Base class for plugins.
Definition: cbplugin.h:84
DepsMap m_ProjectDeps
ProjectManager & operator=(cb_unused const ProjectManager &rhs)
wxString m_InitialDir
cbPlugin * m_RunningPlugin
#define _T(string)
cbProjectManagerUI & GetUI()
bool m_CanSendWorkspaceChanged
const FilesGroupsAndMasks * GetFilesGroupsAndMasks() const
Represents a file in a Code::Blocks project.
Definition: projectfile.h:39
A generic Code::Blocks event.
Definition: sdk_events.h:20
ProjectsArray * m_pProjects
FilesGroupsAndMasks * GetFilesGroupsAndMasks()
WX_DECLARE_HASH_MAP(cbProject *, ProjectsArray *, wxPointerHash, wxPointerEqual, DepsMap)
#define DLLIMPORT
Definition: settings.h:16
static bool CanShutdown()
Can the app shutdown? (actually: is ProjectManager busy at the moment?)
Represents a Code::Blocks project.
Definition: cbproject.h:96
cbWorkspace * m_pWorkspace
A workspace class.
Definition: cbworkspace.h:26
virtual ~cbProjectManagerUI()
Base class that all "editors" should inherit from.
Definition: editorbase.h:30
cbProject * GetActiveProject()
Retrieve the active project.
wxString wxEmptyString
FilesGroupsAndMasks * m_pFileGroups
Definition: manager.h:183
#define cbThrow(message)
Definition: cbexception.h:42
cbProject * m_pProjectToActivate
wxArray< int > wxArrayInt
The entry point singleton for working with projects.
A notebook class This class is derived from wxAuiNotebook, to enhance its abilities.
Definition: cbauibook.h:30
DLLIMPORT const wxString DEFAULT_WORKSPACE
Definition: globals.cpp:55
cbProjectManagerUI * m_ui
WX_DEFINE_ARRAY(cbProject *, ProjectsArray)
ProjectsArray * GetProjects()
Retrieve an array of all the opened projects.
cbProject * m_pActiveProject
static bool s_CanShutdown