-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSourceFileForm.cs
More file actions
263 lines (204 loc) · 9.11 KB
/
Copy pathSourceFileForm.cs
File metadata and controls
263 lines (204 loc) · 9.11 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
251
252
253
254
255
256
257
258
259
260
261
262
263
/*
* Copyright (C), 2007, Mathieu Kooiman < xdc@scriptorama.nl>
* $Id: SourceFileForm.cs 20 2007-04-30 07:47:59Z mathieuk $
*
* This file is part of XDebugClient.
*
* XDebugClient is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
* XDebugClient is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with XDebugClient; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI;
using WeifenLuo.WinFormsUI.Docking;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Document;
using xdc.XDebug;
namespace xdc.Forms
{
public partial class SourceFileForm : DockContent
{
static Color BreakpointColor = Color.FromArgb(255, 213, 211);
static Color CurrentLineColor = Color.FromName("Yellow");
private string _filename;
private xdc.XDebug.Client _xdebugClient;
public SourceFileForm(xdc.XDebug.Client xdebugClient, string filename)
{
this._xdebugClient = xdebugClient;
this._filename = filename;
InitializeComponent();
this.textEditor.TextEditorProperties.UseCustomLine = true;
this.textEditor.TextEditorProperties.ShowEOLMarker = false;
this.textEditor.TextEditorProperties.ShowSpaces = false;
this.textEditor.Document.ReadOnly = true;
this.textEditor.TextEditorProperties.CreateBackupCopy = false;
this.textEditor.ActiveTextAreaControl.TextArea.IconBarMargin.MouseDown += new ICSharpCode.TextEditor.MarginMouseEventHandler(OnIconBarMarginMouseDown);
this.textEditor.Document.BookmarkManager.Removed += new ICSharpCode.TextEditor.Document.BookmarkEventHandler(OnBookmarkRemoved);
this.textEditor.Document.BookmarkManager.Added += new ICSharpCode.TextEditor.Document.BookmarkEventHandler(OnBookmarkAdded);
}
// Lexikos: AutoHotkey syntax highlighting.
static SourceFileForm()
{
HighlightingManager.Manager.AddSyntaxModeFileProvider(new Syntax.AhkSyntaxModeProvider());
}
public void LoadFile(string filename)
{
this.textEditor.LoadFile(filename);
}
public string getFilename()
{
return this._filename;
}
public void setFilename(string filename)
{
this._filename = filename;
}
public void ToggleMenuItems(bool started)
{
inspectToolStripMenuItem.Enabled = started;
}
#region Utility functions
public ICSharpCode.TextEditor.Document.BookmarkManager getBookmarkManager()
{
return this.textEditor.Document.BookmarkManager;
}
// Lexikos
public ICSharpCode.TextEditor.Document.IDocument getDocument()
{
return this.textEditor.Document;
}
private void setLineColor(int lineNumber, Color color)
{
IDocument d = this.textEditor.Document;
d.CustomLineManager.RemoveCustomLine(lineNumber);
d.CustomLineManager.AddCustomLine(lineNumber, color, false);
d.RequestUpdate(
new ICSharpCode.TextEditor.TextAreaUpdate(
ICSharpCode.TextEditor.TextAreaUpdateType.SingleLine,
lineNumber
)
);
d.CommitUpdate();
}
#endregion
#region Eventhandlers
void OnIconBarMarginMouseDown(ICSharpCode.TextEditor.AbstractMargin sender, Point mousepos, MouseButtons mouseButtons)
{
if (mouseButtons != MouseButtons.Left)
return;
ICSharpCode.TextEditor.IconBarMargin marginObj = (ICSharpCode.TextEditor.IconBarMargin)sender;
Rectangle viewRect = marginObj.TextArea.TextView.DrawingPosition;
Point logicPos = marginObj.TextArea.TextView.GetLogicalPosition(0, mousepos.Y - viewRect.Top);
if (logicPos.Y >= 0 && logicPos.Y < marginObj.TextArea.Document.TotalNumberOfLines)
{
LineSegment l = marginObj.Document.GetLineSegment(logicPos.Y);
string s = marginObj.Document.GetText(l);
if (s.Trim().Length == 0)
return;
// FIXME:
// Not quite happy with this. It's hidden. Also, removing
// the breakpoint has extra code in OnBookmarkManager not
// matching up with OnBookmarkAdded.
this.textEditor.Document.BookmarkManager.AddMark
(
new Breakpoint (
this._filename,
this.textEditor.Document,
logicPos.Y
)
);
this.RedrawBreakpoints();
marginObj.Paint(marginObj.TextArea.CreateGraphics(), marginObj.TextArea.DisplayRectangle);
}
}
public void SetActiveMark(int Line)
{
ActiveMark mark = new ActiveMark(this._filename, this.textEditor.Document, Line);
this.textEditor.Document.BookmarkManager.AddMark(mark);
this.setLineColor(Line, Color.FromName("Yellow"));
this.textEditor.ActiveTextAreaControl.ScrollTo(Line + 10);
}
public void RemoveActiveMark()
{
BookmarkManager mgr = this.textEditor.Document.BookmarkManager;
foreach (Bookmark mark in mgr.Marks)
{
if (mark is ActiveMark)
{
mgr.RemoveMark(mark);
this.textEditor.Document.CustomLineManager.RemoveCustomLine(mark.LineNumber);
break;
}
}
this.RedrawBreakpoints();
}
private void RedrawBreakpoints()
{
foreach (Bookmark mark in this.textEditor.Document.BookmarkManager.Marks)
{
if (mark is Breakpoint)
{
this.setLineColor(mark.LineNumber, SourceFileForm.BreakpointColor);
}
}
}
void OnBookmarkAdded(object sender, ICSharpCode.TextEditor.Document.BookmarkEventArgs e)
{
}
void OnBookmarkRemoved(object sender, ICSharpCode.TextEditor.Document.BookmarkEventArgs e)
{
this.textEditor.Document.CustomLineManager.RemoveCustomLine(e.Bookmark.LineNumber);
this.textEditor.Document.RequestUpdate(
new ICSharpCode.TextEditor.TextAreaUpdate(
ICSharpCode.TextEditor.TextAreaUpdateType.SingleLine,
e.Bookmark.LineNumber
)
);
this.textEditor.Document.CommitUpdate();
}
#endregion
private void inspectToolStripMenuItem_Click(object sender, EventArgs e)
{
if (_xdebugClient.State == XdebugClientState.Break)
{
string s = textEditor.ActiveTextAreaControl.SelectionManager.SelectedText;
Property p = _xdebugClient.GetPropertyValue(s, 0);
if (p == null)
{
MessageBox.Show("Property '" + s + "' is not available in this scope.", "Unavailable");
return;
}
PropertyForm propForm = new PropertyForm(_xdebugClient);
propForm.LoadProperty(p, null);
propForm.Show();
}
}
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
inspectToolStripMenuItem.Enabled = (_xdebugClient.State == XdebugClientState.Break);
}
public void LoadSourceAsFile(string sourceCode)
{
this.textEditor.BeginUpdate();
// Lexikos: Use AHK syntax highlighting.
this.textEditor.Document.HighlightingStrategy = ICSharpCode.TextEditor.Document.HighlightingStrategyFactory.CreateHighlightingStrategy("AHK");
this.textEditor.Text = sourceCode;
this.textEditor.EndUpdate();
}
}
}