Explorar o código

Bug 1471: Allow controlling progress windows using keyboard

https://winscp.net/tracker/1471
(cherry picked from commit 6d0b308c727e1ce4b980cde95ee989d43661b545)

Source commit: 54b14138fdf7f9b7e0f1e2e0207e4971bf404e6c
Martin Prikryl %!s(int64=9) %!d(string=hai) anos
pai
achega
bea45ac706

+ 0 - 24
source/forms/CustomScpExplorer.cpp

@@ -8551,30 +8551,6 @@ void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sende
   UpdateRemotePathComboBox(true);
 }
 //---------------------------------------------------------------------------
-void __fastcall TCustomScpExplorerForm::ClickToolbarItem(TTBCustomItem * Item,
-  bool PositionCursor)
-{
-  TTBCustomItem * TopItem = Item;
-  while (TopItem->Parent != NULL)
-  {
-    TopItem = TopItem->Parent;
-  }
-  TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(TopItem->ParentComponent);
-  DebugAssert(Toolbar != NULL);
-  TTBItemViewer * Viewer = Toolbar->View->Find(Item);
-  DebugAssert(Viewer != NULL);
-
-  int X = Viewer->BoundsRect.Left + (Viewer->BoundsRect.Width() / 2);
-  int Y = Viewer->BoundsRect.Top + (Viewer->BoundsRect.Height() / 2);
-
-  if (PositionCursor)
-  {
-    Mouse->CursorPos = Toolbar->ClientToScreen(TPoint(X, Y));
-  }
-
-  PostMessage(Toolbar->Handle, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(X, Y));
-}
-//---------------------------------------------------------------------------
 void __fastcall TCustomScpExplorerForm::DirViewEditing(
   TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
 {

+ 0 - 1
source/forms/CustomScpExplorer.h

@@ -514,7 +514,6 @@ protected:
   virtual void __fastcall ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width);
   virtual void __fastcall CreateWnd();
   virtual void __fastcall DestroyWnd();
-  void __fastcall ClickToolbarItem(TTBCustomItem * Item, bool PositionCursor);
   virtual bool __fastcall OpenBookmark(UnicodeString Local, UnicodeString Remote);
   void __fastcall DoFindFiles(UnicodeString Directory, const TFileMasks & FileMask,
     TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile);

+ 19 - 8
source/forms/Progress.cpp

@@ -573,6 +573,19 @@ void __fastcall TProgressForm::ResetOnceDoneOperation()
   SetOnceDoneOperation(odoIdle);
 }
 //---------------------------------------------------------------------------
+void __fastcall TProgressForm::CMDialogKey(TCMDialogKey & Message)
+{
+  if (Message.CharCode == VK_TAB)
+  {
+    Toolbar->KeyboardOpen(L'\0', false);
+    Message.Result = 1;
+  }
+  else
+  {
+    TForm::Dispatch(&Message);
+  }
+}
+//---------------------------------------------------------------------------
 void __fastcall TProgressForm::Dispatch(void * AMessage)
 {
   TMessage & Message = *reinterpret_cast<TMessage *>(AMessage);
@@ -580,6 +593,10 @@ void __fastcall TProgressForm::Dispatch(void * AMessage)
   {
     CancelOperation();
   }
+  else if (Message.Msg == CM_DIALOGKEY)
+  {
+    CMDialogKey(reinterpret_cast<TCMDialogKey &>(Message));
+  }
   else
   {
     TForm::Dispatch(AMessage);
@@ -646,14 +663,8 @@ void __fastcall TProgressForm::SpeedComboBoxItemAdjustImageIndex(
   ImageIndex = Sender->ImageIndex;
 }
 //---------------------------------------------------------------------------
-void __fastcall TProgressForm::FormKeyDown(
-  TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
+void __fastcall TProgressForm::SpeedComboBoxItemClick(TObject * Sender)
 {
-  // We do not have Cancel button, so we have to handle Esc key explicitly
-  if (Key == VK_ESCAPE)
-  {
-    CancelOperation();
-    Key = 0;
-  }
+  ClickToolbarItem(DebugNotNull(dynamic_cast<TTBCustomItem *>(Sender)), false);
 }
 //---------------------------------------------------------------------------

+ 7 - 1
source/forms/Progress.dfm

@@ -13,7 +13,6 @@ object ProgressForm: TProgressForm
   OldCreateOrder = False
   Position = poOwnerFormCenter
   OnHide = FormHide
-  OnKeyDown = FormKeyDown
   OnShow = FormShow
   DesignSize = (
     360
@@ -214,22 +213,26 @@ object ProgressForm: TProgressForm
         DragHandleStyle = dhNone
         Images = ImageList
         ParentShowHint = False
+        ProcessShortCuts = True
         ShowHint = True
         TabOrder = 0
         Color = clWindow
         object CancelItem: TTBXItem
           Caption = '&CancelX'
           ImageIndex = 0
+          ShortCut = 27
           OnClick = CancelItemClick
         end
         object MinimizeItem: TTBXItem
           Caption = '&Minimize'
           ImageIndex = 1
+          ShortCut = 32845
           OnClick = MinimizeItemClick
         end
         object MoveToQueueItem: TTBXItem
           Caption = 'Proceed in &Background'
           ImageIndex = 7
+          ShortCut = 32834
           OnClick = MoveToQueueItemClick
         end
         object CycleOnceDoneItem: TTBXSubmenuItem
@@ -237,6 +240,7 @@ object ProgressForm: TProgressForm
           DropdownCombo = True
           Hint = 'Action to perform once the operation finishes'
           ImageIndex = 2
+          ShortCut = 32838
           OnClick = CycleOnceDoneItemClick
           object IdleOnceDoneItem: TTBXItem
             Caption = '&Stay Idle'
@@ -268,7 +272,9 @@ object ProgressForm: TProgressForm
           EditWidth = 110
           Hint = 'Speed limit (KB/s)'
           ImageIndex = 6
+          ShortCut = 32851
           OnAcceptText = SpeedComboBoxItemAcceptText
+          OnClick = SpeedComboBoxItemClick
           ShowImage = True
           OnAdjustImageIndex = SpeedComboBoxItemAdjustImageIndex
           OnItemClick = SpeedComboBoxItemItemClick

+ 2 - 1
source/forms/Progress.h

@@ -79,8 +79,8 @@ __published:
   void __fastcall SpeedComboBoxItemItemClick(TObject *Sender);
   void __fastcall SpeedComboBoxItemAdjustImageIndex(TTBXComboBoxItem *Sender, const UnicodeString AText,
           int AIndex, int &ImageIndex);
-  void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
   void __fastcall ApplicationModalBegin(TObject * Sender);
+  void __fastcall SpeedComboBoxItemClick(TObject *Sender);
 
 private:
   TCancelStatus FCancel;
@@ -118,6 +118,7 @@ private:
   void __fastcall GlobalMinimize(TObject * Sender);
   UnicodeString __fastcall ItemSpeed(const UnicodeString & Text, TTBXComboBoxItem * Item);
   bool __fastcall ApplicationHook(TMessage & Message);
+  void __fastcall CMDialogKey(TCMDialogKey & Message);
 
 protected:
   void __fastcall CancelOperation();

+ 17 - 11
source/forms/SynchronizeProgress.cpp

@@ -122,6 +122,19 @@ void __fastcall TSynchronizeProgressForm::GlobalMinimize(TObject * /*Sender*/)
   FMinimizedByMe = true;
 }
 //---------------------------------------------------------------------------
+void __fastcall TSynchronizeProgressForm::CMDialogKey(TCMDialogKey & Message)
+{
+  if (Message.CharCode == VK_TAB)
+  {
+    Toolbar->KeyboardOpen(L'\0', false);
+    Message.Result = 1;
+  }
+  else
+  {
+    TForm::Dispatch(&Message);
+  }
+}
+//---------------------------------------------------------------------------
 void __fastcall TSynchronizeProgressForm::Dispatch(void * AMessage)
 {
   TMessage & Message = *reinterpret_cast<TMessage *>(AMessage);
@@ -129,6 +142,10 @@ void __fastcall TSynchronizeProgressForm::Dispatch(void * AMessage)
   {
     CancelOperation();
   }
+  else if (Message.Msg == CM_DIALOGKEY)
+  {
+    CMDialogKey(reinterpret_cast<TCMDialogKey &>(Message));
+  }
   else
   {
     TForm::Dispatch(AMessage);
@@ -145,14 +162,3 @@ void __fastcall TSynchronizeProgressForm::MinimizeItemClick(TObject * Sender)
   CallGlobalMinimizeHandler(Sender);
 }
 //---------------------------------------------------------------------------
-void __fastcall TSynchronizeProgressForm::FormKeyDown(
-  TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
-{
-  // We do not have Cancel button, so we have to handle Esc key explicitly
-  if (Key == VK_ESCAPE)
-  {
-    CancelOperation();
-    Key = 0;
-  }
-}
-//---------------------------------------------------------------------------

+ 3 - 1
source/forms/SynchronizeProgress.dfm

@@ -10,7 +10,6 @@ object SynchronizeProgressForm: TSynchronizeProgressForm
   ParentFont = True
   OldCreateOrder = False
   Position = poOwnerFormCenter
-  OnKeyDown = FormKeyDown
   DesignSize = (
     424
     193)
@@ -112,17 +111,20 @@ object SynchronizeProgressForm: TSynchronizeProgressForm
         DragHandleStyle = dhNone
         Images = ImageList
         ParentShowHint = False
+        ProcessShortCuts = True
         ShowHint = True
         TabOrder = 0
         Color = clWindow
         object CancelItem: TTBXItem
           Caption = 'Cancel'
           ImageIndex = 0
+          ShortCut = 27
           OnClick = CancelItemClick
         end
         object MinimizeItem: TTBXItem
           Caption = '&Minimize'
           ImageIndex = 1
+          ShortCut = 32845
           OnClick = MinimizeItemClick
         end
       end

+ 1 - 1
source/forms/SynchronizeProgress.h

@@ -42,7 +42,6 @@ __published:
   void __fastcall UpdateTimerTimer(TObject *Sender);
   void __fastcall MinimizeItemClick(TObject *Sender);
   void __fastcall CancelItemClick(TObject *Sender);
-  void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
 
 public:
   __fastcall TSynchronizeProgressForm(TComponent * Owner, bool AllowMinimize,
@@ -71,6 +70,7 @@ private:
   void __fastcall UpdateControls();
   void __fastcall GlobalMinimize(TObject * Sender);
   void __fastcall CancelOperation();
+  void __fastcall CMDialogKey(TCMDialogKey & Message);
 };
 //---------------------------------------------------------------------------
 #endif

+ 23 - 0
source/windows/WinInterface.cpp

@@ -1422,6 +1422,29 @@ bool __fastcall HandleMinimizeSysCommand(TMessage & Message)
   return Result;
 }
 //---------------------------------------------------------------------------
+void __fastcall ClickToolbarItem(TTBCustomItem * Item, bool PositionCursor)
+{
+  TTBCustomItem * TopItem = Item;
+  while (TopItem->Parent != NULL)
+  {
+    TopItem = TopItem->Parent;
+  }
+  TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(TopItem->ParentComponent);
+  DebugAssert(Toolbar != NULL);
+  TTBItemViewer * Viewer = Toolbar->View->Find(Item);
+  DebugAssert(Viewer != NULL);
+
+  int X = Viewer->BoundsRect.Left + (Viewer->BoundsRect.Width() / 2);
+  int Y = Viewer->BoundsRect.Top + (Viewer->BoundsRect.Height() / 2);
+
+  if (PositionCursor)
+  {
+    Mouse->CursorPos = Toolbar->ClientToScreen(TPoint(X, Y));
+  }
+
+  PostMessage(Toolbar->Handle, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(X, Y));
+}
+//---------------------------------------------------------------------------
 void __fastcall WinInitialize()
 {
   if (JclHookExceptions())

+ 1 - 0
source/windows/WinInterface.h

@@ -96,6 +96,7 @@ namespace Tb2item { class TTBCustomItem; }
 namespace Tbx { class TTBXSeparatorItem; }
 Tbx::TTBXSeparatorItem * __fastcall AddMenuSeparator(Tb2item::TTBCustomItem * Menu);
 void __fastcall AddMenuLabel(Tb2item::TTBCustomItem * Menu, const UnicodeString & Label);
+void __fastcall ClickToolbarItem(Tb2item::TTBCustomItem * Item, bool PositionCursor);
 
 // windows\WinHelp.cpp
 void __fastcall InitializeWinHelp();