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

📄 uselectparseddirectory.pas

📁 DelphiDoc is a program for automatic generation of documentation on a Delphi-Project. At the momen
💻 PAS
📖 第 1 页 / 共 2 页
字号:
        Root := AddDirs(ExtractFileDir(Dir), '', Root); //add it
        Dir := ExtractFileName(Dir);
       end;
     end;

    Result := Root.GetFirstChild;      //will be added under it
    while assigned(Result) and (Result.Text <> Dir) do //search the class
     Result := Result.GetNextSibling;
    if not assigned(Result) then       //class not already added?
     begin
      Result := TreeView.Items.AddChild(Root, Dir);  //add the node
      Result.ImageIndex := 0;
      Result.SelectedIndex := 0;
     end;
   end
  else
   Result := Root;
 end;


var       LongBaseDir :String;         //base directory of all parsed files
          Root        :TTreeNode;      //root for the base directory
          i           :Integer;        //counter through list of classes
begin
 TreeView.Items.Clear;                 //clear the tree view

 if not FFileList.IsEmpty then
  begin
   //get the common base directory of all parsed files
   LongBaseDir := FFileList.GetLongPathName(FFileList.GetCommonBasePath);
   if LongBaseDir = '' then              //create root with the base directory
    Root := TreeView.Items.Add(nil, 'All parsed Files')
   else
    Root := TreeView.Items.Add(nil, LongBaseDir);
   Root.ImageIndex := 0;
   Root.SelectedIndex := 0;

   for i := 0 to FFileList.Count - 1 do  //for each class in the list
    AddDirs(FFileList.GetLongPathName(ExtractFileDir(FFileList[i].FilePath)),
            LongBaseDir, Root).Data := FFileList[i];  //add directories
   TreeView.FullExpand;                  //and show all nodes
   Root.Selected := True;
  end;
end;

{Calculates the path for the specified node.
~param Node the node for which to calculate the path
~param Path out: the path represented by the node
~result whether a valid node was specified }
function TFormSelectParsedDirectory.CalculatePath(Node: TTreeNode;
                                                  var Path: String): Boolean;
         //to search a node representing a path with files
var      DataNode                  :TTreeNode;
         Depth                     :Integer;   //level where node is searched
begin
 Result := assigned(Node);
 if Result then                             //a node specified?
  begin
   //base directory = all files/classes selected?
   if not assigned(Node.Data) and (Node = TreeView.Items.GetFirstNode) and
      (FFileList.GetCommonBasePath = '') then
    Path := ''                                //return the most common path
   else
    begin
     DataNode := Node;                        //start search at current node
     Depth := 0;                              //this is at the current level
     while not assigned(DataNode.Data) do     //while no files found
      begin
       inc(Depth);                              //got to the next level
       DataNode := DataNode.GetFirstChild;      //search first sub-directory
       assert(assigned(DataNode));
      end;

     assert(assigned(DataNode));
     assert(assigned(DataNode.Data));

     //get the path of a file in that directory
     Path := ExtractFileDir(TPascalFile(DataNode.Data).FilePath);
     //and retrace the search levels by removing any trailing paths
     for Depth := 1 to Depth do
      Path := ExtractFileDir(Path);
    end;
  end
 else
  Path := '';                                 //no common path, invalid node
end;













{Called when another node in the ~[link TreeView] of directories is selected.
~param Sender the sender of the event, ~[link TreeView]
~param Node   the newly selected node }
procedure TFormSelectParsedDirectory.TreeViewChange(Sender: TObject;
                                                    Node: TTreeNode);
var       Directory                 :String;   //directory of the selected node
          i                         :Integer;  //counter through all files
          Path                      :String;   //path of each file
begin
 ListViewFiles.Items.BeginUpdate;              //begin filling the file list
 try
   ListViewFiles.Items.Clear;                  //clear the list
   if CalculatePath(Node, Directory) then      //a node selected?
    for i := 0 to FFileList.Count - 1 do         //for each file
     begin
      Path := FFileList[i].FilePath;
      //check if it is in the directory of the selected node
      if ExtractFileDir(Path) = Directory then
//      if Copy(Path, 1, Length(Directory)) = Directory then
       //add the file to the list of files
       ListViewFiles.Items.Add.Caption := ExtractFileName(
                                             FFileList.GetLongPathName(Path));
     end;
 finally
  ListViewFiles.Items.EndUpdate;               //end filling the file list
 end;

 CheckBoxSubDirectoriesClick(Sender);          //show number of files
end;

{Called when a node in the ~[link TreeView] of directories is collapsed.
~param Sender the sender of the event, ~[link TreeView]
~param Node   the collapsed node }
procedure TFormSelectParsedDirectory.TreeViewCollapsed(Sender: TObject; Node: TTreeNode);
begin
 Node.ImageIndex := 0;         //set new image indicating the node is collapsed
 Node.SelectedIndex := 0;
end;

{Called when a node in the ~[link TreeView] of directories is expanded.
~param Sender the sender of the event, ~[link TreeView]
~param Node   the expanded node }
procedure TFormSelectParsedDirectory.TreeViewExpanded(Sender: TObject; Node: TTreeNode);
begin
 Node.ImageIndex := 1;         //set new image indicating the node is expanded
 Node.SelectedIndex := 1;
end;


{Called when the check box to select whether also files in sub-directories
 should be selected is toggled.
~param Sender the sender of the event, ~[link CheckBoxSubDirectories] }
procedure TFormSelectParsedDirectory.CheckBoxSubDirectoriesClick(Sender: TObject);
var       Count                     :Integer;  //number of selected files
          Directory                 :String;   //directory of the selected node
          i                         :Integer;  //counter through all files
begin
 Count := 0;                                   //no matching files found so far
 if CalculatePath(TreeView.Selected, Directory) then //a node selected?
  //select also files in sub-directories?
  if CheckBoxSubDirectories.Checked then
   begin
    for i := 0 to FFileList.Count - 1 do         //count all files
     if Copy(FFileList[i].FilePath, 1, Length(Directory)) = Directory then
      inc(Count);
   end
  else
   for i := 0 to FFileList.Count - 1 do          //count all files
    if ExtractFileDir(FFileList[i].FilePath) = Directory then
     inc(Count);

 if Count = 1 then                          //show the number of selected files
  LabelFileCount.Caption := '1 File selected'
 else
  LabelFileCount.Caption := IntToStr(Count) + ' Files selected';
end;



{Called when one of the buttons of the actions to be performed on the selected
 files is is chosen.
~param Sender the sender of the event, ~[link ButtonSelect], ~[link ButtonAdd],
              ~[link ButtonRemove] or ~[link ButtonRemoveOthers] }
procedure TFormSelectParsedDirectory.ButtonActionClick(Sender: TObject);
begin
 assert(Sender is TButton);
 assert((TButton(Sender).Tag >= Ord(Low(FAction))) and
        (TButton(Sender).Tag <= Ord(High(FAction))));

 //save the selected action
 FAction := TDiagramDirectoryAction(TButton(Sender).Tag);
 //dialog will be closed after this with ModalResult = mrOK
end;


{Called when the menu item to expand the whole tree is chosen.
~param Sender the sender of the event, ~[link MenuItemExpandAll] }
procedure TFormSelectParsedDirectory.MenuItemExpandAllClick(Sender: TObject);
begin
 TreeView.FullExpand;
end;

{Called when the menu item to collapse the whole tree is chosen.
~param Sender the sender of the event, ~[link MenuItemCollapseAll] }
procedure TFormSelectParsedDirectory.MenuItemCollapseAllClick(Sender: TObject);
begin
 TreeView.FullCollapse;
end;

end.

⌨️ 快捷键说明

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