瀏覽代碼

Bug 1951: When opening or switching to a session whose local directory does not exist, open the nearest existing parent directory

https://winscp.net/tracker/1951
(cherry picked from commit 10aa9e9018712ce2481c9fa7d1ab8d6fdca417b2)

# Conflicts:
#	source/forms/ScpCommander.cpp

Source commit: cc258beb565c161b003fb845b10753c364a1ceea
Martin Prikryl 4 年之前
父節點
當前提交
58303ecfb9
共有 2 個文件被更改,包括 28 次插入0 次删除
  1. 4 0
      source/forms/ScpCommander.cpp
  2. 24 0
      source/packages/filemng/DirView.pas

+ 4 - 0
source/forms/ScpCommander.cpp

@@ -545,6 +545,10 @@ void __fastcall TScpCommanderForm::TerminalChanged(bool Replaced)
           {
             Terminal->ShowExtendedException(&E);
           }
+          else
+          {
+            ALocalDirView->OpenFallbackPath(LocalDirectory);
+          }
         }
       }
     }

+ 24 - 0
source/packages/filemng/DirView.pas

@@ -270,6 +270,7 @@ type
     function ItemFileName(Item: TListItem): string; override;
     function ItemFileSize(Item: TListItem): Int64; override;
     function ItemFileTime(Item: TListItem; var Precision: TDateTimePrecision): TDateTime; override;
+    procedure OpenFallbackPath(Value: string);
 
     {Thread handling: }
     procedure StartWatchThread;
@@ -970,6 +971,29 @@ begin
   end;
 end;
 
+procedure TDirView.OpenFallbackPath(Value: string);
+var
+  APath: string;
+begin
+  while True do
+  begin
+    APath := ExtractFileDir(Value);
+    if (APath = '') or (APath = Value) then
+    begin
+      Break;
+    end
+      else
+    begin
+      try
+        Path := APath;
+        Break;
+      except
+        Value := APath;
+      end;
+    end;
+  end;
+end;
+
 procedure TDirView.SetLoadEnabled(Value: Boolean);
 begin
   if Value <> LoadEnabled then