From c051f8de945d3d699476b2251cde5aae782accdf Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Fri, 27 Sep 2013 16:57:50 +0100 Subject: [PATCH] CA-82957: Refactoring to our custom ComboBoxes with regards to resource management and disposal. Signed-off-by: Konstantina Chremmou --- .../Controls/ComboBoxes/CDChanger.Designer.cs | 36 ------- XenAdmin/Controls/ComboBoxes/CDChanger.cs | 3 +- .../Controls/ComboBoxes/EnableableComboBox.cs | 30 ++---- .../ComboBoxes/ISODropDownBox.Designer.cs | 47 -------- .../Controls/ComboBoxes/ISODropDownBox.cs | 19 ++-- ...gner.cs => LongStringComboBox.Designer.cs} | 15 ++- .../Controls/ComboBoxes/LongStringComboBox.cs | 18 +--- ....zh-CN.resx => LongStringComboBox.ja.resx} | 6 +- ...opDownBox.resx => LongStringComboBox.resx} | 18 ++++ ....ja.resx => LongStringComboBox.zh-CN.resx} | 6 +- .../Controls/ComboBoxes/NetworkComboBox.cs | 6 +- .../ComboBoxes/NetworkComboBox.ja.resx | 101 ------------------ .../Controls/ComboBoxes/NetworkComboBox.resx | 101 ------------------ .../ComboBoxes/NetworkComboBox.zh-CN.resx | 101 ------------------ XenAdmin/Controls/ComboBoxes/VgpuComboBox.cs | 2 +- ...PoolMigrateTransferNetworkPage.Designer.cs | 1 - .../GenericPages/TvmIpPage.Designer.cs | 1 - XenAdmin/XenAdmin.csproj | 40 +++---- 18 files changed, 70 insertions(+), 481 deletions(-) delete mode 100644 XenAdmin/Controls/ComboBoxes/CDChanger.Designer.cs delete mode 100644 XenAdmin/Controls/ComboBoxes/ISODropDownBox.Designer.cs rename XenAdmin/Controls/ComboBoxes/{NetworkComboBox.Designer.cs => LongStringComboBox.Designer.cs} (67%) rename XenAdmin/Controls/ComboBoxes/{ISODropDownBox.zh-CN.resx => LongStringComboBox.ja.resx} (94%) rename XenAdmin/Controls/ComboBoxes/{ISODropDownBox.resx => LongStringComboBox.resx} (83%) rename XenAdmin/Controls/ComboBoxes/{ISODropDownBox.ja.resx => LongStringComboBox.zh-CN.resx} (94%) delete mode 100644 XenAdmin/Controls/ComboBoxes/NetworkComboBox.ja.resx delete mode 100644 XenAdmin/Controls/ComboBoxes/NetworkComboBox.resx delete mode 100644 XenAdmin/Controls/ComboBoxes/NetworkComboBox.zh-CN.resx diff --git a/XenAdmin/Controls/ComboBoxes/CDChanger.Designer.cs b/XenAdmin/Controls/ComboBoxes/CDChanger.Designer.cs deleted file mode 100644 index ebcb0d8bc..000000000 --- a/XenAdmin/Controls/ComboBoxes/CDChanger.Designer.cs +++ /dev/null @@ -1,36 +0,0 @@ -namespace XenAdmin.Controls -{ - partial class CDChanger - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Component Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - components = new System.ComponentModel.Container(); - } - - #endregion - } -} diff --git a/XenAdmin/Controls/ComboBoxes/CDChanger.cs b/XenAdmin/Controls/ComboBoxes/CDChanger.cs index ac5d609fc..a7f9e4a07 100644 --- a/XenAdmin/Controls/ComboBoxes/CDChanger.cs +++ b/XenAdmin/Controls/ComboBoxes/CDChanger.cs @@ -36,11 +36,10 @@ using XenAdmin.Core; namespace XenAdmin.Controls { - public partial class CDChanger : ISODropDownBox + public class CDChanger : ISODropDownBox { public CDChanger() { - InitializeComponent(); Empty = true; } diff --git a/XenAdmin/Controls/ComboBoxes/EnableableComboBox.cs b/XenAdmin/Controls/ComboBoxes/EnableableComboBox.cs index ea2e90da1..de849be56 100644 --- a/XenAdmin/Controls/ComboBoxes/EnableableComboBox.cs +++ b/XenAdmin/Controls/ComboBoxes/EnableableComboBox.cs @@ -51,45 +51,31 @@ namespace XenAdmin.Controls { public EnableableComboBox() { - DrawItem += m_comboBoxConnection_DrawItem; DrawMode = DrawMode.OwnerDrawVariable; DropDownStyle = ComboBoxStyle.DropDownList; } - private bool disposed; - protected override void Dispose(bool disposing) + protected override void OnDrawItem(DrawItemEventArgs e) { - if(disposing) - { - if(!disposed) - { - DrawItem -= m_comboBoxConnection_DrawItem; - } - disposed = true; - } - base.Dispose(disposing); - } - - private void m_comboBoxConnection_DrawItem(object sender, DrawItemEventArgs e) - { - e.DrawBackground(); - ComboBox cb = (ComboBox)sender; int index = e.Index; - if (index > -1 && cb != null) + if (index > -1) { - IEnableableComboBoxItem item = cb.Items[index] as IEnableableComboBoxItem; + e.DrawBackground(); + + IEnableableComboBoxItem item = Items[index] as IEnableableComboBoxItem; Color textColor = SystemColors.ControlText; //Paint disabled items grey - otherwise leave them black if (item != null && !item.Enabled) - textColor = SystemColors.GrayText; + textColor = SystemColors.GrayText; if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) textColor = SystemColors.HighlightText; - Drawing.DrawText(e.Graphics, cb.Items[index].ToString(), cb.Font, e.Bounds.Location, textColor); + Drawing.DrawText(e.Graphics, Items[index].ToString(), Font, e.Bounds.Location, textColor); } + base.OnDrawItem(e); } public new bool Enabled diff --git a/XenAdmin/Controls/ComboBoxes/ISODropDownBox.Designer.cs b/XenAdmin/Controls/ComboBoxes/ISODropDownBox.Designer.cs deleted file mode 100644 index 2afb84c8e..000000000 --- a/XenAdmin/Controls/ComboBoxes/ISODropDownBox.Designer.cs +++ /dev/null @@ -1,47 +0,0 @@ -namespace XenAdmin.Controls -{ - partial class ISODropDownBox - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - // deregisteres all event handlers - DeregisterEvents(); - - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Component Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.SuspendLayout(); - // - // ISODropDownBox - // - this.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed; - this.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.FormattingEnabled = true; - this.ResumeLayout(false); - - } - - #endregion - } -} diff --git a/XenAdmin/Controls/ComboBoxes/ISODropDownBox.cs b/XenAdmin/Controls/ComboBoxes/ISODropDownBox.cs index 4ccca8d18..7300b731e 100644 --- a/XenAdmin/Controls/ComboBoxes/ISODropDownBox.cs +++ b/XenAdmin/Controls/ComboBoxes/ISODropDownBox.cs @@ -33,22 +33,15 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; -using System.Data; -using System.Text; using System.Windows.Forms; -using System.Collections; -using System.Text.RegularExpressions; - -using XenAdmin; using XenAdmin.Core; using XenAdmin.Network; using XenAPI; -using System.Runtime.InteropServices; namespace XenAdmin.Controls { - public partial class ISODropDownBox : NonSelectableComboBox + public class ISODropDownBox : NonSelectableComboBox { public VM vm; protected VBD cdrom; @@ -75,7 +68,15 @@ namespace XenAdmin.Controls public ISODropDownBox() { SR_CollectionChangedWithInvoke = Program.ProgramInvokeHandler(SR_CollectionChanged); - InitializeComponent(); + DrawMode = DrawMode.OwnerDrawFixed; + DropDownStyle = ComboBoxStyle.DropDownList; + FormattingEnabled = true; + } + + protected override void Dispose(bool disposing) + { + DeregisterEvents(); + base.Dispose(disposing); } private void RefreshSRs_() diff --git a/XenAdmin/Controls/ComboBoxes/NetworkComboBox.Designer.cs b/XenAdmin/Controls/ComboBoxes/LongStringComboBox.Designer.cs similarity index 67% rename from XenAdmin/Controls/ComboBoxes/NetworkComboBox.Designer.cs rename to XenAdmin/Controls/ComboBoxes/LongStringComboBox.Designer.cs index dd8b33528..ec9fe1c3a 100644 --- a/XenAdmin/Controls/ComboBoxes/NetworkComboBox.Designer.cs +++ b/XenAdmin/Controls/ComboBoxes/LongStringComboBox.Designer.cs @@ -1,11 +1,11 @@ namespace XenAdmin.Controls { - partial class NetworkComboBox + partial class LongStringComboBox { /// /// Required designer variable. /// - private System.ComponentModel.IContainer components = null; + private System.ComponentModel.IContainer components; /// /// Clean up any resources being used. @@ -28,10 +28,15 @@ /// private void InitializeComponent() { - components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.components = new System.ComponentModel.Container(); + this.toolTip = new System.Windows.Forms.ToolTip(this.components); + this.SuspendLayout(); + this.ResumeLayout(false); + } #endregion + + private System.Windows.Forms.ToolTip toolTip; } -} +} \ No newline at end of file diff --git a/XenAdmin/Controls/ComboBoxes/LongStringComboBox.cs b/XenAdmin/Controls/ComboBoxes/LongStringComboBox.cs index ce0d4e9d3..bc9f9e9d5 100644 --- a/XenAdmin/Controls/ComboBoxes/LongStringComboBox.cs +++ b/XenAdmin/Controls/ComboBoxes/LongStringComboBox.cs @@ -30,7 +30,6 @@ */ using System; -using System.Drawing; using System.Windows.Forms; using XenAdmin.Core; @@ -41,22 +40,11 @@ namespace XenAdmin.Controls /// A combobox that automatically resizes the dropdown's width to be as big /// as the longest string in the items list /// - public class LongStringComboBox : ComboBox + public partial class LongStringComboBox : ComboBox { - private readonly ToolTip toolTip = new ToolTip(); - - private bool disposed; - protected override void Dispose(bool disposing) + public LongStringComboBox() { - if (disposing) - { - if (!disposed) - { - toolTip.Dispose(); - } - disposed = true; - } - base.Dispose(disposing); + InitializeComponent(); } protected override void OnDropDown(EventArgs e) diff --git a/XenAdmin/Controls/ComboBoxes/ISODropDownBox.zh-CN.resx b/XenAdmin/Controls/ComboBoxes/LongStringComboBox.ja.resx similarity index 94% rename from XenAdmin/Controls/ComboBoxes/ISODropDownBox.zh-CN.resx rename to XenAdmin/Controls/ComboBoxes/LongStringComboBox.ja.resx index 3276f5c01..5bc1e6ec9 100644 --- a/XenAdmin/Controls/ComboBoxes/ISODropDownBox.zh-CN.resx +++ b/XenAdmin/Controls/ComboBoxes/LongStringComboBox.ja.resx @@ -117,7 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - False - + + + \ No newline at end of file diff --git a/XenAdmin/Controls/ComboBoxes/ISODropDownBox.resx b/XenAdmin/Controls/ComboBoxes/LongStringComboBox.resx similarity index 83% rename from XenAdmin/Controls/ComboBoxes/ISODropDownBox.resx rename to XenAdmin/Controls/ComboBoxes/LongStringComboBox.resx index 3276f5c01..2a5487cf9 100644 --- a/XenAdmin/Controls/ComboBoxes/ISODropDownBox.resx +++ b/XenAdmin/Controls/ComboBoxes/LongStringComboBox.resx @@ -117,7 +117,25 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 0, 0 + False + + True + + + toolTip + + + System.Windows.Forms.ToolTip, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + LongStringComboBox + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/XenAdmin/Controls/ComboBoxes/ISODropDownBox.ja.resx b/XenAdmin/Controls/ComboBoxes/LongStringComboBox.zh-CN.resx similarity index 94% rename from XenAdmin/Controls/ComboBoxes/ISODropDownBox.ja.resx rename to XenAdmin/Controls/ComboBoxes/LongStringComboBox.zh-CN.resx index 3276f5c01..5bc1e6ec9 100644 --- a/XenAdmin/Controls/ComboBoxes/ISODropDownBox.ja.resx +++ b/XenAdmin/Controls/ComboBoxes/LongStringComboBox.zh-CN.resx @@ -117,7 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - False - + + + \ No newline at end of file diff --git a/XenAdmin/Controls/ComboBoxes/NetworkComboBox.cs b/XenAdmin/Controls/ComboBoxes/NetworkComboBox.cs index c3fe26780..b4ad5dad0 100644 --- a/XenAdmin/Controls/ComboBoxes/NetworkComboBox.cs +++ b/XenAdmin/Controls/ComboBoxes/NetworkComboBox.cs @@ -38,12 +38,10 @@ using XenAPI; namespace XenAdmin.Controls { - public partial class NetworkComboBox : LongStringComboBox + public class NetworkComboBox : LongStringComboBox { - public NetworkComboBox() { - InitializeComponent(); DropDownStyle = ComboBoxStyle.DropDownList; } @@ -136,7 +134,5 @@ namespace XenAdmin.Controls : new KeyValuePair(selectedItem.Network.uuid, selectedItem.Network.Name); } } - - public AutoScaleMode AutoScaleMode { get; set; } } } diff --git a/XenAdmin/Controls/ComboBoxes/NetworkComboBox.ja.resx b/XenAdmin/Controls/ComboBoxes/NetworkComboBox.ja.resx deleted file mode 100644 index 85c909092..000000000 --- a/XenAdmin/Controls/ComboBoxes/NetworkComboBox.ja.resx +++ /dev/null @@ -1,101 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 1.3 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/XenAdmin/Controls/ComboBoxes/NetworkComboBox.resx b/XenAdmin/Controls/ComboBoxes/NetworkComboBox.resx deleted file mode 100644 index 85c909092..000000000 --- a/XenAdmin/Controls/ComboBoxes/NetworkComboBox.resx +++ /dev/null @@ -1,101 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 1.3 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/XenAdmin/Controls/ComboBoxes/NetworkComboBox.zh-CN.resx b/XenAdmin/Controls/ComboBoxes/NetworkComboBox.zh-CN.resx deleted file mode 100644 index 85c909092..000000000 --- a/XenAdmin/Controls/ComboBoxes/NetworkComboBox.zh-CN.resx +++ /dev/null @@ -1,101 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 1.3 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/XenAdmin/Controls/ComboBoxes/VgpuComboBox.cs b/XenAdmin/Controls/ComboBoxes/VgpuComboBox.cs index 7fb4f675c..cdc44c67f 100644 --- a/XenAdmin/Controls/ComboBoxes/VgpuComboBox.cs +++ b/XenAdmin/Controls/ComboBoxes/VgpuComboBox.cs @@ -48,7 +48,7 @@ namespace XenAdmin.Controls protected override void OnDrawItem(DrawItemEventArgs e) { - if (e.Index != -1) + if (e.Index > -1) { e.DrawBackground(); diff --git a/XenAdmin/Wizards/CrossPoolMigrateWizard/CrossPoolMigrateTransferNetworkPage.Designer.cs b/XenAdmin/Wizards/CrossPoolMigrateWizard/CrossPoolMigrateTransferNetworkPage.Designer.cs index a374ec0fb..ebee4f7b7 100644 --- a/XenAdmin/Wizards/CrossPoolMigrateWizard/CrossPoolMigrateTransferNetworkPage.Designer.cs +++ b/XenAdmin/Wizards/CrossPoolMigrateWizard/CrossPoolMigrateTransferNetworkPage.Designer.cs @@ -59,7 +59,6 @@ // // networkComboBox // - this.networkComboBox.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.networkComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.networkComboBox.FormattingEnabled = true; this.networkComboBox.IncludeOnlyEnabledNetworksInComboBox = false; diff --git a/XenAdmin/Wizards/GenericPages/TvmIpPage.Designer.cs b/XenAdmin/Wizards/GenericPages/TvmIpPage.Designer.cs index b2116fd81..e74f51336 100644 --- a/XenAdmin/Wizards/GenericPages/TvmIpPage.Designer.cs +++ b/XenAdmin/Wizards/GenericPages/TvmIpPage.Designer.cs @@ -132,7 +132,6 @@ // // m_comboBoxNetwork // - this.m_comboBoxNetwork.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; resources.ApplyResources(this.m_comboBoxNetwork, "m_comboBoxNetwork"); this.m_comboBoxNetwork.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.m_comboBoxNetwork.FormattingEnabled = true; diff --git a/XenAdmin/XenAdmin.csproj b/XenAdmin/XenAdmin.csproj index e00ed46b1..a196803c2 100644 --- a/XenAdmin/XenAdmin.csproj +++ b/XenAdmin/XenAdmin.csproj @@ -988,9 +988,6 @@ Component - - CDChanger.cs - Component @@ -1018,9 +1015,6 @@ Component - - ISODropDownBox.cs - Component @@ -1941,10 +1935,6 @@ Designer HelpButton.cs - - Designer - ISODropDownBox.cs - HomeServerEditPage.cs Designer @@ -2206,6 +2196,9 @@ UserControl + + LongStringComboBox.cs + Component @@ -2312,9 +2305,6 @@ Component - - NetworkComboBox.cs - @@ -4165,6 +4155,15 @@ ColorsHelper.cs + + LongStringComboBox.cs + + + LongStringComboBox.cs + + + LongStringComboBox.cs + SearchTextBox.cs @@ -4267,15 +4266,6 @@ NavigationView.cs - - NetworkComboBox.cs - - - NetworkComboBox.cs - - - NetworkComboBox.cs - SummaryPanel.cs @@ -4422,12 +4412,6 @@ HelpButton.cs - - ISODropDownBox.cs - - - ISODropDownBox.cs - MultipleDvdIsoList.cs