Browse Source

Disabling Username and Password boxes on a Login dialog when Bypass authentication entirely is enabled.

Source commit: 709bcf383c6a0194a243617a050befbca7d9aa10
Martin Prikryl 9 years ago
parent
commit
7393a60258

+ 6 - 2
source/forms/Login.cpp

@@ -591,8 +591,12 @@ void __fastcall TLoginDialog::UpdateControls()
     ReadOnlyControl(HostNameEdit, !Editable);
     ReadOnlyControl(PortNumberEdit, !Editable);
     PortNumberEdit->ButtonsVisible = Editable;
-    ReadOnlyControl(UserNameEdit, !Editable);
-    ReadOnlyControl(PasswordEdit, !Editable);
+    // FSessionData may be NULL temporary even when Editable while switching nodes
+    bool NoAuth = Editable && SshProtocol && (FSessionData != NULL) && FSessionData->SshNoUserAuth;
+    ReadOnlyAndEnabledControl(UserNameEdit, !Editable, !NoAuth);
+    EnableControl(UserNameLabel, UserNameEdit->Enabled);
+    ReadOnlyAndEnabledControl(PasswordEdit, !Editable, !NoAuth);
+    EnableControl(PasswordLabel, PasswordEdit->Enabled);
 
     // sites
     if (SitesIncrementalSearchLabel->Visible != !FSitesIncrementalSearch.IsEmpty())

+ 2 - 2
source/forms/Login.dfm

@@ -117,7 +117,7 @@ object LoginDialog: TLoginDialog
           Caption = 'Po&rt number:'
           FocusControl = PortNumberEdit
         end
-        object Label3: TLabel
+        object UserNameLabel: TLabel
           Left = 12
           Top = 122
           Width = 55
@@ -125,7 +125,7 @@ object LoginDialog: TLoginDialog
           Caption = '&User name:'
           FocusControl = UserNameEdit
         end
-        object Label4: TLabel
+        object PasswordLabel: TLabel
           Left = 178
           Top = 122
           Width = 50

+ 2 - 2
source/forms/Login.h

@@ -82,8 +82,8 @@ __published:
   TGroupBox *BasicGroup;
   TLabel *Label1;
   TLabel *Label2;
-  TLabel *Label3;
-  TLabel *Label4;
+  TLabel *UserNameLabel;
+  TLabel *PasswordLabel;
   TLabel *Label22;
   TLabel *FtpsLabel;
   TLabel *WebDavsLabel;

+ 27 - 0
source/windows/VCLCommon.cpp

@@ -251,6 +251,33 @@ void __fastcall EnableControl(TControl * Control, bool Enable)
   }
 };
 //---------------------------------------------------------------------------
+void __fastcall ReadOnlyAndEnabledControl(TControl * Control, bool ReadOnly, bool Enabled)
+{
+  if (dynamic_cast<TCustomEdit *>(Control) != NULL)
+  {
+    DebugAssert(dynamic_cast<TWinControl *>(Control)->ControlCount == 0);
+    DebugAssert(dynamic_cast<TMemo *>(Control) == NULL);
+
+    if (ReadOnly)
+    {
+      Control->Enabled = Enabled;
+      ReadOnlyControl(Control, true);
+    }
+    else
+    {
+      // ReadOnlyControl(..., false) would set color to clWindow,
+      // but we want to reflect the Enabled state and avoid flicker.
+      ((TEdit*)Control)->ReadOnly = false;
+
+      EnableControl(Control, Enabled);
+    }
+  }
+  else
+  {
+    DebugFail();
+  }
+}
+//---------------------------------------------------------------------------
 void __fastcall ReadOnlyControl(TControl * Control, bool ReadOnly)
 {
   if (dynamic_cast<TCustomEdit *>(Control) != NULL)

+ 1 - 0
source/windows/VCLCommon.h

@@ -13,6 +13,7 @@ void __fastcall FixListColumnWidth(TListView * TListView, int Index);
 void __fastcall AutoSizeListColumnsWidth(TListView * ListView, int ColumnToShrinkIndex = -1);
 void __fastcall EnableControl(TControl* Control, bool Enable);
 void __fastcall ReadOnlyControl(TControl * Control, bool ReadOnly = true);
+void __fastcall ReadOnlyAndEnabledControl(TControl * Control, bool ReadOnly, bool Enabled);
 void __fastcall InitializeSystemSettings();
 void __fastcall FinalizeSystemSettings();
 void __fastcall LocalSystemSettings(TCustomForm * Control);