Menu

[r2009]: / trunk / Src / FmFindXRefsDlg.pas  Maximize  Restore  History

Download this file

419 lines (374 with data), 13.4 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
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
{
* FmFindXRefsDlg.pas
*
* Dialog box that is used to select criteria for searches for cross referenced
* snippets. Also defines a class that is used to persist the last chosen search
* criteria.
*
* $Rev$
* $Date$
*
* ***** BEGIN LICENSE BLOCK *****
*
* Version: MPL 1.1
*
* 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 FmFindXRefsDlg.pas
*
* The Initial Developer of the Original Code is Peter Johnson
* (http://www.delphidabbler.com/).
*
* Portions created by the Initial Developer are Copyright (C) 2006-2012 Peter
* Johnson. All Rights Reserved.
*
* Contributor(s)
* NONE
*
* ***** END LICENSE BLOCK *****
}
unit FmFindXRefsDlg;
interface
uses
// Delphi
StdCtrls, Controls, ExtCtrls, Classes,
// Project
DB.USnippet, FmGenericOKDlg, UBaseObjects, USearch;
type
TXRefSearchParams = class;
{
TFindXRefsDlg:
Defines a dialog box that is used to select criteria for searches for
cross referenced snippets.
}
TFindXRefsDlg = class(TGenericOKDlg, INoPublicConstruct)
lblDesc: TLabel;
lblSnippetName: TLabel;
chkRequired: TCheckBox;
chkSeeAlso: TCheckBox;
chkIncludeSnippet: TCheckBox;
chkRequiredRecurse: TCheckBox;
chkSeeAlsoRecurse: TCheckBox;
lblOverwriteSearch: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure SearchCheckClick(Sender: TObject);
procedure btnOKClick(Sender: TObject);
strict private
fSearchParams: TXRefSearchParams; // Persists XRef search options
fSearch: ISearch; // Search for user's criteria
fSnippet: TSnippet; // Snippet whose x-refs to be found
procedure UpdateControls;
{Updates state of controls.
}
strict protected
procedure ConfigForm; override;
{Style labels and record name of snippet in labels and checkboxes.
}
procedure ArrangeForm; override;
{Arranges components on form and rezize form as required.
}
procedure InitForm; override;
{Populates and initialises controls.
}
public
class function Execute(const AOwner: TComponent; const Snippet: TSnippet;
out ASearch: ISearch): Boolean;
{Displays dialog and returns search object based on entered criteria.
@param AOwner [in] Component that owns this dialog.
@param Snippet [in] Snippet whose cross references are to be found.
@param ASearch [out] Search to be performed if user OKs. Has criteria
that causes specified cross references be returned by search. Set to
nil if user cancels.
@return True if user OKs and search object created or false if user
cancels and search object is nil.
}
end;
{
TXRefSearchParams:
Object used to store persistent parameters for cross-reference search.
Format in ini file is
+ Whether to include base snippet in search in 'IncludeRoutine'
+ Whether to include required snippets in search in 'Required'
+ Whether to recusively include required snippets in 'RequiredRecurse'
+ Whether to include "see also" snippets in search in 'SeeAlso'
+ Whether to recusively include "see also" snippets in 'SeeAlsoRecurse'
}
TXRefSearchParams = class(TObject)
strict private
fUpdated: Boolean; // Flag true if object's properties change
fOptions: TXRefSearchOptions; // Options controlling X-ref search
procedure SetOptions(const Value: TXRefSearchOptions);
{Write accessor for Options property.
@param Value [in] Option controlling X-ref search.
}
procedure Updated;
{Sets updated flag.
}
procedure ReadValues;
{Reads search parameters from persistent storage.
}
procedure WriteValues;
{Writes search parameters to persistent storage.
}
public
constructor Create;
{Class constructor. Sets up object with parameters from persistent
storage.
}
destructor Destroy; override;
{Class destructor. Tears down object and saves current values to
persistent storage if they have changed.
}
property Options: TXRefSearchOptions
read fOptions write SetOptions;
{X-ref search options}
end;
implementation
uses
// Delphi
SysUtils, Graphics,
// Project
UColours, UCtrlArranger, UQuery, USettings;
{$R *.dfm}
{ TFindXRefsDlg }
procedure TFindXRefsDlg.ArrangeForm;
{Arranges components on form and rezize form as required.
}
begin
// Horizontal alignment & sizing
// Place snippet name after end of description label
TCtrlArranger.AlignLefts(
[lblDesc, chkRequired, chkSeeAlso, chkIncludeSnippet, lblOverwriteSearch], 0
);
TCtrlArranger.AlignLefts([chkRequiredRecurse, chkSeeAlsoRecurse], 24);
TCtrlArranger.MoveToRightOf(lblDesc, lblSnippetName);
// Check if snippet name is clipped at right of dialog box and increase
// available body panel space if so
// Don't use TCtrlArranger.TotalControlWidth here
if lblSnippetName.Left + lblSnippetName.Width > pnlBody.ClientWidth then
pnlBody.ClientWidth := lblSnippetName.Left + lblSnippetName.Width;
lblOverwriteSearch.Width := pnlBody.ClientWidth;
TCtrlArranger.SetLabelHeight(lblOverwriteSearch);
// Vertical alignment & sizing
TCtrlArranger.AlignVCentres(0, [lblDesc, lblSnippetName]);
TCtrlArranger.MoveBelow([lblDesc, lblSnippetName], chkRequired, 12);
TCtrlArranger.MoveBelow(chkRequired, chkRequiredRecurse, 6);
TCtrlArranger.MoveBelow(chkRequiredRecurse, chkSeeAlso, 12);
TCtrlArranger.MoveBelow(chkSeeAlso, chkSeeAlsoRecurse, 6);
TCtrlArranger.MoveBelow(chkSeeAlsoRecurse, chkIncludeSnippet, 12);
if lblOverwriteSearch.Visible then
TCtrlArranger.MoveBelow(chkIncludeSnippet, lblOverwriteSearch, 12)
else
lblOverwriteSearch.SetBounds(0, 0, 0, 0); // hide from panel sizing
pnlBody.ClientHeight := TCtrlArranger.TotalControlHeight(pnlBody) + 4;
// Inherited arrangement: will set dialog width based on body panel width
inherited;
end;
procedure TFindXRefsDlg.btnOKClick(Sender: TObject);
{OK button click event handler. Creates and records search criteria.
@param Sender [in] Not used.
}
// ---------------------------------------------------------------------------
function GetOptionsFromUI: TXRefSearchOptions;
{Builds set of options selected by user in user interface.
@return Required option set.
}
begin
Result := [];
if chkRequired.Checked then
Include(Result, soRequired);
if chkRequiredRecurse.Checked then
Include(Result, soRequiredRecurse);
if chkSeeAlso.Checked then
Include(Result, soSeeAlso);
if chkSeeAlsoRecurse.Checked then
Include(Result, soSeeAlsoRecurse);
if chkIncludeSnippet.Checked then
Include(Result, soIncludeSnippet);
end;
// ---------------------------------------------------------------------------
var
SearchCriteria: IXRefSearchCriteria; // user's search criteria
begin
// Create search criteria from entries made in dialog box
SearchCriteria := TSearchCriteriaFactory.CreateXRefSearchCriteria(
fSnippet, GetOptionsFromUI
);
// Persist the search criteria
fSearchParams.Options := SearchCriteria.Options;
// Create search object from the entered criteria
fSearch := TSearchFactory.CreateXRefSearch(SearchCriteria);
end;
procedure TFindXRefsDlg.ConfigForm;
{Style labels and record name of snippet in labels and checkboxes.
}
begin
inherited;
// Set label font styles and colours
lblSnippetName.Font.Style := [fsBold];
if fSnippet.UserDefined then
lblSnippetName.Font.Color := clUserSnippet;
// Display selected snippet name in appropriate controls
lblSnippetName.Caption := fSnippet.Name;
chkIncludeSnippet.Caption := Format(
chkIncludeSnippet.Caption, [fSnippet.Name]
);
// Display or hide warning about overwriting searches
lblOverwriteSearch.Visible := Query.IsSearchActive;
end;
class function TFindXRefsDlg.Execute(const AOwner: TComponent;
const Snippet: TSnippet; out ASearch: ISearch): Boolean;
{Displays dialog and returns search object based on entered criteria.
@param AOwner [in] Component that owns this dialog.
@param Snippet [in] Snippet whose cross references are to be found.
@param ASearch [out] Search to be performed if user OKs. Has criteria that
causes specified cross references be returned by search. Set to nil if
user cancels.
@return True if user OKs and search object created or false if user cancels
and search object is nil.
}
begin
Assert(Assigned(Snippet), ClassName + '.Execute: Snippet is nil');
with InternalCreate(AOwner) do
try
fSnippet := Snippet;
Result := (ShowModal = mrOK);
ASearch := fSearch;
finally
Free;
end;
end;
procedure TFindXRefsDlg.FormCreate(Sender: TObject);
{Creates owned objects when form is created.
@param Sender [in] Not used.
}
begin
inherited;
// Create search params object with default values
fSearchParams := TXRefSearchParams.Create;
end;
procedure TFindXRefsDlg.FormDestroy(Sender: TObject);
{Frees owned object when form destroyed.
@param Sender [in] Not used.
}
begin
inherited;
FreeAndNil(fSearchParams);
end;
procedure TFindXRefsDlg.InitForm;
{Populates and initialises controls.
}
begin
inherited;
// Check appropriate check boxes
chkRequired.Checked := soRequired in fSearchParams.Options;
chkRequiredRecurse.Checked := soRequiredRecurse in fSearchParams.Options;
chkSeeAlso.Checked := soSeeAlso in fSearchParams.Options;
chkSeeAlsoRecurse.Checked := soSeeAlsoRecurse in fSearchParams.Options;
chkIncludeSnippet.Checked := soIncludeSnippet in fSearchParams.Options;
// Update other controls per state of check boxes
UpdateControls;
end;
procedure TFindXRefsDlg.SearchCheckClick(Sender: TObject);
{Click event handler for "required snippets" and "see also" check boxes.
Updates state of OK button.
@param Sender [in] Not used.
}
begin
UpdateControls;
end;
procedure TFindXRefsDlg.UpdateControls;
{Updates state of controls.
}
begin
btnOK.Enabled := chkRequired.Checked or chkSeeAlso.Checked;
chkRequiredRecurse.Enabled := chkRequired.Checked;
chkSeeAlsoRecurse.Enabled := chkSeeAlso.Checked;
end;
{ TXRefSearchParams }
constructor TXRefSearchParams.Create;
{Class constructor. Sets up object with parameters from persistent storage.
}
begin
inherited Create;
ReadValues;
fUpdated := False;
end;
destructor TXRefSearchParams.Destroy;
{Class destructor. Tears down object and saves current values to persistent
storage if they have changed.
}
begin
if fUpdated then
WriteValues;
inherited;
end;
procedure TXRefSearchParams.ReadValues;
{Reads search parameters from persistent storage.
}
var
Storage: ISettingsSection; // object used to access persistent storage
begin
Storage := Settings.ReadSection(ssFindXRefs);
fOptions := [];
if Boolean(StrToIntDef(Storage.ItemValues['IncludeRoutine'], 1)) then
Include(fOptions, soIncludeSnippet);
if Boolean(StrToIntDef(Storage.ItemValues['Required'], 1)) then
Include(fOptions, soRequired);
if Boolean(StrToIntDef(Storage.ItemValues['RequiredRecurse'], 0)) then
Include(fOptions, soRequiredRecurse);
if Boolean(StrToIntDef(Storage.ItemValues['SeeAlso'], 0)) then
Include(fOptions, soSeeAlso);
if Boolean(StrToIntDef(Storage.ItemValues['SeeAlsoRecurse'], 0)) then
Include(fOptions, soSeeAlsoRecurse);
end;
procedure TXRefSearchParams.SetOptions(const Value: TXRefSearchOptions);
{Write accessor for Options property.
@param Value [in] Option controlling X-ref search.
}
begin
fOptions := Value;
Updated;
end;
procedure TXRefSearchParams.Updated;
{Sets updated flag.
}
begin
fUpdated := True;
end;
procedure TXRefSearchParams.WriteValues;
{Writes search parameters to persistent storage.
}
var
Storage: ISettingsSection; // object used to access persistent storage
// ---------------------------------------------------------------------------
procedure StoreOption(const Name: string; const Option: TXRefSearchOption);
{Stores a X-ref search option in persistent storage object.
@param Name [in] Name of option in storage.
@param Option [in] Option to store.
}
begin
// Store boolean flag as string for each option
Storage.ItemValues[Name] := IntToStr(Ord(Option in fOptions));
end;
// ---------------------------------------------------------------------------
begin
// Create blank persistent storage object
Storage := Settings.EmptySection(ssFindXRefs);
// Record parameters
StoreOption('IncludeRoutine', soIncludeSnippet);
StoreOption('Required', soRequired);
StoreOption('RequiredRecurse', soRequiredRecurse);
StoreOption('SeeAlso', soSeeAlso);
StoreOption('SeeAlsoRecurse', soSeeAlsoRecurse);
// Store data
Storage.Save;
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.