⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ucatexpert.pas

📁 DelphiDoc is a program for automatic generation of documentation on a Delphi-Project. At the momen
💻 PAS
📖 第 1 页 / 共 5 页
字号:
{  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 UCatExpert;

{Contains a dialog, ~[link TFormCatExpert], for the user to edit options
 through the interface of ~[link TOptionWrapper]. The options are in an outline
 sorted by their category and subcategories.
 }

interface

{$IFDEF LINUX}
{$DEFINE USENORMALSPINEDIT}
{$ENDIF}

uses
  Windows, Classes,
{$IFNDEF LINUX}
  Graphics, Forms, Controls, ComCtrls, ImgList, StdCtrls, Buttons, ExtCtrls,
  Messages,
{$ELSE}
  Qt, QGraphics, QForms, QMenus, QTypes, QStdCtrls, QControls,
  QImgList, QButtons, QComCtrls, QExtCtrls,
{$ENDIF}
  UOptions,
  UCatExpertSearchDlg;


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 for the user to edit options through the interface of
   ~[link TOptionWrapper]. The options are in an outline sorted by their
   category and subcategories. }
  TFormCatExpert = class(TForm)
    LabelOptions: TLabel;
    ImageList: TImageList;
    StatusBar: TStatusBar;
    GroupBoxValue: TGroupBox;
    LabelName: TLabel;
    LabelCategory: TLabel;
    LabelDefaultValue: TLabel;
    LabelValue: TLabel;
    LabelClass: TLabel;
    EditName: TEdit;
    EditCategory: TEdit;
    EditDefaultValue: TEdit;
    EditClass: TEdit;
    BitBtnClose: TBitBtn;
    GroupBoxFileOperations: TGroupBox;
    CheckBoxByHierarchy: TCheckBox;
    ButtonSaveOptionsFile: TButton;
    ButtonSaveOptionsDefault: TButton;
    ButtonLoadOptionsDefault: TButton;
    ButtonLoadOptionsFile: TButton;
    RadioGroupShowOptions: TRadioGroup;
    ComboBoxTopics: TComboBox;
    LabelAttributes: TLabel;
    EditAttributes: TEdit;
    ButtonSearchDlg: TButton;
    procedure FormResize(Sender: TObject);
    procedure TreeViewChange(Sender: TObject; Node: TTreeNode);
    procedure TreeViewCollapsed(Sender: TObject; Node: TTreeNode);
    procedure TreeViewExpanded(Sender: TObject; Node: TTreeNode);
    procedure TreeViewDblClick(Sender: TObject);
    procedure TreeViewEditing(Sender: TObject; Node: TTreeNode; var AllowEdit: Boolean);
    procedure ButtonSearchDlgClick(Sender: TObject);
    procedure EditValueKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure StatusBarDrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel; const Rect: TRect);
    procedure OptionTopicChanged(Sender: TObject);
    procedure ButtonLoadOptionsDefaultClick(Sender: TObject);
    procedure ButtonLoadOptionsFileClick(Sender: TObject);
    procedure ButtonSaveOptionsDefaultClick(Sender: TObject);
    procedure ButtonSaveOptionsFileClick(Sender: TObject);
  private
    TreeView: TTreeView;      //the component to select the option to edit
{$IFNDEF LINUX}
    //the component to show the help text of the currently selected option
    RichEditHelpText: TRichEdit;
    //the component to resize the ~[link RichEditHelpText rich edit] and the
    //~[link TreeView tree view]
    PanelSplitter: TPanel;
    //a timer to handle the resizing of components after Delphi (the VCL/CLX)
    //has done it
    TimerResize: TTimer;
{$ENDIF}

    FOptions: TOptionWrapper; //the options to edit
    FLastNode: TTreeNode;     //the node of the currently edited option

    //the component to edit the currently chosen option
    FEditControl: TEditComponent;


    //the last text to search an option by
    FOptionSearchText: String;
    //the last attributes of options to search a text in
    FOptionSearchAttributes: TOptionSearchAttributes;
    //the dialog to enter the search attributes in and start a search
    FSearchDialog: TFormOptionSearchDialog;


    //Called when the user finishes editing the value of an option directly in
    //the tree view.
    procedure TreeViewEdited(Sender: TObject; Node: TTreeNode;
                             var S: {$IFDEF LINUX} WideString
                                    {$ELSE}        String {$ENDIF});


{$IFNDEF LINUX}
    //Handles key-presses as shortcuts.
    procedure FormShortCut(var Msg: TWMKey; var Handled: Boolean);
{$ELSE}
    //Handles key-presses as shortcuts.
    procedure FormShortCut(Key: Integer; Shift: TShiftState;
                           var Handled: Boolean);
{$ENDIF}

{$IFNDEF LINUX}
    //Called when the users starts to drag the splitter.
    procedure PanelSplitterMouseDown(Sender: TObject; Button: TMouseButton;
                                     Shift: TShiftState; X, Y: Integer);
    //Called when the users is dragging the splitter.
    procedure PanelSplitterMouseMove(Sender: TObject; Shift: TShiftState;
                                     X, Y: Integer);
    //Called via a timer after the form has been resized.
    procedure TimerResizeTimer(Sender: TObject);

    //Resizes the tree view and the rich edit.
    procedure ResizeTreeView(Height: Integer);
    //Shows the help text for the option.
    procedure ShowHelpText(OptionIndex, HelpOptionIndex: Cardinal;
                           const OptionName: String);
    //Shows the help text of an option at the anchor.
    procedure ShowAnchorHelpText(const AnchorName: String);
{$ENDIF}


    //Fills the combo box with all topics of the options.
    procedure FillComboBox;
    //Fills the outline with all available options.
    procedure FillTreeView(First, Last: Integer);
    //Refreshes the text of all nodes.
    procedure RefreshAllNodes;

    //Saves the value in the component of the currently chosen options.
    procedure SaveOption(RefreshTreeView: Boolean);

    //Loads the options from the file.
    procedure LoadOptions(FileName: String);
    //Writes the options to the file.
    procedure SaveOptions(FileName: String; Hierarchy: Boolean);

    //Searches an option.
    procedure DoSearch(TrySearchAgain: Boolean);
    //Does the actual search for an option.
    procedure SearchOption(const Text: String;
                           Attributes: TOptionSearchAttributes);

  public
    //Creates the dialog to edit the options.
    constructor Create(Options: TOptionWrapper); reintroduce;
    //Frees the dialog.
    destructor Destroy; override;
  end;




//Shows a dialog to edit the options.
procedure EditOptionsByCategory(Options: TOptionWrapper);



implementation

{$R *.dfm}

uses SysUtils, Math, IniFiles,
{$IFNDEF LINUX}
     Dialogs, CommCtrl,
{$ELSE}
     QDialogs,
{$ENDIF}
{$IFNDEF USENORMALSPINEDIT}
     GVSpin,
{$ELSE}
{$IFNDEF LINUX}
     Spin,
{$ENDIF}
{$ENDIF}
     General, GeneralVCL,
     SetButton,
     UFilePaths,
     USettingsKeeper,
     UCommandParameters;



{Shows a dialog to edit the options.
~param Options the options to edit }
procedure EditOptionsByCategory(Options: TOptionWrapper);
begin
 with TFormCatExpert.Create(Options) do    //create the dialog
  try
    ShowModal;                             //show the dialog
  finally
   Free;                                   //free the dialog
  end;
end;














type
  {Loads and saves the settings of the dialog to search options. }
  TOptionCatExpertFormSettings = class(TFormSettings)
  private
{$IFNDEF LINUX}
    //the height of the rich edit
    FRichEditHeight: Integer;
{$ENDIF}
    //whether the settings should be saved hierarchical by topic
    FSaveByHierarchy: Boolean;
  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: TFormCatExpert);


{$IFNDEF LINUX}
    property RichEditHeight: Integer read FRichEditHeight;
{$ENDIF}
    property SaveByHierarchy: Boolean read FSaveByHierarchy;
  end;





{Loads the settings from the ini file.
~param Ini the ini file to load the settings from }
procedure TOptionCatExpertFormSettings.LoadFromIni(Ini: TCustomIniFile);
begin
 inherited LoadFromIni(Ini);             //read general form settings

 //read the other settings
{$IFNDEF LINUX}
 FRichEditHeight := Ini.ReadInteger(Name, 'RichEditHeight', FRichEditHeight);
{$ENDIF}
 FSaveByHierarchy := Ini.ReadBool(Name, 'SaveByHierarchy', FSaveByHierarchy);
end;

{Saves the settings to the ini file.
~param Ini the ini file to save the settings to }
procedure TOptionCatExpertFormSettings.SaveToIni(Ini: TCustomIniFile);
begin
 inherited SaveToIni(Ini);               //write general form settings

 //write the other settings
{$IFNDEF LINUX}
 Ini.WriteInteger(Name, 'RichEditHeight', FRichEditHeight);
{$ENDIF}
 Ini.WriteBool(Name, 'SaveByHierarchy', FSaveByHierarchy);
end;

{Gets the settings from the form.
~param Form the form to read the values from }
procedure TOptionCatExpertFormSettings.ReadValues(Form: TFormCatExpert);
begin
 GetValuesFromForm(Form);                 //get general values of the form

 //get the other settings
{$IFNDEF LINUX}
 FRichEditHeight := Form.RichEditHelpText.Height;
{$ENDIF}
 FSaveByHierarchy := Form.CheckBoxByHierarchy.Checked;
end;


















     //enumeration type for the indices of the images for the outline/tree
type TImageIndex = (
                    iiOption,      //an option
                    iiClosed,      //an opened category
                    iiOpen);       //an closed category

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -