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

📄 ushowsourceform.pas

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

{Contains a window to show the source code of the parsed files. }

interface


//{$DEFINE USESOURCECODEGRID}

{$IFDEF LINUX}
{$DEFINE USESOURCECODEGRID}
{$ENDIF}

uses
{$IFNDEF LINUX}
  Windows,
{$ELSE}
  Qt,
{$ENDIF}
  Classes, Forms, Controls, StdCtrls, ExtCtrls,
{$IFNDEF USESOURCECODEGRID}
  PascalMemo,
{$ELSE}
  SourceGrid,
{$ENDIF}
  UPascalConsts, UBaseIdents,
  UJADDState;


type
  {Contains a window to show the source code of the parsed files. }
  TFormShowSource = class(TForm)
    PanelNavigate: TPanel;
    ComboBox: TComboBox;
    ListBox: TListBox;
    PanelSplitter: TPanel;
    LabelIncludedBy: TLabel;
    ButtonGoInluded: TButton;
    LabelIncludedFile: TLabel;
    ButtonFileStatistics: TButton;
    ButtonAllStatistics: TButton;
    procedure FormResize(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure PanelSplitterMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure PanelSplitterMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure PanelSplitterDblClick(Sender: TObject);
    procedure ComboBoxChange(Sender: TObject);
    procedure ButtonGoInludedClick(Sender: TObject);
    procedure ListBoxClick(Sender: TObject);
    procedure ListBoxDblClick(Sender: TObject);
    procedure ButtonFileStatisticsClick(Sender: TObject);
    procedure ButtonAllStatisticsClick(Sender: TObject);
  private
    //the state containing the parsed files to show the source code of
    FState: TJADDState;


{$IFNDEF USESOURCECODEGRID}
    //the control to show the source of the parsed files
    FPascalMemo: TPascalMemo;
{$ELSE}
    //the control to show the source of the parsed files
    FPascalMemo: TSourceGrid;
{$ENDIF}


    //the file including the file shown at the last call to
    //~[link ShowSourceCode]
    FIncludingFile: TPascalFile;
    //the position where the ~[link FIncludingFile file] includes the file
    //shown at the last call to ~[link ShowSourceCode]
    FIncludingPosition: TPosition;




    //Sets the file and position where the currently shown file has been
    //included.
    procedure SetIncluded(IncludingFile: TPascalFile;
                          IncludingPosition: TPosition);
    //Sets that the currently shown file has not been included.
    procedure NotIncluded;


    //Called when the list of parsed file changes.
    procedure StateFileListChanged(State: TJADDState);


    //Shows the declaration of an identifier in the source code.
    procedure ShowSourceCodeOfIdentifier(Identifier: TIdentifier;
                                         Impl: Boolean);

    //Shows the statistics in a dialog.
    procedure ShowStatistics(Header: String;
                             Statistics: TStatisticOfPascalFile;
                             HelpContext: THelpContext);

    { private declarations }
  public
    //Creates the window to show parsed source code.
    constructor Create(State: TJADDState); reintroduce;
    //Unregisters the event handlers and frees the window.
    destructor Destroy; override;


    //Shows the source code at the identifier or position.
    procedure ShowSourceCode(Ident: TIdentifier;
                             TheFile: TPascalFile; Position: TPosition;
                             EffectiveFile: TPascalFile;
                             EffectivePosition: TPosition);
    { public declarations }
  end;



implementation

{$R *.dfm}

uses SysUtils, Math, IniFiles, Dialogs,
     General,
     UExtIdents,
     USettingsKeeper;




type

  {Loads and saves the settings of the form to show the parsed source code. }
  TSourceFormSettings = class(TFormSettings)
  private
    //the height of the lists of identifiers declared in the selected file
    FIdentifierListHeight: Integer;
  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 form.
    procedure ReadValues(Form: TFormShowSource);

    property IdentifierListHeight: Integer read FIdentifierListHeight;
  end;






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

 //read height of the list
 FIdentifierListHeight := Ini.ReadInteger(Name, 'IdentifierListHeight',
                                                FIdentifierListHeight);
end;

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

 //write height of the list
 Ini.WriteInteger(Name, 'IdentifierListHeight', FIdentifierListHeight);
end;


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

 //get height of the list
 FIdentifierListHeight := Form.ListBox.Height;
end;










{Creates the form to show the source code of the parsed files.
~param State the state containing the parsed files to show the source code of }
constructor TFormShowSource.Create(State: TJADDState);
var         Settings       :TSourceFormSettings; //to read ini settings
begin
 inherited Create(nil);                       //create the form

 FState := State;                             //save the state


 //create control to show the source code
{$IFNDEF USESOURCECODEGRID}
 FPascalMemo := TPascalMemo.Create(Self);
{$ELSE}
 FPascalMemo := TSourceGrid.Create(Self);
{$ENDIF}

 FPascalMemo.Parent := Self;
 FPascalMemo.Left := 0;                       //fill it almost
 FPascalMemo.Top := 36;
 FPascalMemo.Width := 650;
 FPascalMemo.Height := 288;
 FPascalMemo.Align := alClient;               //yes, fill it
{$IFNDEF USESOURCECODEGRID}
 FPascalMemo.HideSelection := False;          //always show selected identifier
{$ENDIF}
// FPascalMemo.ParentFont := False;
// FPascalMemo.ScrollBars := ssBoth;
 FPascalMemo.TabOrder := 0;                   //it's the first (main) control
 FPascalMemo.HelpContext := 27001;
 FPascalMemo.Hint := 'Shows the source code of the files in the parsed data.';


 //register state changed handler
 State.OnFileListChanged.Add(StateFileListChanged);


 StateFileListChanged(State);                 //and handle the current data


 //get object to load the settings from
 Settings := TSourceFormSettings(TSourceFormSettings.GetSettings(ClassName));
 if not assigned(Settings) then        //no object initialized?
  begin                                  //create a new object
   Settings := TSourceFormSettings.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
 ListBox.Height := Settings.IdentifierListHeight;
end;



{Frees the dialog. }
destructor TFormShowSource.Destroy;
var        Settings       :TSourceFormSettings; //to save settings of form
begin
 if assigned(FState) then
  //unregister state changed handler
  FState.OnFileListChanged.Remove(StateFileListChanged);

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

 inherited Destroy;                             //free the form
end;








{Sets the file and position where the currently shown file has been included.
~param IncludingFile     the file which includes the current file
~param IncludingPosition the position in the file where it includes the other
                         one }
procedure TFormShowSource.SetIncluded(IncludingFile: TPascalFile;
                                      IncludingPosition: TPosition);
begin
 FIncludingFile := IncludingFile;            //save the data
 FIncludingPosition := IncludingPosition;

 //and show the position on the GUI and the button to go to it
 LabelIncludedFile.Caption := IncludingFile.InternalFileName;
 LabelIncludedFile.Visible := True;
 LabelIncludedBy.Visible := True;
 ButtonGoInluded.Visible := True;
end;

{Sets that the currently shown file has not been included. }
procedure TFormShowSource.NotIncluded;
begin
 LabelIncludedFile.Visible := False; //hide controls to go to an including file
 LabelIncludedBy.Visible := False;
 ButtonGoInluded.Visible := False;
end;

⌨️ 快捷键说明

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