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

📄 umfgenerator.pas

📁 DelphiDoc is a program for automatic generation of documentation on a Delphi-Project. At the momen
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{  JADD - Just Another DelphiDoc: Documentation from Delphi Source Code

Copyright (C) 2002-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 UMFGenerator;

{Contains a page to select the generator to generate the documentation with and
 to edit its options. It is also the base class of all the pages to select
 objects for the generation. }

interface

uses Windows, Classes, Graphics, Forms, Controls, StdCtrls, ExtCtrls, ComCtrls,
     UMainFormFrame,
     UJADDState,
     UOptions;

type
  {A page to select the generator to generate the documentation with and to
   edit its options. It is also the base class of all the pages to select
   objects for the generation. }
  TMFGenerator = class(TMainFormFrame)
    TreeView: TTreeView;
    GroupBoxOptions: TGroupBox;
    ButtonEditOptionsCategory: TButton;
    ButtonEditOptionsAsList: TButton;
    ButtonResetOptions: TButton;
    Memo: TMemo;
    CheckBoxMonochrome: TCheckBox;
    procedure TreeViewChange(Sender: TObject; Node: TTreeNode);
    procedure TreeViewDblClick(Sender: TObject);
    procedure TreeViewMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure CheckBoxMonochromeClick(Sender: TObject);
    procedure ButtonEditOptionsCategoryClick(Sender: TObject);
    procedure ButtonEditOptionsAsListClick(Sender: TObject);
    procedure ButtonResetOptionsClick(Sender: TObject);
  private
  protected
    //Called when the generator changes.
    procedure StateGeneratorChanged(State: TJADDState); override;


    //Fills the tree view hierarchically with the classes in the list.
    procedure FillTreeView(Classes: TStrings;
                           BaseClass, HighlightClass: TClass;
                           SelectedClass: String);
    //Selects the node in the tree representing the specified class.
    function SelectByClassName(ClassName: String): Boolean;


    //Initializes the tree view.
    procedure Init; virtual;
    //Checks whether an object of the class is curently used.
    function IsCurrentClass(AClass: TClass): Boolean; virtual;
    //Called to select the class.
    procedure SetClass(AClass: TClass); virtual;
    //Returns an object to edit the options of the current object.
    function GetOptions: TOptionWrapper; virtual;
    //Resets the current object.
    procedure ResetOptions; virtual;





{$IFNDEF LINUX}

    //Called whenever a node in the ~[link TreeView] has to be drawn.
    procedure TreeViewCustomDrawItem(Sender: TCustomTreeView;
                                     Node: TTreeNode; State: TCustomDrawState;
                                     var DefaultDraw: Boolean);

{$ELSE}

    //Called whenever a node in the ~[link TreeView] has to be drawn.
    procedure TreeViewCustomDrawItem(Sender: TCustomViewControl;
                                     Item: TCustomViewItem;
                                     Canvas: TCanvas; const Rect: TRect;
                                     State: TCustomDrawState;
                                     Stage: TCustomDrawStage;
                                     var DefaultDraw: Boolean);

{$ENDIF}

  public
    //Creates the components and fills the tree view.
    constructor Create(Parent: TWinControl; State: TJADDState); override;
    //Shows all nodes of the tree view.
    procedure AfterConstruction; override;
    //Unregisters the event handlers and ensures no invalid nodes are selected.
    destructor Destroy; override;

    //Called sometimes when the frame is to be replaced by another frame.
    procedure SelectNextFrame(var NewFrameClass: TMainFormFrameClass;
                              IsNext: Boolean); override;
  end;


implementation

{$R *.dfm}

uses Dialogs,
     IniFiles,
     GeneralVCL,
     USettingsKeeper,
     UExpert, UCatExpert,
     UMakeDoc, UICCommentDoc,
     UMFEvaluator, UMFGenerate;





type
  {Loads and saves the settings of the pages to select classes to generate
   documentation. }
  TClassSelectPageSettings = class(TAbstractSettings)
  private
    //whether ~[link TMFGenerator.TreeView] should be drawn monochrome
    FMonochrome: Boolean;

  protected
  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 page.
    procedure ReadValues(Page: TMFGenerator);

    property Monochrome: Boolean read FMonochrome;
  end;






{Loads the settings from the ini file.
~param Ini the ini file to load the settings from }
procedure TClassSelectPageSettings.LoadFromIni(Ini: TCustomIniFile);
begin
 //read state of the check box
 FMonochrome := Ini.ReadBool(Name, 'Monochrome', FMonochrome);
end;

{Saves the settings to the ini file.
~param Ini the ini file to save the settings to }
procedure TClassSelectPageSettings.SaveToIni(Ini: TCustomIniFile);
begin
 //write state of the check box
 Ini.WriteBool(Name, 'Monochrome', FMonochrome);
end;

{Gets the settings from the page.
~param Page the page to read the values from }
procedure TClassSelectPageSettings.ReadValues(Page: TMFGenerator);
begin
 //get state of the check box
 FMonochrome := Page.CheckBoxMonochrome.Checked;
end;











{Creates the components and fills the tree view.
~param Parent the component to show the frame in, preferably a TPanel or a
              similar component
~param State  the state of the program }
constructor TMFGenerator.Create(Parent: TWinControl; State: TJADDState);
var         Settings    :TClassSelectPageSettings;  //to read ini settings
begin
 inherited Create(Parent, State);         //create frame

 TreeView.OnCustomDrawItem := TreeViewCustomDrawItem;

 Init;                                    //fill the TreeView
{$IFDEF LINUX}
 //this does not work, it seems the nodes are always sorted with the text
 //specified when creating the nodes, but the texts are changed partially!
 TreeView.AlphaSort;                      //make sure it is sorted
{$ENDIF}
 if Assigned(TreeView.Selected) then      //show information of selected object
  SetClass(TreeView.Selected.Data);

 //get object to load the settings from
 Settings := TClassSelectPageSettings(TClassSelectPageSettings.
                                          GetSettings(TMFGenerator.ClassName));
 if not Assigned(Settings) then        //no object initialized?
  begin                                  //create a new object
   Settings := TClassSelectPageSettings.Create(TMFGenerator.ClassName);
   Settings.ReadValues(Self);            //initialize with the default values
   Settings.Initialize;                  //and read from the ini file
  end;
 //initialize page with read values
 CheckBoxMonochrome.Checked := Settings.Monochrome;
end;

{Shows all nodes of the tree view. }
procedure TMFGenerator.AfterConstruction;
begin
 inherited AfterConstruction;;         //call inherited handler

 TreeView.FullExpand;                  //and show all nodes

 //and only show vertical scroll bar when it's needed
 GeneralVCL.RegisterMemoToHideVerticalScrollbar(Memo);
end;

{Unregisters the event handlers and frees the frame. }
destructor TMFGenerator.Destroy;
var        Settings    :TClassSelectPageSettings;  //to read ini settings
begin
 if Assigned(TreeView) then
  TreeView.OnChange := nil;                 //don't select invalid nodes

 //get object to save the settings in
 Settings := TClassSelectPageSettings(TClassSelectPageSettings.
                                          GetSettings(TMFGenerator.ClassName));
 if Assigned(Settings) then
  Settings.ReadValues(Self);                //save current settings

 inherited Destroy;                       //free the page
end;



{Called when the generator changes.
~param State the state that has been changed }
procedure TMFGenerator.StateGeneratorChanged(State: TJADDState);
begin                                     //update the shown selected generator
 SelectByClassName(State.Generate.GeneratorClassName);
end;




{Called sometimes when the frame is to be replaced by another frame. This
 method is ~[em not] always called before the frame is being replaced (and
 freed).
~param NewFrameClass the class of the frame that should replace this one
~param IsNext        if the next frame should be shown (instead of the previous
                     one) in some kind of an order }
procedure TMFGenerator.SelectNextFrame(var NewFrameClass: TMainFormFrameClass;
                                       IsNext: Boolean);
begin
 if IsNext then
  if not State.Generate.GeneratorUsesCommentExtractors then
   if not State.Generate.GeneratorUsesCommentEvaluators then
    NewFrameClass := TMFGenerate      //skip directly to generate documentation
   else
    NewFrameClass := TMFEvaluator;
end;











{Fills the tree view hierarchically with the classes in the list.
~param Classes        the list of classes to put in the tree view (and their
                      ancestors)
~param BaseClass      the base class of all the classes and up to which the
                      ancestors should be filled in the tree view
~param HighlightClass if not nil the class and its descendants will be
                      highlighted
~param SelectedClass  the name of the currently selected class }
procedure TMFGenerator.FillTreeView(Classes: TStrings;
                                    BaseClass, HighlightClass: TClass;
                                    SelectedClass: String);

 {Adds the class (and its ancestors) to the tree view.
 ~param AClass the class to add to the tree view
 ~result the node of the added class }
 function AddClass(AClass: TClass): TTreeNode;
 var      NewNode :Boolean;      //if a new node has been created for the class
          Node    :TTreeNode;    //the node of the super class
 begin
  NewNode := False;              //no new node created so far
  if AClass = BaseClass then     //is the base class?
   begin
    Result := TreeView.Items.GetFirstNode;   //the root node
    if not assigned(Result) then             //tree view is empty?
     begin                                     //create the root
      Result := TreeView.Items.Add(nil, AClass.ClassName);
      NewNode := True;                         //a new node has been created
     end;
   end
  else
   begin
    Node := AddClass(AClass.ClassParent);    //add the ancestors' nodes
    Result := Node.GetFirstChild;            //will be added under it
    while assigned(Result) and (Result.Data <> AClass) do //search the class
     Result := Result.GetNextSibling;
    if not assigned(Result) then            //class not already added?
     begin                                    //add the node
      Result := TreeView.Items.AddChild(Node, AClass.ClassName);
      NewNode := True;                        //a new node has been created
     end;
   end;

  if NewNode then                //a new node has been created?
   Result.Data := AClass;          //assign its class
 end;

var       i           :Integer;        //counter through list of classes
          AClass      :TClass;         //each class in the list
          Node        :TTreeNode;      //nodes of the classes in the list
          Selected    :TTreeNode;      //node of the currently selected class
begin
 TreeView.Items.Clear;                 //clear the tree view
 Selected := nil;                      //no node selected so far
 for i := 0 to Classes.Count - 1 do    //for each class in the list
  begin
   AClass := TClass(Classes.Objects[i]); //get the class
   Node := AddClass(AClass);             //and add a node for it
   //set state of the node (how to highlight)

⌨️ 快捷键说明

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