![]() |
MustangpeakVirtualshellTools um Wildcards/PathMatchSpecW erweitern
Eben habe ich auf Github MustangpeakVirtualshellTools entdeckt. Das ist scheinbar ein VirtualStringTree mit Explorer-Ansicht. Das ist genau das was ich suche weil ich nicht weiß wie ich das selber basteln kann. Mit nur einer Zeile kann man Einträge aus einem Memo mit dem Tree abgleichen und alle Ordner anhaken lassen. Perfekt!
Was die Komponente aber nicht kann, sind Wildcards. Ich möchte, dass bei D:\Dateien\*.txt alle Textdateien im Ordner Dateien angehakt werden. Oder eben bei D:\Dateien\* alle Dateien. Dafür habe ich
Delphi-Quellcode:
Aber wo baue ich das ein?
function StrMatchesMask(const pszFile: string; pszSpec: string): Boolean;
begin if Copy(pszSpec, 1, 1) <> '\' then pszSpec := '*' + pszSpec + '*'; Result := PathMatchSpecW(PWideChar(pszFile), PWideChar(pszSpec)); end; Hier der Code zum anhaken der Nodes anhand eines Memos/TStrings
Delphi-Quellcode:
procedure TForm1.SetPathsButtonClick(Sender: TObject);
begin VCS.SetCheckedFileNames(TreeMemo.Lines); end; procedure TVirtualCheckboxesSynchronizer.SetCheckedFileNames(AStrings: TStrings); var I: integer; Node: PVirtualNode; begin if not Assigned(FTree) then Exit; FTree.BeginUpdate; try //Clear all checked nodes, and clear the storage FTree.GetFirst.CheckState := csUncheckedNormal; SyncCheckedNode(True, FTree.GetFirst); //Iterate the checked files list for i := 0 to AStrings.Count - 1 do begin Node := FindNodeByFilename(FTree, AStrings[I]); if Assigned(Node) then begin Node.CheckState := csCheckedNormal; SyncCheckedNode(True, Node); end; end; finally FTree.EndUpdate; end; end; function FindNodeByFilename(VET: TVirtualExplorerTreeview; Filename: string; StartingPoint: PVirtualNode): PVirtualNode; //Finds the corresponding Node of a given Filename in the Tree. //It's the same as VET.FindNode method, but it searches through uninitialized Parent Nodes. function FindNamespace(ParentNode: PVirtualNode; Filename: string): PVirtualNode; var N: PVirtualNode; NS: TNamespace; begin Result := nil; //Iterate the Tree N := ParentNode.FirstChild; while Assigned(N) do begin if VET.ValidateNamespace(N, NS) then if WideStrIComp(PWideChar(NS.NameForParsing), PWideChar(Filename)) = 0 then begin Result := N; Exit; //found it, get out of here end; N := N.NextSibling; end; end; var N: PVirtualNode; I: integer; L: TStringList; WS: string; begin Result := nil; if not Assigned(VET) or (not DirectoryExists(Filename) and not FileExists(Filename)) then Exit; if not Assigned(StartingPoint) then StartingPoint := VET.FindNodeByPIDL(DrivesFolder.AbsolutePIDL); //default to MyComputer L := TStringList.Create; try //Parse the Filename and get the list of drive/folders/file that compose the Filename WS := Filename; L.Insert(0, WS); while Length(WS) > 3 do begin WS := ExtractFileDir(WS); L.Insert(0, WS); end; N := StartingPoint; for I := 0 to L.count -1 do begin //Initialize child nodes if needed ForceInit(VET, N); //Iterate the Tree N := FindNamespace(N, L[I]); if not Assigned(N) then Exit; //no luck end; if Assigned(N) then Result := N; finally L.Free; end; end;; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:33 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz