浏览代码

Holding down Ctrl and Shift keys while running a local custom command copies the command to clipboard instead of executing it

Source commit: 23e8d376c3df17e496b707f743de1314b3896ed4
Martin Prikryl 9 年之前
父节点
当前提交
a59b47fb8e
共有 4 个文件被更改,包括 46 次插入19 次删除
  1. 1 1
      source/forms/CustomScpExplorer.cpp
  2. 38 17
      source/windows/GUITools.cpp
  3. 6 1
      source/windows/Tools.cpp
  4. 1 0
      source/windows/Tools.h

+ 1 - 1
source/forms/CustomScpExplorer.cpp

@@ -8554,7 +8554,7 @@ void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
       // to actually release the button, "mouse down" is still raised,
       // but we do not get "mouse up" event, so dragging is not cancelled,
       // prevent that by not beginning dragging in the first place.
-      if (FLAGSET(GetAsyncKeyState(VK_LBUTTON), 0x8000))
+      if (IsKeyPressed(VK_LBUTTON))
       {
         // when user clicks the "+", we get mouse down only after the session
         // is closed, when new session tab is already on X:Y, so dragging

+ 38 - 17
source/windows/GUITools.cpp

@@ -174,10 +174,27 @@ bool __fastcall FindTool(const UnicodeString & Name, UnicodeString & Path)
   return Result;
 }
 //---------------------------------------------------------------------------
+static bool __fastcall CopyShellCommandToClipboard(const UnicodeString & Path, const UnicodeString & Params)
+{
+  bool Result = UseAlternativeFunction() && IsKeyPressed(VK_CONTROL);
+  if (Result)
+  {
+    TInstantOperationVisualizer Visualizer;
+    CopyToClipboard(FormatCommand(Path, Params));
+  }
+  return Result;
+}
+//---------------------------------------------------------------------------
 bool __fastcall ExecuteShell(const UnicodeString Path, const UnicodeString Params)
 {
-  return ((int)ShellExecute(NULL, L"open", (wchar_t*)Path.data(),
-    (wchar_t*)Params.data(), NULL, SW_SHOWNORMAL) > 32);
+  bool Result = true;
+  if (!CopyShellCommandToClipboard(Path, Params))
+  {
+    Result =
+      ((int)ShellExecute(NULL, L"open", (wchar_t*)Path.data(),
+        (wchar_t*)Params.data(), NULL, SW_SHOWNORMAL) > 32);
+  }
+  return Result;
 }
 //---------------------------------------------------------------------------
 bool __fastcall ExecuteShell(const UnicodeString Command)
@@ -219,27 +236,31 @@ bool __fastcall ExecuteShellAndWait(HWND Handle, const UnicodeString Path,
   const UnicodeString Params, TProcessMessagesEvent ProcessMessages)
 {
   HANDLE ProcessHandle;
-  bool Result = DoExecuteShell(Handle, Path, Params, ProcessHandle);
-
-  if (Result)
+  bool Result = true;
+  if (!CopyShellCommandToClipboard(Path, Params))
   {
-    if (ProcessMessages != NULL)
+    Result = DoExecuteShell(Handle, Path, Params, ProcessHandle);
+
+    if (Result)
     {
-      unsigned long WaitResult;
-      do
+      if (ProcessMessages != NULL)
       {
-        WaitResult = WaitForSingleObject(ProcessHandle, 200);
-        if (WaitResult == WAIT_FAILED)
+        unsigned long WaitResult;
+        do
         {
-          throw Exception(LoadStr(DOCUMENT_WAIT_ERROR));
+          WaitResult = WaitForSingleObject(ProcessHandle, 200);
+          if (WaitResult == WAIT_FAILED)
+          {
+            throw Exception(LoadStr(DOCUMENT_WAIT_ERROR));
+          }
+          ProcessMessages();
         }
-        ProcessMessages();
+        while (WaitResult == WAIT_TIMEOUT);
+      }
+      else
+      {
+        WaitForSingleObject(ProcessHandle, INFINITE);
       }
-      while (WaitResult == WAIT_TIMEOUT);
-    }
-    else
-    {
-      WaitForSingleObject(ProcessHandle, INFINITE);
     }
   }
   return Result;

+ 6 - 1
source/windows/Tools.cpp

@@ -307,9 +307,14 @@ bool __fastcall ExecuteShellAndWait(const UnicodeString Command)
     &Application->ProcessMessages);
 }
 //---------------------------------------------------------------------------
+bool __fastcall IsKeyPressed(int VirtualKey)
+{
+  return FLAGSET(GetAsyncKeyState(VirtualKey), 0x8000);
+}
+//---------------------------------------------------------------------------
 bool __fastcall UseAlternativeFunction()
 {
-  return FLAGSET(GetAsyncKeyState(VK_SHIFT), 0x8000);
+  return IsKeyPressed(VK_SHIFT);
 }
 //---------------------------------------------------------------------------
 bool __fastcall OpenInNewWindow()

+ 1 - 0
source/windows/Tools.h

@@ -12,6 +12,7 @@
 void __fastcall CenterFormOn(TForm * Form, TControl * CenterOn);
 bool __fastcall ExecuteShellAndWait(const UnicodeString Path, const UnicodeString Params);
 bool __fastcall ExecuteShellAndWait(const UnicodeString Command);
+bool __fastcall IsKeyPressed(int VirtualKey);
 bool __fastcall UseAlternativeFunction();
 bool __fastcall OpenInNewWindow();
 void __fastcall ExecuteNewInstance(const UnicodeString & Param);