Browse Source

Bug 1740: Start main window with the last user local folder instead of always starting in Documents folder

https://winscp.net/tracker/1740

Source commit: 8fd910ca9c7851fb03c0ad6c9ce4851dbf363c6b
Martin Prikryl 6 years ago
parent
commit
df836a05c9

+ 25 - 14
source/forms/ScpCommander.cpp

@@ -232,6 +232,7 @@ void __fastcall TScpCommanderForm::StoreParams()
     StorePanelParams(LocalDirView, LocalDriveView, LocalStatusBar, CommanderConfiguration.LocalPanel);
     StorePanelParams(RemoteDirView, RemoteDrivePanel, RemoteStatusBar, CommanderConfiguration.RemotePanel);
 
+    CommanderConfiguration.LocalPanel.LastPath = LocalDirView->Path;
 
     CommanderConfiguration.WindowParams = StoreForm(this);
 
@@ -536,9 +537,8 @@ void __fastcall TScpCommanderForm::TerminalChanged(bool Replaced)
     if (FFirstTerminal || !WinConfiguration->ScpCommander.PreserveLocalDirectory)
     {
       UnicodeString LocalDirectory = ManagedTerminal->StateData->LocalDirectory;
-      bool DocumentsDir = LocalDirectory.IsEmpty();
 
-      if (!DocumentsDir)
+      if (!LocalDirectory.IsEmpty())
       {
         try
         {
@@ -546,18 +546,12 @@ void __fastcall TScpCommanderForm::TerminalChanged(bool Replaced)
         }
         catch(Exception & E)
         {
-          DocumentsDir = true;
           if (!Terminal->SessionData->UpdateDirectories)
           {
             Terminal->ShowExtendedException(&E);
           }
         }
       }
-
-      if (DocumentsDir)
-      {
-        LocalDefaultDirectory();
-      }
     }
     FFirstTerminal = false;
 
@@ -586,15 +580,32 @@ void __fastcall TScpCommanderForm::TerminalChanged(bool Replaced)
 //---------------------------------------------------------------------------
 void __fastcall TScpCommanderForm::LocalDefaultDirectory()
 {
-  try
+  bool DocumentsDir = true;
+  UnicodeString LastPath = WinConfiguration->ScpCommander.LocalPanel.LastPath;
+  if (!LastPath.IsEmpty())
   {
-    LocalDirView->HomeDirectory = L"";
-    LocalDirView->ExecuteHomeDirectory();
+    try
+    {
+      LocalDirView->Path = LastPath;
+      DocumentsDir = false;
+    }
+    catch (...)
+    {
+    }
   }
-  catch(Exception & E)
+
+  if (DocumentsDir)
   {
-    ShowExtendedException(NULL, &E);
-    LocalDirView->Path = ExtractFilePath(Application->ExeName);
+    try
+    {
+      LocalDirView->HomeDirectory = L"";
+      LocalDirView->ExecuteHomeDirectory();
+    }
+    catch(Exception & E)
+    {
+      ShowExtendedException(NULL, &E);
+      LocalDirView->Path = ExtractFilePath(Application->ExeName);
+    }
   }
 }
 //---------------------------------------------------------------------------

+ 4 - 0
source/windows/WinConfiguration.cpp

@@ -753,6 +753,7 @@ void __fastcall TWinConfiguration::Default()
   FScpCommander.RemotePanel.DriveViewHeightPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
   FScpCommander.RemotePanel.DriveViewWidth = 100;
   FScpCommander.RemotePanel.DriveViewWidthPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
+  FScpCommander.RemotePanel.LastPath = UnicodeString();
   FScpCommander.LocalPanel.DirViewParams = L"0;1;0|150,1;70,1;120,1;150,1;55,0;55,0;@" + SaveDefaultPixelsPerInch() + L"|5;0;1;2;3;4";
   FScpCommander.LocalPanel.StatusBar = true;
   FScpCommander.LocalPanel.DriveView = false;
@@ -760,6 +761,7 @@ void __fastcall TWinConfiguration::Default()
   FScpCommander.LocalPanel.DriveViewHeightPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
   FScpCommander.LocalPanel.DriveViewWidth = 100;
   FScpCommander.LocalPanel.DriveViewWidthPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
+  FScpCommander.LocalPanel.LastPath = UnicodeString();
 
   FBookmarks->Clear();
 }
@@ -1133,6 +1135,7 @@ THierarchicalStorage * TWinConfiguration::CreateScpStorage(bool & SessionList)
     KEY(Integer, ScpCommander.LocalPanel.DriveViewHeightPixelsPerInch); \
     KEY(Integer, ScpCommander.LocalPanel.DriveViewWidth); \
     KEY(Integer, ScpCommander.LocalPanel.DriveViewWidthPixelsPerInch); \
+    KEY(String,  ScpCommander.LocalPanel.LastPath); \
   ); \
   BLOCK(L"Interface\\Commander\\RemotePanel", CANCREATE, \
     KEY(String,  ScpCommander.RemotePanel.DirViewParams); \
@@ -1142,6 +1145,7 @@ THierarchicalStorage * TWinConfiguration::CreateScpStorage(bool & SessionList)
     KEY(Integer, ScpCommander.RemotePanel.DriveViewHeightPixelsPerInch); \
     KEY(Integer, ScpCommander.RemotePanel.DriveViewWidth); \
     KEY(Integer, ScpCommander.RemotePanel.DriveViewWidthPixelsPerInch); \
+    KEY(String,  ScpCommander.RemotePanel.LastPath); \
   ); \
   BLOCK(L"Security", CANCREATE, \
     KEYEX(Bool,  FUseMasterPassword, L"UseMasterPassword"); \

+ 2 - 1
source/windows/WinConfiguration.h

@@ -40,10 +40,11 @@ struct TScpCommanderPanelConfiguration {
   int DriveViewHeightPixelsPerInch;
   int DriveViewWidth;
   int DriveViewWidthPixelsPerInch;
+  UnicodeString LastPath;
   bool __fastcall operator !=(TScpCommanderPanelConfiguration & rhc)
     { return C(DirViewParams) C(StatusBar)
         C(DriveView) C(DriveViewHeight) C(DriveViewHeightPixelsPerInch)
-        C(DriveViewWidth) C(DriveViewWidthPixelsPerInch) 0; };
+        C(DriveViewWidth) C(DriveViewWidthPixelsPerInch) C(LastPath) 0; };
 };
 //---------------------------------------------------------------------------
 struct TScpCommanderConfiguration {