forked from fdorg/flashdevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethodCallTip.cs
More file actions
250 lines (215 loc) · 7.65 KB
/
MethodCallTip.cs
File metadata and controls
250 lines (215 loc) · 7.65 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
using System.Drawing;
using System.Windows.Forms;
using ScintillaNet;
namespace PluginCore.Controls
{
public class MethodCallTip: RichToolTip
{
public delegate void UpdateCallTipHandler(ScintillaControl sender, int position);
// events
public event UpdateCallTipHandler OnUpdateCallTip;
public static string HLTextStyleBeg = "[B]";
public static string HLTextStyleEnd = "[/B]";
public static string HLBgStyleBeg = "[BGCOLOR=#000:OVERLAY]";
public static string HLBgStyleEnd = "[/BGCOLOR]";
// state
protected string currentText;
protected int currentHLStart;
protected int currentHLEnd;
protected bool isActive;
protected int memberPos;
protected int startPos;
protected int currentPos;
protected int deltaPos;
protected int currentLine;
public MethodCallTip(IMainForm mainForm): base(mainForm)
{
}
public bool CallTipActive
{
get { return isActive; }
}
public bool Focused
{
get { return toolTipRTB.Focused; }
}
public override void Hide()
{
if (isActive)
{
isActive = false;
UITools.Manager.UnlockControl(); // unlock keys
}
faded = false;
currentText = null;
currentHLStart = -1;
currentHLEnd = -1;
base.Hide();
}
public bool CheckPosition(int position)
{
return position == currentPos;
}
public void CallTipShow(ScintillaControl sci, int position, string text)
{
CallTipShow(sci, position, text, true);
}
public void CallTipShow(ScintillaControl sci, int position, string text, bool redraw)
{
if (toolTip.Visible && position == memberPos && text == currentText)
return;
toolTip.Visible = false;
currentText = text;
SetText(text, true);
memberPos = position;
startPos = memberPos + toolTipRTB.Text.IndexOf('(');
currentPos = sci.CurrentPos;
deltaPos = startPos - currentPos + 1;
currentLine = sci.CurrentLine;
PositionControl(sci);
// state
isActive = true;
faded = false;
UITools.Manager.LockControl(sci);
}
public void PositionControl(ScintillaControl sci)
{
// compute control location
Point p = new Point(sci.PointXFromPosition(memberPos), sci.PointYFromPosition(memberPos));
p = ((Form)PluginBase.MainForm).PointToClient(((Control)sci).PointToScreen(p));
toolTip.Left = p.X /*+ sci.Left*/;
bool hasListUp = !CompletionList.Active || CompletionList.listUp;
if (currentLine > sci.LineFromPosition(memberPos) || !hasListUp) toolTip.Top = p.Y - toolTip.Height /*+ sci.Top*/;
else toolTip.Top = p.Y + UITools.Manager.LineHeight(sci) /*+ sci.Top*/;
// Keep on control area
if (toolTip.Right > ((Form)PluginBase.MainForm).ClientRectangle.Right)
{
toolTip.Left = ((Form)PluginBase.MainForm).ClientRectangle.Right - toolTip.Width;
}
toolTip.Show();
toolTip.BringToFront();
}
public void CallTipSetHlt(int start, int end)
{
CallTipSetHlt(start, end, true);
}
public void CallTipSetHlt(int start, int end, bool forceRedraw)
{
if (currentHLStart == start && currentHLEnd == end)
return;
currentHLStart = start;
currentHLEnd = end;
if (start != end)
{
string savedRawText = rawText;
try
{
rawText = rawText.Substring(0, start)
+ HLBgStyleBeg + HLTextStyleBeg
+ rawText.Substring(start, end - start)
+ HLTextStyleEnd + HLBgStyleEnd
+ rawText.Substring(end);
Redraw();
}
catch { }
rawText = savedRawText;
}
else
{
Redraw();
}
}
#region Keys handling
public void OnChar(ScintillaControl sci, int value)
{
currentPos++;
UpdateTip(sci);
}
public new void UpdateTip(ScintillaControl sci)
{
if (OnUpdateCallTip != null) OnUpdateCallTip(sci, currentPos);
}
public bool HandleKeys(ScintillaControl sci, Keys key)
{
switch (key)
{
case Keys.Multiply:
case Keys.Subtract:
case Keys.Divide:
case Keys.Decimal:
case Keys.Add:
return false;
case Keys.Up:
if (!CompletionList.Active) sci.LineUp();
return false;
case Keys.Down:
if (!CompletionList.Active) sci.LineDown();
return false;
case Keys.Up | Keys.Shift:
sci.LineUpExtend();
return false;
case Keys.Down | Keys.Shift:
sci.LineDownExtend();
return false;
case Keys.Left | Keys.Shift:
sci.CharLeftExtend();
return false;
case Keys.Right | Keys.Shift:
sci.CharRightExtend();
return false;
case Keys.Right:
if (!CompletionList.Active)
{
sci.CharRight();
currentPos = sci.CurrentPos;
if (sci.CurrentLine != currentLine) Hide();
else if (OnUpdateCallTip != null) OnUpdateCallTip(sci, currentPos);
}
return true;
case Keys.Left:
if (!CompletionList.Active)
{
sci.CharLeft();
currentPos = sci.CurrentPos;
if (currentPos < startPos) Hide();
else
{
if (sci.CurrentLine != currentLine) Hide();
else if (OnUpdateCallTip != null) OnUpdateCallTip(sci, currentPos);
}
}
return true;
case Keys.Back:
sci.DeleteBack();
currentPos = sci.CurrentPos;
if (currentPos + deltaPos < startPos) Hide();
else if (OnUpdateCallTip != null) OnUpdateCallTip(sci, currentPos);
return true;
case Keys.Tab:
case Keys.Space:
return false;
default:
if (!CompletionList.Active) Hide();
return false;
}
}
#endregion
#region Controls fading on Control key
private static bool faded;
internal void FadeOut()
{
if (faded) return;
faded = true;
//base.Hide();
toolTip.Visible = false;
}
internal void FadeIn()
{
if (!faded) return;
faded = false;
//base.Show();
toolTip.Visible = true;
}
#endregion
}
}