~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

Viewing changes to src/plugins/codecompletion/classbrowserbuilderthread.h

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

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 General Public License, version 3
 
3
 * http://www.gnu.org/licenses/gpl-3.0.html
 
4
 */
 
5
 
 
6
#ifndef CLASSBROWSERBUILDERTHREAD_H
 
7
#define CLASSBROWSERBUILDERTHREAD_H
 
8
 
 
9
#include <wx/thread.h>
 
10
#include <wx/treectrl.h>
 
11
 
 
12
#include "cctreectrl.h"
 
13
#include "nativeparser.h"
 
14
#include "parser/token.h"
 
15
#include "parser/parser.h"
 
16
 
 
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.
 
20
 */
 
21
class ClassBrowserBuilderThread : public wxThread
 
22
{
 
23
public:
 
24
    /** the builder threads' event sent to the GUI(class browser window) */
 
25
    enum EThreadEvent
 
26
    {
 
27
        selectItemRequired,  /// an item is selected
 
28
        buildTreeStart,      /// the thread is starting to (re)build the tree
 
29
        buildTreeEnd         /// finishing (re)build the tree
 
30
    };
 
31
 
 
32
    /** constructor
 
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
 
35
     */
 
36
    ClassBrowserBuilderThread(wxEvtHandler* evtHandler, wxSemaphore& sem);
 
37
 
 
38
    /** destructor */
 
39
    virtual ~ClassBrowserBuilderThread();
 
40
 
 
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,
 
45
              int idThreadEvent);
 
46
 
 
47
 
 
48
    /** construct the children of the tree item
 
49
     *  Called from external, BuildTree():
 
50
     */
 
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():
 
55
     */
 
56
    void CollapseItem(wxTreeItemId item);
 
57
#endif // CC_NO_COLLAPSE_ITEM
 
58
 
 
59
    // Called from external and SelectItemRequired():
 
60
    void SelectItem(wxTreeItemId item);
 
61
 
 
62
    // Called from external:
 
63
    void SelectItemRequired();
 
64
 
 
65
    /** ask the worker thread to die
 
66
     *  Called from external: when the class browser window get destroyed
 
67
     */
 
68
    void RequestTermination(bool terminate = true) { m_TerminationRequested = terminate; }
 
69
 
 
70
protected:
 
71
    virtual void* Entry();
 
72
 
 
73
    // Called from Entry():
 
74
    void BuildTree();
 
75
 
 
76
    // Called from BuildTree():
 
77
    void RemoveInvalidNodes(CCTreeCtrl* tree, wxTreeItemId parent); // recursive
 
78
 
 
79
    /** recursively construct the children of node's children, which matches tokenKind
 
80
     *  Called from BuildTree():
 
81
     *  @param level the recursive level
 
82
     */
 
83
    void ExpandNamespaces(wxTreeItemId node, TokenKind tokenKind, int level);
 
84
 
 
85
    // Called from ExpandItem():
 
86
    bool CreateSpecialFolders(CCTreeCtrl* tree, wxTreeItemId parent);
 
87
 
 
88
    // Called from CreateSpecialFolders():
 
89
    wxTreeItemId AddNodeIfNotThere(CCTreeCtrl* tree, wxTreeItemId parent,
 
90
                                   const wxString& name, int imgIndex = -1, CCTreeCtrlData* data = 0);
 
91
 
 
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);
 
99
 
 
100
private:
 
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);
 
104
 
 
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);
 
110
 
 
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();
 
116
 
 
117
protected:
 
118
    wxEvtHandler*    m_Parent;
 
119
    wxSemaphore&     m_ClassBrowserSemaphore;
 
120
 
 
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.
 
126
     */
 
127
    wxMutex          m_ClassBrowserBuilderThreadMutex;
 
128
    NativeParser*    m_NativeParser;
 
129
 
 
130
    /** pointer to the top wxTreeCtrl */
 
131
    CCTreeCtrl*      m_CCTreeCtrlTop;
 
132
    /** pointer to the bottom wxTreeCtrl */
 
133
    CCTreeCtrl*      m_CCTreeCtrlBottom;
 
134
 
 
135
    wxString         m_ActiveFilename;
 
136
    void*            m_UserData; // active project
 
137
    BrowserOptions   m_BrowserOptions;
 
138
    TokenTree*       m_TokenTree;
 
139
 
 
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
 
143
     */
 
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;
 
149
 
 
150
private:
 
151
    ExpandedItemVect m_ExpandedVect;
 
152
    SelectedItemPath m_SelectedPath;
 
153
    bool             m_InitDone;
 
154
 
 
155
    /** if this variable is true, the Entry() function should return */
 
156
    bool             m_TerminationRequested;
 
157
    int              m_idThreadEvent;
 
158
    wxTreeItemId     m_SelectItemRequired;
 
159
};
 
160
 
 
161
#endif // CLASSBROWSERBUILDERTHREAD_H