1
//////////////////////////////////////////////////////////////////////////////
2
//////////////////////////////////////////////////////////////////////////////
4
// copyright : (C) 2008 by Eran Ifrah
5
// file name : manager.h
7
// -------------------------------------------------------------------------
10
// / __ \ | | | | (_) |
11
// | / \/ ___ __| | ___| | _| |_ ___
12
// | | / _ \ / _ |/ _ \ | | | __/ _ )
13
// | \__/\ (_) | (_| | __/ |___| | || __/
14
// \____/\___/ \__,_|\___\_____/_|\__\___|
18
// This program is free software; you can redistribute it and/or modify
19
// it under the terms of the GNU General Public License as published by
20
// the Free Software Foundation; either version 2 of the License, or
21
// (at your option) any later version.
23
//////////////////////////////////////////////////////////////////////////////
24
//////////////////////////////////////////////////////////////////////////////
28
#include "acceltabledlg.h"
29
#include "singleton.h"
31
#include "wx/string.h"
35
#include "context_base.h"
36
#include "ctags_manager.h"
37
#include "workspace.h"
40
#include "compile_request.h"
41
#include "clean_request.h"
43
#include "filehistory.h"
44
#include "browse_record.h"
46
#include "breakpointsmgr.h"
47
#include "debuggermanager.h"
48
#include "debuggerobserver.h"
55
// ====================================================================
57
// ====================================================================
58
class Manager : public wxEvtHandler, public IDebuggerObserver
60
friend class Singleton<Manager>;
61
wxString m_startupDir;
62
ShellCommand *m_shellProcess;
63
AsyncExeCmd *m_asyncExeCmd;
64
FileHistory m_recentFiles;
65
FileHistory m_recentWorkspaces;
66
BreakptMgr* m_breakptsmgr;
67
bool m_dbgCanInteract;
68
bool m_dbgWaitingFirstBp; // TODO: This doesn't seem to be used for anything :/
69
QuickWatchDlg *m_quickWatchDlg;
73
wxString m_installDir;
74
std::list<QueueCommand> m_buildQueue;
75
bool m_workspceClosing;
81
* check if a workspace is open
84
* true if a workspace is open
86
bool IsWorkspaceOpen() const;
89
* Create new file on the disk and open it in the main editor
90
* \param fileName file full path (including directories)
91
* \param vdFullPath path of the virtual directory
93
bool AddNewFileToProject(const wxString &fileName, const wxString &vdFullPath, bool openIt = true);
96
* Add an existing file to workspace
97
* \param fileName file full path (including directories)
98
* \param vdFullPath path of the virtual directory
100
bool AddFileToProject(const wxString &fileName, const wxString &vdFullPath, bool openIt = false);
108
void AddFilesToProject(const wxArrayString &files, const wxString &vdFullPath, wxArrayString &actualAdded);
110
void SetWorkspaceClosing(const bool& inShutdown) {
111
this->m_workspceClosing = inShutdown;
114
const bool& IsWorkspaceClosing() const {
115
return m_workspceClosing;
118
bool IsShutdownInProgress() const {
122
void SetShutdownInProgress(bool b) {
128
* Free all singleton objects initialised in CodeLite
134
* Return a pointer to the breakpoints manager
136
BreakptMgr* GetBreakpointsMgr();
140
* Create a workspace with a given name and path
149
void CreateWorkspace(const wxString &name, const wxString &path);
152
* \brief create an empty project
153
* \param name project name
154
* \param path project file path
155
* \param type project type, Project::STATIC_LIBRARY, Project::DYNAMIC_LIBRARY or Project::EXECUTABLE
157
void CreateProject(ProjectData &data);
160
* Open an existing workspace by path
162
void OpenWorkspace(const wxString &path);
165
* Close the current workspace and save all
168
void CloseWorkspace();
171
* \brief close the currently opened workspace and reload it without saving any modifications made to it, if no workspace is opened, this functiond does anything
173
void ReloadWorkspace();
176
* Return a tree for the file view of a single project
178
ProjectTreePtr GetProjectFileViewTree(const wxString &projectName);
181
* Return all project names under this workspace
183
void GetProjectList(wxArrayString &list);
186
* find project by name
188
ProjectPtr GetProject(const wxString &name) const;
191
* Add an existing project to the workspace. If no workspace is open,
192
* this function does nothing
193
* \param path project file path name to add
195
void AddProject(const wxString &path);
198
* Remove the a project from the workspace
199
* \param name project name to remove
200
* \return true on success false otherwise
202
bool RemoveProject(const wxString &name) ;
205
* \return active project name
207
wxString GetActiveProjectName();
210
* Set project as active
211
* \param name project name to set as active
213
void SetActiveProject(const wxString &name);
216
* Add new virtual directory to the workspace.
217
* \param virtualDirFullPath a dot separated string of the new virtual directory full path up to the parent project
218
* for example: to add a new VD name VD3 under: Project1->VD1->VD2 path should contain: Project1.VD1.VD2.VD3
220
void AddVirtualDirectory(const wxString &virtualDirFullPath);
223
* Remove virtual directory from the workspace.
224
* \param virtualDirFullPath a dot separated string of the virtual directory to be removed
226
void RemoveVirtualDirectory(const wxString &virtualDirFullPath);
231
void SaveWorkspace();
234
* remove file from the workspace
235
* \param fileName the full path of the file to be removed
236
* \param vdFullPath the files' virtual directory path (including project)
238
bool RemoveFile(const wxString &fileName, const wxString &vdFullPath);
241
* Return a project working directory
242
* \param project project name
244
wxString GetProjectCwd(const wxString &project) const;
247
* Show output pane and set focus to focusWin
248
* \param focusWin tab name to set the focus
249
* \return return true if the output pane was hidden and this function forced it to appear. false if the window was already
250
* shown and nothing needed to be done
252
bool ShowOutputPane(wxString focusWin = wxEmptyString, bool commit = true );
255
* Show the debugger pane
257
void ShowDebuggerPane(bool commit = true);
260
* Show the main toolbar
261
* \param show set to true to show it, false otherwise
263
void ShowMainToolbar(bool show = true);
266
* Show the workspace pane and set focus to focusWin
267
* \param focusWin tab name to set the focus
269
void ShowWorkspacePane(wxString focusWin = wxEmptyString, bool commit = true );
274
void HidePane(const wxString &paneName, bool commit = true);
277
* Return project settings by name
278
* \param projectName project name
279
* \return project settings smart prt
281
ProjectSettingsPtr GetProjectSettings(const wxString &projectName) const;
284
* Set project settings
285
* \param projectName project name
286
* \param settings settings to update
288
void SetProjectSettings(const wxString &projectName, ProjectSettingsPtr settings);
291
* Return the workspace build matrix
293
BuildMatrixPtr GetWorkspaceBuildMatrix() const;
296
* Set or update the workspace build matrix
298
void SetWorkspaceBuildMatrix(BuildMatrixPtr matrix);
301
* Hide/Show all panes. This function saves the current prespective and
302
* then hides all panes, when called again, all panes are restored
307
* create default new compiler
308
* \return true on success false when a compiler with this name already exist
310
bool CreateDefaultNewCompiler(const wxString &name);
314
* \param name compiler to delete
316
bool DeleteCompiler(const wxString &name);
319
* Return a list of availanle project templates
322
void GetProjectTemplateList(std::list<ProjectPtr> &list);
325
* Save project as template
326
* \param proj project to duplicate
327
* \param name the template name
328
* \param description project short description
330
void SaveProjectTemplate(ProjectPtr proj, const wxString &name, const wxString &description);
333
* Set lite editor's startup directory
335
void SetStarupDirectory(const wxString &path) {
340
* Get lite editor's startup directory
342
const wxString &GetStarupDirectory() const {
347
* \brief return the OS specific installation directory
349
const wxString &GetInstallDir() const {
354
* \brief set the installation directory
356
void SetInstallDir(const wxString &dir) {
361
* Popup project dependencies dialog
362
* \param projectName project name
364
void PopupProjectDependsDlg(const wxString &projectName);
367
* \brief when building using custom build, execute the makefile generation command provided by the user
368
* \param project project to execute it for
370
void RunCustomPreMakeCommand(const wxString &project);
373
* compile single file from a given
376
void CompileFile(const wxString &project, const wxString &fileName, bool preprocessOnly = false);
379
* Stop current build process
384
* return true if a compilation is in process (either clean or build)
386
bool IsBuildInProgress() const;
389
* return true a child program is running
391
bool IsProgramRunning() const;
394
* Kill child program which is running
399
* Execute the project with no debugger
401
void ExecuteNoDebug(const wxString &projectName);
404
* Return the active's project build configuration that matches
405
* the workspace selected configuration
407
BuildConfigPtr GetActiveProjectBuildConf();
410
* use an external database
412
void SetExternalDatabase(const wxFileName &dbname);
415
* close the currenlty open extern database
416
* and free all its resources
418
void CloseExternalDatabase();
421
* return list of files that are part of the workspace
423
void GetWorkspaceFiles(std::vector<wxFileName> &files, bool absPath = false);
426
* check if a file is part of the workspace
427
* \param fileName the file name in absolute path
429
bool IsFileInWorkspace(const wxString &fileName);
432
* Search for (non-absolute) file in the workspace
434
wxFileName FindFile(const wxString &fileName, const wxString &project = wxEmptyString);
437
* Rebuild the database by removing all entries from the database
438
* that belongs to a given project, and then re-index all files
439
* \param projectName project to re-tag
441
void RetagProject(const wxString &projectName);
446
void RetagWorkspace();
449
* \brief retag a given file
452
void RetagFile(const wxString &filename);
455
* Add a debug message in the debug output window
458
void DebugMessage(wxString msg);
461
* Add a message in the output tab window
464
void OutputMessage(wxString msg);
467
* return the project name that 'fullPathFileName' belogs to. if 2 matches were found, return
468
* the first one, or empty string if no match was found
470
wxString GetProjectNameByFile(const wxString &fullPathFileName);
473
* Import a workspace from a makefile
475
// void ImportFromMakefile(const wxString &path);
478
* add single file to the recently opened files
480
void AddToRecentlyOpenedFiles(const wxString &fileName);
483
* return the FileHistory object that holds the recently opened
486
FileHistory &GetRecentlyOpenedFilesClass() {
487
return m_recentFiles;
491
* \brief clear the recent workspace / files list
493
void ClearFileHistory();
496
* \brief return true if the file history is not empty, false otherwise
498
bool HasHistory() const;
501
* add workspace file to the recently opened workspaces
503
void AddToRecentlyOpenedWorkspaces(const wxString &fileName);
506
* return the FileHistory object that holds the recently opened
509
FileHistory &GetRecentlyOpenedWorkspacesClass() {
510
return m_recentWorkspaces;
514
* Return list of recently opened files from the configuration file
515
* \param files [output]
517
void GetRecentlyOpenedFiles(wxArrayString &files);
520
* Return list of recently opened workspaces from the configuration file
521
* \param files [output]
523
void GetRecentlyOpenedWorkspaces(wxArrayString &files);
525
bool MoveFileToVD(const wxString &fileName, const wxString &srcVD, const wxString &targetVD);
528
* return list of files in absolute path of a given project
529
* \param project project name
531
void GetProjectFiles(const wxString &project, wxArrayString &files);
534
* return list of files in absolute path of the whole workspace
536
void GetWorkspaceFiles(wxArrayString &files);
539
* Import a MS Solution file and open it in the editor
540
* \param path path to the .sln file
542
void ImportMSVSSolution(const wxString &path);
545
* Expand variables to their real value, if expanding fails
546
* the return value is same as input. The variable is expanded
547
* in the project context
549
wxString ExpandVariables(const wxString &expression, ProjectPtr proj);
552
* return true if the last buid ended successfully
554
bool IsBuildEndedSuccessfully() const;
557
* \brief update the path & name of the build tool
558
* on windows, try to locate make, followed by mingw32-make
560
void UpdateBuildTools();
563
* \brief open file specified by the 'fileName' parameter and append 'text'
565
* \param fileName file to open. Must be in full path
566
* \param text string text to append
567
* \return true on success, false otherwise
569
bool OpenFileAndAppend(const wxString &fileName, const wxString &text);
572
* \brief update the menu bar accelerators
574
void UpdateMenuAccelerators();
577
* \brief load accelerator table from the configuration section
581
void LoadAcceleratorTable(const wxArrayString &files, MenuItemDataMap &map);
584
* \brief retrun map of the accelerator table. the StringMap maps between the actions and their accelerators
586
void GetAcceleratorMap(MenuItemDataMap& accelMap);
589
* \brief retrun map of the default accelerator table
591
void GetDefaultAcceleratorMap(MenuItemDataMap& accelMap);
594
* \brief parse list of files and construct a token database that will be used for refactoring
595
* \param word word to search
596
* \param files list of files to parse
598
void BuildRefactorDatabase(const wxString& word, CppTokensMap &l);
601
* \brief replace list of toens representd by li with 'word'
605
void ReplaceInFiles(const wxString &word, std::list<CppToken> &li);
607
void UpdateMenu(wxMenu *menu, MenuItemDataMap &accelMap, std::vector< wxAcceleratorEntry > &accelVec);
610
* \brief return the project excution command as it appears in the project settings
612
* \param wd the working directory that the command should be running from
613
* \param considerPauseWhenExecuting when set to true (default) CodeLite will take into consideration the value set in the project
614
* settings 'Pause when execution ends'
615
* \return project execution command or wxEmptyString if the project does not exist
617
wxString GetProjectExecutionCommand(const wxString &projectName, wxString &wd, bool considerPauseWhenExecuting = true);
620
* \brief add build job to the internal queue
623
void PushQueueCommand(const QueueCommand &buildInfo);
626
* \brief process the next build job
628
void ProcessCommandQueue();
631
* \brief build the entire workspace. This operation is equal to
632
* manually right clicking on each project in the workspace and selecting
635
void BuildWorkspace();
638
* \brief clean the entire workspace. This operation is equal to
639
* manually right clicking on each project in the workspace and selecting
642
void CleanWorkspace();
645
* \brief clean, followed by buid of the entire workspace. This operation is equal to
646
* manually right clicking on each project in the workspace and selecting
649
void RebuildWorkspace();
652
* \brief test if pane_name is resides in the wxAuiManager and is visible
653
* \param pane_name pane name to search for
654
* \return true on success (exist in the AUI manager and visible), false otherwise
656
bool IsPaneVisible(const wxString &pane_name);
658
//--------------------------------------------------------------------
659
//IDebuggerObserver implementation. These set of functions are called
660
//from the debugger whenever event occurs there
661
//--------------------------------------------------------------------
662
void UpdateStopped();
663
void UpdateAddLine(const wxString &line);
664
void UpdateRemoteTargetConnected(const wxString &line);
665
void UpdateBpAdded(const int internal_id, const int debugger_id);
666
void UpdateFileLine(const wxString &file, int lineno);
667
void UpdateGotControl(DebuggerReasons reason);
668
void UpdateLostControl();
669
void UpdateLocals(TreeNode<wxString, NodeData> *tree);
670
void UpdateExpression(const wxString &expression, const wxString &evaluated);
671
void UpdateQuickWatch(const wxString &expression, TreeNode<wxString, NodeData> *tree);
672
void UpdateStackList(const StackEntryArray &stackArray);
674
//----------------------------------------------------------
676
//----------------------------------------------------------
677
void DbgStart(long pid = wxNOT_FOUND);
679
void DbgDoSimpleCommand(int cmd);
680
void DbgMarkDebuggerLine(const wxString &fileName, int lineno);
681
void DbgUnMarkDebuggerLine();
682
void DbgQuickWatch(const wxString &expression, bool useTipWin = false, long pos = wxNOT_FOUND);
683
void DbgCancelQuickWatchTip();
684
void DbgSetFrame(int frame, int lineno);
685
void DbgSetThread(long threadId);
686
bool DbgCanInteract() {
687
return m_dbgCanInteract;
689
void UpdateDebuggerPane();
690
void SetMemory(const wxString &address, size_t count, const wxString &hex_value);
694
virtual ~Manager(void);
695
void OnProcessEnd(wxProcessEvent &event);
696
void DoShowPane(const wxString &pane);
697
void DoSetupWorkspace(const wxString &path);
698
void DoCleanProject(const QueueCommand &buildInfo);
699
void DoBuildProject(const QueueCommand &buildInfo);
700
void DoCustomBuild(const QueueCommand &buildInfo);
701
void DoCmdWorkspace(int cmd);
702
void DoGetAccelFiles(wxArrayString &files);
706
* Update the symbol & file tress
708
void RebuildFileView();
711
* Remove a file from the gui tree
713
void RemoveFileFromSymbolTree(const wxFileName &fileName, const wxString &project);
715
void DumpMenu( wxMenu *menu, const wxString &label, wxString &content );
717
wxFileName FindFile ( const wxArrayString& files, const wxFileName &fn );
720
typedef Singleton<Manager> ManagerST;