فهرست منبع

Commands to copy hostkey/certificate fingerprint to clipboard hs a form of a link, instead of a message button + Changed appearance of background confirmation options link

Source commit: f879203973f823de535a1b7f4ed3c30b79fc6f93
Martin Prikryl 7 سال پیش
والد
کامیت
e3dc7f5d84

+ 1 - 0
source/core/Interface.h

@@ -94,6 +94,7 @@ struct TQueryButtonAlias
   TShiftState GrouppedShiftState;
   bool ElevationRequired;
   bool MenuButton;
+  UnicodeString ActionAlias;
 
   static TQueryButtonAlias CreateYesToAllGrouppedWithYes();
   static TQueryButtonAlias CreateNoToAllGrouppedWithNo();

+ 1 - 0
source/core/SecureShell.cpp

@@ -2351,6 +2351,7 @@ void __fastcall TSecureShell::VerifyHostKey(
       TQueryButtonAlias Aliases[4];
       Aliases[0].Button = qaRetry;
       Aliases[0].Alias = LoadStr(COPY_KEY_BUTTON);
+      Aliases[0].ActionAlias = LoadStr(COPY_KEY_ACTION);
       Aliases[0].OnSubmit = &ClipboardHandler.Copy;
       Aliases[1].Button = qaIgnore;
       Aliases[1].Alias = LoadStr(PASTE_KEY_BUTTON);

+ 1 - 0
source/core/Terminal.cpp

@@ -7472,6 +7472,7 @@ bool __fastcall TTerminal::ConfirmCertificate(
   TQueryButtonAlias Aliases[1];
   Aliases[0].Button = qaRetry;
   Aliases[0].Alias = LoadStr(COPY_KEY_BUTTON);
+  Aliases[0].ActionAlias = LoadStr(COPY_CERTIFICATE_ACTION);
   Aliases[0].OnSubmit = &ClipboardHandler.Copy;
 
   TQueryParams Params(qpWaitInBatch);

+ 68 - 38
source/forms/MessageDlg.cpp

@@ -852,6 +852,7 @@ TForm * __fastcall TMessageForm::Create(const UnicodeString & Msg,
   int ButtonWidths = 0;
   int ButtonHeight = -1;
   std::vector<TButton *> ButtonControls;
+  TStaticText * LinkControl = NULL;
   TAnswerButtons AnswerButtons;
   for (unsigned int Answer = qaFirst; Answer <= qaLast; Answer = Answer << 1)
   {
@@ -868,6 +869,7 @@ TForm * __fastcall TMessageForm::Create(const UnicodeString & Msg,
       TShiftState GrouppedShiftState;
       bool ElevationRequired = false;
       bool MenuButton = false;
+      UnicodeString ActionAlias;
       if (Aliases != NULL)
       {
         for (unsigned int i = 0; i < AliasesCount; i++)
@@ -883,61 +885,80 @@ TForm * __fastcall TMessageForm::Create(const UnicodeString & Msg,
             GrouppedShiftState = Aliases[i].GrouppedShiftState;
             ElevationRequired = Aliases[i].ElevationRequired;
             MenuButton = Aliases[i].MenuButton;
+            ActionAlias = Aliases[i].ActionAlias;
             DebugAssert((OnSubmit == NULL) || (GrouppedShiftState == TShiftState()));
             break;
           }
         }
       }
 
-      // we hope that all grouped-with buttons are for answer with greater
-      // value that the answer to be grouped with
-      if (GroupWith >= 0)
+      // implemented for a one link only for now
+      if (!ActionAlias.IsEmpty() &&
+          DebugAlwaysTrue(LinkControl == NULL) &&
+          DebugAlwaysTrue(OnSubmit != NULL) &&
+          DebugAlwaysTrue(GroupWith < 0))
       {
-        if (DebugAlwaysFalse(GroupWith >= static_cast<int>(Answer)) ||
-            DebugAlwaysFalse(Answer == TimeoutAnswer) &&
-            DebugAlwaysFalse(Answer == DefaultAnswer) &&
-            DebugAlwaysFalse(Answer == CancelAnswer))
-        {
-          GroupWith = -1;
-        }
+        LinkControl = new TStaticText(Result);
+        LinkControl->Name = Name;
+        LinkControl->Caption = ActionAlias;
+        LinkControl->Alignment = taRightJustify;
+        LinkControl->Anchors = TAnchors() << akRight << akTop;
+        LinkActionLabel(LinkControl);
+        LinkControl->OnClick = Result->ButtonSubmit;
+        Result->FButtonSubmitEvents[LinkControl] = OnSubmit;
       }
-
-      bool IsTimeoutButton = (TimeoutButton != NULL) && (Answer == TimeoutAnswer);
-
-      if (Answer == qaHelp)
-      {
-        DebugAssert(OnSubmit == NULL);
-        OnSubmit = Result->HelpButtonSubmit;
-      }
-
-      if (Answer == qaReport)
+      else
       {
-        DebugAssert(OnSubmit == NULL);
-        OnSubmit = Result->ReportButtonSubmit;
-      }
+        // we hope that all grouped-with buttons are for answer with greater
+        // value that the answer to be grouped with
+        if (GroupWith >= 0)
+        {
+          if (DebugAlwaysFalse(GroupWith >= static_cast<int>(Answer)) ||
+              DebugAlwaysFalse(Answer == TimeoutAnswer) &&
+              DebugAlwaysFalse(Answer == DefaultAnswer) &&
+              DebugAlwaysFalse(Answer == CancelAnswer))
+          {
+            GroupWith = -1;
+          }
+        }
 
-      TButton * Button = Result->CreateButton(
-        Name, Caption, Answer,
-        OnSubmit, IsTimeoutButton, GroupWith, GrouppedShiftState, ElevationRequired, MenuButton,
-        AnswerButtons, HasMoreMessages, ButtonWidths);
+        bool IsTimeoutButton = (TimeoutButton != NULL) && (Answer == TimeoutAnswer);
 
-      if (Button != NULL)
-      {
-        ButtonControls.push_back(Button);
+        if (Answer == qaHelp)
+        {
+          DebugAssert(OnSubmit == NULL);
+          OnSubmit = Result->HelpButtonSubmit;
+        }
 
-        Button->Default = (Answer == DefaultAnswer);
-        Button->Cancel = (Answer == CancelAnswer);
-        if (ButtonHeight < 0)
+        if (Answer == qaReport)
         {
-          ButtonHeight = Button->Height;
+          DebugAssert(OnSubmit == NULL);
+          OnSubmit = Result->ReportButtonSubmit;
         }
-        DebugAssert(ButtonHeight == Button->Height);
 
-        AnswerButtons.insert(TAnswerButtons::value_type(Answer, Button));
+        TButton * Button = Result->CreateButton(
+          Name, Caption, Answer,
+          OnSubmit, IsTimeoutButton, GroupWith, GrouppedShiftState, ElevationRequired, MenuButton,
+          AnswerButtons, HasMoreMessages, ButtonWidths);
 
-        if (IsTimeoutButton)
+        if (Button != NULL)
         {
-          *TimeoutButton = Button;
+          ButtonControls.push_back(Button);
+
+          Button->Default = (Answer == DefaultAnswer);
+          Button->Cancel = (Answer == CancelAnswer);
+          if (ButtonHeight < 0)
+          {
+            ButtonHeight = Button->Height;
+          }
+          DebugAssert(ButtonHeight == Button->Height);
+
+          AnswerButtons.insert(TAnswerButtons::value_type(Answer, Button));
+
+          if (IsTimeoutButton)
+          {
+            *TimeoutButton = Button;
+          }
         }
       }
     }
@@ -1108,6 +1129,15 @@ TForm * __fastcall TMessageForm::Create(const UnicodeString & Msg,
     }
   }
 
+  int LinkControlHeight = 0;
+  if (LinkControl != NULL)
+  {
+    LinkControl->Parent = Panel;
+    LinkControl->Left = Panel->ClientWidth - HorzMargin - LinkControl->Width;
+    LinkControl->Top = VertMargin + IconTextHeight + VertMargin;
+    IconTextHeight += VertMargin + LinkControl->Height;
+  }
+
   DebugAssert((IconTextWidth > 0) && (IconTextHeight > 0));
 
   IconTextHeight = Max(IconTextHeight, IconHeight);

+ 2 - 0
source/resource/TextsCore.h

@@ -474,6 +474,8 @@
 #define SCRIPT_CP_DESC          559
 #define TIME_UNKNOWN            560
 #define KEY_DETAILS             561
+#define COPY_KEY_ACTION         562
+#define COPY_CERTIFICATE_ACTION 563
 
 #define CORE_VARIABLE_STRINGS   600
 #define PUTTY_BASED_ON          601

+ 2 - 0
source/resource/TextsCore1.rc

@@ -443,6 +443,8 @@ BEGIN
   SCRIPT_CP_DESC, "Duplicates remote file"
   TIME_UNKNOWN, "Unknown"
   KEY_DETAILS, "    Algorithm:\t%s\n    SHA-256:\t%s\n    MD5:\t%s"
+  COPY_KEY_ACTION, "&Copy key fingerprints to clipboard"
+  COPY_CERTIFICATE_ACTION, "&Copy certificate fingerprint to clipboard"
 
   CORE_VARIABLE_STRINGS, "CORE_VARIABLE"
   PUTTY_BASED_ON, "SSH and SCP code based on PuTTY %s"

+ 15 - 2
source/windows/VCLCommon.cpp

@@ -23,6 +23,8 @@
 #include <IEListView.hpp>
 #include <WinApi.h>
 //---------------------------------------------------------------------------
+const UnicodeString LinkAppLabelMark(TraceInitStr(L" \x00BB"));
+//---------------------------------------------------------------------------
 #pragma package(smart_init)
 //---------------------------------------------------------------------------
 void __fastcall FixListColumnWidth(TListView * TListView, int Index)
@@ -1797,7 +1799,8 @@ static void __fastcall FocusableLabelWindowProc(void * Data, TMessage & Message,
       {
         Canvas->DrawFocusRect(R);
       }
-      else if (!StaticText->Font->Style.Contains(fsUnderline))
+      else if ((StaticText->Font->Color != LinkColor) && // LinkActionLabel and LinkLabel
+               !EndsStr(LinkAppLabelMark, StaticText->Caption)) // LinkAppLabel
       {
         Canvas->Pen->Style = psDot;
         Canvas->Brush->Style = bsClear;
@@ -2087,7 +2090,6 @@ static void __fastcall DoLinkLabel(TStaticText * StaticText)
 {
   StaticText->Transparent = false;
   StaticText->ParentFont = true;
-  StaticText->Font->Style = StaticText->Font->Style << fsUnderline;
   StaticText->Cursor = crHandPoint;
 
   TWndMethod WindowProc;
@@ -2101,6 +2103,8 @@ void __fastcall LinkLabel(TStaticText * StaticText, UnicodeString Url,
 {
   DoLinkLabel(StaticText);
 
+  StaticText->Font->Style = StaticText->Font->Style << fsUnderline;
+
   reinterpret_cast<TButton*>(StaticText)->OnEnter = OnEnter;
 
   if (!Url.IsEmpty())
@@ -2146,9 +2150,18 @@ void __fastcall LinkLabel(TStaticText * StaticText, UnicodeString Url,
   StaticText->Font->Color = LinkColor;
 }
 //---------------------------------------------------------------------------
+void __fastcall LinkActionLabel(TStaticText * StaticText)
+{
+  DoLinkLabel(StaticText);
+
+  StaticText->Font->Color = LinkColor;
+}
+//---------------------------------------------------------------------------
 void __fastcall LinkAppLabel(TStaticText * StaticText)
 {
   DoLinkLabel(StaticText);
+
+  StaticText->Caption = StaticText->Caption + LinkAppLabelMark;
 }
 //---------------------------------------------------------------------------
 static void __fastcall HotTrackLabelMouseEnter(void * /*Data*/, TObject * Sender)

+ 1 - 0
source/windows/VCLCommon.h

@@ -23,6 +23,7 @@ void __fastcall UseSystemSettings(TCustomForm * Control);
 void __fastcall ResetSystemSettings(TCustomForm * Control);
 void __fastcall LinkLabel(TStaticText * StaticText, UnicodeString Url = L"",
   TNotifyEvent OnEnter = NULL);
+void __fastcall LinkActionLabel(TStaticText * StaticText);
 void __fastcall LinkAppLabel(TStaticText * StaticText);
 void __fastcall HintLabel(TStaticText * StaticText, UnicodeString Hint = L"");
 void __fastcall HotTrackLabel(TLabel * Label);