ソースを参照

Bug 1905: Allow explicit navigation to a hidden local folder by enabling showing of hidden files and folder, if not enabled yet

https://winscp.net/tracker/1905
(cherry picked from commit dd1128215ebb5ca58905668c8723a9f51895e84c)

# Conflicts:
#	source/forms/ScpCommander.cpp
#	source/forms/ScpCommander.dfm
#	source/forms/ScpCommander.h

Source commit: fa0ca02caa74796fef48c15678bb14702d079712
Martin Prikryl 5 年 前
コミット
addb71d358

+ 8 - 0
source/forms/ScpCommander.cpp

@@ -2329,3 +2329,11 @@ void __fastcall TScpCommanderForm::ThemeChanged()
   LocalDirView->Perform(WM_THEMECHANGED, 0, 0);
 }
 //---------------------------------------------------------------------------
+void __fastcall TScpCommanderForm::LocalDriveViewNeedHiddenDirectories(TObject *)
+{
+  if (DebugAlwaysTrue(!WinConfiguration->ShowHiddenFiles))
+  {
+    ToggleShowHiddenFiles();
+  }
+}
+//---------------------------------------------------------------------------

+ 2 - 0
source/forms/ScpCommander.dfm

@@ -1130,6 +1130,7 @@ inherited ScpCommanderForm: TScpCommanderForm
       Height = 45
       Align = alTop
       Constraints.MinHeight = 30
+        OnNeedHiddenDirectories = LocalDriveViewNeedHiddenDirectories
       inherited RemoteDriveView: TUnixDriveView
         Width = 458
         Height = 45
@@ -1701,6 +1702,7 @@ inherited ScpCommanderForm: TScpCommanderForm
       TabOrder = 2
       TabStop = False
       OnEnter = LocalDriveViewEnter
+      OnNeedHiddenDirectories = LocalDriveViewNeedHiddenDirectories
     end
     object LocalBottomDock: TTBXDock
       Left = 0

+ 1 - 0
source/forms/ScpCommander.h

@@ -495,6 +495,7 @@ __published:
   void __fastcall LocalPathLabelMaskClick(TObject *Sender);
   void __fastcall LocalOpenDirButtonPopup(TTBCustomItem *Sender, bool FromLink);
   void __fastcall RemoteOpenDirButtonPopup(TTBCustomItem *Sender, bool FromLink);
+  void __fastcall LocalDriveViewNeedHiddenDirectories(TObject *Sender);
 
 private:
   bool FConstructed;

+ 29 - 0
source/packages/filemng/DriveView.pas

@@ -141,6 +141,7 @@ type
     {Additional events:}
     FOnDisplayContextMenu: TNotifyEvent;
     FOnRefreshDrives: TNotifyEvent;
+    FOnNeedHiddenDirectories: TNotifyEvent;
 
     {used components:}
     FDirView: TDirView;
@@ -388,6 +389,7 @@ type
     property OnMouseUp;
     property OnStartDock;
     property OnStartDrag;
+    property OnNeedHiddenDirectories: TNotifyEvent read FOnNeedHiddenDirectories write FOnNeedHiddenDirectories;
   end;
 
 procedure Register;
@@ -2185,7 +2187,34 @@ begin
 end; {SetAutoScan}
 
 function TDriveView.FindPathNode(Path: string): TTreeNode;
+var
+  PossiblyHiddenPath: string;
+  Attrs: Integer;
 begin
+  if Assigned(FOnNeedHiddenDirectories) and
+     (not ShowHiddenDirs) and
+     DirectoryExistsFix(Path) then // do not even bother if the path does not exist
+  begin
+    PossiblyHiddenPath := ExcludeTrailingPathDelimiter(Path);
+    while (PossiblyHiddenPath <> '') and
+          (not IsRootPath(PossiblyHiddenPath)) do // Drives have hidden attribute
+    begin
+      Attrs := FileGetAttr(PossiblyHiddenPath, False);
+      if (Attrs and faHidden) = faHidden then
+      begin
+        if Assigned(FOnNeedHiddenDirectories) then
+        begin
+          FOnNeedHiddenDirectories(Self);
+        end;
+        Break;
+      end
+        else
+      begin
+        PossiblyHiddenPath := ExtractFileDir(PossiblyHiddenPath);
+      end;
+    end;
+  end;
+
   {Find existing path or parent path of not existing path:}
   repeat
     Result := FindNodeToPath(Path);