forked from mapic91/JxqyScriptEidtor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJxqyStc.h
130 lines (114 loc) · 3.51 KB
/
JxqyStc.h
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
#ifndef JxqyStc_H
#define JxqyStc_H
#include "wx/stc/stc.h"
#include <map>
class JxqyScriptEditor;
typedef std::map<wxString, wxString>::iterator FunctionMapIterator;
static int CmpStringNoCase(const wxString& first, const wxString& second)
{
return first.CmpNoCase(second);
}
class JxqyStc: public wxStyledTextCtrl
{
public:
JxqyStc(JxqyScriptEditor *parent,
wxWindowID id=wxID_ANY,
const wxPoint &pos=wxDefaultPosition,
const wxSize &size=wxDefaultSize,
long style=0,
const wxString &name=wxSTCNameStr);
virtual ~JxqyStc();
// void SetDefaultFont(wxFont font)
// {
// for(int i = 0; i <= wxSTC_STYLE_DEFAULT; i++)
// {
// StyleSetFont(i, font);
// }
// }
// void SetDefaultForegroundColour(const wxColour &colour)
// {
// for(int i = 0; i <= wxSTC_STYLE_DEFAULT; i++)
// {
// StyleSetForeground(i, colour);
// }
// }
// void SetDefaultBackgroundColour(const wxColour &colour)
// {
// for(int i = 0; i <= wxSTC_STYLE_DEFAULT; i++)
// {
// StyleSetBackground(i, colour);
// }
// }
void SetFunctionKeyword(const wxString &words, bool sortedAndClean = false)
{
if(!sortedAndClean)
{
wxArrayString arrStr = wxSplit(words, wxChar(' '), wxChar(NULL));
SetFunctionKeyword(&arrStr);
}
else
{
SetKeyWords(1, words);
m_functionKeyword = words;
}
}
//Set keywors, the space in words is striped
void SetFunctionKeyword(wxArrayString *words, bool sortedAndClean = false)
{
if(!sortedAndClean)
{
StripBraceContensAndNonalpha(words);
words->Sort(CmpStringNoCase);
}
m_functionKeyword.Clear();
size_t counts = words->Count();
for(size_t i = 0; i < counts; i++)
{
m_functionKeyword += words->Item(i);
m_functionKeyword += wxT(" ");
}
SetKeyWords(1, m_functionKeyword);
}
void ClearFunctionKeyword()
{
m_functionDescribeMap.clear();
m_functionKeyword.clear();
SetKeyWords(1, m_functionKeyword);
}
void SetFunctionKeywordFromFile(const wxString &filename);
bool OpenFromFile(const wxString &filePath);
//if file path is not set, return false
bool Save();
bool SaveToFile(const wxString &filePath);
bool FilePathEmpty(){return m_filePath.IsEmpty();}
wxString GetFilePath(){return m_filePath;}
wxString GetFileName();
//Settings
void SetShowCallTip(bool show = true){m_showCallTip = show;}
void ShowLineNumber(bool show = true);
protected:
void OnMouseMove(wxMouseEvent &event);
void OnAutocompSelection(wxStyledTextEvent &event);
private:
/*
* Helper function
*/
//( ) and contents in ( ) and nonalpha is removed
wxString StripBraceContensAndNonalpha(const wxString &word);
void StripBraceContensAndNonalpha(wxArrayString *words);
wxString GetWordAtPos(int pos);
wxString FindFunctionCallTip(const wxString& kwyword);
void ShowFunctionCallTip(int pos, const wxString &word);
void OnCharAdded(wxStyledTextEvent &event);
void OnStcChange(wxStyledTextEvent &event);
wxString m_functionKeyword;
wxString m_lastCallTipWord;
std::map<wxString, wxString> m_functionDescribeMap;
bool m_autoCompSelected;
int m_autoCompBeginPos;
int m_autoCompSearchLength;
wxString m_filePath;
//Settings
bool m_showCallTip;
};
#endif // JxqyStc_H