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

📄 uselectparseddirectory.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) 2006-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 USelectParsedDirectory;

{Contains a simple dialog, ~[link TFormSelectParsedDirectory], to select a
 directory of files of the parsed data and an action to perform with them. }

interface

uses
  Windows, Classes, Forms, Controls, StdCtrls, Buttons, ComCtrls,
  UBaseIdents, ImgList, Menus;

type
  //An action to perform on the files or classes in the selected module.
  TDiagramDirectoryAction = (
                             //invalid action (none selected)
                             ddaInvalid,
                             //just select the files/classes already in the
                             ddaSelect,          //diagram
                             //add the files/classes to the diagram
                             ddaAdd,
                             //remove the files/classes from the diagram
                             ddaRemove,
                             //only keep the files/classes, remove all others
                             ddaRemoveOthers);   //from the diagram


  {A dialog to select a directory of files of the parsed data and an action to
   perform with them. }
  TFormSelectParsedDirectory = class(TForm)
    ListViewFiles: TListView;
    TreeView: TTreeView;
    CheckBoxSubDirectories: TCheckBox;
    LabelFileCount: TLabel;
    BitBtnCancel: TBitBtn;
    ButtonSelect: TButton;
    ButtonAdd: TButton;
    ButtonRemove: TButton;
    ButtonRemoveOthers: TButton;
    ImageList: TImageList;
    PopupMenu: TPopupMenu;
    MenuItemExpandAll: TMenuItem;
    MenuItemCollapseAll: TMenuItem;
    procedure TreeViewChange(Sender: TObject; Node: TTreeNode);
    procedure TreeViewCollapsed(Sender: TObject; Node: TTreeNode);
    procedure TreeViewExpanded(Sender: TObject; Node: TTreeNode);
    procedure CheckBoxSubDirectoriesClick(Sender: TObject);
    procedure ButtonActionClick(Sender: TObject);
    procedure MenuItemExpandAllClick(Sender: TObject);
    procedure MenuItemCollapseAllClick(Sender: TObject);
  private
    //the list of files in which to select a module
    FFileList: TFileList;
    //whether a module for files or classes should be selected
    //(currently unused)
    FIsFileDiagram: Boolean;

    //the selected action to perform on the files/classes in the selected
    //module
    FAction: TDiagramDirectoryAction;

    //Adds all directories as modules to the tree view so one can be selected.
    procedure ShowDirectories;
    //Calculates the path for the specified node.
    function CalculatePath(Node: TTreeNode; var Path: String): Boolean;
  public
    //Creates the dialog to select a module (directory) and perform an action
    //with it.
    constructor Create(FileList: TFileList; IsFileDiagram: Boolean);
                                                                   reintroduce;
    //Frees the dialog.
    destructor Destroy; override;

    //Returns the result of the dialog, only to be used, when ~[code ShowModal]
    //returns ~[code mrOK].
    function GetResult(Files: TList): TDiagramDirectoryAction;
  end;


implementation

{$R *.dfm}

uses SysUtils,
     UFilePaths,
     USettingsKeeper;



{Creates the dialog to select a module (directory) and perform an action with
 it.
~param FileList      the list of files in which to select a module
~param IsFileDiagram whether a module for files or classes should be selected }
constructor TFormSelectParsedDirectory.Create(FileList: TFileList;
                                              IsFileDiagram: Boolean);
begin
 inherited Create(nil);                    //create the dialog

 FFileList := FileList;                    //save the parameters
 FIsFileDiagram := IsFileDiagram;

 FAction := ddaInvalid;                    //no action selected so far

 ShowDirectories;                          //show the "modules"

 TFormSettings.SaveBasicFormValues(Self);  //read the basic form values
end;

{Frees the dialog. }
destructor TFormSelectParsedDirectory.Destroy;
var        Settings        :TFormSettings; //to save the settings of the form
begin
 //get object to save the settings in
 Settings := TFormSettings(TFormSettings.GetSettings(ClassName));
 if assigned(Settings) then
  Settings.GetValuesFromForm(Self);        //save current settings

 inherited Destroy;                        //free the form
end;


{Returns the result of the dialog, only to be used, when ~[code ShowModal]
 returns ~[code mrOK].
~param Files the list to which the files in the module should be added
~result the action to perform with the files }
function TFormSelectParsedDirectory.GetResult(Files: TList):
                                                       TDiagramDirectoryAction;
var      Directory                 :String;   //the selected "module"
         i                         :Integer;  //counter through all files
begin
 if CalculatePath(TreeView.Selected, Directory) then //get selected module
  if CheckBoxSubDirectories.Checked then               //including sub-modules?
   begin
    //add all files inside the module (or sub-module) to the list
    for i := 0 to FFileList.Count - 1 do
     if Copy(FFileList[i].FilePath, 1, Length(Directory)) = Directory then
      Files.Add(FFileList[i]);
   end
  else
   //add all files inside the module to the list
   for i := 0 to FFileList.Count - 1 do
    if ExtractFileDir(FFileList[i].FilePath) = Directory then
     Files.Add(FFileList[i]);
 Result := FAction;                           //return the selected action
end;






{Adds all directories as modules to the tree view so one can be selected. }
procedure TFormSelectParsedDirectory.ShowDirectories;

 {Adds the directory (and its parent directories) to the tree view.
 ~param Dir     the directory to add to the tree view
 ~param BaseDir the base directory of the root to add the directory to
 ~param Root    the node of the base directory to add the directory to
 ~result the node of the added directory }
 function AddDirs(Dir, BaseDir: String; Root: TTreeNode): TTreeNode;
 var      Drive      :String;        //drive portion of the path
          IsDrive    :Boolean;       //whether a drive should be added
          Index      :Integer;       //index of path delimiter in the string
 begin
  Delete(Dir, 1, Length(BaseDir));   //get relative path
  if Dir <> '' then                  //not the base directory itself?
   begin
    IsDrive := (BaseDir = '');         //no comment base directory?
    if IsDrive then                    //so could include a drive?
     begin
      Drive := ExtractFileDrive(Dir);  //is a drive?
      //may include an additional path delimiter?
      if Length(Drive) <> Length(Dir) then
       begin
        IsDrive := (Length(Drive) = Length(Dir) - 1) and
                   (Dir[Length(Dir)] = PathDelimiter) and
                   (Drive = copy(Dir, 1, Length(Dir) - 1));
        if IsDrive then                  //is a drive with path delimiter?
         Dir := Drive;                     //don't show the path delimiter
       end
      else
       IsDrive := Drive = Dir;           //is a drive?
     end;
    assert(not IsDrive or (Root = TreeView.Items.GetFirstNode));
    assert(not IsDrive or (BaseDir = ''));

    if not IsDrive then                //not a drive?
     begin
      Index := pos(PathDelimiter, Dir);
      if Index <> 0 then                 //has a super directory?
       begin

⌨️ 快捷键说明

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