Browse Source

Local path pattern (!\) for custom commands

Source commit: b79afe6bc0f0704957f32bf1371aab37fd731ab5
Martin Prikryl 9 years ago
parent
commit
0cbf6e94e4
3 changed files with 34 additions and 17 deletions
  1. 9 8
      source/forms/CustomScpExplorer.cpp
  2. 20 7
      source/windows/GUITools.cpp
  3. 5 2
      source/windows/GUITools.h

+ 9 - 8
source/forms/CustomScpExplorer.cpp

@@ -1684,7 +1684,7 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
   else
   {
     TCustomCommandData Data(Terminal);
-    TLocalCustomCommand LocalCustomCommand(Data, Terminal->CurrentDirectory);
+    TLocalCustomCommand LocalCustomCommand(Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory());
     TWinInteractiveCustomCommand InteractiveCustomCommand(
       &LocalCustomCommand, ACommand.Name);
 
@@ -1798,7 +1798,7 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
 
               TCustomCommandData Data(FTerminal);
               TLocalCustomCommand CustomCommand(Data,
-                Terminal->CurrentDirectory, L"", LocalFile, FileList);
+                Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
               UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
 
               if (NonBlocking)
@@ -1821,7 +1821,7 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
                   UnicodeString FileName = RemoteFileList->Strings[Index];
                   TCustomCommandData Data(FTerminal);
                   TLocalCustomCommand CustomCommand(Data,
-                    Terminal->CurrentDirectory, FileName, LocalFile, L"");
+                    Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
                   ExecuteShellAndWait(CustomCommand.Complete(Command, true));
                 }
               }
@@ -1833,7 +1833,7 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
                 {
                   TCustomCommandData Data(FTerminal);
                   TLocalCustomCommand CustomCommand(
-                    Data, Terminal->CurrentDirectory,
+                    Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
                     FileName, LocalFileList->Strings[Index], L"");
                   ExecuteShellAndWait(CustomCommand.Complete(Command, true));
                 }
@@ -1850,7 +1850,7 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
                   UnicodeString FileName = RemoteFileList->Strings[Index];
                   TCustomCommandData Data(FTerminal);
                   TLocalCustomCommand CustomCommand(
-                    Data, Terminal->CurrentDirectory,
+                    Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
                     FileName, LocalFileList->Strings[Index], L"");
                   ExecuteShellAndWait(CustomCommand.Complete(Command, true));
                 }
@@ -1862,7 +1862,8 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
               {
                 TCustomCommandData Data(FTerminal);
                 TLocalCustomCommand CustomCommand(Data,
-                  Terminal->CurrentDirectory, RemoteFileList->Strings[Index], L"", L"");
+                  Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
+                  RemoteFileList->Strings[Index], L"", L"");
                 ExecuteShellAndWait(CustomCommand.Complete(Command, true));
               }
             }
@@ -1972,7 +1973,7 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
         UnicodeString FileList = MakeFileList(LocalFileList.get());
         TCustomCommandData Data(FTerminal);
         TLocalCustomCommand CustomCommand(
-          Data, Terminal->CurrentDirectory,
+          Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
           L"", L"", FileList);
         ExecuteShell(CustomCommand.Complete(Command, true));
       }
@@ -1991,7 +1992,7 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
             UnicodeString FileName = LocalFileList->Strings[Index];
             TCustomCommandData Data(FTerminal);
             TLocalCustomCommand CustomCommand(
-              Data, Terminal->CurrentDirectory,
+              Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
               FileName, L"", L"");
             ExecuteShellAndWait(CustomCommand.Complete(Command, true));
           }

+ 20 - 7
source/windows/GUITools.cpp

@@ -898,24 +898,30 @@ TLocalCustomCommand::TLocalCustomCommand()
 {
 }
 //---------------------------------------------------------------------------
-TLocalCustomCommand::TLocalCustomCommand(const TCustomCommandData & Data,
-    const UnicodeString & Path) :
-  TFileCustomCommand(Data, Path)
+TLocalCustomCommand::TLocalCustomCommand(
+    const TCustomCommandData & Data, const UnicodeString & RemotePath, const UnicodeString & LocalPath) :
+  TFileCustomCommand(Data, RemotePath)
 {
+  FLocalPath = LocalPath;
 }
 //---------------------------------------------------------------------------
 TLocalCustomCommand::TLocalCustomCommand(const TCustomCommandData & Data,
-  const UnicodeString & Path, const UnicodeString & FileName,
+  const UnicodeString & RemotePath, const UnicodeString & LocalPath, const UnicodeString & FileName,
   const UnicodeString & LocalFileName, const UnicodeString & FileList) :
-  TFileCustomCommand(Data, Path, FileName, FileList)
+  TFileCustomCommand(Data, RemotePath, FileName, FileList)
 {
+  FLocalPath = LocalPath;
   FLocalFileName = LocalFileName;
 }
 //---------------------------------------------------------------------------
 int __fastcall TLocalCustomCommand::PatternLen(const UnicodeString & Command, int Index)
 {
   int Len;
-  if ((Index < Command.Length()) && (Command[Index + 1] == L'^'))
+  if ((Index < Command.Length()) && (Command[Index + 1] == L'\\'))
+  {
+    Len = 2;
+  }
+  else if ((Index < Command.Length()) && (Command[Index + 1] == L'^'))
   {
     Len = 3;
   }
@@ -930,7 +936,14 @@ bool __fastcall TLocalCustomCommand::PatternReplacement(
   const UnicodeString & Pattern, UnicodeString & Replacement, bool & Delimit)
 {
   bool Result;
-  if (Pattern == L"!^!")
+  if (Pattern == L"!\\")
+  {
+    // When used as "!\" in an argument to PowerShell, the trailing \ would escpae the ",
+    // so we exclude it
+    Replacement = ExcludeTrailingBackslash(FLocalPath);
+    Result = true;
+  }
+  else if (Pattern == L"!^!")
   {
     Replacement = FLocalFileName;
     Result = true;

+ 5 - 2
source/windows/GUITools.h

@@ -66,8 +66,10 @@ class TLocalCustomCommand : public TFileCustomCommand
 {
 public:
   TLocalCustomCommand();
-  TLocalCustomCommand(const TCustomCommandData & Data, const UnicodeString & Path);
-  TLocalCustomCommand(const TCustomCommandData & Data, const UnicodeString & Path,
+  TLocalCustomCommand(
+    const TCustomCommandData & Data, const UnicodeString & RemotePath, const UnicodeString & LocalPath);
+  TLocalCustomCommand(
+    const TCustomCommandData & Data, const UnicodeString & RemotePath, const UnicodeString & LocalPath,
     const UnicodeString & FileName, const UnicodeString & LocalFileName,
     const UnicodeString & FileList);
 
@@ -81,6 +83,7 @@ protected:
   virtual void __fastcall DelimitReplacement(UnicodeString & Replacement, wchar_t Quote);
 
 private:
+  UnicodeString FLocalPath;
   UnicodeString FLocalFileName;
 };
 //---------------------------------------------------------------------------