AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein GUI-Design mit VCL / FireMonkey / Common Controls MustangpeakVirtualshellTools um Wildcards/PathMatchSpecW erweitern

MustangpeakVirtualshellTools um Wildcards/PathMatchSpecW erweitern

Ein Thema von DieDolly · begonnen am 21. Feb 2021
Antwort Antwort
DieDolly

Registriert seit: 22. Jun 2018
2.173 Beiträge
 
#1

MustangpeakVirtualshellTools um Wildcards/PathMatchSpecW erweitern

  Alt 21. Feb 2021, 12:48
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:
function StrMatchesMask(const pszFile: string; pszSpec: string): Boolean;
begin
 if Copy(pszSpec, 1, 1) <> '\then
  pszSpec := '*' + pszSpec + '*';

 Result := PathMatchSpecW(PWideChar(pszFile), PWideChar(pszSpec));
end;
Aber wo baue ich das ein?
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;

Geändert von DieDolly (21. Feb 2021 um 12:54 Uhr)
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:57 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz