CA-214953: Multiple connection dialogs while attempting to connect (#1060)

* [CA-214953] Multiple connection dialogs while attempting to connect

ConnectingToServerDialog now keeps track of the dialogs for each connection and focuses on them if they already exist, instead of creating new ones.

Signed-off-by: Frezzle <frederico.mazzone@citrix.com>

* [CA-214953] Multiple connection dialogs while attempting to connect

Moved code to handle open connection dialogs to XenConnectionUI, instead of being done inside ConnectingToServerDialog.
Only one error message appears now upon connection failure.
If connection dialog was minimized, and user double-clicks again to connect, it now returns to normal state on the screen as well as taking focus.

Signed-off-by: Frezzle <frederico.mazzone@citrix.com>
This commit is contained in:
Frezzle 2016-07-08 16:24:19 +01:00 committed by Mihaela Stoica
parent 21fe02922f
commit 35f8c3ec2f
2 changed files with 22 additions and 2 deletions

View File

@ -98,6 +98,9 @@ namespace XenAdmin.Dialogs
return;
}
if (_connection != null)
XenConnectionUI.connectionDialogs.Remove(_connection);
base.OnFormClosing(e);
}

View File

@ -34,6 +34,7 @@ using System.Drawing;
using System.IO;
using System.Net;
using System.Windows.Forms;
using System.Collections.Generic;
using XenAdmin.Core;
using XenAdmin.Dialogs;
using XenAPI;
@ -43,6 +44,8 @@ namespace XenAdmin.Network
{
class XenConnectionUI
{
public static Dictionary<IXenConnection, ConnectingToServerDialog> connectionDialogs = new Dictionary<IXenConnection, ConnectingToServerDialog>();
/// <summary>
/// Start connecting to a server
/// </summary>
@ -55,9 +58,23 @@ namespace XenAdmin.Network
public static void BeginConnect(IXenConnection connection, bool interactive, Form owner, bool initiateMasterSearch)
{
Program.AssertOnEventThread();
RegisterEventHandlers(connection);
RegisterEventHandlers(connection);
if (interactive)
new ConnectingToServerDialog(connection).BeginConnect(owner, initiateMasterSearch);
{
// CA-214953 - Focus on this connection's dialog, if one exists, otherwise create one
ConnectingToServerDialog dlg;
if (connectionDialogs.TryGetValue(connection, out dlg))
{
UnregisterEventHandlers(connection);
if (dlg.WindowState == FormWindowState.Minimized)
dlg.WindowState = FormWindowState.Normal;
dlg.Focus();
return;
}
dlg = new ConnectingToServerDialog(connection);
connectionDialogs.Add(connection, dlg);
dlg.BeginConnect(owner, initiateMasterSearch);
}
else
((XenConnection)connection).BeginConnect(initiateMasterSearch, PromptForNewPassword);
}