From 5eca7ef62a296285e59abb48f5c7210e204faad3 Mon Sep 17 00:00:00 2001 From: Judit Varsanyi Rozsa Date: Mon, 11 Nov 2019 13:54:26 -0800 Subject: [PATCH 1/4] Added ColumnHeaderCollectionEditor --- .../Design/ColumnHeaderCollectionEditor.cs | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ColumnHeaderCollectionEditor.cs diff --git a/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ColumnHeaderCollectionEditor.cs b/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ColumnHeaderCollectionEditor.cs new file mode 100644 index 00000000000..d08b4bab8b1 --- /dev/null +++ b/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ColumnHeaderCollectionEditor.cs @@ -0,0 +1,90 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; + +namespace System.Windows.Forms.Design.Editors +{ + internal class ColumnHeaderCollectionEditor : CollectionEditor + { + /// + /// Initializes a new instance of the class. + /// + + //Called through reflection + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public ColumnHeaderCollectionEditor(Type type) : base(type) + { + } + + + /// + /// Gets the help topic to display for the dialog help button or pressing F1. Override to display a different help topic. + /// + protected override string HelpTopic + { + get + { + return "net.ComponentModel.ColumnHeaderCollectionEditor"; + } + } + + /// + /// Sets the specified collection to have the specified array of items. + /// + protected override object SetItems(object editValue, object[] value) + { + + if (editValue != null) + { + // We look to see if the value implements IList, and if it does, we set through that. + Debug.Assert(editValue is System.Collections.IList, "editValue is not an IList"); + ListView.ColumnHeaderCollection list = editValue as ListView.ColumnHeaderCollection; + if (editValue != null) + { + list.Clear(); + ColumnHeader[] colHeaders = new ColumnHeader[value.Length]; + Array.Copy(value, 0, colHeaders, 0, value.Length); + list.AddRange(colHeaders); + } + } + + return editValue; + } + + /// + /// + /// Removes the item from listview column header collection + /// + /// + internal override void OnItemRemoving(object item) + { + if (!(Context.Instance is ListView listview)) + { + return; + } + + if (item is ColumnHeader column) + { + + IComponentChangeService cs = GetService(typeof(IComponentChangeService)) as IComponentChangeService; + PropertyDescriptor itemsProp = null; + if (cs != null) + { + itemsProp = TypeDescriptor.GetProperties(Context.Instance)["Columns"]; + cs.OnComponentChanging(Context.Instance, itemsProp); + } + listview.Columns.Remove(column); + + if (cs != null && itemsProp != null) + { + cs.OnComponentChanged(Context.Instance, itemsProp, null, null); + } + } + } + } +} From 9d7e0f1624ce675fb2d6d093631829cc57036e36 Mon Sep 17 00:00:00 2001 From: Judit Varsanyi Rozsa Date: Tue, 12 Nov 2019 11:33:04 -0800 Subject: [PATCH 2/4] cleanup --- .../Design/ColumnHeaderCollectionEditor.cs | 47 ++++++------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ColumnHeaderCollectionEditor.cs b/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ColumnHeaderCollectionEditor.cs index d08b4bab8b1..e047769ac70 100644 --- a/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ColumnHeaderCollectionEditor.cs +++ b/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ColumnHeaderCollectionEditor.cs @@ -5,62 +5,44 @@ using System.ComponentModel; using System.ComponentModel.Design; using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; namespace System.Windows.Forms.Design.Editors { internal class ColumnHeaderCollectionEditor : CollectionEditor { - /// + /// /// Initializes a new instance of the class. - /// - - //Called through reflection - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + /// public ColumnHeaderCollectionEditor(Type type) : base(type) { } - - /// + /// /// Gets the help topic to display for the dialog help button or pressing F1. Override to display a different help topic. - /// + /// protected override string HelpTopic { - get - { - return "net.ComponentModel.ColumnHeaderCollectionEditor"; - } + get => "net.ComponentModel.ColumnHeaderCollectionEditor"; } - /// + /// /// Sets the specified collection to have the specified array of items. - /// + /// protected override object SetItems(object editValue, object[] value) { - - if (editValue != null) + if (editValue is ListView.ColumnHeaderCollection list) { - // We look to see if the value implements IList, and if it does, we set through that. - Debug.Assert(editValue is System.Collections.IList, "editValue is not an IList"); - ListView.ColumnHeaderCollection list = editValue as ListView.ColumnHeaderCollection; - if (editValue != null) - { - list.Clear(); - ColumnHeader[] colHeaders = new ColumnHeader[value.Length]; - Array.Copy(value, 0, colHeaders, 0, value.Length); - list.AddRange(colHeaders); - } + list.Clear(); + ColumnHeader[] colHeaders = new ColumnHeader[value.Length]; + Array.Copy(value, 0, colHeaders, 0, value.Length); + list.AddRange(colHeaders); } - return editValue; } - /// - /// + /// /// Removes the item from listview column header collection - /// - /// + /// internal override void OnItemRemoving(object item) { if (!(Context.Instance is ListView listview)) @@ -70,7 +52,6 @@ internal override void OnItemRemoving(object item) if (item is ColumnHeader column) { - IComponentChangeService cs = GetService(typeof(IComponentChangeService)) as IComponentChangeService; PropertyDescriptor itemsProp = null; if (cs != null) From 495e675d841c88faaea3d275454ae05d9cb2872c Mon Sep 17 00:00:00 2001 From: Judit Varsanyi Rozsa Date: Wed, 13 Nov 2019 16:47:28 -0800 Subject: [PATCH 3/4] added unit test for column header collection editor --- .../Design/ColumnHeaderCollectionEditor.cs | 7 ++-- .../ColumnHeaderCollectionEditorTests .cs | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 src/System.Windows.Forms.Design.Editors/tests/UnitTests/System/Windows/Forms/Design/ColumnHeaderCollectionEditorTests .cs diff --git a/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ColumnHeaderCollectionEditor.cs b/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ColumnHeaderCollectionEditor.cs index e047769ac70..ca680e9d9be 100644 --- a/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ColumnHeaderCollectionEditor.cs +++ b/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ColumnHeaderCollectionEditor.cs @@ -4,7 +4,6 @@ using System.ComponentModel; using System.ComponentModel.Design; -using System.Diagnostics; namespace System.Windows.Forms.Design.Editors { @@ -18,7 +17,7 @@ public ColumnHeaderCollectionEditor(Type type) : base(type) } /// - /// Gets the help topic to display for the dialog help button or pressing F1. Override to display a different help topic. + /// Gets the help topic to display for the dialog help button or pressing F1. Override to display a different help topic. /// protected override string HelpTopic { @@ -26,7 +25,7 @@ protected override string HelpTopic } /// - /// Sets the specified collection to have the specified array of items. + /// Sets the specified collection to have the specified array of items. /// protected override object SetItems(object editValue, object[] value) { @@ -41,7 +40,7 @@ protected override object SetItems(object editValue, object[] value) } /// - /// Removes the item from listview column header collection + /// Removes the item from listview column header collection /// internal override void OnItemRemoving(object item) { diff --git a/src/System.Windows.Forms.Design.Editors/tests/UnitTests/System/Windows/Forms/Design/ColumnHeaderCollectionEditorTests .cs b/src/System.Windows.Forms.Design.Editors/tests/UnitTests/System/Windows/Forms/Design/ColumnHeaderCollectionEditorTests .cs new file mode 100644 index 00000000000..df2b50fb851 --- /dev/null +++ b/src/System.Windows.Forms.Design.Editors/tests/UnitTests/System/Windows/Forms/Design/ColumnHeaderCollectionEditorTests .cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing.Design; +using System.Windows.Forms.Design.Editors; +using Moq; +using WinForms.Common.Tests; +using Xunit; + +namespace System.Windows.Forms.Design.Tests +{ + public class ColumnHeaderCollectionEditorTests + { + [Fact] + public void ColumnHeaderCollectionEditor_Ctor_Default() + { + var editor = new ColumnHeaderCollectionEditor(typeof(string)); + Assert.False(editor.IsDropDownResizable); + } + + [Fact] + public void ColumnHeaderCollectionEditor_EditValue_ReturnsValue() + { + var editor = new ColumnHeaderCollectionEditor(typeof(string)); + string[] value = new string[] { "asdf", "qwer", "zxcv" }; + + Assert.Same(value, editor.EditValue(null, value)); + } + } +} From e89d9d01646386640f68d7cefcc46f44efa90b3a Mon Sep 17 00:00:00 2001 From: Judit Varsanyi Rozsa Date: Thu, 14 Nov 2019 11:30:24 -0800 Subject: [PATCH 4/4] add type forwarding --- src/System.Design/src/System.Design.Forwards.cs | 2 +- .../Windows/Forms/Design/ColumnHeaderCollectionEditor.cs | 2 +- .../Forms/Design/ColumnHeaderCollectionEditorTests .cs | 6 ------ 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/System.Design/src/System.Design.Forwards.cs b/src/System.Design/src/System.Design.Forwards.cs index 22e156a61d3..521fa88fbce 100644 --- a/src/System.Design/src/System.Design.Forwards.cs +++ b/src/System.Design/src/System.Design.Forwards.cs @@ -3,7 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; - +[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ColumnHeaderCollectionEditor))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.DataMemberFieldConverter))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.FormatStringEditor))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.HelpNamespaceEditor))] diff --git a/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ColumnHeaderCollectionEditor.cs b/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ColumnHeaderCollectionEditor.cs index ca680e9d9be..5191637013e 100644 --- a/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ColumnHeaderCollectionEditor.cs +++ b/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ColumnHeaderCollectionEditor.cs @@ -5,7 +5,7 @@ using System.ComponentModel; using System.ComponentModel.Design; -namespace System.Windows.Forms.Design.Editors +namespace System.Windows.Forms.Design { internal class ColumnHeaderCollectionEditor : CollectionEditor { diff --git a/src/System.Windows.Forms.Design.Editors/tests/UnitTests/System/Windows/Forms/Design/ColumnHeaderCollectionEditorTests .cs b/src/System.Windows.Forms.Design.Editors/tests/UnitTests/System/Windows/Forms/Design/ColumnHeaderCollectionEditorTests .cs index df2b50fb851..aa7e3eebd37 100644 --- a/src/System.Windows.Forms.Design.Editors/tests/UnitTests/System/Windows/Forms/Design/ColumnHeaderCollectionEditorTests .cs +++ b/src/System.Windows.Forms.Design.Editors/tests/UnitTests/System/Windows/Forms/Design/ColumnHeaderCollectionEditorTests .cs @@ -2,12 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Collections.Generic; -using System.ComponentModel; -using System.Drawing.Design; -using System.Windows.Forms.Design.Editors; -using Moq; -using WinForms.Common.Tests; using Xunit; namespace System.Windows.Forms.Design.Tests