mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2025-01-21 07:49:32 +01:00
The ConnectionOptionsPage should not access private controls of its parent but rather communicate its valid state via an event.
Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
parent
ca3e9c0219
commit
a66a82878e
@ -47,7 +47,8 @@ namespace XenAdmin.Dialogs
|
||||
pluginOptionsPage1.PluginManager = pluginManager;
|
||||
verticalTabs.SelectedItem = securityOptionsPage1;
|
||||
|
||||
connectionOptionsPage1.OptionsDialog = this;
|
||||
connectionOptionsPage1.IsValidChanged += ConnectionOptionsPage1_IsValidChanged;
|
||||
|
||||
if (!Application.RenderWithVisualStyles)
|
||||
ContentPanel.BackColor = SystemColors.Control;
|
||||
// call save serverlist on OK
|
||||
@ -57,6 +58,11 @@ namespace XenAdmin.Dialogs
|
||||
verticalTabs.Items.Remove(updatesOptionsPage1);
|
||||
}
|
||||
|
||||
private void ConnectionOptionsPage1_IsValidChanged(bool isPageValid)
|
||||
{
|
||||
okButton.Enabled = isPageValid;
|
||||
}
|
||||
|
||||
private void okButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
foreach (IOptionsPage page in verticalTabs.Items)
|
||||
|
@ -39,7 +39,7 @@ namespace XenAdmin.Dialogs.OptionsPages
|
||||
{
|
||||
public partial class ConnectionOptionsPage : UserControl, IOptionsPage
|
||||
{
|
||||
private OptionsDialog optionsDialog;
|
||||
public event Action<bool> IsValidChanged;
|
||||
|
||||
// used for preventing the event handlers from doing anything when changing controls through code
|
||||
private bool eventsDisabled = true;
|
||||
@ -47,16 +47,10 @@ namespace XenAdmin.Dialogs.OptionsPages
|
||||
public ConnectionOptionsPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
build();
|
||||
Build();
|
||||
}
|
||||
|
||||
public OptionsDialog OptionsDialog
|
||||
{
|
||||
set { this.optionsDialog = value; }
|
||||
}
|
||||
|
||||
private void build()
|
||||
private void Build()
|
||||
{
|
||||
// Proxy server
|
||||
switch ((HTTPHelper.ProxyStyle)Properties.Settings.Default.ProxySetting)
|
||||
@ -110,7 +104,7 @@ namespace XenAdmin.Dialogs.OptionsPages
|
||||
if (eventsDisabled)
|
||||
return;
|
||||
|
||||
enableOK();
|
||||
CheckValid();
|
||||
}
|
||||
|
||||
private void AuthenticationCheckBox_CheckedChanged(object sender, EventArgs e)
|
||||
@ -129,7 +123,7 @@ namespace XenAdmin.Dialogs.OptionsPages
|
||||
|
||||
eventsDisabled = false;
|
||||
|
||||
enableOK();
|
||||
CheckValid();
|
||||
}
|
||||
|
||||
private void GeneralProxySettingsChanged(object sender, EventArgs e)
|
||||
@ -137,7 +131,7 @@ namespace XenAdmin.Dialogs.OptionsPages
|
||||
if (eventsDisabled)
|
||||
return;
|
||||
SelectUseThisProxyServer();
|
||||
enableOK();
|
||||
CheckValid();
|
||||
}
|
||||
|
||||
private void ProxyAuthenticationSettingsChanged(object sender, EventArgs e)
|
||||
@ -145,7 +139,7 @@ namespace XenAdmin.Dialogs.OptionsPages
|
||||
if (eventsDisabled)
|
||||
return;
|
||||
SelectProvideCredentials();
|
||||
enableOK();
|
||||
CheckValid();
|
||||
}
|
||||
|
||||
private void SelectUseThisProxyServer()
|
||||
@ -159,38 +153,34 @@ namespace XenAdmin.Dialogs.OptionsPages
|
||||
UseProxyRadioButton.Checked = true;
|
||||
}
|
||||
|
||||
private void enableOK()
|
||||
private void CheckValid()
|
||||
{
|
||||
if (optionsDialog == null)
|
||||
return;
|
||||
|
||||
if (!UseProxyRadioButton.Checked)
|
||||
{
|
||||
optionsDialog.okButton.Enabled = true;
|
||||
IsValidChanged?.Invoke(true);
|
||||
return;
|
||||
}
|
||||
else if (AuthenticationCheckBox.Checked && string.IsNullOrEmpty(ProxyUsernameTextBox.Text))
|
||||
|
||||
if (AuthenticationCheckBox.Checked && string.IsNullOrEmpty(ProxyUsernameTextBox.Text))
|
||||
{
|
||||
optionsDialog.okButton.Enabled = false;
|
||||
IsValidChanged?.Invoke(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Util.IsValidPort(ProxyPortTextBox.Text))
|
||||
{
|
||||
IsValidChanged?.Invoke(false);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (!Util.IsValidPort(ProxyPortTextBox.Text))
|
||||
{
|
||||
optionsDialog.okButton.Enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var uriHostNameType = Uri.CheckHostName(ProxyAddressTextBox.Text);
|
||||
|
||||
optionsDialog.okButton.Enabled = uriHostNameType != UriHostNameType.Unknown && uriHostNameType != UriHostNameType.IPv6;
|
||||
return;
|
||||
IsValidChanged?.Invoke(uriHostNameType != UriHostNameType.Unknown && uriHostNameType != UriHostNameType.IPv6);
|
||||
}
|
||||
catch
|
||||
{
|
||||
optionsDialog.okButton.Enabled = false;
|
||||
IsValidChanged?.Invoke(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,15 +239,9 @@ namespace XenAdmin.Dialogs.OptionsPages
|
||||
|
||||
#region IVerticalTab Members
|
||||
|
||||
public override string Text
|
||||
{
|
||||
get { return Messages.CONNECTION; }
|
||||
}
|
||||
public override string Text => Messages.CONNECTION;
|
||||
|
||||
public string SubText
|
||||
{
|
||||
get { return Messages.CONNECTION_DESC; }
|
||||
}
|
||||
public string SubText => Messages.CONNECTION_DESC;
|
||||
|
||||
public Image Image => Images.StaticImages._000_Network_h32bit_16;
|
||||
|
||||
|
@ -155,7 +155,7 @@ namespace XenAdmin.Dialogs
|
||||
protected System.Windows.Forms.Panel ContentPanel;
|
||||
protected XenAdmin.Controls.VerticalTabs verticalTabs;
|
||||
protected System.Windows.Forms.Button cancelButton;
|
||||
public System.Windows.Forms.Button okButton;
|
||||
protected System.Windows.Forms.Button okButton;
|
||||
protected System.Windows.Forms.SplitContainer splitContainer;
|
||||
protected XenAdmin.Controls.BlueBorderPanel blueBorder;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user