-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfrmUsagesList.pas
98 lines (87 loc) · 2.3 KB
/
frmUsagesList.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
unit frmUsagesList;
interface
uses
Dialogs, nppp_forms, StdCtrls, Classes, Controls, Vcl.ComCtrls,
JediUtils;
type
TFormUsagesList = class(TNppDockingForm)
lvList: TListView;
procedure lvListData(Sender: TObject; Item: TListItem);
private
FList: TArray<TJediDefinition>;
procedure lvUsagesListDblClick(Sender: TObject);
procedure UpdateTexts;
public
procedure SetUsagesList(list: TArray<TJediDefinition>);
end;
implementation
uses
System.SysUtils, nppp_baseplugin, PyJediPlugin, System.StrUtils;
{$R *.dfm}
function GetFileLine(const fn: string; line: integer): string;
var
fs: TFileStream;
sr: TStreamReader;
begin
fs := TFileStream.Create(fn, fmOpenRead);
sr := TStreamReader.Create(fs);
try
repeat
sr.ReadLine;
Dec(line);
until line = 0;
Result := sr.ReadLine;
finally
sr.Free;
fs.Free;
end;
end;
procedure TFormUsagesList.lvListData(Sender: TObject; Item: TListItem);
const
cPositionFmt = '%d,%d';
begin
with FList[Item.Index] do
begin
Item.Caption := Trim(text);
Item.SubItems.Add(Format(cPositionFmt, [line + 1, column]));
Item.SubItems.Add(typeStr);
Item.SubItems.Add(full_name);
Item.SubItems.Add(module_path);
end;
end;
procedure TFormUsagesList.lvUsagesListDblClick(Sender: TObject);
begin
if lvList.ItemIndex < 0 then
Exit;
with FList[lvList.ItemIndex] do
(FNPPPlugin as TPyJediPlugin).GoToPos(module_path, line, column);
end;
procedure TFormUsagesList.SetUsagesList(list: TArray<TJediDefinition>);
resourcestring
sFormCaption = 'PyJedy usages of "%s"';
begin
FList := list;
UpdateTexts;
Self.Caption := Format(sFormCaption, [FNPPPlugin.NppBaseFuncs.getCurrentWord]);
lvList.OnDblClick := lvUsagesListDblClick;
lvList.Items.Count := Length(FList);
lvList.Repaint;
end;
procedure TFormUsagesList.UpdateTexts;
var
i: integer;
begin
for i := 0 to Length(FList) - 1 do
with FList[i] do
if FileExists(module_path)
and not SameText(module_path, FNPPPlugin.NppBaseFuncs.getFullCurrentPath) then
text := GetFileLine(module_path, line)
else
begin
text := FNPPPlugin.ScintillaFuncs.getTextRange(
FNPPPlugin.ScintillaFuncs.getLineStartPosition(line),
FNPPPlugin.ScintillaFuncs.getLineEndPosition(line)
);
end;
end;
end.