From 4adf835864c086d11c1c590f6c04cd718775c352 Mon Sep 17 00:00:00 2001 From: Vladimir Krestov Date: Tue, 29 Oct 2019 14:12:27 +0300 Subject: [PATCH] Ported ListViewSubItemCollectionEditor --- .../src/System.Design.Forwards.cs | 1 + .../src/Resources/SR.resx | 3 + .../src/Resources/xlf/SR.cs.xlf | 7 +- .../src/Resources/xlf/SR.de.xlf | 5 + .../src/Resources/xlf/SR.es.xlf | 5 + .../src/Resources/xlf/SR.fr.xlf | 5 + .../src/Resources/xlf/SR.it.xlf | 5 + .../src/Resources/xlf/SR.ja.xlf | 5 + .../src/Resources/xlf/SR.ko.xlf | 5 + .../src/Resources/xlf/SR.pl.xlf | 5 + .../src/Resources/xlf/SR.pt-BR.xlf | 5 + .../src/Resources/xlf/SR.ru.xlf | 5 + .../src/Resources/xlf/SR.tr.xlf | 5 + .../src/Resources/xlf/SR.zh-Hans.xlf | 5 + .../src/Resources/xlf/SR.zh-Hant.xlf | 5 + .../Design/ListViewSubItemCollectionEditor.cs | 113 ++++++++++++++++++ .../tests/UnitTests/EnsureEditorsTests.cs | 2 +- 17 files changed, 184 insertions(+), 2 deletions(-) create mode 100644 src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ListViewSubItemCollectionEditor.cs diff --git a/src/System.Design/src/System.Design.Forwards.cs b/src/System.Design/src/System.Design.Forwards.cs index 0d179ec8f23..197f9c5c4e4 100644 --- a/src/System.Design/src/System.Design.Forwards.cs +++ b/src/System.Design/src/System.Design.Forwards.cs @@ -9,6 +9,7 @@ [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ImageCollectionEditor))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ImageIndexEditor))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ListControlStringCollectionEditor))] +[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ListViewSubItemCollectionEditor))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.StringArrayEditor))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.StringCollectionEditor))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.TabPageCollectionEditor))] diff --git a/src/System.Windows.Forms.Design.Editors/src/Resources/SR.resx b/src/System.Windows.Forms.Design.Editors/src/Resources/SR.resx index 321243c60fd..cb18e6b18ee 100644 --- a/src/System.Windows.Forms.Design.Editors/src/Resources/SR.resx +++ b/src/System.Windows.Forms.Design.Editors/src/Resources/SR.resx @@ -181,6 +181,9 @@ All image files + + ListViewSubItem + Metafiles diff --git a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.cs.xlf b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.cs.xlf index 7990a4d0b5d..098b82a9026 100644 --- a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.cs.xlf +++ b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.cs.xlf @@ -130,7 +130,7 @@ Top Right Top Right - + Items collection cannot be modified when the DataSource property is set. @@ -187,6 +187,11 @@ Editor kolekce Images + + ListViewSubItem + ListViewSubItem + + Press Enter to begin a new line. Press Ctrl+Enter to accept Text. diff --git a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.de.xlf b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.de.xlf index 6ea86df8133..219da1252cd 100644 --- a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.de.xlf +++ b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.de.xlf @@ -187,6 +187,11 @@ Bildsammlungs-Editor + + ListViewSubItem + ListViewSubItem + + Press Enter to begin a new line. Press Ctrl+Enter to accept Text. diff --git a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.es.xlf b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.es.xlf index 9314ce44352..3e5e3a36fa9 100644 --- a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.es.xlf +++ b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.es.xlf @@ -187,6 +187,11 @@ Editor de la colección Imágenes + + ListViewSubItem + ListViewSubItem + + Press Enter to begin a new line. Press Ctrl+Enter to accept Text. diff --git a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.fr.xlf b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.fr.xlf index 883e5bd2a65..efbcdeb4eda 100644 --- a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.fr.xlf +++ b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.fr.xlf @@ -187,6 +187,11 @@ Éditeur de collections Images + + ListViewSubItem + ListViewSubItem + + Press Enter to begin a new line. Press Ctrl+Enter to accept Text. diff --git a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.it.xlf b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.it.xlf index a08fb26fe6d..6924ead42c4 100644 --- a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.it.xlf +++ b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.it.xlf @@ -187,6 +187,11 @@ Editor della raccolta Images + + ListViewSubItem + ListViewSubItem + + Press Enter to begin a new line. Press Ctrl+Enter to accept Text. diff --git a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.ja.xlf b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.ja.xlf index eba43c504b1..c71dfe7199d 100644 --- a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.ja.xlf +++ b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.ja.xlf @@ -187,6 +187,11 @@ イメージ コレクション エディター + + ListViewSubItem + ListViewSubItem + + Press Enter to begin a new line. Press Ctrl+Enter to accept Text. diff --git a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.ko.xlf b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.ko.xlf index fcaeb30077b..79571ee1580 100644 --- a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.ko.xlf +++ b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.ko.xlf @@ -187,6 +187,11 @@ 이미지 컬렉션 편집기 + + ListViewSubItem + ListViewSubItem + + Press Enter to begin a new line. Press Ctrl+Enter to accept Text. diff --git a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.pl.xlf b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.pl.xlf index de12588e8e9..572da7304c6 100644 --- a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.pl.xlf +++ b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.pl.xlf @@ -187,6 +187,11 @@ Edytor kolekcji obrazów + + ListViewSubItem + ListViewSubItem + + Press Enter to begin a new line. Press Ctrl+Enter to accept Text. diff --git a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.pt-BR.xlf b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.pt-BR.xlf index 712ec5fcd4c..26390c4969b 100644 --- a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.pt-BR.xlf +++ b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.pt-BR.xlf @@ -187,6 +187,11 @@ Editor de Coleção de Imagens + + ListViewSubItem + ListViewSubItem + + Press Enter to begin a new line. Press Ctrl+Enter to accept Text. diff --git a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.ru.xlf b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.ru.xlf index fe8bbe04c7b..13d3c6483e2 100644 --- a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.ru.xlf +++ b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.ru.xlf @@ -187,6 +187,11 @@ Редактор коллекции изображений + + ListViewSubItem + ListViewSubItem + + Press Enter to begin a new line. Press Ctrl+Enter to accept Text. diff --git a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.tr.xlf b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.tr.xlf index f519445f98a..ba2d3643bb2 100644 --- a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.tr.xlf +++ b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.tr.xlf @@ -187,6 +187,11 @@ Görüntüler Koleksiyonu Düzenleyicisi + + ListViewSubItem + ListViewSubItem + + Press Enter to begin a new line. Press Ctrl+Enter to accept Text. diff --git a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.zh-Hans.xlf b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.zh-Hans.xlf index 5116475e313..cd4ab043647 100644 --- a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.zh-Hans.xlf +++ b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.zh-Hans.xlf @@ -187,6 +187,11 @@ 图像集合编辑器 + + ListViewSubItem + ListViewSubItem + + Press Enter to begin a new line. Press Ctrl+Enter to accept Text. diff --git a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.zh-Hant.xlf b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.zh-Hant.xlf index fc39f8f476f..ceaecdb2939 100644 --- a/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.zh-Hant.xlf +++ b/src/System.Windows.Forms.Design.Editors/src/Resources/xlf/SR.zh-Hant.xlf @@ -187,6 +187,11 @@ 影像集合編輯器 + + ListViewSubItem + ListViewSubItem + + Press Enter to begin a new line. Press Ctrl+Enter to accept Text. diff --git a/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ListViewSubItemCollectionEditor.cs b/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ListViewSubItemCollectionEditor.cs new file mode 100644 index 00000000000..d35a018cfcf --- /dev/null +++ b/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ListViewSubItemCollectionEditor.cs @@ -0,0 +1,113 @@ +// 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; +using System.ComponentModel; +using System.ComponentModel.Design; + +namespace System.Windows.Forms.Design +{ + /// + /// Provides an editor for a ListView subitems collection. + /// + internal class ListViewSubItemCollectionEditor : CollectionEditor + { + private static int _count = 0; + private ListViewItem.ListViewSubItem _firstSubItem = null; + + /// + /// Initializes a new instance of the class. + /// + public ListViewSubItemCollectionEditor(Type type) : base(type) + { } + + /// + /// Creates an instance of the specified type in the collection. + /// + protected override object CreateInstance(Type type) + { + object instance = base.CreateInstance(type); + + // slap in a default site-like name + if (instance is ListViewItem.ListViewSubItem) + { + ((ListViewItem.ListViewSubItem)instance).Name = SR.ListViewSubItemBaseName + _count++; + } + + return instance; + } + + /// + /// Retrieves the display text for the given list sub item. + /// + protected override string GetDisplayText(object value) + { + if (value == null) + { + return string.Empty; + } + + string text; + + PropertyDescriptor prop = TypeDescriptor.GetDefaultProperty(CollectionType); + + if (prop != null && prop.PropertyType == typeof(string)) + { + text = (string)prop.GetValue(value); + + if (text != null && text.Length > 0) + { + return text; + } + } + + text = TypeDescriptor.GetConverter(value).ConvertToString(value); + + if (text == null || text.Length == 0) + { + text = value.GetType().Name; + } + + return text; + } + + protected override object[] GetItems(object editValue) + { + // take the fist sub item out of the collection + ListViewItem.ListViewSubItemCollection subItemsColl = (ListViewItem.ListViewSubItemCollection)editValue; + + // add all the other sub items + object[] values = new object[subItemsColl.Count]; + ((ICollection)subItemsColl).CopyTo(values, 0); + + if (values.Length > 0) + { + // save the first sub item + _firstSubItem = subItemsColl[0]; + + // now return the rest. + object[] subValues = new object[values.Length - 1]; + Array.Copy(values, 1, subValues, 0, subValues.Length); + values = subValues; + } + + return values; + } + + protected override object SetItems(object editValue, object[] value) + { + IList list = editValue as IList; + list.Clear(); + + list.Add(_firstSubItem); + + for (int i = 0; i < value.Length; i++) + { + list.Add(value[i]); + } + + return editValue; + } + } +} diff --git a/src/System.Windows.Forms.Design.Editors/tests/UnitTests/EnsureEditorsTests.cs b/src/System.Windows.Forms.Design.Editors/tests/UnitTests/EnsureEditorsTests.cs index b52a672590b..480fb206669 100644 --- a/src/System.Windows.Forms.Design.Editors/tests/UnitTests/EnsureEditorsTests.cs +++ b/src/System.Windows.Forms.Design.Editors/tests/UnitTests/EnsureEditorsTests.cs @@ -94,7 +94,7 @@ public void EnsureUITypeEditorForType(Type type, Type expectedEditorType) [InlineData(typeof(ListViewItem), "ImageIndex", typeof(ImageIndexEditor))] [InlineData(typeof(ListViewItem), "ImageKey", typeof(ImageIndexEditor))] [InlineData(typeof(ListViewItem), "StateImageIndex", typeof(ImageIndexEditor))] - //[InlineData(typeof(ListViewItem), "SubItems", typeof(ListViewSubItemCollectionEditor))] + [InlineData(typeof(ListViewItem), "SubItems", typeof(ListViewSubItemCollectionEditor))] //[InlineData(typeof(MaskedTextBox), "Mask", typeof(MaskPropertyEditor))] //[InlineData(typeof(MaskedTextBox), "Text", typeof(MaskedTextBoxTextEditor))] [InlineData(typeof(NotifyIcon), "BalloonTipText", typeof(MultilineStringEditor))]