-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrmFindReplace.pas
427 lines (362 loc) · 12.6 KB
/
FrmFindReplace.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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
(* ************************************************************
KEYNOTE: MOZILLA PUBLIC LICENSE STATEMENT.
-----------------------------------------------------------
The contents of this file are subject to the Mozilla Public
License Version 1.1 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of
the License at http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
implied. See the License for the specific language governing
rights and limitations under the License.
The Original Code is KeyNote 1.0.
The Initial Developer of the Original Code is Marek Jedlinski
<eristic@lodz.pdi.net> (Poland).
Portions created by Marek Jedlinski are
Copyright (C) 2000, 2001. All Rights Reserved.
-----------------------------------------------------------
Contributor(s):
-----------------------------------------------------------
History:
-----------------------------------------------------------
Released: 30 June 2001
-----------------------------------------------------------
URLs:
- for OpenSource development:
http://keynote.sourceforge.net
- original author's software site:
http://www.lodz.pdi.net/~eristic/free/index.html
http://go.to/generalfrenetics
Email addresses (at least one should be valid)
<eristic@lodz.pdi.net>
<cicho@polbox.com>
<cicho@tenbit.pl>
************************************************************ *)
unit FrmFindReplace;
interface
uses
Windows, Messages, SysUtils,
Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls,
gf_misc, kn_Info, kn_Const,
kn_NoteObj, kn_FileObj,
Placemnt, kn_TabSelect,
gf_strings, kn_INI, TntStdCtrls, ComCtrls95;
type
//TReplaceEvent = procedure( ReplaceAll : boolean ) of object;
TReplaceEvent = procedure( ReplaceAll : boolean ); //*1
TNotifyEvent_ = procedure(Sender: TObject); //*1
type
TForm_FindReplace = class(TForm)
Button_Find: TTntButton;
Button_Cancel: TTntButton;
Combo_Text: TTntComboBox;
GroupBox_Opts: TTntGroupBox;
CheckBox_MatchCase: TTntCheckBox;
CheckBox_EntireScope: TTntCheckBox;
FormPlacement: TFormPlacement;
CheckBox_WholeWordsOnly: TTntCheckBox;
CheckBox_AllTabs: TTntCheckBox;
CheckBox_AllNodes: TTntCheckBox;
Combo_Replace: TTntComboBox;
Button_Replace: TTntButton;
Button_ReplaceAll: TTntButton;
CheckBox_HiddenNodes: TTntCheckBox;
CheckBox_SelectedText: TTntCheckBox;
CheckBox_Confirm: TTntCheckBox;
CheckBox_Wrap: TTntCheckBox;
Pages: TPage95Control;
Tab_Find: TTab95Sheet;
Tab_Replace: TTab95Sheet;
TntLabel1: TTntLabel;
TntLabel2: TTntLabel;
TntLabel3: TTntLabel;
procedure PagesChange(Sender: TObject);
procedure CheckBox_AllNodesClick(Sender: TObject);
procedure CheckBox_ScopeChanged(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure Combo_TextChange(Sender: TObject);
procedure Button_FindClick(Sender: TObject);
procedure Button_CancelClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDeactivate(Sender: TObject);
private
{ Private declarations }
procedure CreateParams(var Params: TCreateParams); override;
function GetModeReplace: boolean;
procedure SetModeReplace(value: boolean);
public
{ Public declarations }
OK_Click : boolean;
Initializing : boolean;
myFindOptions : TFindOptions;
ReplaceEvent : TReplaceEvent;
FormCloseEvent : TNotifyEvent_;
FindEvent : TNotifyEvent_;
myNotifyproc : TBooleanNotifyProc;
procedure OptionsToForm;
procedure FormToOptions;
procedure HistoryToCombo;
procedure ComboToHistory;
property ModeReplace:Boolean read GetModeReplace write SetModeReplace;
end;
implementation
uses WideStrUtils, kn_Global, kn_MacroMng, kn_FindReplaceMng, kn_Main;
{$R *.DFM}
procedure TForm_FindReplace.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.WndParent := _MainFormHandle;
end; // CreateParams
procedure TForm_FindReplace.FormCreate(Sender: TObject);
begin
OK_Click := false;
Initializing := true;
myNotifyProc := nil;
ReplaceEvent := nil;
FormCloseEvent := nil;
with FormPlacement do
begin
UseRegistry := _FORMPOS_USE_REGISTRY;
IniFileName := _FORMPOS_INIFILENAME;
end;
InitializeFindOptions( myFindOptions );
end; // CREATE
procedure TForm_FindReplace.FormActivate(Sender: TObject);
var
enableReplace: boolean;
begin
if assigned( myNotifyProc ) then
myNotifyProc( false );
if Initializing then
begin
Initializing := false;
OptionsToForm;
Button_Find.Enabled := ( Combo_Text.Text <> '' );
if IsRecordingMacro then begin // Opciones limitadas
CheckBox_AllTabs.Enabled := False;
CheckBox_EntireScope.Enabled := False;
CheckBox_AllNodes.Enabled := False;
CheckBox_HiddenNodes.Enabled := False;
CheckBox_Wrap.Enabled:= False;
CheckBox_Confirm.Enabled := False;
end;
end
else begin
if not myFindOptions.AllTabs then
if (ActiveNote <> StartNote) or
(not myFindOptions.AllNodes) and ((ActiveNote.Kind = ntTree) and (TTreeNote(ActiveNote).TV.Selected <> StartNode)) then
myFindOptions.FindNew := true;
end;
if Form_Main.NoteIsReadOnly( ActiveNote, true) then begin
modeReplace:= False;
Tab_Replace.Enabled:= False;
end
else
Tab_Replace.Enabled:= True;
Pages.Refresh;
enableReplace:= Tab_Replace.Enabled and Button_Find.Enabled;
Button_Replace.Enabled := enableReplace;
Button_ReplaceAll.Enabled := enableReplace;
myFindOptions.SelectedText:= False;
if ( ActiveNote.Editor.SelLength > 0 ) then begin
CheckBox_SelectedText.Enabled:= True;
myFindOptions.SelectedText:= not IsWord(Trim(ActiveNote.Editor.SelTextW));
end
else
CheckBox_SelectedText.Enabled:= False;
CheckBox_SelectedText.Checked:= myFindOptions.SelectedText;
end; // ACTIVATE
procedure TForm_FindReplace.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
OK_Click := false;
end; // CLOSE QUERY
procedure TForm_FindReplace.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case key of
27 : if (( shift = [] ) and ( not
( Combo_Text.DroppedDown or Combo_Replace.DroppedDown )
)) then
begin
key := 0;
OK_Click := false;
Close;
end;
end;
end; // KEY DOWN
procedure TForm_FindReplace.HistoryToCombo;
begin
Combo_Text.Items.BeginUpdate;
try
DelimTextToWStrs( Combo_Text.Items, myFindOptions.History, HISTORY_SEPARATOR );
finally
Combo_Text.Items.EndUpdate;
Combo_Text.SetFocus;
end;
Combo_Replace.Items.BeginUpdate;
try
DelimTextToWStrs( Combo_Replace.Items, myFindOptions.ReplaceHistory, HISTORY_SEPARATOR );
finally
Combo_Replace.Items.EndUpdate;
end;
end;
// HistoryToCombo
procedure TForm_FindReplace.CheckBox_AllNodesClick(Sender: TObject);
begin
CheckBox_HiddenNodes.Enabled := CheckBox_AllNodes.Checked;
myFindOptions.FindNew := true;
end;
procedure TForm_FindReplace.CheckBox_ScopeChanged(Sender: TObject);
begin
myFindOptions.FindNew := true;
end;
procedure TForm_FindReplace.ComboToHistory;
var
i : integer;
begin
if ( Combo_Text.Text <> '' ) then
begin
myFindOptions.History := WideQuotedStr( Combo_Text.Text, '"' );
for i := 0 to pred( Combo_Text.Items.Count ) do
begin
if ( i >= myFindOptions.HistoryMaxCnt ) then break;
if ( Combo_Text.Items[i] <> Combo_Text.Text ) then
myFindOptions.History := myFindOptions.History + HISTORY_SEPARATOR + WideQuotedStr( Combo_Text.Items[i], '"' );
end;
end;
if ( Combo_Replace.Text <> '' ) then
begin
myFindOptions.ReplaceHistory := WideQuotedStr( Combo_Replace.Text, '"' );
for i := 0 to pred( Combo_Replace.Items.Count ) do
begin
if ( i >= myFindOptions.HistoryMaxCnt ) then break;
if ( Combo_Replace.Items[i] <> Combo_Replace.Text ) then
myFindOptions.ReplaceHistory := myFindOptions.ReplaceHistory + HISTORY_SEPARATOR + WideQuotedStr( Combo_Replace.Items[i], '"' );
end;
end;
end; // ComboToHistory
procedure TForm_FindReplace.OptionsToForm;
begin
HistoryToCombo;
with myFindOptions do
begin
CheckBox_MatchCase.Checked := MatchCase;
CheckBox_WholeWordsOnly.Checked := WholeWordsOnly;
Combo_Text.Text := Pattern;
Combo_Replace.Text := ReplaceWith;
Combo_Text.SelectAll;
CheckBox_AllTabs.Checked := AllTabs and not IsRecordingMacro;
CheckBox_EntireScope.Checked := EntireScope and not IsRecordingMacro;
CheckBox_AllNodes.Checked := AllNodes and not IsRecordingMacro;
CheckBox_HiddenNodes.Checked := HiddenNodes and not IsRecordingMacro;
CheckBox_Wrap.Checked:= Wrap and not IsRecordingMacro;
CheckBox_Confirm.Checked := ReplaceConfirm and not IsRecordingMacro;
end;
end;
function TForm_FindReplace.GetModeReplace: boolean;
begin
Result:= (Pages.ActivePage = Tab_Replace);
end;
procedure TForm_FindReplace.SetModeReplace(value: boolean);
begin
if value then
Pages.ActivePage := Tab_Replace
else
Pages.ActivePage := Tab_Find;
PagesChange(nil);
end;
procedure TForm_FindReplace.PagesChange(Sender: TObject);
var
showReplace: boolean;
begin
showReplace:= modeReplace;
Button_Replace.Visible := showReplace;
Button_ReplaceAll.Visible := showReplace;
Combo_Replace.Visible := showReplace;
CheckBox_Confirm.Visible:= showReplace;
CheckBox_SelectedText.Visible:= showReplace;
if showReplace then
Caption:= Tab_Replace.Caption
else
Caption:= Tab_Find.Caption;
end;
// OptionsToForm
procedure TForm_FindReplace.FormToOptions;
begin
with myFindOptions do
begin
AllNodes := CheckBox_AllNodes.Checked;
AllTabs := CheckBox_AllTabs.Checked;
EntireScope := CheckBox_EntireScope.Checked;
MatchCase := CheckBox_MatchCase.Checked;
WholeWordsOnly := ( CheckBox_WholeWordsOnly.Enabled and CheckBox_WholeWordsOnly.Checked );
ReplaceConfirm := CheckBox_Confirm.Checked;
Pattern := Combo_Text.Text;
ReplaceWith := Combo_Replace.Text;
HiddenNodes:= CheckBox_HiddenNodes.Checked;
SelectedText:= CheckBox_SelectedText.Checked;
Wrap := CheckBox_Wrap.Checked;
end;
// ComboToHistory;
end; // FormToOptions
procedure TForm_FindReplace.Combo_TextChange(Sender: TObject);
var
enableReplace: boolean;
begin
Button_Find.Enabled := ( Combo_Text.Text <> '' );
enableReplace:= Tab_Replace.Enabled and Button_Find.Enabled;
Button_Replace.Enabled := enableReplace;
Button_ReplaceAll.Enabled := enableReplace;
CheckBox_WholeWordsOnly.Enabled := IsWord( Combo_Text.Text );
myFindOptions.FindNew := True;
end;
procedure TForm_FindReplace.Button_FindClick(Sender: TObject);
begin
if (( Combo_Text.Text <> '' ) and ( Combo_Text.Items.IndexOf( Combo_Text.Text ) < 0 )) then
Combo_Text.Items.Insert( 0, Combo_Text.Text );
if (( Combo_Replace.Text <> '' ) and ( Combo_Replace.Items.IndexOf( Combo_Replace.Text ) < 0 )) then
Combo_Replace.Items.Insert( 0, Combo_Replace.Text );
FormToOptions;
OK_Click := true;
case ( sender as TButton ).Tag of
0 : // Find
if assigned( FindEvent ) then begin
myFindOptions.SelectedText:= False;
FindEvent( self );
end;
1 : // Replace
if assigned( ReplaceEvent ) then begin
myFindOptions.SelectedText:= False;
ReplaceEvent( false );
end;
2 : // Replace All
if assigned( ReplaceEvent ) then begin
myFindOptions.FindNew := True;
ReplaceEvent( true );
end;
end;
myFindOptions.FindNew := False;
end;
procedure TForm_FindReplace.Button_CancelClick(Sender: TObject);
begin
OK_Click := false;
Close;
end;
procedure TForm_FindReplace.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
ComboToHistory;
if assigned( FormCloseEvent ) then
FormCloseEvent( self );
end;
procedure TForm_FindReplace.FormDeactivate(Sender: TObject);
begin
if assigned( myNotifyProc ) then
myNotifyProc( true );
end;
end.