Forráskód Böngészése

Bug fix: Local custom commands that do not work with files froze the interface + Local custom commands that work with list of files do not block the interface

Source commit: 72aed8f875f137e1ce2e9eb7544012b955a814d3
Martin Prikryl 9 éve
szülő
commit
111b7f4db9

+ 43 - 26
source/forms/CustomScpExplorer.cpp

@@ -1708,7 +1708,7 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
 
     if (!LocalCustomCommand.IsFileCommand(Command))
     {
-      ExecuteShellAndWait(LocalCustomCommand.Complete(Command, true));
+      ExecuteShell(LocalCustomCommand.Complete(Command, true));
     }
     // remote files?
     else if ((FCurrentSide == osRemote) || LocalFileCommand)
@@ -1782,11 +1782,16 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
             ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
           }
 
+          bool NonBlocking = FileListCommand && RemoteFiles;
+
           TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
 
-          Progress.Start(foCustomCommand, osRemote, FileListCommand ? 1 : FileList->Count);
-          DebugAssert(FProgressForm != NULL);
-          FProgressForm->ReadOnly = true;
+          if (!NonBlocking)
+          {
+            Progress.Start(foCustomCommand, osRemote, FileListCommand ? 1 : FileList->Count);
+            DebugAssert(FProgressForm != NULL);
+            FProgressForm->ReadOnly = true;
+          }
 
           try
           {
@@ -1805,7 +1810,16 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
               TCustomCommandData Data(FTerminal);
               TLocalCustomCommand CustomCommand(Data,
                 Terminal->CurrentDirectory, L"", LocalFile, FileList);
-              ExecuteShellAndWait(CustomCommand.Complete(Command, true));
+              UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
+
+              if (NonBlocking)
+              {
+                ExecuteShell(ShellCommand);
+              }
+              else
+              {
+                ExecuteShellAndWait(ShellCommand);
+              }
             }
             else if (LocalFileCommand)
             {
@@ -1866,7 +1880,10 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
           }
           __finally
           {
-            Progress.Stop();
+            if (!NonBlocking)
+            {
+              Progress.Stop();
+            }
           }
 
           DebugAssert(!FAutoOperation);
@@ -1961,24 +1978,24 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
         }
       }
 
-      TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
+      if (FileListCommand)
+      {
+        UnicodeString FileList = MakeFileList(LocalFileList.get());
+        TCustomCommandData Data(FTerminal);
+        TLocalCustomCommand CustomCommand(
+          Data, Terminal->CurrentDirectory,
+          L"", L"", FileList);
+        ExecuteShell(CustomCommand.Complete(Command, true));
+      }
+      else
+      {
+        TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
 
-      Progress.Start(foCustomCommand, osRemote, FileListCommand ? 1 : LocalFileList->Count);
-      DebugAssert(FProgressForm != NULL);
-      FProgressForm->ReadOnly = true;
+        Progress.Start(foCustomCommand, osRemote, FileListCommand ? 1 : LocalFileList->Count);
+        DebugAssert(FProgressForm != NULL);
+        FProgressForm->ReadOnly = true;
 
-      try
-      {
-        if (FileListCommand)
-        {
-          UnicodeString FileList = MakeFileList(LocalFileList.get());
-          TCustomCommandData Data(FTerminal);
-          TLocalCustomCommand CustomCommand(
-            Data, Terminal->CurrentDirectory,
-            L"", L"", FileList);
-          ExecuteShellAndWait(CustomCommand.Complete(Command, true));
-        }
-        else
+        try
         {
           for (int Index = 0; Index < LocalFileList->Count; Index++)
           {
@@ -1990,10 +2007,10 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
             ExecuteShellAndWait(CustomCommand.Complete(Command, true));
           }
         }
-      }
-      __finally
-      {
-        Progress.Stop();
+        __finally
+        {
+          Progress.Stop();
+        }
       }
     }
   }

+ 6 - 1
source/windows/GUITools.cpp

@@ -179,7 +179,12 @@ bool __fastcall ExecuteShell(const UnicodeString Path, const UnicodeString Param
     (wchar_t*)Params.data(), NULL, SW_SHOWNORMAL) > 32);
 }
 //---------------------------------------------------------------------------
-bool __fastcall ExecuteShell(const UnicodeString Path, const UnicodeString Params,
+bool __fastcall ExecuteShell(const UnicodeString Command)
+{
+  UnicodeString Program, Params, Dir;
+  SplitCommand(Command, Program, Params, Dir);
+  return ExecuteShell(Program, Params);
+}
 //---------------------------------------------------------------------------
 static bool __fastcall DoExecuteShell(HWND ApplicationHandle, const UnicodeString Path, const UnicodeString Params,
   HANDLE & Handle)

+ 1 - 0
source/windows/GUITools.h

@@ -21,6 +21,7 @@ typedef void __fastcall (__closure* TProcessMessagesEvent)();
 bool __fastcall FindFile(UnicodeString & Path);
 bool __fastcall FindTool(const UnicodeString & Name, UnicodeString & Path);
 bool __fastcall ExecuteShell(const UnicodeString Path, const UnicodeString Params);
+bool __fastcall ExecuteShell(const UnicodeString Command);
 bool __fastcall ExecuteShell(const UnicodeString Path, const UnicodeString Params,
   HANDLE & Handle);
 bool __fastcall ExecuteShellAndWait(HWND Handle, const UnicodeString Path,