forked from Alexey-T/CudaLister
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform_find.pas
162 lines (138 loc) · 3.01 KB
/
form_find.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
unit form_find;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ButtonPanel,
StdCtrls, IniFiles, file_proc;
type
{ TfmFind }
TfmFind = class(TForm)
bCount: TButton;
bMarkAll: TButton;
bFind: TButton;
bCancel: TButton;
bRep: TButton;
bRepAll: TButton;
chkInSel: TCheckBox;
chkFromCaret: TCheckBox;
chkConfirm: TCheckBox;
chkRep: TCheckBox;
chkRegex: TCheckBox;
chkBack: TCheckBox;
chkCase: TCheckBox;
chkWords: TCheckBox;
edFind: TComboBox;
edRep: TEdit;
Label1: TLabel;
procedure bFindClick(Sender: TObject);
procedure chkRegexChange(Sender: TObject);
procedure chkRepChange(Sender: TObject);
procedure FormShow(Sender: TObject);
private
procedure Update; reintroduce;
{ private declarations }
public
procedure LoadSearchText;
procedure SaveSearchText;
{ public declarations }
end;
var
fmFind: TfmFind;
SearchTextIniFilename: string = '';
SearchTextSection: string = 'SearchText';
implementation
{$R *.lfm}
{ TfmFind }
procedure TfmFind.LoadSearchText;
var
I: TIniFile;
L: TStringList;
X: Integer;
V: String;
begin
//ShowMessage(ChangeFileExt(_GetDllFilename, '.ini'));
SearchTextIniFilename:= ChangeFileExt(_GetDllFilename, '.ini');
I:= TIniFile.Create(SearchTextIniFilename);
try
L:= TStringList.Create;
try
edFind.Items.Clear;
//edFind.ItemHeight:=32;
I.ReadSection(SearchTextSection, L);
for X:= 0 to L.Count-1 do begin
V:= I.ReadString(SearchTextSection, L[X], '');
if V <> '' then edFind.Items.Add(V);
end;
finally
L.Free;
end;
finally
I.Free;
end;
end;
procedure TfmFind.SaveSearchText;
var
I: TIniFile;
H, X ,J: Integer;
V: String;
begin
I:= TIniFile.Create(SearchTextIniFilename);
J:= 0;
try
if edFind.Text <> '' then
begin
I.WriteString(SearchTextSection, IntToStr(0), edFind.Text);
if edFind.Items.Count < 9 then H:=edFind.Items.Count else H:=9;
for X:= 0 to H - 1 do
begin
V:= edFind.Items[X];
if V <> edFind.Text then
begin
I.WriteString(SearchTextSection, IntToStr(J + 1), V);
J:= J + 1;
end;
end;
end;
finally
I.Free;
end;
end;
procedure TfmFind.chkRegexChange(Sender: TObject);
begin
Update;
end;
procedure TfmFind.bFindClick(Sender: TObject);
begin
SaveSearchText;
end;
procedure TfmFind.chkRepChange(Sender: TObject);
begin
Update;
end;
procedure TfmFind.FormShow(Sender: TObject);
begin
LoadSearchText;
Update;
end;
procedure TfmFind.Update;
var
rep: boolean;
begin
rep:= chkRep.Checked;
chkWords.Enabled:= not chkRegex.Checked;
chkBack.Enabled:= not chkRegex.Checked;
chkConfirm.Enabled:= rep;
edRep.Enabled:= rep;
bFind.Visible:= not rep;
bRep.Visible:= rep;
bRepAll.Visible:= rep;
if rep then
Caption:= '替换'
else
Caption:= '查找';
if rep then
bRep.Default:= true
else
bFind.Default:= true;
end;
end.