-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIDEEdit.pas
374 lines (339 loc) · 9.91 KB
/
IDEEdit.pas
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
unit IDEEdit;
interface
uses
Classes, Types, Controls, Graphics, SysUtils, SynEdit, SimpleRefactor, SynEditTextBuffer, Generics.Collections, LineInfo,
UnitMapping, LineMapping;
type
TBreakPointEvent = procedure(AUnit: string; ALine: Integer) of object;
TIDEEdit = class(TSynEdit)
private
FRefactor: TSimpleRefactor;
FBuffer: TSynEditStringList;
FLineDeleted: TStringListChangeEvent;
FLineInserted: TStringListChangeEvent;
FLinePutt: TStringListChangeEvent;
FLineInfo: TObjectList<TLineInfo>;
FOnAddBreakPoint: TBreakPointEvent;
FOnDeleteBreakPoint: TBreakPointEvent;
FD16UnitName: string;
FBreakPointColor: TColor;
FDebugCursor: Integer;
FDebugCursorColor: TColor;
FErrorCursor: Integer;
FErrorCursorColor: TColor;
procedure InternalKeyPress(Sender: TObject; var Key: Char);
procedure HandleLineDelete(Sender: TObject; Index, Count: Integer);
procedure HandleLineInserted(Sender: TObject; Index, Count: Integer);
procedure HandleLinePutt(Sender: TObject; Index, Count: Integer);
procedure InterceptBuffer();
procedure HandleGutterClick(Sender: TObject; Button: TMouseButton;
X, Y, Line: Integer; Mark: TSynEditMark);
procedure HandleGutterPaint(Sender: TObject; aLine, X, Y: Integer);
procedure HandleSpecialLineColors(Sender: TObject; Line: Integer;
var Special: Boolean; var FG, BG: TColor);
procedure DoAddBreakPoint(AUnit: string; ALine: Integer);
procedure DoDeleteBreakPoint(AUnit: string; ALine: Integer);
procedure ShiftBreakpoints(AFrom: Integer; AOffset: Integer);
procedure InitColors();
procedure SetDebugCursor(const Value: Integer);
procedure SetErrorCursor(const Value: Integer);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy(); override;
procedure SaveToFile(AFile: string);
procedure LoadFromFile(AFile: string);
procedure MarkAllLines(AState: TLineState);
procedure ClearMappings();
procedure UpdateMapping(AMapping: TUnitMapping);
property D16UnitName: string read FD16UnitName write FD16UnitName;
property Refactor: TSimpleRefactor read FRefactor;
property BreakPointColor: TColor read FBreakPointColor write FBreakPointColor;
property DebugCursorColor: TColor read FDebugCursorColor write FDebugCursorColor;
property ErrorCursorColor: TColor read FErrorCursorColor write FErrorCursorColor;
property DebugCursor: Integer read FDebugCursor write SetDebugCursor;
property ErrorCursor: Integer read FErrorCursor write SetErrorCursor;
property OnAddBreakPoint: TBreakPointEvent read FOnAddBreakPoint write FOnAddBreakPoint;
property OnDeleteBreakPoint: TBreakPointEvent read FOnDeleteBreakPoint write FOnDeleteBreakPoint;
end;
implementation
uses
SynD16Highlighter, SynEditSearch, BreakPoint, ColorFunctions;
{ TIDEEdit }
procedure TIDEEdit.ClearMappings;
var
LInfo: TLineInfo;
begin
for LInfo in FLineInfo do
begin
LInfo.Mapping.Clear();
end;
end;
constructor TIDEEdit.Create(AOwner: TComponent);
begin
inherited;
FLineInfo := TObjectList<TLineInfo>.Create();
InterceptBuffer();
FRefactor := TSimpleRefactor.Create(Self);
Highlighter := TSynD16Syn.Create(Self);
Name := 'IDEEdit';
Gutter.ShowLineNumbers := True;
WantTabs := True;
TabWidth := 2;
Options := Options - [eoSmartTabs];
DoubleBuffered := True;
SearchEngine := TSynEditSearch.Create(Self);
OnKeyPress := InternalKeyPress;
OnGutterPaint := HandleGutterPaint;
OnGutterClick := HandleGutterClick;
OnSpecialLineColors := HandleSpecialLineColors;
FDebugCursor := -1;
FErrorCursor := -1;
InitColors();
end;
destructor TIDEEdit.Destroy;
begin
FRefactor.Free;
FLineInfo.Free;
inherited;
end;
procedure TIDEEdit.DoAddBreakPoint(AUnit: string; ALine: Integer);
begin
if Assigned(FOnAddBreakPoint) then
begin
FOnAddBreakPoint(AUnit, ALine);
end;
end;
procedure TIDEEdit.DoDeleteBreakPoint(AUnit: string; ALine: Integer);
begin
if Assigned(FOnDeleteBreakPoint) then
begin
FOnDeleteBreakPoint(AUnit, ALine);
end;
end;
procedure TIDEEdit.HandleGutterClick(Sender: TObject; Button: TMouseButton; X,
Y, Line: Integer; Mark: TSynEditMark);
begin
if X > 16 then Exit;
if FLineInfo.Items[Line-1].BreakPointState = bpsNone then
begin
FLineInfo.Items[Line-1].BreakPointState := bpsNormal;
DoAddBreakPoint(FD16UnitName, Line);
end
else
begin
FLineInfo.Items[Line-1].BreakPointState := bpsNone;
DoDeleteBreakPoint(FD16UnitName, Line);
end;
Self.Repaint();
end;
procedure TIDEEdit.HandleGutterPaint(Sender: TObject; aLine, X, Y: Integer);
var
LColor: TColor;
begin
if (FLineInfo.Count > 0) then
begin
if Assigned(BookMarkOptions.BookmarkImages) then
begin
if FLineInfo.Items[ALine-1].BreakPointState <> bpsNone then
begin
BookMarkOptions.BookmarkImages.Draw(Canvas, X, Y, 1);
end
else
begin
if (FLineInfo.Items[ALine-1].IsPossibleBreakPoint) then
begin
BookMarkOptions.BookmarkImages.Draw(Canvas, X, Y, 0);
end;
end;
if aLine = DebugCursor then
begin
BookMarkOptions.BookmarkImages.Draw(Canvas, X, Y, 2);
end;
end;
if FLineInfo.Items[ALine-1].State = ltNone then Exit;
if FLineInfo.Items[ALine-1].State = ltModified then
begin
LColor := clYellow;
end
else
begin
LColor := clGreen;
end;
Canvas.Brush.Color := LColor;
Canvas.Pen.Color := LColor;
Canvas.Rectangle(x + 20, y, x+25, y+17);
end;
end;
procedure TIDEEdit.HandleLineDelete(Sender: TObject; Index, Count: Integer);
var
I: Integer;
begin
if Assigned(FLineDeleted) then
begin
FLineDeleted(Sender, Index, Count);
end;
ShiftBreakpoints(Index + (Count-1), -Count);
for i := Index + (Count-1) downto Index do
begin
FLineInfo.Delete(i);
end;
end;
procedure TIDEEdit.HandleLineInserted(Sender: TObject; Index, Count: Integer);
var
i: Integer;
begin
if Assigned(FLineInserted) then
begin
FLineInserted(Sender, Index, Count);
end;
ShiftBreakpoints(Index, Count);
for i := Index to Index + (Count-1) do
begin
FLineInfo.Insert(Index, TLineInfo.Create(ltModified));
end;
end;
procedure TIDEEdit.HandleLinePutt(Sender: TObject; Index, Count: Integer);
var
i: Integer;
begin
if Assigned(FLinePutt) then
begin
FLinePutt(Sender, Index, Count);
end;
for i := Index to Index + (Count-1) do
begin
FLineInfo.Items[i].State := ltModified;
end;
//in case we have an errorcursor, remove it on changing
FErrorCursor := -1;
end;
procedure TIDEEdit.HandleSpecialLineColors(Sender: TObject; Line: Integer;
var Special: Boolean; var FG, BG: TColor);
begin
if FLineInfo.Items[Line - 1].BreakPointState <> bpsNone then
begin
FG := clNone;
BG := FBreakPointColor;
Special := True;
end
else
begin
if DebugCursor = Line then
begin
FG := clNone;
BG := DebugCursorColor;
Special := True;
end
else
begin
if ErrorCursor = Line then
begin
FG := clNone;
BG := ErrorCursorColor;
Special := True;
end;
end;
end;
end;
procedure TIDEEdit.InitColors;
begin
//c7c7ff
FBreakPointColor := HexToTColor('c7c7ff');
ActiveLineColor := HexToTColor('F0F0F0');//HexToTColor('D6D6D6');
DebugCursorColor := HexToTColor('cc9999');
ErrorCursorColor := clRed;
end;
procedure TIDEEdit.InterceptBuffer;
begin
FBuffer := Lines as TSynEditStringList;
FLineDeleted := FBuffer.OnDeleted;
FLineInserted := FBuffer.OnInserted;
FLinePutt := FBuffer.OnPutted;
FBuffer.OnDeleted := HandleLineDelete;
FBuffer.OnInserted := HandleLineInserted;
FBuffer.OnPutted := HandleLinePutt;
end;
procedure TIDEEdit.InternalKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
begin
FRefactor.CompleteBlocks();
end;
end;
procedure TIDEEdit.LoadFromFile(AFile: string);
begin
Lines.LoadFromFile(AFile);
MarkAllLines(ltNone);
end;
procedure TIDEEdit.MarkAllLines(AState: TLineState);
var
i: Integer;
begin
for i := 0 to FLineInfo.Count - 1 do
begin
if (FLineInfo.Items[i].State <> ltNone) or (AState = ltNone) then
begin
FLineInfo.Items[i].State := AState;
end;
end;
Repaint();
end;
procedure TIDEEdit.SaveToFile(AFile: string);
begin
Lines.SaveToFile(AFile);
MarkAllLines(ltSaved);
end;
procedure TIDEEdit.SetDebugCursor(const Value: Integer);
begin
FDebugCursor := Value;
if FDebugCursor > -1 then
begin
CaretY := Value;
end;
Repaint();
end;
procedure TIDEEdit.SetErrorCursor(const Value: Integer);
begin
FErrorCursor := Value;
if FErrorCursor > -1 then
begin
CaretY := Value;
end;
Repaint();
end;
procedure TIDEEdit.ShiftBreakpoints(AFrom: Integer; AOffset: Integer);
var
i: Integer;
begin
for i := AFrom to FLineInfo.Count - 1 do
begin
if FLineInfo.Items[i].BreakPointState <> bpsNone then
begin
DoDeleteBreakPoint(FD16UnitName, i + 1);
DoAddBreakPoint(FD16UnitName, i + AOffset + 1);
end;
end;
end;
procedure TIDEEdit.UpdateMapping(AMapping: TUnitMapping);
var
LMapping: TLineMapping;
LBreak: TBreakPoint;
begin
ClearMappings();
for LMapping in AMapping.Mapping do
begin
if (LMapping.UnitLine > 0) and (LMapping.UnitLine <= FLineInfo.Count) then
begin
FLineInfo.Items[LMapping.UnitLine - 1].Mapping.Assign(LMapping);
FLineInfo.Items[LMapping.UnitLine - 1].BreakPointState := bpsNone;
end;
end;
for LBreak in AMapping.BreakPoints do
begin
if (LBreak.UnitLine > 0) and (LBreak.UnitLine < FLineInfo.Count) then
begin
FLineInfo.Items[LBreak.UnitLine - 1].BreakPointState := bpsNormal;
end;
end;
end;
end.