MainWindow code tidy: removed methods constructing ToolStripMenuItems as unecessary.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2013-08-22 16:48:16 +01:00
parent a516796006
commit 60bca4d1df
4 changed files with 88 additions and 121 deletions

View File

@ -74,8 +74,11 @@ namespace XenAdmin.Controls
private void AddMenuItem(string name, object tag, Image image, bool selected) private void AddMenuItem(string name, object tag, Image image, bool selected)
{ {
ToolStripMenuItem menuItem = MainWindow.NewToolStripMenuItem(name, image, null); var menuItem = new ToolStripMenuItem(name)
menuItem.Tag = tag; {
Image = image,
Tag = tag
};
comboButtonViews.AddItem(menuItem); comboButtonViews.AddItem(menuItem);
if (selected) if (selected)
comboButtonViews.SelectedItem = menuItem; comboButtonViews.SelectedItem = menuItem;

View File

@ -2366,7 +2366,7 @@ namespace XenAdmin
foreach (Form form in GetAuxWindows()) foreach (Form form in GetAuxWindows())
{ {
ToolStripMenuItem item = NewToolStripMenuItem(form.Text.EscapeAmpersands()); ToolStripMenuItem item = new ToolStripMenuItem(form.Text.EscapeAmpersands());
item.Tag = form; item.Tag = form;
windowToolStripMenuItem.DropDown.Items.Add(item); windowToolStripMenuItem.DropDown.Items.Add(item);
} }
@ -3668,40 +3668,6 @@ namespace XenAdmin
} }
} }
/// <summary>
/// Create a new ToolStripMenuItem, setting the appropriate default font, and configuring it with the given text, icon, and click handler.
/// </summary>
/// <param name="text">The menu item text. Don't forget that this may need to have its ampersands escaped.</param>
/// <param name="ico">May be null, in which case no icon is set.</param>
/// <param name="clickHandler">May be null, in which case no click handler is set.</param>
/// <returns>The new ToolStripMenuItem</returns>
internal static ToolStripMenuItem NewToolStripMenuItem(string text, Image ico, EventHandler clickHandler)
{
ToolStripMenuItem m = new ToolStripMenuItem(text);
m.Font = Program.DefaultFont;
if (ico != null)
m.Image = ico;
if (clickHandler != null)
m.Click += clickHandler;
return m;
}
/// <summary>
/// Equivalent to NewToolStripMenuItem(text, null, null).
/// </summary>
internal static ToolStripMenuItem NewToolStripMenuItem(string text)
{
return NewToolStripMenuItem(text, null, null);
}
/// <summary>
/// Equivalent to NewToolStripMenuItem(text, null, clickHandler).
/// </summary>
internal static ToolStripMenuItem NewToolStripMenuItem(string text, EventHandler clickHandler)
{
return NewToolStripMenuItem(text, null, clickHandler);
}
internal void FocusTreeView() internal void FocusTreeView()
{ {
treeView.Focus(); treeView.Focus();

View File

@ -499,11 +499,12 @@ namespace XenAdmin.TabPages
{ {
PDSection s = pdSectionManagementInterfaces; PDSection s = pdSectionManagementInterfaces;
ToolStripMenuItem editValue = MainWindow.NewToolStripMenuItem(Messages.EDIT, Properties.Resources.edit_16, delegate(object sender, EventArgs e) ToolStripMenuItem editValue = new ToolStripMenuItem(Messages.EDIT) { Image = Properties.Resources.edit_16 };
{ editValue.Click += delegate
NetworkingProperties p = new NetworkingProperties(Host, null); {
p.ShowDialog(Program.MainWindow); NetworkingProperties p = new NetworkingProperties(Host, null);
}); p.ShowDialog(Program.MainWindow);
};
List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>(); List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();
menuItems.Add(editValue); menuItems.Add(editValue);
@ -556,12 +557,13 @@ namespace XenAdmin.TabPages
foreach (CustomField customField in customFields) foreach (CustomField customField in customFields)
{ {
ToolStripMenuItem editValue = MainWindow.NewToolStripMenuItem(Messages.EDIT, Properties.Resources.edit_16, delegate(object sender, EventArgs e) ToolStripMenuItem editValue = new ToolStripMenuItem(Messages.EDIT){Image= Properties.Resources.edit_16};
{ editValue.Click += delegate
PropertiesDialog dialog = new PropertiesDialog(xenObject); {
dialog.SelectPage(dialog.CustomFieldsEditPage); PropertiesDialog dialog = new PropertiesDialog(xenObject);
dialog.ShowDialog(); dialog.SelectPage(dialog.CustomFieldsEditPage);
}); dialog.ShowDialog();
};
List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>(); List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();
menuItems.Add(editValue); menuItems.Add(editValue);
CustomFieldWrapper cfWrapper = new CustomFieldWrapper(xenObject, customField.Definition); CustomFieldWrapper cfWrapper = new CustomFieldWrapper(xenObject, customField.Definition);
@ -679,17 +681,18 @@ namespace XenAdmin.TabPages
bool detached = !sr.HasPBDs; bool detached = !sr.HasPBDs;
List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>(); List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();
ToolStripMenuItem repair = MainWindow.NewToolStripMenuItem(sr.NeedsUpgrading ? Messages.UPGRADE_SR : Messages.GENERAL_SR_CONTEXT_REPAIR, ToolStripMenuItem repair = new ToolStripMenuItem
Properties.Resources._000_StorageBroken_h32bit_16, {
delegate(object sender, EventArgs e) Text = sr.NeedsUpgrading ? Messages.UPGRADE_SR : Messages.GENERAL_SR_CONTEXT_REPAIR,
Image = Properties.Resources._000_StorageBroken_h32bit_16
};
repair.Click += delegate
{ {
if (sr.NeedsUpgrading) if (sr.NeedsUpgrading)
{
new UpgradeSRCommand(Program.MainWindow.CommandInterface, sr).Execute(); new UpgradeSRCommand(Program.MainWindow.CommandInterface, sr).Execute();
}
else else
Program.MainWindow.ShowPerConnectionWizard(xenObject.Connection, new RepairSRDialog(sr)); Program.MainWindow.ShowPerConnectionWizard(xenObject.Connection, new RepairSRDialog(sr));
}); };
menuItems.Add(repair); menuItems.Add(repair);
if (broken && !detached) if (broken && !detached)
@ -932,19 +935,19 @@ namespace XenAdmin.TabPages
if (info.ContainsKey("expiry")) if (info.ContainsKey("expiry"))
{ {
ToolStripMenuItem editItem = MainWindow.NewToolStripMenuItem(Messages.LAUNCH_LICENSE_MANAGER, delegate ToolStripMenuItem editItem = new ToolStripMenuItem(Messages.LAUNCH_LICENSE_MANAGER);
{ editItem.Click += delegate
if(LicenseLauncher != null)
{ {
LicenseLauncher.Parent = Program.MainWindow; if (LicenseLauncher != null)
LicenseLauncher.LaunchIfRequired(false, ConnectionsManager.XenConnections); {
} LicenseLauncher.Parent = Program.MainWindow;
LicenseLauncher.LaunchIfRequired(false, ConnectionsManager.XenConnections);
}); }
};
GeneralTabLicenseStatusStringifier ss = new GeneralTabLicenseStatusStringifier(licenseStatus); GeneralTabLicenseStatusStringifier ss = new GeneralTabLicenseStatusStringifier(licenseStatus);
s.AddEntry(Messages.LICENSE_STATUS, ss.ExpiryStatus, new List<ToolStripMenuItem>(new [] { editItem })); s.AddEntry(Messages.LICENSE_STATUS, ss.ExpiryStatus, new List<ToolStripMenuItem>(new [] { editItem }));
s.AddEntry(FriendlyName("host.license_params-expiry"), ss.ExpiryDate, new List<ToolStripMenuItem>(new ToolStripMenuItem[] { editItem })); s.AddEntry(FriendlyName("host.license_params-expiry"), ss.ExpiryDate, new List<ToolStripMenuItem>(new [] { editItem }));
info.Remove("expiry"); info.Remove("expiry");
} }
@ -1094,31 +1097,33 @@ namespace XenAdmin.TabPages
} }
else if (!host.enabled) else if (!host.enabled)
{ {
var item = new ToolStripMenuItem(Messages.EXIT_MAINTENANCE_MODE);
item.Click += delegate
{
new HostMaintenanceModeCommand(Program.MainWindow.CommandInterface, host,
HostMaintenanceModeCommandParameter.Exit).Execute();
};
s.AddEntry(FriendlyName("host.enabled"), s.AddEntry(FriendlyName("host.enabled"),
host.MaintenanceMode ? Messages.HOST_IN_MAINTENANCE_MODE : Messages.DISABLED, host.MaintenanceMode ? Messages.HOST_IN_MAINTENANCE_MODE : Messages.DISABLED,
new List<ToolStripMenuItem>(new ToolStripMenuItem[] { new List<ToolStripMenuItem>(new[] { item }),
MainWindow.NewToolStripMenuItem(Messages.EXIT_MAINTENANCE_MODE, delegate(object sender, EventArgs e)
{
new HostMaintenanceModeCommand(Program.MainWindow.CommandInterface, host, HostMaintenanceModeCommandParameter.Exit).Execute();
})
}),
Color.Red); Color.Red);
} }
else else
{ {
var item = new ToolStripMenuItem(Messages.ENTER_MAINTENANCE_MODE);
item.Click += delegate
{
new HostMaintenanceModeCommand(Program.MainWindow.CommandInterface, host,
HostMaintenanceModeCommandParameter.Enter).Execute();
};
s.AddEntry(FriendlyName("host.enabled"), Messages.YES, s.AddEntry(FriendlyName("host.enabled"), Messages.YES,
new List<ToolStripMenuItem>(new ToolStripMenuItem[] { new List<ToolStripMenuItem>(new [] {item}));
MainWindow.NewToolStripMenuItem(Messages.ENTER_MAINTENANCE_MODE, delegate(object sender, EventArgs e)
{
new HostMaintenanceModeCommand(Program.MainWindow.CommandInterface, host, HostMaintenanceModeCommandParameter.Enter).Execute();
})
}));
} }
s.AddEntry(FriendlyName("host.iscsi_iqn"), host.iscsi_iqn, s.AddEntry(FriendlyName("host.iscsi_iqn"), host.iscsi_iqn,
new List<ToolStripMenuItem>(new ToolStripMenuItem[] { EditMenuItem("GeneralEditPage", "txtIQN") })); new List<ToolStripMenuItem>(new [] { EditMenuItem("GeneralEditPage", "txtIQN") }));
s.AddEntry(FriendlyName("host.log_destination"), host.SysLogDestination ?? Messages.HOST_LOG_DESTINATION_LOCAL, s.AddEntry(FriendlyName("host.log_destination"), host.SysLogDestination ?? Messages.HOST_LOG_DESTINATION_LOCAL,
new List<ToolStripMenuItem>(new ToolStripMenuItem[] { EditMenuItem("LogDestinationEditPage", "localRadioButton") })); new List<ToolStripMenuItem>(new [] { EditMenuItem("LogDestinationEditPage", "localRadioButton") }));
PrettyTimeSpan uptime = host.Uptime; PrettyTimeSpan uptime = host.Uptime;
PrettyTimeSpan agentUptime = host.AgentUptime; PrettyTimeSpan agentUptime = host.AgentUptime;
@ -1144,12 +1149,13 @@ namespace XenAdmin.TabPages
var appl = vm.Connection.Resolve(vm.appliance); var appl = vm.Connection.Resolve(vm.appliance);
if (appl != null) if (appl != null)
{ {
ToolStripMenuItem applProperties = MainWindow.NewToolStripMenuItem(Messages.VM_APPLIANCE_PROPERTIES, var applProperties = new ToolStripMenuItem(Messages.VM_APPLIANCE_PROPERTIES);
(sender, e) => applProperties.Click +=
{ (sender, e) =>
using (PropertiesDialog propertiesDialog = new PropertiesDialog(appl)) {
propertiesDialog.ShowDialog(this); using (PropertiesDialog propertiesDialog = new PropertiesDialog(appl))
}); propertiesDialog.ShowDialog(this);
};
s.AddEntryLink(Messages.VM_APPLIANCE, appl.Name, new List<ToolStripMenuItem>(new[] { applProperties }), s.AddEntryLink(Messages.VM_APPLIANCE, appl.Name, new List<ToolStripMenuItem>(new[] { applProperties }),
() => () =>
@ -1177,13 +1183,14 @@ namespace XenAdmin.TabPages
{ {
if (InstallToolsCommand.CanExecute(vm)) if (InstallToolsCommand.CanExecute(vm))
{ {
ToolStripMenuItem installtools = MainWindow.NewToolStripMenuItem( var installtools = new ToolStripMenuItem(Messages.INSTALL_XENSERVER_TOOLS_DOTS);
Messages.INSTALL_XENSERVER_TOOLS_DOTS, delegate(object sender, EventArgs e) installtools.Click += delegate
{ {
new InstallToolsCommand(Program.MainWindow.CommandInterface, vm).Execute(); new InstallToolsCommand(Program.MainWindow.CommandInterface, vm).Execute();
}); };
s.AddEntryLink(FriendlyName("VM.VirtualizationState"), vm.VirtualisationStatusString, s.AddEntryLink(FriendlyName("VM.VirtualizationState"), vm.VirtualisationStatusString,
new List<ToolStripMenuItem>(new ToolStripMenuItem[] { installtools }), new InstallToolsCommand(Program.MainWindow.CommandInterface, vm)); new List<ToolStripMenuItem>(new [] { installtools }),
new InstallToolsCommand(Program.MainWindow.CommandInterface, vm));
} }
else else
{ {
@ -1369,20 +1376,18 @@ namespace XenAdmin.TabPages
private void GenTagRow(PDSection s) private void GenTagRow(PDSection s)
{ {
List<ToolStripMenuItem> toolStrip = new List<ToolStripMenuItem>(new ToolStripMenuItem[] { EditMenuItem("GeneralEditPage", "") }); List<ToolStripMenuItem> toolStrip = new List<ToolStripMenuItem>(new [] { EditMenuItem("GeneralEditPage", "") });
string[] tags = Tags.GetTags(xenObject); string[] tags = Tags.GetTags(xenObject);
if (tags != null && tags.Length > 0) if (tags != null && tags.Length > 0)
{ {
ToolStripMenuItem goToTag = MainWindow.NewToolStripMenuItem(Messages.VIEW_TAG_MENU_OPTION); ToolStripMenuItem goToTag = new ToolStripMenuItem(Messages.VIEW_TAG_MENU_OPTION);
foreach (string tag in tags) foreach (string tag in tags)
{ {
goToTag.DropDownItems.Add(MainWindow.NewToolStripMenuItem(tag.Ellipsise(30), var item = new ToolStripMenuItem(tag.Ellipsise(30));
delegate(object sender, EventArgs e) item.Click += delegate { Program.MainWindow.SearchForTag(tag); };
{ goToTag.DropDownItems.Add(item);
Program.MainWindow.SearchForTag(tag);
}));
} }
toolStrip.Insert(0, goToTag); toolStrip.Insert(0, goToTag);
s.AddEntry(Messages.TAGS, TagsString(), toolStrip); s.AddEntry(Messages.TAGS, TagsString(), toolStrip);
@ -1407,13 +1412,9 @@ namespace XenAdmin.TabPages
List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>(); List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();
if (xenObject.Path != "") if (xenObject.Path != "")
{ {
menuItems.Add( var item = new ToolStripMenuItem(Messages.VIEW_FOLDER_MENU_OPTION);
MainWindow.NewToolStripMenuItem(Messages.VIEW_FOLDER_MENU_OPTION, item.Click += delegate { Program.MainWindow.SearchForFolder(xenObject.Path); };
delegate(object sender, EventArgs e) menuItems.Add(item);
{
Program.MainWindow.SearchForFolder(xenObject.Path);
})
);
} }
menuItems.Add(EditMenuItem("GeneralEditPage", "")); menuItems.Add(EditMenuItem("GeneralEditPage", ""));
s.AddEntry( s.AddEntry(

View File

@ -329,10 +329,8 @@ namespace XenAdmin.TabPages
if (redBold) if (redBold)
{ {
newChild.Items[1].ForeColor = Color.Red; newChild.Items[1].ForeColor = Color.Red;
ToolStripMenuItem editHa = MainWindow.NewToolStripMenuItem(Messages.CONFIGURE_HA_ELLIPSIS, delegate(object sender, EventArgs e) ToolStripMenuItem editHa = new ToolStripMenuItem(Messages.CONFIGURE_HA_ELLIPSIS);
{ editHa.Click += delegate { EditHA(pool); };
EditHA(pool);
});
newChild.MenuItems.Add(editHa); newChild.MenuItems.Add(editHa);
newChild.DefaultMenuItem = editHa; newChild.DefaultMenuItem = editHa;
} }
@ -351,10 +349,8 @@ namespace XenAdmin.TabPages
if (redBold) if (redBold)
{ {
newChild.Items[1].ForeColor = Color.Red; newChild.Items[1].ForeColor = Color.Red;
ToolStripMenuItem editHa = MainWindow.NewToolStripMenuItem(Messages.CONFIGURE_HA_ELLIPSIS, delegate(object sender, EventArgs e) ToolStripMenuItem editHa = new ToolStripMenuItem(Messages.CONFIGURE_HA_ELLIPSIS);
{ editHa.Click += delegate { EditHA(pool); };
EditHA(pool);
});
newChild.MenuItems.Add(editHa); newChild.MenuItems.Add(editHa);
newChild.DefaultMenuItem = editHa; newChild.DefaultMenuItem = editHa;
} }
@ -575,19 +571,20 @@ namespace XenAdmin.TabPages
{ {
menu.Items.Add(item); menu.Items.Add(item);
} }
ToolStripMenuItem copyItem = MainWindow.NewToolStripMenuItem(Messages.COPY, Properties.Resources.copy_16, delegate(object sender2, EventArgs eve) ToolStripMenuItem copyItem = new ToolStripMenuItem(Messages.COPY) { Image = Properties.Resources.copy_16 };
{ copyItem.Click += delegate
try
{ {
String text = Helpers.ToWindowsLineEndings(e.Item.Tag != null ? e.Item.Tag.ToString() : e.Item.Text); try
Clipboard.SetText(text); {
} String text = Helpers.ToWindowsLineEndings(e.Item.Tag != null ? e.Item.Tag.ToString() : e.Item.Text);
catch (Exception ex) Clipboard.SetText(text);
{ }
log.Error("Exception while trying to set clipboard text.", ex); catch (Exception ex)
log.Error(ex, ex); {
} log.Error("Exception while trying to set clipboard text.", ex);
}); log.Error(ex, ex);
}
};
menu.Items.Add(copyItem); menu.Items.Add(copyItem);
menu.Show(this, PointToClient(MousePosition)); menu.Show(this, PointToClient(MousePosition));
} }