Skip to content

Commit

Permalink
Bug 2217: Make it harder to mis-click "never show this again" checkboxes
Browse files Browse the repository at this point in the history
https://winscp.net/tracker/2217

Source commit: 7157c1f4fe74785f34861fd9f24c4c03042e4588
  • Loading branch information
martinprikryl committed Sep 20, 2023
1 parent b96d7d0 commit e3fe05f
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 18 deletions.
13 changes: 13 additions & 0 deletions source/forms/Copy.cpp
Expand Up @@ -137,6 +137,8 @@ __fastcall TCopyDialog::TCopyDialog(
OkButton->Style = TCustomButton::bsSplitButton;
}

AutoSizeCheckBox(NeverShowAgainCheck);

UseSystemSettings(this);
}
//---------------------------------------------------------------------------
Expand Down Expand Up @@ -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);
}
//---------------------------------------------------------------------------
2 changes: 1 addition & 1 deletion source/forms/Copy.dfm
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions source/forms/Copy.h
Expand Up @@ -84,6 +84,7 @@ class TCopyDialog : public TForm
bool __fastcall RemotePaths();
void __fastcall CopyParamListPopup(TRect R, int AdditionalOptions);
int __fastcall ActualCopyParamAttrs();
virtual void __fastcall Dispatch(void * Message);

INTERFACE_HOOK;

Expand Down
13 changes: 13 additions & 0 deletions source/forms/CopyLocal.cpp
Expand Up @@ -47,6 +47,8 @@ TCopyLocalDialog::TCopyLocalDialog(TComponent * Owner, bool Move, int Options)
ClientHeight = ClientHeight - ShortCutHintPanel->Height;
}

AutoSizeCheckBox(NeverShowAgainCheck);

UseSystemSettings(this);
}
//---------------------------------------------------------------------------
Expand Down Expand Up @@ -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 changes: 3 additions & 0 deletions source/forms/CopyLocal.h
Expand Up @@ -41,6 +41,9 @@ class TCopyLocalDialog : public TForm

INTERFACE_HOOK;

protected:
virtual void __fastcall Dispatch(void * Message);

public:
TCopyLocalDialog(TComponent * Owner, bool Move, int Options);

Expand Down
13 changes: 13 additions & 0 deletions source/forms/Login.cpp
Expand Up @@ -93,6 +93,7 @@ __fastcall TLoginDialog::TLoginDialog(TComponent* AOwner)
FPasswordLabel = PasswordLabel->Caption;

FSiteButtonsPadding = SitesPanel->ClientHeight - ToolsMenuButton->Top - ToolsMenuButton->Height;
AutoSizeCheckBox(ShowAgainCheck);
}
//---------------------------------------------------------------------
__fastcall TLoginDialog::~TLoginDialog()
Expand Down Expand Up @@ -1739,6 +1740,7 @@ void __fastcall TLoginDialog::CMDpiChanged(TMessage & Message)
TForm::Dispatch(&Message);
GenerateImages();
CenterButtonImage(LoginButton);
AutoSizeCheckBox(ShowAgainCheck);
}
//---------------------------------------------------------------------------
void __fastcall TLoginDialog::Dispatch(void * Message)
Expand Down Expand Up @@ -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;
}
}
}
//---------------------------------------------------------------------------
7 changes: 2 additions & 5 deletions source/forms/Login.dfm
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions source/forms/Login.h
Expand Up @@ -293,6 +293,7 @@ class TLoginDialog : public TForm
void __fastcall S3CredentialsEnvCheck3Click(TObject *Sender);
void __fastcall EncryptionComboChange(TObject *Sender);
void __fastcall S3ProfileComboChange(TObject *Sender);
void __fastcall ShowAgainCheckClick(TObject *Sender);

private:
int NoUpdate;
Expand Down
28 changes: 16 additions & 12 deletions source/forms/MessageDlg.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -361,6 +362,10 @@ void __fastcall TMessageForm::Dispatch(void * Message)
{
LoadMessageBrowser();
}
if (NeverAskAgainCheck != NULL)
{
AutoSizeCheckBox(NeverAskAgainCheck);
}
TForm::Dispatch(Message);
}
else
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions source/forms/MessageDlg.h
Expand Up @@ -57,6 +57,7 @@ class TMessageForm : public TForm
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);
Expand Down
1 change: 1 addition & 0 deletions source/resource/HelpWin.h
Expand Up @@ -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 change: 1 addition & 0 deletions source/resource/TextsWin.h
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions source/resource/TextsWin1.rc
Expand Up @@ -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"
Expand Down
12 changes: 12 additions & 0 deletions source/windows/VCLCommon.cpp
Expand Up @@ -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;
//---------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions source/windows/VCLCommon.h
Expand Up @@ -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);
Expand Down

0 comments on commit e3fe05f

Please sign in to comment.