📄 ucatexpertsearchdlg.pas
字号:
{ JADD - Just Another DelphiDoc: Documentation from Delphi Source Code
Copyright (C) 2008 Gerold Veith
This file is part of JADD - Just Another DelphiDoc.
DelphiDoc is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as
published by the Free Software Foundation.
DelphiDoc is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
}
unit UCatExpertSearchDlg;
{Contains a ~[link TFormOptionSearchDialog simple dialog] to set the values to
search options by.
}
interface
uses Classes,
{$IFNDEF LINUX}
Forms, Controls, StdCtrls, Buttons;
{$ELSE}
Qt, QGraphics, QForms, QMenus, QTypes, QStdCtrls, QControls,
QImgList, QButtons, QComCtrls, QExtCtrls;
{$ENDIF}
type
//what attributes of options to search a text in
TOptionSearchAttribute = (
osaName, //check the names of the options
osaDescription, //check the descriptions of options
osaCategory, //check the categories of options
osaTopic); //check the topics of the options
//what attributes of options to search a text in
TOptionSearchAttributes = set of TOptionSearchAttribute;
{Does the actual search for an option.
~param Text the text to search options by
~param Attributes the attributes of options to check for the text }
TSearchOptionProc = procedure(const Text: String;
Attributes: TOptionSearchAttributes) of object;
{A simple dialog to set the values to search options by. }
TFormOptionSearchDialog = class(TForm)
LabelSearchText: TLabel;
EditSearchText: TEdit;
BitBtnSearch: TBitBtn;
BitBtnClose: TBitBtn;
CheckBoxName: TCheckBox;
CheckBoxDescription: TCheckBox;
CheckBoxCategory: TCheckBox;
CheckBoxTopic: TCheckBox;
procedure SearchOptionsChanged(Sender: TObject);
procedure BitBtnSearchClick(Sender: TObject);
procedure BitBtnCloseClick(Sender: TObject);
private
//the procedure to be called to search the options
FSearchProc: TSearchOptionProc;
//an array to access the check boxes by the attributes they represent
FCheckBoxes: array[TOptionSearchAttribute] of TCheckBox;
public
//Creates the dialog and saves the procedure to search options.
constructor Create(Owner: TComponent;
SearchProc: TSearchOptionProc); reintroduce;
//Frees the form after saving its settings.
destructor Destroy; override;
//Shows the dialog again.
procedure ShowUnModal;
//Returns the selected attributes of the options to search the text in.
function GetSearchAttributes: TOptionSearchAttributes;
end;
implementation
uses IniFiles,
USettingsKeeper;
{$R *.dfm}
type
{Loads and saves the settings of the dialog to search options. }
TOptionSearchDialogFormSettings = class(TFormSettings)
private
//the last attributes of options to search a text in
FAttributes: TOptionSearchAttributes;
public
//Loads the settings from the ini file.
procedure LoadFromIni(Ini: TCustomIniFile); override;
//Saves the settings to the ini file.
procedure SaveToIni(Ini: TCustomIniFile); override;
//Gets the settings from the form.
procedure ReadValues(Form: TFormOptionSearchDialog);
property Attributes: TOptionSearchAttributes read FAttributes;
end;
{Loads the settings from the ini file.
~param Ini the ini file to load the settings from }
procedure TOptionSearchDialogFormSettings.LoadFromIni(Ini: TCustomIniFile);
var Str :String; //the value as a string
Attr :TOptionSearchAttribute; //runner through all attributes
begin
inherited LoadFromIni(Ini); //read general form settings
//read the selected attributes
Str := Ini.ReadString(Name, 'Attributes', '');
//the value has the correct length?
if Length(Str) = Ord(High(Attr)) - Ord(Low(Attr)) + 1 then
begin
FAttributes := [];
for Attr := Low(Attr) to High(Attr) do //for each attribute
if Str[Ord(Attr) + 1] = '1' then //is selected?
Include(FAttributes, Attr); //add it
end;
end;
{Saves the settings to the ini file.
~param Ini the ini file to save the settings to }
procedure TOptionSearchDialogFormSettings.SaveToIni(Ini: TCustomIniFile);
var Str :String; //the value as a string
Attr :TOptionSearchAttribute; //runner through all attributes
begin
inherited SaveToIni(Ini); //write general form settings
//write the selected attributes
Str := ''; //so far none selected
for Attr := Low(Attr) to High(Attr) do //for each attribute add
Str := Str + Char(Ord('0') + Ord(Attr in FAttributes)); //either '0' or '1'
Ini.WriteString(Name, 'Attributes', Str);
end;
{Gets the settings from the form.
~param Form the form to read the values from }
procedure TOptionSearchDialogFormSettings.ReadValues(Form:
TFormOptionSearchDialog);
begin
GetValuesFromForm(Form); //get general values of the form
FAttributes := Form.GetSearchAttributes; //get selected attributes
end;
{Creates the dialog and saves the procedure to search options.
~param Owner the owner of the dialog, should be an instance of
~[link UCatExpert.TFormCatExpert]
~param SearchProc the method to be called to search an option }
constructor TFormOptionSearchDialog.Create(Owner: TComponent;
SearchProc: TSearchOptionProc);
var Settings :TOptionSearchDialogFormSettings; //to read ini settings
Attr :TOptionSearchAttribute; //runner through all attributes
begin
inherited Create(Owner); //create the form
FSearchProc := SearchProc; //save the procedure
//assign the check boxes to the array
FCheckBoxes[osaName] := CheckBoxName;
FCheckBoxes[osaDescription] := CheckBoxDescription;
FCheckBoxes[osaCategory] := CheckBoxCategory;
FCheckBoxes[osaTopic] := CheckBoxTopic;
//get object to load the settings from
Settings := TOptionSearchDialogFormSettings(TOptionSearchDialogFormSettings.
GetSettings(ClassName));
if not Assigned(Settings) then //no object initialized?
begin //create a new object
Settings := TOptionSearchDialogFormSettings.Create(ClassName);
Settings.ReadValues(Self); //initialize with the default values
Settings.Initialize; //and read from the ini file
end;
Settings.SetValuesToForm(Self); //initialize form with read values
for Attr := Low(Attr) to High(Attr) do //for each attribute set whether
FCheckBoxes[Attr].Checked := Attr in Settings.Attributes; //it is selected
end;
{Frees the form after saving its settings. }
destructor TFormOptionSearchDialog.Destroy;
var Settings :TOptionSearchDialogFormSettings; //saves settings of form
begin
//get object to save the settings in
Settings := TOptionSearchDialogFormSettings(TOptionSearchDialogFormSettings.
GetSettings(ClassName));
if Assigned(Settings) then
Settings.ReadValues(Self); //save current settings
inherited Destroy; //free this window
end;
{Shows the dialog again. }
procedure TFormOptionSearchDialog.ShowUnModal;
begin
Show; //show the dialog or bring it to the front
EditSearchText.SetFocus; //always focus the search text by default
EditSearchText.SelectAll; //and select all the text
end;
{Returns the selected attributes of the options to search the text in.
~result the selected attributes of the options }
function TFormOptionSearchDialog.GetSearchAttributes: TOptionSearchAttributes;
var Attr :TOptionSearchAttribute; //runner through all attributes
begin
Result := []; //so far none selected
for Attr := Low(Attr) to High(Attr) do //for each attribute
if FCheckBoxes[Attr].Checked then //if it is selected
Include(Result, Attr); //add it
end;
{Called when an option for the search is changed
~param Sender the changed component, either ~[link EditSearchText] or one of
the check boxes, ~[link CheckBoxName],
~[link CheckBoxDescription], ~[link CheckBoxCategory] or
~[link CheckBoxTopic] }
procedure TFormOptionSearchDialog.SearchOptionsChanged(Sender: TObject);
begin
//only allow the search if a text to be searched has been entered and at least
//one attribute to search it in is selected
BitBtnSearch.Enabled := (EditSearchText.Text <> '') and
(GetSearchAttributes <> []);
end;
{Called when the button to start the search is clicked or, as it is the default
button, the return key is pressed on any other component.
~param Sender the sender of the event, the button ~[link BitBtnSearch] }
procedure TFormOptionSearchDialog.BitBtnSearchClick(Sender: TObject);
begin
//a text to be searched was entered and at least one attribute to search it in
//is selected?
if (EditSearchText.Text <> '') and (GetSearchAttributes <> []) then
//search the next option with the parameter
FSearchProc(EditSearchText.Text, GetSearchAttributes);
end;
{Called when the button to close the dialog is clicked or, as it is the cancel
button, the escape key is pressed.
~param Sender the sender of the event, the button ~[link BitBtnClose] }
procedure TFormOptionSearchDialog.BitBtnCloseClick(Sender: TObject);
begin
Hide; //only hide the window
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -