Explorar o código

Bug 909: Expand environment variables in Open Directory/Location Profiles dialogs for local paths

https://winscp.net/tracker/909

Source commit: ba4ff1c3bbcf6267e86dd42c31b20cc8bd560edf
Martin Prikryl %!s(int64=3) %!d(string=hai) anos
pai
achega
195ad9a64a

+ 7 - 4
source/forms/CustomScpExplorer.cpp

@@ -4461,9 +4461,7 @@ bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookm
   bool Result = !Path.IsEmpty();
   if (Result)
   {
-    // While we might get here when the session is closed (from location profiles),
-    // it's not a problem as the Path setter is noop then
-    DirView(Side)->Path = Path;
+    TryOpenDirectory(Side, Path);
   }
   return Result;
 }
@@ -10870,14 +10868,19 @@ bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, co
   bool Remote = !IsSideLocalBrowser(Side);
   try
   {
+    UnicodeString APath = Path;
     if (Remote)
     {
       Terminal->ExceptionOnFail = true;
     }
+    else
+    {
+      APath = ExpandEnvironmentVariables(Path);
+    }
 
     try
     {
-      DirView(Side)->Path = Path;
+      DirView(Side)->Path = APath;
     }
     __finally
     {

+ 1 - 6
source/forms/LocationProfiles.cpp

@@ -953,12 +953,7 @@ void __fastcall TLocationProfilesDialog::ProfilesViewGetSelectedIndex(
 void __fastcall TLocationProfilesDialog::LocalDirectoryBrowseButtonClick(
   TObject * /*Sender*/)
 {
-  UnicodeString Directory = LocalDirectoryEdit->Text;
-  if (SelectDirectory(Directory, LoadStr(SELECT_LOCAL_DIRECTORY), true))
-  {
-    LocalDirectoryEdit->Text = Directory;
-    DirectoryEditChange(LocalDirectoryEdit);
-  }
+  SelectDirectoryForEdit(LocalDirectoryEdit);
 }
 //---------------------------------------------------------------------------
 void __fastcall TLocationProfilesDialog::SwitchButtonClick(TObject * /*Sender*/)

+ 1 - 6
source/forms/OpenDirectory.cpp

@@ -552,12 +552,7 @@ void __fastcall TOpenDirectoryDialog::BookmarksListKeyDown(TObject * Sender,
 void __fastcall TOpenDirectoryDialog::LocalDirectoryBrowseButtonClick(
   TObject * /*Sender*/)
 {
-  UnicodeString Directory = LocalDirectoryEdit->Text;
-  if (SelectDirectory(Directory, LoadStr(SELECT_LOCAL_DIRECTORY), true))
-  {
-    LocalDirectoryEdit->Text = Directory;
-    DirectoryEditChange(NULL);
-  }
+  SelectDirectoryForEdit(LocalDirectoryEdit);
 }
 //---------------------------------------------------------------------------
 void __fastcall TOpenDirectoryDialog::SwitchButtonClick(TObject * /*Sender*/)

+ 2 - 1
source/forms/ScpCommander.cpp

@@ -1736,7 +1736,8 @@ void __fastcall TScpCommanderForm::DoOpenBookmark(UnicodeString Local, UnicodeSt
   {
     if (!Local.IsEmpty())
     {
-      LocalDirView->Path = Local;
+      DebugAssert(!IsLocalBrowserMode());
+      LocalDirView->Path = ExpandEnvironmentVariables(Local);
     }
   }
   __finally

+ 15 - 0
source/windows/VCLCommon.cpp

@@ -1329,6 +1329,21 @@ bool __fastcall SelectDirectory(UnicodeString & Path, const UnicodeString Prompt
   return Result;
 }
 //---------------------------------------------------------------------------
+void SelectDirectoryForEdit(THistoryComboBox * Edit)
+{
+  UnicodeString OriginalDirectory = ExpandEnvironmentVariables(Edit->Text);
+  UnicodeString Directory = OriginalDirectory;
+  if (SelectDirectory(Directory, LoadStr(SELECT_LOCAL_DIRECTORY), true) &&
+      !SamePaths(OriginalDirectory, Directory))
+  {
+    Edit->Text = Directory;
+    if (Edit->OnChange != NULL)
+    {
+      Edit->OnChange(Edit);
+    }
+  }
+}
+//---------------------------------------------------------------------------
 bool __fastcall ListViewAnyChecked(TListView * ListView, bool Checked)
 {
   bool AnyChecked = false;

+ 2 - 0
source/windows/VCLCommon.h

@@ -6,6 +6,7 @@
 #include "Configuration.h"
 #include "Exceptions.h"
 #include <ComCtrls.hpp>
+#include <HistoryComboBox.hpp>
 //---------------------------------------------------------------------------
 const TColor LinkColor = clBlue;
 //---------------------------------------------------------------------------
@@ -36,6 +37,7 @@ bool __fastcall ReleaseAsModal(TForm * Form, void *& Storage);
 bool __fastcall IsMainFormLike(TCustomForm * Form);
 bool __fastcall SelectDirectory(UnicodeString & Path, const UnicodeString Prompt,
   bool PreserveFileName);
+void SelectDirectoryForEdit(THistoryComboBox * Edit);
 enum TListViewCheckAll { caCheck, caUncheck, caToggle };
 bool __fastcall ListViewAnyChecked(TListView * ListView, bool Checked = true);
 void __fastcall ListViewCheckAll(TListView * ListView,