Sfoglia il codice sorgente

Bug 2217: Make it harder to mis-click "never show this again" checkboxes

https://winscp.net/tracker/2217

Source commit: 7157c1f4fe74785f34861fd9f24c4c03042e4588
Martin Prikryl 2 anni fa
parent
commit
e3fe05fcbb

+ 13 - 0
source/forms/Copy.cpp

@@ -137,6 +137,8 @@ __fastcall TCopyDialog::TCopyDialog(
     OkButton->Style = TCustomButton::bsSplitButton;
   }
 
+  AutoSizeCheckBox(NeverShowAgainCheck);
+
   UseSystemSettings(this);
 }
 //---------------------------------------------------------------------------
@@ -628,3 +630,14 @@ void __fastcall TCopyDialog::OkButtonDropDownClick(TObject *)
   MenuPopup(OkMenu, OkButton);
 }
 //---------------------------------------------------------------------------
+void __fastcall TCopyDialog::Dispatch(void * Message)
+{
+  TMessage * M = reinterpret_cast<TMessage*>(Message);
+  if (M->Msg == CM_DPICHANGED)
+  {
+    AutoSizeCheckBox(NeverShowAgainCheck);
+  }
+
+  TForm::Dispatch(Message);
+}
+//---------------------------------------------------------------------------

+ 1 - 1
source/forms/Copy.dfm

@@ -113,7 +113,7 @@ object CopyDialog: TCopyDialog
   object NeverShowAgainCheck: TCheckBox
     Left = 12
     Top = 167
-    Width = 493
+    Width = 253
     Height = 17
     Caption = '&Do not show this dialog box again'
     TabOrder = 10

+ 1 - 0
source/forms/Copy.h

@@ -84,6 +84,7 @@ protected:
   bool __fastcall RemotePaths();
   void __fastcall CopyParamListPopup(TRect R, int AdditionalOptions);
   int __fastcall ActualCopyParamAttrs();
+  virtual void __fastcall Dispatch(void * Message);
 
   INTERFACE_HOOK;
 

+ 13 - 0
source/forms/CopyLocal.cpp

@@ -47,6 +47,8 @@ TCopyLocalDialog::TCopyLocalDialog(TComponent * Owner, bool Move, int Options)
     ClientHeight = ClientHeight - ShortCutHintPanel->Height;
   }
 
+  AutoSizeCheckBox(NeverShowAgainCheck);
+
   UseSystemSettings(this);
 }
 //---------------------------------------------------------------------------
@@ -154,3 +156,14 @@ void __fastcall TCopyLocalDialog::LocalDirectoryBrowseButtonClick(TObject *)
   }
 }
 //---------------------------------------------------------------------------
+void __fastcall TCopyLocalDialog::Dispatch(void * Message)
+{
+  TMessage * M = reinterpret_cast<TMessage*>(Message);
+  if (M->Msg == CM_DPICHANGED)
+  {
+    AutoSizeCheckBox(NeverShowAgainCheck);
+  }
+
+  TForm::Dispatch(Message);
+}
+//---------------------------------------------------------------------------

+ 3 - 0
source/forms/CopyLocal.h

@@ -41,6 +41,9 @@ private:
 
   INTERFACE_HOOK;
 
+protected:
+  virtual void __fastcall Dispatch(void * Message);
+
 public:
   TCopyLocalDialog(TComponent * Owner, bool Move, int Options);
 

+ 13 - 0
source/forms/Login.cpp

@@ -93,6 +93,7 @@ __fastcall TLoginDialog::TLoginDialog(TComponent* AOwner)
   FPasswordLabel = PasswordLabel->Caption;
 
   FSiteButtonsPadding = SitesPanel->ClientHeight - ToolsMenuButton->Top - ToolsMenuButton->Height;
+  AutoSizeCheckBox(ShowAgainCheck);
 }
 //---------------------------------------------------------------------
 __fastcall TLoginDialog::~TLoginDialog()
@@ -1739,6 +1740,7 @@ void __fastcall TLoginDialog::CMDpiChanged(TMessage & Message)
   TForm::Dispatch(&Message);
   GenerateImages();
   CenterButtonImage(LoginButton);
+  AutoSizeCheckBox(ShowAgainCheck);
 }
 //---------------------------------------------------------------------------
 void __fastcall TLoginDialog::Dispatch(void * Message)
@@ -3335,3 +3337,14 @@ void __fastcall TLoginDialog::S3ProfileComboChange(TObject *)
   UpdateControls();
 }
 //---------------------------------------------------------------------------
+void __fastcall TLoginDialog::ShowAgainCheckClick(TObject *)
+{
+  if (!ShowAgainCheck->Checked)
+  {
+    if (MessageDialog(LoadStr(LOGIN_NOT_SHOWING_AGAIN), qtConfirmation, qaOK | qaCancel, HELP_SHOW_LOGIN) != qaOK)
+    {
+      ShowAgainCheck->Checked = true;
+    }
+  }
+}
+//---------------------------------------------------------------------------

+ 2 - 5
source/forms/Login.dfm

@@ -529,21 +529,18 @@ object LoginDialog: TLoginDialog
     BevelOuter = bvNone
     TabOrder = 1
     OnMouseDown = PanelMouseDown
-    DesignSize = (
-      873
-      24)
     object ShowAgainCheck: TCheckBox
       Left = 12
       Top = 0
-      Width = 849
+      Width = 405
       Height = 17
-      Anchors = [akLeft, akTop, akRight]
       Caption = 
         '&Show Login dialog on startup and when the last session is close' +
         'd'
       Checked = True
       State = cbChecked
       TabOrder = 0
+      OnClick = ShowAgainCheckClick
     end
   end
   object ActionList: TActionList

+ 1 - 0
source/forms/Login.h

@@ -293,6 +293,7 @@ __published:
   void __fastcall S3CredentialsEnvCheck3Click(TObject *Sender);
   void __fastcall EncryptionComboChange(TObject *Sender);
   void __fastcall S3ProfileComboChange(TObject *Sender);
+  void __fastcall ShowAgainCheckClick(TObject *Sender);
 
 private:
   int NoUpdate;

+ 16 - 12
source/forms/MessageDlg.cpp

@@ -75,6 +75,7 @@ __fastcall TMessageForm::TMessageForm(TComponent * AOwner) : TForm(AOwner)
   MessageMemo = NULL;
   MessageBrowserPanel = NULL;
   MessageBrowser = NULL;
+  NeverAskAgainCheck = NULL;
   FUpdateForShiftStateTimer = NULL;
   UseSystemSettingsPre(this);
   FDummyForm = new TForm(this);
@@ -361,6 +362,10 @@ void __fastcall TMessageForm::Dispatch(void * Message)
     {
       LoadMessageBrowser();
     }
+    if (NeverAskAgainCheck != NULL)
+    {
+      AutoSizeCheckBox(NeverAskAgainCheck);
+    }
     TForm::Dispatch(Message);
   }
   else
@@ -944,12 +949,11 @@ TForm * __fastcall TMessageForm::Create(const UnicodeString & Msg,
   }
 
   int NeverAskAgainWidth = 0;
+  int NeverAskAgainBaseWidth = 0;
   if (!NeverAskAgainCaption.IsEmpty())
   {
-    NeverAskAgainWidth =
-      ScaleByTextHeightRunTime(Result, 16) + // checkbox
-      Result->Canvas->TextWidth(NeverAskAgainCaption) +
-      ScaleByTextHeightRunTime(Result, 16); // margin
+    NeverAskAgainBaseWidth = CalculateCheckBoxWidth(Result, NeverAskAgainCaption);
+    NeverAskAgainWidth = NeverAskAgainBaseWidth + ScaleByTextHeightRunTime(Result, 8); // even more margin
   }
 
   int ButtonSpacing = ScaleByTextHeightRunTime(Result, mcButtonSpacing);
@@ -1211,23 +1215,23 @@ TForm * __fastcall TMessageForm::Create(const UnicodeString & Msg,
   if (!NeverAskAgainCaption.IsEmpty() &&
       !ButtonControls.empty())
   {
-    TCheckBox * NeverAskAgainCheck = new TCheckBox(Result);
-    NeverAskAgainCheck->Name = L"NeverAskAgainCheck";
-    NeverAskAgainCheck->Parent = Result;
-    NeverAskAgainCheck->Caption = NeverAskAgainCaption;
+    Result->NeverAskAgainCheck = new TCheckBox(Result);
+    Result->NeverAskAgainCheck->Name = L"NeverAskAgainCheck";
+    Result->NeverAskAgainCheck->Parent = Result;
+    Result->NeverAskAgainCheck->Caption = NeverAskAgainCaption;
     // Previously we set anchor to akBottom, but as we do not do that for buttons, we removed that.
     // When showing window on 100% DPI monitor, with system DPI 100%, but main monitor 150%,
     // the title bar seems to start on 150% DPI reducing later, leaving the form client height
     // sligtly higher than needed and the checkbox being aligned differently than the button.
-    // Removing the akBottom aligning improves this sligtly, while the main problem stil should be fixed.
+    // Removing the akBottom aligning improves this sligtly, while the main problem still should be fixed.
 
     TButton * FirstButton = ButtonControls[0];
-    int NeverAskAgainHeight = ScaleByTextHeightRunTime(Result, NeverAskAgainCheck->Height);
+    int NeverAskAgainHeight = ScaleByTextHeightRunTime(Result, Result->NeverAskAgainCheck->Height);
     int NeverAskAgainTop = FirstButton->Top + ((FirstButton->Height - NeverAskAgainHeight) / 2);
     int NeverAskAgainLeft = HorzMargin;
 
-    NeverAskAgainCheck->SetBounds(
-      NeverAskAgainLeft, NeverAskAgainTop, NeverAskAgainWidth, NeverAskAgainHeight);
+    Result->NeverAskAgainCheck->SetBounds(
+      NeverAskAgainLeft, NeverAskAgainTop, NeverAskAgainBaseWidth, NeverAskAgainHeight);
   }
 
   return Result;

+ 1 - 0
source/forms/MessageDlg.h

@@ -57,6 +57,7 @@ private:
   TForm * FDummyForm;
   bool FShowNoActivate;
   std::map<TObject *, TButtonSubmitEvent> FButtonSubmitEvents;
+  TCheckBox * NeverAskAgainCheck;
 
   void __fastcall HelpButtonSubmit(TObject * Sender, unsigned int & Answer);
   void __fastcall ReportButtonSubmit(TObject * Sender, unsigned int & Answer);

+ 1 - 0
source/resource/HelpWin.h

@@ -72,5 +72,6 @@
 #define HELP_TOO_MANY_SESSIONS       "ui_tabs"
 #define HELP_STORE_TRANSITION        "microsoft_store#transitioning"
 #define HELP_SSH_HOST_CA             "ui_ssh_host_ca"
+#define HELP_SHOW_LOGIN              "ui_pref_window#show_login"
 
 #endif // TextsWin

+ 1 - 0
source/resource/TextsWin.h

@@ -689,6 +689,7 @@
 #define SSH_HOST_CA_SIGNATURES  6203
 #define SSH_HOST_CA_NO_HOSTS    6204
 #define SSH_HOST_CA_HOSTS_INVALID 6205
+#define LOGIN_NOT_SHOWING_AGAIN 6206
 
 // 2xxx is reserved for TextsFileZilla.h
 

+ 1 - 0
source/resource/TextsWin1.rc

@@ -694,6 +694,7 @@ BEGIN
         SSH_HOST_CA_SIGNATURES, "SHA-&1|SHA-&256|SHA-&512"
         SSH_HOST_CA_NO_HOSTS, "No validity expression configured."
         SSH_HOST_CA_HOSTS_INVALID, "Error in validity expression."
+        LOGIN_NOT_SHOWING_AGAIN, "**Stop showing Login dialog automatically?** Please confirm if you really want to WinSCP stop showing Login dialog automatically on startup and when the last session is closed.\n\nIf you change your mind later, you can revert this in Preferences on Environment > Window page."
 
         WIN_VARIABLE_STRINGS, "WIN_VARIABLE"
         WINSCP_COPYRIGHT, "Copyright © 2000–2023 Martin Prikryl"

+ 12 - 0
source/windows/VCLCommon.cpp

@@ -382,6 +382,18 @@ void __fastcall ReadOnlyControl(TControl * Control, bool ReadOnly)
   DoReadOnlyControl(Control, ReadOnly, true);
 }
 //---------------------------------------------------------------------------
+int CalculateCheckBoxWidth(TControl * Control, const UnicodeString & Caption)
+{
+  return
+    ScaleByTextHeight(Control, 13 + 3 + 8) + // checkbox, padding and buffer
+    GetParentForm(Control)->Canvas->TextWidth(StripHotkey(Caption));
+}
+//---------------------------------------------------------------------------
+void AutoSizeCheckBox(TCheckBox * CheckBox)
+{
+  CheckBox->Width = CalculateCheckBoxWidth(CheckBox, CheckBox->Caption);
+}
+//---------------------------------------------------------------------------
 // Some of MainFormLike code can now be obsolete, thanks to Application->OnGetMainFormHandle.
 static TForm * MainLikeForm = NULL;
 //---------------------------------------------------------------------------

+ 2 - 0
source/windows/VCLCommon.h

@@ -15,6 +15,8 @@ void __fastcall AutoSizeListColumnsWidth(TListView * ListView, int ColumnToShrin
 void __fastcall EnableControl(TControl* Control, bool Enable);
 void __fastcall ReadOnlyControl(TControl * Control, bool ReadOnly = true);
 void __fastcall ReadOnlyAndEnabledControl(TControl * Control, bool ReadOnly, bool Enabled);
+int CalculateCheckBoxWidth(TControl * Control, const UnicodeString & Caption);
+void AutoSizeCheckBox(TCheckBox * CheckBox);
 void __fastcall InitializeSystemSettings();
 void __fastcall FinalizeSystemSettings();
 void __fastcall LocalSystemSettings(TCustomForm * Control);