浏览代码

All read-only edit boxes/selectable labels have user friendly context menu for copying contents

Source commit: dbb1de54b8da22a5d8f880a14381d03eeea71c22
Martin Prikryl 7 年之前
父节点
当前提交
c602b9e39b

+ 1 - 1
source/forms/CustomScpExplorer.cpp

@@ -2117,7 +2117,7 @@ void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
       TMessageParams Params;
       TQueryButtonAlias Aliases[1];
       Aliases[0].Button = qaRetry;
-      Aliases[0].Alias = LoadStr(URL_LINK_COPY); // misuse
+      Aliases[0].Alias = LoadStr(EDIT_COPY);
       Aliases[0].OnSubmit = &ClipboardHandler.Copy;
       Params.Aliases = Aliases;
       Params.AliasesCount = LENOF(Aliases);

+ 0 - 6
source/forms/GenerateUrl.cpp

@@ -952,12 +952,6 @@ void __fastcall TGenerateUrlDialog::CreateParams(TCreateParams & Params)
   Params.Style = Params.Style | WS_THICKFRAME;
 }
 //---------------------------------------------------------------------------
-void __fastcall TGenerateUrlDialog::ResultMemoContextPopup(TObject * Sender,
-  TPoint & MousePos, bool & Handled)
-{
-  MenuPopup(Sender, MousePos, Handled);
-}
-//---------------------------------------------------------------------------
 void __fastcall TGenerateUrlDialog::FormShow(TObject * /*Sender*/)
 {
   UpdateControls();

+ 0 - 26
source/forms/GenerateUrl.dfm

@@ -182,9 +182,7 @@ object GenerateUrlDialog: TGenerateUrlDialog
       BevelInner = bvNone
       BevelOuter = bvNone
       BorderStyle = bsNone
-      PopupMenu = ResultPopupMenu
       TabOrder = 0
-      OnContextPopup = ResultMemoContextPopup
     end
   end
   object CancelBtn: TButton
@@ -218,28 +216,4 @@ object GenerateUrlDialog: TGenerateUrlDialog
     TabOrder = 2
     OnClick = ClipboardButtonClick
   end
-  object ResultPopupMenu: TPopupMenu
-    Left = 64
-    Top = 160
-    object TMenuItem
-      Action = EditCopyAction
-    end
-    object TMenuItem
-      Action = EditSelectAllAction
-    end
-  end
-  object ResultActionList: TActionList
-    Left = 184
-    Top = 160
-    object EditCopyAction: TEditCopy
-      Category = 'Edit'
-      Caption = '&Copy'
-      ShortCut = 16451
-    end
-    object EditSelectAllAction: TEditSelectAll
-      Category = 'Edit'
-      Caption = 'Select &All'
-      ShortCut = 16449
-    end
-  end
 end

+ 0 - 5
source/forms/GenerateUrl.h

@@ -39,15 +39,10 @@ __published:
   TComboBox *AssemblyLanguageCombo;
   TLabel *ScriptDescriptionLabel;
   TLabel *AssemblyDescriptionLabel;
-  TPopupMenu *ResultPopupMenu;
-  TActionList *ResultActionList;
-  TEditCopy *EditCopyAction;
-  TEditSelectAll *EditSelectAllAction;
   void __fastcall ControlChange(TObject *Sender);
   void __fastcall ClipboardButtonClick(TObject *Sender);
   void __fastcall HelpButtonClick(TObject *Sender);
   void __fastcall WMNCCreate(TWMNCCreate & Message);
-  void __fastcall ResultMemoContextPopup(TObject *Sender, TPoint &MousePos, bool &Handled);
   void __fastcall FormShow(TObject *Sender);
 
 private:

+ 2 - 1
source/resource/TextsWin.h

@@ -384,7 +384,6 @@
 #define EDITOR_EDIT             1739
 #define ABOUT_BASED_ON_PRODUCT  1740
 #define URL_LINK_OPEN           1741
-#define URL_LINK_COPY           1742
 #define SYNCHRONIZE_SAME_SIZE   1743
 #define ABOUT_REGISTRATION_LICENSES 1744
 #define ABOUT_REGISTRATION_PRODUCTID 1745
@@ -594,6 +593,8 @@
 #define USAGE_FILTER            1984
 #define USAGE_COPY              1985
 #define IMPORT_KNOWNHOSTS_INFO_TIP 1986
+#define EDIT_COPY               1987
+#define EDIT_SELECT_ALL         1988
 
 // 2xxx is reserved for TextsFileZilla.h
 

+ 2 - 1
source/resource/TextsWin1.rc

@@ -388,7 +388,6 @@ BEGIN
         EDITOR_EDIT, "Edit editor"
         ABOUT_BASED_ON_PRODUCT, "%s, Based on %s version %s"
         URL_LINK_OPEN, "&Open"
-        URL_LINK_COPY, "&Copy"
         SYNCHRONIZE_SAME_SIZE, "Same si&ze only"
         ABOUT_REGISTRATION_LICENSES, "Number of Licenses: %s|Unlimited"
         ABOUT_REGISTRATION_PRODUCTID, "Product ID: %s"
@@ -597,6 +596,8 @@ BEGIN
         USAGE_FILTER, "&Filter:"
         USAGE_COPY, "&Copy to Clipboard"
         IMPORT_KNOWNHOSTS_INFO_TIP, "Host: %s\nHost key: %s"
+        EDIT_COPY, "&Copy"
+        EDIT_SELECT_ALL, "Select &All"
 
         WIN_VARIABLE_STRINGS, "WIN_VARIABLE"
         WINSCP_COPYRIGHT, "Copyright © 2000-2017 Martin Prikryl"

+ 32 - 3
source/windows/VCLCommon.cpp

@@ -12,6 +12,8 @@
 #include <Tools.h>
 #include <CustomWinConfiguration.h>
 
+#include <Vcl.StdActns.hpp>
+#include <PasswordEdit.hpp>
 #include <FileCtrl.hpp>
 #include <PathLabel.hpp>
 #include <PasTools.hpp>
@@ -306,11 +308,17 @@ void __fastcall ReadOnlyAndEnabledControl(TControl * Control, bool ReadOnly, boo
   }
 }
 //---------------------------------------------------------------------------
+static void __fastcall ReadOnlyEditContextPopup(void * /*Data*/, TObject * Sender, const TPoint & MousePos, bool & Handled)
+{
+  MenuPopup(Sender, MousePos, Handled);
+}
+//---------------------------------------------------------------------------
 void __fastcall ReadOnlyControl(TControl * Control, bool ReadOnly)
 {
   if (dynamic_cast<TCustomEdit *>(Control) != NULL)
   {
-    ((TEdit*)Control)->ReadOnly = ReadOnly;
+    TEdit * Edit = static_cast<TEdit *>(Control);
+    Edit->ReadOnly = ReadOnly;
     TMemo * Memo = dynamic_cast<TMemo *>(Control);
     if (ReadOnly)
     {
@@ -322,12 +330,33 @@ void __fastcall ReadOnlyControl(TControl * Control, bool ReadOnly)
         // See also MemoKeyDown
         Memo->WantReturns = false;
       }
+
+      if ((Edit->PopupMenu == NULL) && (dynamic_cast<TPasswordEdit *>(Control) == NULL))
+      {
+        std::unique_ptr<TPopupMenu> PopupMenu(new TPopupMenu(Edit));
+
+        TMenuItem * Item;
+        Item = new TMenuItem(PopupMenu.get());
+        PopupMenu->Items->Add(Item);
+        Item->Action = new TEditCopy(Item);
+        Item->Caption = LoadStr(EDIT_COPY);
+        Item->ShortCut = ShortCut(L'C', TShiftState() << ssCtrl);
+        Item = new TMenuItem(PopupMenu.get());
+        PopupMenu->Items->Add(Item);
+        Item->Action = new TEditSelectAll(Item);
+        Item->Caption = LoadStr(EDIT_SELECT_ALL);
+        Item->ShortCut = ShortCut(L'A', TShiftState() << ssCtrl);
+
+        Edit->PopupMenu = PopupMenu.release();
+        Edit->OnContextPopup = MakeMethod<TContextPopupEvent>(NULL, ReadOnlyEditContextPopup);
+      }
     }
     else
     {
-      ((TEdit*)Control)->Color = clWindow;
+      Edit->Color = clWindow;
       // not supported atm, we need to persist previous value of WantReturns
       DebugAssert(Memo == NULL);
+      delete Edit->PopupMenu;
     }
   }
   else if ((dynamic_cast<TCustomComboBox *>(Control) != NULL) ||
@@ -2167,7 +2196,7 @@ void __fastcall LinkLabel(TStaticText * StaticText, UnicodeString Url,
       StaticText->PopupMenu->Items->Add(Item);
 
       Item = new TMenuItem(StaticText->PopupMenu);
-      Item->Caption = LoadStr(URL_LINK_COPY);
+      Item->Caption = LoadStr(EDIT_COPY);
       Item->Tag = 1;
       Item->ShortCut = ShortCut(L'C', TShiftState() << ssCtrl);
       Item->OnClick = ContextMenuOnClick;