-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCodeEditorPaintText.Main.pas
More file actions
211 lines (180 loc) · 6.3 KB
/
CodeEditorPaintText.Main.pas
File metadata and controls
211 lines (180 loc) · 6.3 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
unit CodeEditorPaintText.Main;
interface
procedure Register;
implementation
uses
System.Classes, System.Types, System.SysUtils, Winapi.Windows, System.IOUtils, System.Generics.Collections,
ToolsAPI, ToolsAPI.Editor, Vcl.Graphics, Vcl.Controls, Vcl.GraphUtil, System.StrUtils,
ReadPALUses;
type
// TPALIDENotifier = class(TNotifierObject, IOTAIDENotifier)
// private
// procedure AfterCompile(Succeeded: Boolean);
// procedure BeforeCompile(const Project: IOTAProject; var Cancel: Boolean);
// procedure FileNotification(NotifyCode: TOTAFileNotification; const FileName: string; var Cancel: Boolean);
// public
// constructor Create;
// destructor Destroy; override;
// end;
TIDEWizard = class(TNotifierObject, IOTAWizard, IOTAIDENotifier)
private
FEditorEventsNotifier: Integer;
FNotifierIndex: Integer;
procedure PaintText(const Rect: TRect; const ColNum: SmallInt; const Text: string;
const SyntaxCode: TOTASyntaxCode; const Hilight, BeforeEvent: Boolean;
var AllowDefaultPainting: Boolean; const Context: INTACodeEditorPaintContext);
procedure AfterCompile(Succeeded: Boolean);
procedure BeforeCompile(const Project: IOTAProject; var Cancel: Boolean);
procedure FileNotification(NotifyCode: TOTAFileNotification; const FileName: string; var Cancel: Boolean);
protected
UsesDictionary: TModulesDictIntf;
public
constructor Create;
destructor Destroy; override;
function GetIDString: string;
procedure Execute;
function GetName: string;
function GetState: TWizardState;
end;
TCodeEditorNotifier = class(TNTACodeEditorNotifier)
protected
function AllowedEvents: TCodeEditorEvents; override;
end;
procedure Register;
begin
RegisterPackageWizard(TIDEWizard.Create);
end;
{ TIDEWizard }
procedure TIDEWizard.AfterCompile(Succeeded: Boolean);
begin
end;
procedure TIDEWizard.BeforeCompile(const Project: IOTAProject; var Cancel: Boolean);
begin
end;
constructor TIDEWizard.Create;
begin
inherited;
var LNotifier := TCodeEditorNotifier.Create;
var LEditorServices: INTACodeEditorServices;
if Supports(BorlandIDEServices, INTACodeEditorServices, LEditorServices) then
FEditorEventsNotifier := LEditorServices.AddEditorEventsNotifier(LNotifier)
else
FEditorEventsNotifier := -1;
var LServices: IOTAServices;
if Supports(BorlandIDEServices, IOTAServices, LServices) then
FNotifierIndex := LServices.AddNotifier(Self)
else
FNotifierIndex := -1;
UsesDictionary := TModulesDictIntf.Create([doOwnsValues]);
// On change of project reload data - so move elsewhere
// UsesDictionary.loadData('MyProject'); // Filename generated by project
// var Services: IOTAServices;
// if not BorlandIDEServices.GetService(IOTAServices, Services) then
// Exit;
// NotifierIndex := Services.AddNotifier(TPALIDENotifier.Create);
//
// UsesDictionary.runPAL('MyProject');
//
LNotifier.OnEditorPaintText := PaintText;
// LIDENotifier.FileNotification := Fil
end;
destructor TIDEWizard.Destroy;
begin
var LEditorServices: INTACodeEditorServices;
if Supports(BorlandIDEServices, INTACodeEditorServices, LEditorServices) and
(FEditorEventsNotifier <> -1) and Assigned(LEditorServices) then
LEditorServices.RemoveEditorEventsNotifier(FEditorEventsNotifier);
// var LServices: IOTAServices;
// if Supports(BorlandIDEServices, IOTAServices, LServices) and
// (FNotifierIndex <> -1) and Assigned(LServices) then
// LServices.RemoveNotifier(FNotifierIndex);
// FNotifierIndex := -1;
inherited;
end;
procedure TIDEWizard.Execute;
begin
end;
procedure TIDEWizard.FileNotification(NotifyCode: TOTAFileNotification; const FileName: string; var Cancel: Boolean);
begin
if NotifyCode in [ofnProjectDesktopLoad, ofnActiveProjectChanged] then
begin
UsesDictionary.loadData(TPath.GetFileNameWithoutExtension(FileName)); // Filename generated by project
// CodeSite.Send(TPath.GetFileNameWithoutExtension(FileName));
// UsesDictionary.ProjectName := FileName;
end;
end;
function TIDEWizard.GetIDString: string;
begin
Result := '[ED8831C6-F7F8-41DF-B93E-D503940DA689]';
end;
function TIDEWizard.GetName: string;
begin
Result := 'CodeEditor.PaintText.Uses';
end;
function TIDEWizard.GetState: TWizardState;
begin
Result := [wsEnabled];
end;
procedure TIDEWizard.PaintText(const Rect: TRect; const ColNum: SmallInt;
const Text: string; const SyntaxCode: TOTASyntaxCode; const Hilight,
BeforeEvent: Boolean; var AllowDefaultPainting: Boolean;
const Context: INTACodeEditorPaintContext);
var
unitList: TUsesList;
sulist: TStringList;
origColor: TColor;
found: Boolean;
begin
AllowDefaultPainting := True;
// Unfortunately is there now way to know that we are exactly in the uses section of the code but this is close enough.
if BeforeEvent and (SyntaxCode = atIdentifier) then
begin
// and in a uses statement
AllowDefaultPainting := True;
origColor := Context.Canvas.Font.Color;
// Set filename on change view
if UsesDictionary.TryGetValue(TPath.GetFileNameWithoutExtension(Context.FileName), unitList) then
begin
sulist := TStringList.Create;
try
sulist.DelimitedText := Text;
if suList.Count>0 then
begin
Context.Canvas.TextOut(Rect.Left, Rect.Top, Text);
for var str in sulist do
begin
Context.Canvas.Font.Color := origColor;
Context.Canvas.Font.Style := Context.Canvas.Font.Style-[fsStrikeOut];
found := false;
if unitList.getflag(str)=1 then // remove
begin
Context.Canvas.Font.Style := Context.Canvas.Font.Style+[fsStrikeOut];
found := True;
end;
if unitList.getflag(str)=2 then // move
begin
Context.Canvas.Font.Color := clGrayText;
found := True;
end;
if found then
begin
var x := Context.Canvas.TextWidth(copy(Text, 0, pos(str, Text)-1));
Context.Canvas.TextOut(Rect.Left+x, Rect.Top, str);
AllowDefaultPainting := False;
end;
end;
end
else
AllowDefaultPainting := True;
finally
sulist.Free;
end;
end;
end;
end;
{ TCodeEditorNotifier }
function TCodeEditorNotifier.AllowedEvents: TCodeEditorEvents;
begin
Result := [cevPaintTextEvents];
end;
end.