2
* This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
3
* http://www.gnu.org/licenses/gpl-3.0.html
6
#ifndef CLASSBROWSERBUILDERTHREAD_H
7
#define CLASSBROWSERBUILDERTHREAD_H
10
#include <wx/treectrl.h>
12
#include "cctreectrl.h"
13
#include "nativeparser.h"
14
#include "parser/token.h"
15
#include "parser/parser.h"
17
/** worker thread to build the symbol browser tree controls(both the top tree and the bottom tree)
18
* When the thread is started, it is waiting for the semaphore, and once the GUI post the semaphore
19
* the builder will do the dirty job, once finished, it will wait again.
21
class ClassBrowserBuilderThread : public wxThread
24
/** the builder threads' event sent to the GUI(class browser window) */
27
selectItemRequired, /// an item is selected
28
buildTreeStart, /// the thread is starting to (re)build the tree
29
buildTreeEnd /// finishing (re)build the tree
33
* @param evtHandler parent window notification events will sent to
34
* @param sem a semaphore reference which is used synchronize the GUI and the builder thread
36
ClassBrowserBuilderThread(wxEvtHandler* evtHandler, wxSemaphore& sem);
39
virtual ~ClassBrowserBuilderThread();
41
// Called from external:
42
void Init(NativeParser* np, CCTreeCtrl* treeTop, CCTreeCtrl* treeBottom,
43
const wxString& active_filename, void* user_data/*active project*/,
44
const BrowserOptions& bo, TokenTree* tt,
48
/** construct the children of the tree item
49
* Called from external, BuildTree():
51
void ExpandItem(wxTreeItemId item);
52
#ifndef CC_NO_COLLAPSE_ITEM
53
/** remove the children of the tree item
54
* Called from external, BuildTree(), RemoveInvalidNodes():
56
void CollapseItem(wxTreeItemId item);
57
#endif // CC_NO_COLLAPSE_ITEM
59
// Called from external and SelectItemRequired():
60
void SelectItem(wxTreeItemId item);
62
// Called from external:
63
void SelectItemRequired();
65
/** ask the worker thread to die
66
* Called from external: when the class browser window get destroyed
68
void RequestTermination(bool terminate = true) { m_TerminationRequested = terminate; }
71
virtual void* Entry();
73
// Called from Entry():
76
// Called from BuildTree():
77
void RemoveInvalidNodes(CCTreeCtrl* tree, wxTreeItemId parent); // recursive
79
/** recursively construct the children of node's children, which matches tokenKind
80
* Called from BuildTree():
81
* @param level the recursive level
83
void ExpandNamespaces(wxTreeItemId node, TokenKind tokenKind, int level);
85
// Called from ExpandItem():
86
bool CreateSpecialFolders(CCTreeCtrl* tree, wxTreeItemId parent);
88
// Called from CreateSpecialFolders():
89
wxTreeItemId AddNodeIfNotThere(CCTreeCtrl* tree, wxTreeItemId parent,
90
const wxString& name, int imgIndex = -1, CCTreeCtrlData* data = 0);
92
// Called from ExpandItem():
93
bool AddChildrenOf(CCTreeCtrl* tree, wxTreeItemId parent, int parentTokenIdx,
94
short int tokenKindMask = 0xffff, int tokenScopeMask = 0);
95
bool AddAncestorsOf(CCTreeCtrl* tree, wxTreeItemId parent, int tokenIdx);
96
bool AddDescendantsOf(CCTreeCtrl* tree, wxTreeItemId parent, int tokenIdx, bool allowInheritance = true);
97
// Called from ExpandItem(), SelectItem():
98
void AddMembersOf(CCTreeCtrl* tree, wxTreeItemId node);
101
// Called from AddChildrenOf(), AddAncestorsOf(), AddDescendantsOf():
102
bool AddNodes(CCTreeCtrl* tree, wxTreeItemId parent, const TokenIdxSet* tokens,
103
short int tokenKindMask = 0xffff, int tokenScopeMask = 0, bool allowGlobals = false);
105
// Called from RemoveInvalidNodes(), AddNodes(), CreateSpecialFolder():
106
// if the token should be shown, it will return true
107
bool TokenMatchesFilter(const Token* token, bool locked = false);
108
// Called from AddNodes():
109
bool TokenContainsChildrenOfKind(const Token* token, int kind);
111
// Called from BuildTree():
112
void SaveExpandedItems(CCTreeCtrl* tree, wxTreeItemId parent, int level);
113
void ExpandSavedItems(CCTreeCtrl* tree, wxTreeItemId parent, int level);
114
void SaveSelectedItem();
115
void SelectSavedItem();
118
wxEvtHandler* m_Parent;
119
wxSemaphore& m_ClassBrowserSemaphore;
121
/** Some member functions of ClassBrowserBuilderThread such as ExpandItem() can either be called
122
* from the main GUI thread(in ClassBrowser::OnTreeItemExpanding(wxTreeEvent& event)), or be
123
* called in the worker thread(in BuildTree() which is called in ClassBrowserBuilderThread::Entry()),
124
* to protect the member variables of the class(especially the wxTreeCtrl, we use the Mutex so
125
* that only one thread can access to those member variables.
127
wxMutex m_ClassBrowserBuilderThreadMutex;
128
NativeParser* m_NativeParser;
130
/** pointer to the top wxTreeCtrl */
131
CCTreeCtrl* m_CCTreeCtrlTop;
132
/** pointer to the bottom wxTreeCtrl */
133
CCTreeCtrl* m_CCTreeCtrlBottom;
135
wxString m_ActiveFilename;
136
void* m_UserData; // active project
137
BrowserOptions m_BrowserOptions;
138
TokenTree* m_TokenTree;
140
// pair of current-file-filter
141
/** symbol tree contains the tokens from those files, e.g. if we specify only show tokens
142
* from a.cpp, then m_CurrentFileSet could maybe contains two files: a.cpp and a.h
144
TokenFileSet m_CurrentFileSet;
145
/** tokens belong to the files in m_CurrentFileSet */
146
TokenIdxSet m_CurrentTokenSet;
147
/** special global scope tokens to the files in m_CurrentFileSet */
148
TokenIdxSet m_CurrentGlobalTokensSet;
151
ExpandedItemVect m_ExpandedVect;
152
SelectedItemPath m_SelectedPath;
155
/** if this variable is true, the Entry() function should return */
156
bool m_TerminationRequested;
158
wxTreeItemId m_SelectItemRequired;
161
#endif // CLASSBROWSERBUILDERTHREAD_H