CP-6093: The Window menu item on the top MainWindow menu should be disabled when

no forms are open. Since there is no event notifying about the Application.OpenForms
changing, created a new base class for all XenCenter dialogs and wizards with a
static event to which the main windw can subscribe.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2013-11-23 16:03:21 +00:00
parent 406a555a1c
commit 5d04edae99
6 changed files with 90 additions and 10 deletions

View File

@ -0,0 +1,63 @@
/* Copyright (c) Citrix Systems Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
using System;
using System.Windows.Forms;
namespace XenAdmin
{
public class XenCenterForm : Form
{
public static event Action ApplicationOpenFormsChanged;
protected XenCenterForm()
{
Shown += XenCenterForm_Shown;
FormClosed += XenCenterForm_FormClosed;
}
private void OnApplicationOpenFormsChanged()
{
if (ApplicationOpenFormsChanged != null)
ApplicationOpenFormsChanged();
}
private void XenCenterForm_Shown(object sender, EventArgs e)
{
OnApplicationOpenFormsChanged();
}
private void XenCenterForm_FormClosed(object sender, EventArgs e)
{
OnApplicationOpenFormsChanged();
}
}
}

View File

@ -32,16 +32,13 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using XenAdmin.Network;
using XenAdmin.Core;
namespace XenAdmin.Dialogs
{
public partial class XenDialogBase : Form
public partial class XenDialogBase : XenCenterForm
{
private static Dictionary<IXenConnection, List<XenDialogBase>> instances = new Dictionary<IXenConnection, List<XenDialogBase>>();

View File

@ -33,6 +33,7 @@ namespace XenAdmin
ConnectionsManager.History.CollectionChanged -= History_CollectionChanged;
Alert.DeregisterAlertCollectionChanged(XenCenterAlerts_CollectionChanged);
XenCenterForm.ApplicationOpenFormsChanged -= XenCenterForm_ApplicationOpenFormsChanged;
ConnectionsManager.XenConnections.CollectionChanged -= XenConnection_CollectionChanged;
Program.StorageLinkConnections.CollectionChanged -= StorageLinkConnections_CollectionChanged;
Program.StorageLinkConnections.Dispose();

View File

@ -135,7 +135,9 @@ namespace XenAdmin
InitializeComponent();
SetMenuItemStartIndexes();
Icon = Properties.Resources.AppIcon;
#region Add Tab pages
components.Add(NICPage);
components.Add(VMStoragePage);
components.Add(SrStoragePage);
@ -170,6 +172,8 @@ namespace XenAdmin
AddTabContents(GpuPage, TabPageGPU);
AddTabContents(SearchPage, TabPageSearch);
#endregion
TheTabControl.SelectedIndexChanged += TheTabControl_SelectedIndexChanged;
navigationPane.DragDropCommandActivated += navigationPane_DragDropCommandActivated;
@ -198,7 +202,6 @@ namespace XenAdmin
FormFontFixer.Fix(this);
Folders.InitFolders();
OtherConfigAndTagsWatcher.InitEventHandlers();
// Fix colour of text on gradient panels
@ -206,6 +209,8 @@ namespace XenAdmin
loggedInLabel1.SetTextColor(Program.TitleBarForeColor);
statusProgressBar.Visible = false;
windowToolStripMenuItem.Enabled = false;
XenCenterForm.ApplicationOpenFormsChanged += XenCenterForm_ApplicationOpenFormsChanged;
SelectionManager.BindTo(MainMenuBar.Items, commandInterface);
SelectionManager.BindTo(ToolStrip.Items, commandInterface);
@ -215,6 +220,20 @@ namespace XenAdmin
GeneralPage.LicenseLauncher = licenseManagerLauncher;
}
private void XenCenterForm_ApplicationOpenFormsChanged()
{
foreach (Form form in Application.OpenForms)
{
if (form != this && form.Text != "" && !(form is ConnectingToServerDialog))
{
windowToolStripMenuItem.Enabled = true;
return;
}
}
windowToolStripMenuItem.Enabled = false;
}
private void Default_SettingChanging(object sender, SettingChangingEventArgs e)
{
if (e == null)

View File

@ -32,9 +32,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using XenAdmin.Controls;
@ -43,7 +40,7 @@ using XenAdmin.Network;
namespace XenAdmin.Wizards
{
public partial class XenWizardBase : Form
public partial class XenWizardBase : XenCenterForm
{
protected static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

View File

@ -2315,6 +2315,9 @@
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\ComboBoxes\NetworkComboBoxItem.cs" />
<Compile Include="Core\XenCenterForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="OrganizationalView.cs" />
<Compile Include="Controls\SrPickerItem.cs" />
<Compile Include="Controls\SummaryPanel\ISummaryPanelView.cs" />