📄 uexpert.pas
字号:
{ JADD - Just Another DelphiDoc: Documentation from Delphi Source Code
Copyright (C) 2003-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 UExpert;
{Contains a dialog, ~[link TFormExpert], for the user to edit options through
the interface of ~[link TOptionWrapper]. It looks like a simple object
inspector (in the old style).
}
interface
{$IFDEF LINUX}
{$DEFINE USENORMALSPINEDIT}
{$ENDIF}
uses
Windows, Classes,
{$IFNDEF LINUX}
ComCtrls, Controls, Forms, StdCtrls, Grids,
{$ELSE}
Qt,
QExtCtrls, QStdCtrls, QComCtrls, QControls, QGrids, QForms,
{$ENDIF}
UOptions;
type
{$IFNDEF LINUX}
//the common base class, of all components to edit options
TEditComponent = TWinControl;
{$ELSE}
//the common base class, of all components to edit options
TEditComponent = TWidgetControl;
{$ENDIF}
//the class of a component to edit an option
TEditComponentClass = class of TEditComponent;
{A dialog to edit options through the interface of ~[link TOptionWrapper],
looking like a simple object inspector (in the old style). }
TFormExpert = class(TForm)
StringGridOptions: TStringGrid;
StatusBar: TStatusBar;
procedure FormShow(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure StringGridOptionsSelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
procedure StringGridOptionsKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure StringGridOptionsTopLeftChanged(Sender: TObject);
procedure StatusBarDrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel; const Rect: TRect);
private
//options to be edited
FOptions: TOptionWrapper;
//the component to edit the currently chosen option
FEditControl: TEditComponent;
//Fills the list with all available options.
procedure FillGrid;
//Saves the value in the component of the currently chosen options.
procedure SaveData(Index: Cardinal; Control: TEditComponent);
//Gets a new component to edit the current option and initializes it.
function GetEditControlAndData(Index: Cardinal): TEditComponent;
//Called when a key is pressed in ~[link FEditControl].
procedure EditControlKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
{ private declarations }
public
//Creates the dialog to edit the options.
constructor Create(Options: TOptionWrapper); reintroduce;
//Frees the dialog.
destructor Destroy; override;
{ public declarations }
end;
//Shows a dialog to edit the options.
procedure EditOptions(Options: TOptionWrapper);
implementation
{$R *.dfm}
uses SysUtils,
{$IFNDEF USENORMALSPINEDIT}
GVSpin,
{$ELSE}
{$IFNDEF LINUX}
Spin,
{$ENDIF}
{$ENDIF}
SetButton,
USettingsKeeper;
{Shows a dialog to edit the options.
~param Options the options to edit }
procedure EditOptions(Options: TOptionWrapper);
begin
with TFormExpert.Create(Options) do //create the dialog
try
ShowModal; //show the dialog
finally
Free; //free the dialog
end;
end;
{Creates the dialog to edit the options.
~param Options the options to edit }
constructor TFormExpert.Create(Options: TOptionWrapper);
begin
inherited Create(nil); //create the form
FOptions := Options; //save interface to the options
StringGridOptions.Cells[0, 0] := '#'; //set headers of the list
StringGridOptions.Cells[1, 0] := 'Name';
StringGridOptions.Cells[2, 0] := 'Category';
StringGridOptions.Cells[3, 0] := 'Value';
StringGridOptions.Cells[4, 0] := 'Default';
StringGridOptions.Cells[5, 0] := 'Attributes';
StringGridOptions.Cells[6, 0] := 'Description';
StringGridOptions.Col := 3; //activate column of the value
FillGrid; //fill the list
Caption := 'Options of ' + FOptions.DefaultTopic;
TFormSettings.SaveBasicFormValues(Self); //read the basic form values
end;
{Frees the dialog. }
destructor TFormExpert.Destroy;
var Settings :TFormSettings; //to save the settings of the form
begin
if assigned(FEditControl) then //option is edited?
SaveData(StringGridOptions.Row - 1, FEditControl); //save its value
//get object to save the settings in
Settings := TFormSettings(TFormSettings.GetSettings(ClassName));
if assigned(Settings) then
Settings.GetValuesFromForm(Self); //save current settings
FEditControl.Free; //free the control of the option
inherited Destroy; //free the form
end;
{Fills the list with all options. }
procedure TFormExpert.FillGrid;
var OptionCount :Cardinal; //number of options
i :Cardinal; //counter through options
Descr :TOptionDescription; //description of the options
AttrText :String; //attributes of the options
Attribute :TOptionOption; //counter through attributes
Dummy :Boolean; //not used
begin
OptionCount := FOptions.Count; //get number of options
if OptionCount = 0 then //no options available?
StringGridOptions.Enabled := False //disable list
else
begin
StringGridOptions.RowCount := OptionCount + 1; //set size of the list
for i := 0 to OptionCount - 1 do //for each option
begin
FOptions.Description(i, Descr); //get its description
StringGridOptions.Cells[0, i + 1] := Format('%u', [i]); //show all values
StringGridOptions.Cells[1, i + 1] := Descr.Name;
StringGridOptions.Cells[2, i + 1] := Descr.Category;
//show the current value
StringGridOptions.Cells[3, i + 1] := ValueToString(FOptions.Option[i],
Descr);
StringGridOptions.Cells[4, i + 1] := ValueToString(Descr.DefaultValue,
Descr);
AttrText := ''; //no attributes so far
for Attribute := Low(Attribute) to High(Attribute) do
if Attribute in Descr.Options then //for each attribute
begin
if AttrText <> '' then //not the first one?
AttrText := AttrText + ', '; //add a separator
AttrText := AttrText + OptionOptionTexts[Attribute]; //show attribute
end;
StringGridOptions.Cells[5, i + 1] := AttrText;
StringGridOptions.Cells[6, i + 1] := Descr.Description;
end;
//edit the first option
StringGridOptionsSelectCell(nil, StringGridOptions.Col,
StringGridOptions.Row, Dummy);
end;
end;
{Saves the value in the component of the currently chosen options.
~param Index the index of the option to save
~param Control the control containing the value to save }
procedure TFormExpert.SaveData(Index: Cardinal; Control: TEditComponent);
var Descr :TOptionDescription; //description of the option
Value :TOptionValue; //value of the option
i :Integer; //counter through all options
begin
FOptions.Description(Index, Descr); //get type of the option
case Descr.DataType of //save value depending on type
otString: Value.StrData := TEdit(Control).Text;
otBoolean: Value.BoolData := TCheckBox(Control).Checked;
{$IFNDEF USENORMALSPINEDIT}
otInteger: Value.IntData := TGVSpinEdit(Control).Value;
{$ELSE}
otInteger: Value.IntData := TSpinEdit(Control).Value;
{$ENDIF}
{$IFNDEF USENORMALSPINEDIT}
otReal: Value.RealData := TExtSpinEdit(Control).Value;
{$ELSE}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -