File: context_base.h

package info (click to toggle)
codelite 12.0+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 95,112 kB
  • sloc: cpp: 424,040; ansic: 18,284; php: 9,569; lex: 4,186; yacc: 2,820; python: 2,294; sh: 312; makefile: 51; xml: 13
file content (170 lines) | stat: -rw-r--r-- 6,286 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2008 by Eran Ifrah
// file name            : context_base.h
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#ifndef CONTEXT_BASE_H
#define CONTEXT_BASE_H

#include "wx/string.h"
#include <wx/stc/stc.h>
#include "smart_ptr.h"
#include "wx/filename.h"
#include "lexer_configuration.h"
#include <vector>
#include "entry.h"
#include <set>
#include "macros.h"

class LEditor;

/**
 * \ingroup LiteEditor
 * \brief This class defines the language context of the editor
 *
 * \version 1.0
 * first version
 *
 * \date 04-30-2007
 *
 * \author Eran
 *
 */
class ContextBase : public wxEvtHandler
{
protected:
    LEditor* m_container;
    wxString m_name;
    wxString m_selectedWord;
    std::vector<wxMenuItem*> m_dynItems;
    wxStringSet_t m_completionTriggerStrings;

protected:
    void SetName(const wxString& name) { m_name = name; }
    void DoApplySettings(LexerConf::Ptr_t lexPtr);
    void PrependMenuItem(wxMenu* menu, const wxString& text, wxObjectEventFunction func, int eventId = -1);
    void PrependMenuItem(wxMenu* menu, const wxString& text, int id);
    void PrependMenuItemSeparator(wxMenu* menu);

    /**
     * @brief search for the next 'what' in the editor
     */
    int FindNext(const wxString& what, int& pos, bool wholePage = false);
    /**
     * @brief search for the next 'what' in the editor
     */
    int FindPrev(const wxString& what, int& pos, bool wholePage = false);

public:
    // ctor-dtor
    ContextBase(LEditor* container);
    ContextBase(const wxString& name);
    virtual ~ContextBase();

    /**
     * @brief return true if str is a string that should trigger a code completion
     */
    virtual bool IsStringTriggerCodeComplete(const wxString& str) const;

    /**
     * @brief when the context is requested to display a code completion for keywords
     * this functions determines which keyword set to display ( there are up to 5, indexed from: 0-4)
     */
    virtual int GetActiveKeywordSet() const { return 0; }

    /**
     * Return the context parent control
     */
    LEditor& GetCtrl() { return *m_container; }

    LEditor& GetCtrl() const { return *m_container; }
    /**
     * Return the context name
     */
    const wxString& GetName() const { return m_name; }

    // every Context derived class must implement the following methods
    virtual ContextBase* NewInstance(LEditor* container) = 0;
    virtual void ApplySettings() = 0;

    // functions with default implementation:
    virtual bool IsDefaultContext() const { return true; }
    virtual void OnCallTipClick(wxStyledTextEvent& event) { event.Skip(); }
    virtual void OnCalltipCancel(){};
    virtual void OnDwellEnd(wxStyledTextEvent& event) { event.Skip(); }
    virtual void OnDbgDwellEnd(wxStyledTextEvent& event) { event.Skip(); }
    virtual void OnDwellStart(wxStyledTextEvent& event) { event.Skip(); }
    virtual void OnDbgDwellStart(wxStyledTextEvent& event) { event.Skip(); }
    virtual void OnKeyDown(wxKeyEvent& event) { event.Skip(); }
    virtual void AddMenuDynamicContent(wxMenu* WXUNUSED(menu)) {}
    virtual void RemoveMenuDynamicContent(wxMenu* WXUNUSED(menu)) {}
    virtual void OnSciUpdateUI(wxStyledTextEvent& WXUNUSED(event)) {}
    virtual void OnFileSaved() {}
    virtual void OnEnterHit() {}
    virtual void RetagFile() {}
    virtual void OnUserTypedXChars(const wxString& word);
    virtual wxString CallTipContent() { return wxEmptyString; }
    virtual void SetActive() {}
    virtual bool IsCommentOrString(long WXUNUSED(pos)) { return false; }
    /**
     * @brief return true if the caret is at a block comment
     */
    virtual bool IsAtBlockComment() const { return false; }
    /**
     * @brief return true if the caret is at a line comment
     */
    virtual bool IsAtLineComment() const { return false; }
    virtual void AutoIndent(const wxChar&);
    virtual void AutoAddComment();
    virtual void CompleteWord() {}
    virtual void CodeComplete(long pos = wxNOT_FOUND) { wxUnusedVar(pos); }
    virtual void GotoDefinition() {}
    virtual TagEntryPtr GetTagAtCaret(bool scoped, bool impl) { return NULL; }
    virtual wxString GetCurrentScopeName() { return wxEmptyString; }
    virtual void SemicolonShift() {}
    virtual int DoGetCalltipParamterIndex();

    // ctrl-click style navigation support
    virtual int GetHyperlinkRange(int pos, int& start, int& end);
    virtual void GoHyperlink(int start, int end, int type, bool alt);

    // override this method if you wish to provide context based right click menu
    virtual wxMenu* GetMenu();

    /**
     * @brief colour tokens in the current editor
     * @param workspaceTokens list of token that are associated with the workspace
     */
    virtual void ColourContextTokens(const wxString& workspaceTokensStr, const wxString& localsTokensStr)
    {
        wxUnusedVar(workspaceTokensStr);
        wxUnusedVar(localsTokensStr);
    }

    /**
     * @brief process any idle actions by the context
     */
    virtual void ProcessIdleActions() {}
};

typedef SmartPtr<ContextBase> ContextBasePtr;
#endif // CONTEXT_BASE_H