From ba790680cc9dfdceb1ecce6e90f3391ea6ce6244 Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Fri, 5 Jul 2019 14:21:49 +1000 Subject: [PATCH 1/4] Port IntegerCollectionEditor from NET Fx Closes #1274 --- .../src/Resources/SR.resx | 17 +- .../src/Resources/xlf/SR.cs.xlf | 25 ++ .../src/Resources/xlf/SR.de.xlf | 25 ++ .../src/Resources/xlf/SR.es.xlf | 25 ++ .../src/Resources/xlf/SR.fr.xlf | 25 ++ .../src/Resources/xlf/SR.it.xlf | 25 ++ .../src/Resources/xlf/SR.ja.xlf | 25 ++ .../src/Resources/xlf/SR.ko.xlf | 25 ++ .../src/Resources/xlf/SR.pl.xlf | 25 ++ .../src/Resources/xlf/SR.pt-BR.xlf | 25 ++ .../src/Resources/xlf/SR.ru.xlf | 25 ++ .../src/Resources/xlf/SR.tr.xlf | 25 ++ .../src/Resources/xlf/SR.zh-Hans.xlf | 25 ++ .../src/Resources/xlf/SR.zh-Hant.xlf | 25 ++ .../Forms/Design/IntegerCollectionEditor.cs | 292 ++++++++++++++++++ 15 files changed, 633 insertions(+), 1 deletion(-) create mode 100644 src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/IntegerCollectionEditor.cs diff --git a/src/System.Windows.Forms.Design/src/Resources/SR.resx b/src/System.Windows.Forms.Design/src/Resources/SR.resx index 7593eb44755..f17e17ad53a 100644 --- a/src/System.Windows.Forms.Design/src/Resources/SR.resx +++ b/src/System.Windows.Forms.Design/src/Resources/SR.resx @@ -747,4 +747,19 @@ '{0}' - + + Cancel + + + &Help + + + Enter the integers in the array (one per line): + + + &OK + + + Integer Collection Editor + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.cs.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.cs.xlf index 368bef2d700..1b9abdd682b 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.cs.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.cs.xlf @@ -503,6 +503,31 @@ Jen pro čtení + + Cancel + Cancel + + + + &Help + &Help + + + + Enter the integers in the array (one per line): + Enter the integers in the array (one per line): + + + + &OK + &OK + + + + Integer Collection Editor + Integer Collection Editor + + '{1}' is not a valid value for '{0}'. Hodnota {1} není platnou hodnotou pro argument {0}. diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.de.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.de.xlf index 4d1a1a12d80..7a8367964cd 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.de.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.de.xlf @@ -503,6 +503,31 @@ Schreibgeschützt + + Cancel + Cancel + + + + &Help + &Help + + + + Enter the integers in the array (one per line): + Enter the integers in the array (one per line): + + + + &OK + &OK + + + + Integer Collection Editor + Integer Collection Editor + + '{1}' is not a valid value for '{0}'. {1} ist kein gültiger Wert für {0}. diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.es.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.es.xlf index f9a40861830..fff439e90a7 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.es.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.es.xlf @@ -503,6 +503,31 @@ Solo lectura + + Cancel + Cancel + + + + &Help + &Help + + + + Enter the integers in the array (one per line): + Enter the integers in the array (one per line): + + + + &OK + &OK + + + + Integer Collection Editor + Integer Collection Editor + + '{1}' is not a valid value for '{0}'. '{1}' no es un valor válido para '{0}'. diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.fr.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.fr.xlf index bf5eafb0e07..81dfe9305d8 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.fr.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.fr.xlf @@ -503,6 +503,31 @@ En lecture seule + + Cancel + Cancel + + + + &Help + &Help + + + + Enter the integers in the array (one per line): + Enter the integers in the array (one per line): + + + + &OK + &OK + + + + Integer Collection Editor + Integer Collection Editor + + '{1}' is not a valid value for '{0}'. '{1}' n'est pas une valeur valide pour '{0}'. diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.it.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.it.xlf index 9061ed5f4e8..aed855c7fe5 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.it.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.it.xlf @@ -503,6 +503,31 @@ Sola lettura + + Cancel + Cancel + + + + &Help + &Help + + + + Enter the integers in the array (one per line): + Enter the integers in the array (one per line): + + + + &OK + &OK + + + + Integer Collection Editor + Integer Collection Editor + + '{1}' is not a valid value for '{0}'. '{1}' non è un valore valido per '{0}'. diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ja.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ja.xlf index f592a641d53..66e42039893 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ja.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ja.xlf @@ -503,6 +503,31 @@ 読み取り専用 + + Cancel + Cancel + + + + &Help + &Help + + + + Enter the integers in the array (one per line): + Enter the integers in the array (one per line): + + + + &OK + &OK + + + + Integer Collection Editor + Integer Collection Editor + + '{1}' is not a valid value for '{0}'. '{1}' は '{0}' に有効な値ではありません。 diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ko.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ko.xlf index dd9c610952b..869c2d8f1d3 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ko.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ko.xlf @@ -503,6 +503,31 @@ 읽기 전용 + + Cancel + Cancel + + + + &Help + &Help + + + + Enter the integers in the array (one per line): + Enter the integers in the array (one per line): + + + + &OK + &OK + + + + Integer Collection Editor + Integer Collection Editor + + '{1}' is not a valid value for '{0}'. '{1}'은(는) '{0}'에 사용할 수 없는 값입니다. diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pl.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pl.xlf index 8aca0938a44..6cf53c46008 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pl.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pl.xlf @@ -503,6 +503,31 @@ Tylko do odczytu + + Cancel + Cancel + + + + &Help + &Help + + + + Enter the integers in the array (one per line): + Enter the integers in the array (one per line): + + + + &OK + &OK + + + + Integer Collection Editor + Integer Collection Editor + + '{1}' is not a valid value for '{0}'. „{1}” nie jest prawidłową wartością elementu „{0}”. diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pt-BR.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pt-BR.xlf index bf82ee5d991..760a7c38507 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pt-BR.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pt-BR.xlf @@ -503,6 +503,31 @@ Somente Leitura + + Cancel + Cancel + + + + &Help + &Help + + + + Enter the integers in the array (one per line): + Enter the integers in the array (one per line): + + + + &OK + &OK + + + + Integer Collection Editor + Integer Collection Editor + + '{1}' is not a valid value for '{0}'. '{1}' não é um valor válido para '{0}'. diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ru.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ru.xlf index 8ed37b32ce6..b4587b03a1e 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ru.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ru.xlf @@ -503,6 +503,31 @@ Только для чтения + + Cancel + Cancel + + + + &Help + &Help + + + + Enter the integers in the array (one per line): + Enter the integers in the array (one per line): + + + + &OK + &OK + + + + Integer Collection Editor + Integer Collection Editor + + '{1}' is not a valid value for '{0}'. '{1}' не является допустимым значением для '{0}'. diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.tr.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.tr.xlf index 9514c98b05d..f5690ed004a 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.tr.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.tr.xlf @@ -503,6 +503,31 @@ Salt Okunur + + Cancel + Cancel + + + + &Help + &Help + + + + Enter the integers in the array (one per line): + Enter the integers in the array (one per line): + + + + &OK + &OK + + + + Integer Collection Editor + Integer Collection Editor + + '{1}' is not a valid value for '{0}'. '{1}' değeri '{0}' öğesi için geçerli değil. diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hans.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hans.xlf index 221986e06e5..dff0b3afc62 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hans.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hans.xlf @@ -503,6 +503,31 @@ 只读 + + Cancel + Cancel + + + + &Help + &Help + + + + Enter the integers in the array (one per line): + Enter the integers in the array (one per line): + + + + &OK + &OK + + + + Integer Collection Editor + Integer Collection Editor + + '{1}' is not a valid value for '{0}'. “{1}”不是“{0}”的有效值。 diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hant.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hant.xlf index 201b5d5c268..3b22934b1ad 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hant.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hant.xlf @@ -503,6 +503,31 @@ 唯讀 + + Cancel + Cancel + + + + &Help + &Help + + + + Enter the integers in the array (one per line): + Enter the integers in the array (one per line): + + + + &OK + &OK + + + + Integer Collection Editor + Integer Collection Editor + + '{1}' is not a valid value for '{0}'. '{1}' 不是 '{0}' 的有效值。 diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/IntegerCollectionEditor.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/IntegerCollectionEditor.cs new file mode 100644 index 00000000000..f67e6975a32 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/IntegerCollectionEditor.cs @@ -0,0 +1,292 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +//------------------------------------------------------------------------------ + +#define NEEDHELPBUTTON + +/* + */ +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "System.Windows.Forms.Design.IntegerCollectionEditor..ctor(System.Type)")] + +namespace System.Windows.Forms.Design +{ + using System; + using System.ComponentModel.Design; + using System.Diagnostics.CodeAnalysis; + using System.Drawing; + using System.Globalization; + using System.Windows.Forms; + + /// + /// + /// The IntegerCollectionEditor is a collection editor that is specifically + /// designed to edit collections containing Integers. + /// + internal class IntegerCollectionEditor : CollectionEditor + { + + public IntegerCollectionEditor(Type type) : base(type) + { + } + + /// + /// + /// Creates a new form to show the current collection. You may inherit + /// from CollectionForm to provide your own form. + /// + protected override CollectionForm CreateCollectionForm() + { + return new IntegerCollectionForm(this); + } + + /// + /// + /// 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.IntegerCollectionEditor"; + } + } + + /// + /// + /// IntegerCollectionEditor allows visible editing of a integer array. Each line in + /// the edit box is an array entry. + /// + private class IntegerCollectionForm : CollectionForm + { + + private Label instruction = new Label(); + private TextBox textEntry = new TextBox(); + private Button okButton = new Button(); + private Button cancelButton = new Button(); +#if NEEDHELPBUTTON + private Button helpButton = new Button(); +#endif + + private IntegerCollectionEditor editor = null; + + /// + /// + /// Constructs a StringCollectionForm. + /// + public IntegerCollectionForm(CollectionEditor editor) : base(editor) + { + this.editor = (IntegerCollectionEditor)editor; + InitializeComponent(); + } + + private void Edit1_keyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Escape) + { + cancelButton.PerformClick(); + e.Handled = true; + } + } + + private void HelpButton_click(object sender, EventArgs e) + { + editor.ShowHelp(); + } + + private void Form_HelpRequested(object sender, HelpEventArgs e) + { + editor.ShowHelp(); + } + + /// + /// + /// NOTE: The following code is required by the form + /// designer. It can be modified using the form editor. Do not + /// modify it using the code editor. + /// + [SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters")] + private void InitializeComponent() + { + instruction.Location = new Point(4, 7); + instruction.Size = new Size(422, 14); + instruction.TabIndex = 0; + instruction.TabStop = false; + instruction.Text = SR.IntegerCollectionEditorInstruction; + + textEntry.Location = new Point(4, 22); + textEntry.Size = new Size(422, 244); + textEntry.TabIndex = 0; + textEntry.Text = ""; + textEntry.AcceptsTab = false; + textEntry.AcceptsReturn = true; + textEntry.AutoSize = false; + textEntry.Multiline = true; + textEntry.ScrollBars = ScrollBars.Both; + textEntry.WordWrap = false; + textEntry.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right; + textEntry.KeyDown += new KeyEventHandler(this.Edit1_keyDown); + +#if NEEDHELPBUTTON + okButton.Location = new Point(185, 274); +#else + okButton.Location = new Point(264, 274); +#endif + okButton.Size = new Size(75, 23); + okButton.TabIndex = 1; + okButton.Text = SR.IntegerCollectionEditorOKCaption; + okButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + okButton.DialogResult = DialogResult.OK; + okButton.Click += new EventHandler(this.OKButton_click); + +#if NEEDHELPBUTTON + cancelButton.Location = new Point(264, 274); +#else + cancelButton.Location = new Point(343, 274); +#endif + cancelButton.Size = new Size(75, 23); + cancelButton.TabIndex = 2; + cancelButton.Text = SR.IntegerCollectionEditorCancelCaption; + cancelButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + cancelButton.DialogResult = DialogResult.Cancel; + +#if NEEDHELPBUTTON + helpButton.Location = new Point(343, 274); + helpButton.Size = new Size(75, 23); + helpButton.TabIndex = 3; + helpButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + helpButton.Text = SR.IntegerCollectionEditorHelpCaption; +#endif + + this.Location = new Point(7, 7); + this.Text = SR.IntegerCollectionEditorTitle; + this.AcceptButton = okButton; + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoScaleDimensions = new SizeF(6, 13); + this.CancelButton = cancelButton; + this.ClientSize = new Size(429, 307); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.ControlBox = false; + this.ShowInTaskbar = false; + // VSWhidbey 94233: Force the dialog to open using FormStartPosition.CenterScreen. + this.StartPosition = FormStartPosition.CenterScreen; + this.MinimumSize = new Size(300, 200); + + helpButton.Click += new EventHandler(this.HelpButton_click); + this.HelpRequested += new HelpEventHandler(this.Form_HelpRequested); + + this.Controls.Clear(); + this.Controls.AddRange(new Control[] { + instruction, + textEntry, + okButton, + cancelButton, + #if NEEDHELPBUTTON + helpButton + #endif + }); + } + + /// + /// + /// Commits the changes to the editor. + /// + private void OKButton_click(object sender, EventArgs e) + { + char[] delims = new char[] { '\n' }; + char[] trims = new char[] { '\r' }; + + string[] strings = textEntry.Text.Split(delims); + object[] curItems = Items; + + int nItems = strings.Length; + // If the final line is blank, we don't want to create an item from it + // + if (strings.Length > 0 && strings[strings.Length - 1].Length == 0) + { + nItems--; + } + int[] currentValues = new int[nItems]; + + for (int i = 0; i < nItems; i++) + { + strings[i] = strings[i].Trim(trims); + try + { + currentValues[i] = Int32.Parse(strings[i], CultureInfo.CurrentCulture); + } + catch (Exception ex) + { + DisplayError(ex); + if (ClientUtils.IsCriticalException(ex)) + { + throw; + } + } + + } + + bool dirty = true; + + if (nItems == curItems.Length) + { + int i; + for (i = 0; i < nItems; ++i) + { + if (!currentValues[i].Equals((int)curItems[i])) + { + break; + } + } + + if (i == nItems) + dirty = false; + } + + if (!dirty) + { + DialogResult = DialogResult.Cancel; + return; + } + + object[] values = new object[nItems]; + for (int i = 0; i < nItems; i++) + { + values[i] = currentValues[i]; + } + + Items = values; + } + + // + // This is called when the value property in the CollectionForm has changed. + // In it you should update your user interface to reflect the current value. + // + // + protected override void OnEditValueChanged() + { + object[] items = Items; + string text = string.Empty; + + for (int i = 0; i < items.Length; i++) + { + if (items[i] is int) + { + text += ((Int32)items[i]).ToString(CultureInfo.CurrentCulture); + if (i != items.Length - 1) + { + text += "\r\n"; + } + } + } + + textEntry.Text = text; + } + } + } +} + + From 437d823241037c99856d6566dbd0252cb1465ee1 Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Fri, 5 Jul 2019 15:11:14 +1000 Subject: [PATCH 2/4] chore: General cleanup - Fix xml-docs - Fix names - Remove unused usings - Remove `this.` - Add missing braces - Use arrow functions, where appropriate --- .../Forms/Design/IntegerCollectionEditor.cs | 275 ++++++++---------- 1 file changed, 123 insertions(+), 152 deletions(-) diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/IntegerCollectionEditor.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/IntegerCollectionEditor.cs index f67e6975a32..8de03aba2a5 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/IntegerCollectionEditor.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/IntegerCollectionEditor.cs @@ -1,205 +1,174 @@ -//------------------------------------------------------------------------------ -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// -//------------------------------------------------------------------------------ +// 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. -#define NEEDHELPBUTTON +#define NEEDHELPBUTTON -/* - */ -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "System.Windows.Forms.Design.IntegerCollectionEditor..ctor(System.Type)")] +using System.ComponentModel.Design; +using System.Drawing; +using System.Globalization; namespace System.Windows.Forms.Design { - using System; - using System.ComponentModel.Design; - using System.Diagnostics.CodeAnalysis; - using System.Drawing; - using System.Globalization; - using System.Windows.Forms; - - /// - /// - /// The IntegerCollectionEditor is a collection editor that is specifically - /// designed to edit collections containing Integers. - /// + /// + /// The is a collection editor that is specifically + /// designed to edit collections containing Integers. + /// internal class IntegerCollectionEditor : CollectionEditor { - - public IntegerCollectionEditor(Type type) : base(type) - { - } - - /// - /// - /// Creates a new form to show the current collection. You may inherit - /// from CollectionForm to provide your own form. - /// - protected override CollectionForm CreateCollectionForm() - { - return new IntegerCollectionForm(this); - } - - /// - /// - /// 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 + public IntegerCollectionEditor(Type type) + : base(type) { - get - { - return "net.ComponentModel.IntegerCollectionEditor"; - } } - /// - /// - /// IntegerCollectionEditor allows visible editing of a integer array. Each line in - /// the edit box is an array entry. - /// + /// + /// Creates a new form to show the current collection. + /// You may inherit from CollectionForm to provide your own form. + /// + protected override CollectionForm CreateCollectionForm() => new IntegerCollectionForm(this); + + /// + ///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 => "net.ComponentModel.IntegerCollectionEditor"; + + /// + /// IntegerCollectionEditor allows visible editing of a integer array. + /// Each line in the edit box is an array entry. + /// private class IntegerCollectionForm : CollectionForm { - - private Label instruction = new Label(); - private TextBox textEntry = new TextBox(); - private Button okButton = new Button(); - private Button cancelButton = new Button(); + private readonly IntegerCollectionEditor _editor; + private readonly Label _instruction = new Label(); + private readonly TextBox _textEntry = new TextBox(); + private readonly Button _okButton = new Button(); + private readonly Button _cancelButton = new Button(); #if NEEDHELPBUTTON - private Button helpButton = new Button(); + private readonly Button _helpButton = new Button(); #endif - private IntegerCollectionEditor editor = null; - - /// - /// - /// Constructs a StringCollectionForm. - /// - public IntegerCollectionForm(CollectionEditor editor) : base(editor) + /// + /// Constructs a StringCollectionForm. + /// + public IntegerCollectionForm(CollectionEditor editor) + : base(editor) { - this.editor = (IntegerCollectionEditor)editor; + _editor = (IntegerCollectionEditor)editor; InitializeComponent(); } private void Edit1_keyDown(object sender, KeyEventArgs e) { - if (e.KeyCode == Keys.Escape) + if (e.KeyCode != Keys.Escape) { - cancelButton.PerformClick(); - e.Handled = true; + return; } - } - private void HelpButton_click(object sender, EventArgs e) - { - editor.ShowHelp(); + _cancelButton.PerformClick(); + e.Handled = true; } - private void Form_HelpRequested(object sender, HelpEventArgs e) - { - editor.ShowHelp(); - } + private void HelpButton_click(object sender, EventArgs e) => _editor.ShowHelp(); + + private void Form_HelpRequested(object sender, HelpEventArgs e) => _editor.ShowHelp(); - /// - /// - /// NOTE: The following code is required by the form - /// designer. It can be modified using the form editor. Do not - /// modify it using the code editor. - /// - [SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters")] + /// + /// NOTE: The following code is required by the form designer. It can be modified using the form editor. + /// Do not modify it using the code editor. + /// private void InitializeComponent() { - instruction.Location = new Point(4, 7); - instruction.Size = new Size(422, 14); - instruction.TabIndex = 0; - instruction.TabStop = false; - instruction.Text = SR.IntegerCollectionEditorInstruction; - - textEntry.Location = new Point(4, 22); - textEntry.Size = new Size(422, 244); - textEntry.TabIndex = 0; - textEntry.Text = ""; - textEntry.AcceptsTab = false; - textEntry.AcceptsReturn = true; - textEntry.AutoSize = false; - textEntry.Multiline = true; - textEntry.ScrollBars = ScrollBars.Both; - textEntry.WordWrap = false; - textEntry.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right; - textEntry.KeyDown += new KeyEventHandler(this.Edit1_keyDown); + _instruction.Location = new Point(4, 7); + _instruction.Size = new Size(422, 14); + _instruction.TabIndex = 0; + _instruction.TabStop = false; + _instruction.Text = SR.IntegerCollectionEditorInstruction; + + _textEntry.Location = new Point(4, 22); + _textEntry.Size = new Size(422, 244); + _textEntry.TabIndex = 0; + _textEntry.Text = ""; + _textEntry.AcceptsTab = false; + _textEntry.AcceptsReturn = true; + _textEntry.AutoSize = false; + _textEntry.Multiline = true; + _textEntry.ScrollBars = ScrollBars.Both; + _textEntry.WordWrap = false; + _textEntry.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right; + _textEntry.KeyDown += new KeyEventHandler(Edit1_keyDown); #if NEEDHELPBUTTON - okButton.Location = new Point(185, 274); + _okButton.Location = new Point(185, 274); #else - okButton.Location = new Point(264, 274); + _okButton.Location = new Point(264, 274); #endif - okButton.Size = new Size(75, 23); - okButton.TabIndex = 1; - okButton.Text = SR.IntegerCollectionEditorOKCaption; - okButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - okButton.DialogResult = DialogResult.OK; - okButton.Click += new EventHandler(this.OKButton_click); + _okButton.Size = new Size(75, 23); + _okButton.TabIndex = 1; + _okButton.Text = SR.IntegerCollectionEditorOKCaption; + _okButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + _okButton.DialogResult = DialogResult.OK; + _okButton.Click += new EventHandler(OKButton_click); #if NEEDHELPBUTTON - cancelButton.Location = new Point(264, 274); + _cancelButton.Location = new Point(264, 274); #else - cancelButton.Location = new Point(343, 274); + _cancelButton.Location = new Point(343, 274); #endif - cancelButton.Size = new Size(75, 23); - cancelButton.TabIndex = 2; - cancelButton.Text = SR.IntegerCollectionEditorCancelCaption; - cancelButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - cancelButton.DialogResult = DialogResult.Cancel; + _cancelButton.Size = new Size(75, 23); + _cancelButton.TabIndex = 2; + _cancelButton.Text = SR.IntegerCollectionEditorCancelCaption; + _cancelButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + _cancelButton.DialogResult = DialogResult.Cancel; #if NEEDHELPBUTTON - helpButton.Location = new Point(343, 274); - helpButton.Size = new Size(75, 23); - helpButton.TabIndex = 3; - helpButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - helpButton.Text = SR.IntegerCollectionEditorHelpCaption; + _helpButton.Location = new Point(343, 274); + _helpButton.Size = new Size(75, 23); + _helpButton.TabIndex = 3; + _helpButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + _helpButton.Text = SR.IntegerCollectionEditorHelpCaption; + + _helpButton.Click += new EventHandler(HelpButton_click); + HelpRequested += new HelpEventHandler(Form_HelpRequested); #endif - this.Location = new Point(7, 7); - this.Text = SR.IntegerCollectionEditorTitle; - this.AcceptButton = okButton; - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.AutoScaleDimensions = new SizeF(6, 13); - this.CancelButton = cancelButton; - this.ClientSize = new Size(429, 307); - this.MaximizeBox = false; - this.MinimizeBox = false; - this.ControlBox = false; - this.ShowInTaskbar = false; + Location = new Point(7, 7); + Text = SR.IntegerCollectionEditorTitle; + AcceptButton = _okButton; + AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + AutoScaleDimensions = new SizeF(6, 13); + CancelButton = _cancelButton; + ClientSize = new Size(429, 307); + MaximizeBox = false; + MinimizeBox = false; + ControlBox = false; + ShowInTaskbar = false; // VSWhidbey 94233: Force the dialog to open using FormStartPosition.CenterScreen. - this.StartPosition = FormStartPosition.CenterScreen; - this.MinimumSize = new Size(300, 200); - - helpButton.Click += new EventHandler(this.HelpButton_click); - this.HelpRequested += new HelpEventHandler(this.Form_HelpRequested); - - this.Controls.Clear(); - this.Controls.AddRange(new Control[] { - instruction, - textEntry, - okButton, - cancelButton, + StartPosition = FormStartPosition.CenterScreen; + MinimumSize = new Size(300, 200); + + Controls.Clear(); + Controls.AddRange(new Control[] { + _instruction, + _textEntry, + _okButton, + _cancelButton, #if NEEDHELPBUTTON - helpButton + _helpButton #endif }); } /// - /// - /// Commits the changes to the editor. - /// + /// + /// Commits the changes to the editor. + /// private void OKButton_click(object sender, EventArgs e) { char[] delims = new char[] { '\n' }; char[] trims = new char[] { '\r' }; - string[] strings = textEntry.Text.Split(delims); + string[] strings = _textEntry.Text.Split(delims); object[] curItems = Items; int nItems = strings.Length; @@ -243,7 +212,9 @@ private void OKButton_click(object sender, EventArgs e) } if (i == nItems) + { dirty = false; + } } if (!dirty) @@ -262,8 +233,8 @@ private void OKButton_click(object sender, EventArgs e) } // - // This is called when the value property in the CollectionForm has changed. - // In it you should update your user interface to reflect the current value. + // This is called when the value property in the CollectionForm has changed. + // In it you should update your user interface to reflect the current value. // // protected override void OnEditValueChanged() @@ -283,7 +254,7 @@ protected override void OnEditValueChanged() } } - textEntry.Text = text; + _textEntry.Text = text; } } } From ca7cad2c2da3be754e10b4dff00947043c51552f Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Wed, 10 Jul 2019 13:17:30 +1000 Subject: [PATCH 3/4] Remove `NEEDHELPBUTTON` macro --- .../Forms/Design/IntegerCollectionEditor.cs | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/IntegerCollectionEditor.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/IntegerCollectionEditor.cs index 8de03aba2a5..ff4e94663f4 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/IntegerCollectionEditor.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/IntegerCollectionEditor.cs @@ -2,8 +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. -#define NEEDHELPBUTTON - using System.ComponentModel.Design; using System.Drawing; using System.Globalization; @@ -44,9 +42,7 @@ private class IntegerCollectionForm : CollectionForm private readonly TextBox _textEntry = new TextBox(); private readonly Button _okButton = new Button(); private readonly Button _cancelButton = new Button(); -#if NEEDHELPBUTTON private readonly Button _helpButton = new Button(); -#endif /// /// Constructs a StringCollectionForm. @@ -98,11 +94,7 @@ private void InitializeComponent() _textEntry.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right; _textEntry.KeyDown += new KeyEventHandler(Edit1_keyDown); -#if NEEDHELPBUTTON _okButton.Location = new Point(185, 274); -#else - _okButton.Location = new Point(264, 274); -#endif _okButton.Size = new Size(75, 23); _okButton.TabIndex = 1; _okButton.Text = SR.IntegerCollectionEditorOKCaption; @@ -110,27 +102,20 @@ private void InitializeComponent() _okButton.DialogResult = DialogResult.OK; _okButton.Click += new EventHandler(OKButton_click); -#if NEEDHELPBUTTON _cancelButton.Location = new Point(264, 274); -#else - _cancelButton.Location = new Point(343, 274); -#endif _cancelButton.Size = new Size(75, 23); _cancelButton.TabIndex = 2; _cancelButton.Text = SR.IntegerCollectionEditorCancelCaption; _cancelButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; _cancelButton.DialogResult = DialogResult.Cancel; -#if NEEDHELPBUTTON _helpButton.Location = new Point(343, 274); _helpButton.Size = new Size(75, 23); _helpButton.TabIndex = 3; _helpButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; _helpButton.Text = SR.IntegerCollectionEditorHelpCaption; - _helpButton.Click += new EventHandler(HelpButton_click); HelpRequested += new HelpEventHandler(Form_HelpRequested); -#endif Location = new Point(7, 7); Text = SR.IntegerCollectionEditorTitle; @@ -153,9 +138,7 @@ private void InitializeComponent() _textEntry, _okButton, _cancelButton, - #if NEEDHELPBUTTON _helpButton - #endif }); } From e465a59e87495875b831e3ace62fc07aeae03f56 Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Wed, 10 Jul 2019 11:21:51 +1000 Subject: [PATCH 4/4] Add manual test Exercise functionality manually and provide a way to visually confirm the editor is operational. --- .../src/Properties/InternalsVisibleTo.cs | 3 +- .../WinFormsControlsClassicTests.csproj | 8 ++- .../WinformsControlsTest/MainForm.Designer.cs | 14 +++++ .../WinformsControlsTest/MainForm.cs | 7 ++- .../UserControlWithCollectionEditors.cs | 57 +++++++++++++++++++ .../WinformsControlsTest.csproj | 8 +-- 6 files changed, 88 insertions(+), 9 deletions(-) create mode 100644 src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/UserControls/UserControlWithCollectionEditors.cs diff --git a/src/System.Windows.Forms.Design/src/Properties/InternalsVisibleTo.cs b/src/System.Windows.Forms.Design/src/Properties/InternalsVisibleTo.cs index 0741412e41c..3e7514f6c88 100644 --- a/src/System.Windows.Forms.Design/src/Properties/InternalsVisibleTo.cs +++ b/src/System.Windows.Forms.Design/src/Properties/InternalsVisibleTo.cs @@ -4,4 +4,5 @@ using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("System.Windows.Forms.Design.Tests, PublicKey=00000000000000000400000000000000")] \ No newline at end of file +[assembly: InternalsVisibleTo("System.Windows.Forms.Design.Tests, PublicKey=00000000000000000400000000000000")] +[assembly: InternalsVisibleTo("WinformsControlsTest, PublicKey=00000000000000000400000000000000")] diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinFormsControlsClassicTests/WinFormsControlsClassicTests.csproj b/src/System.Windows.Forms/tests/IntegrationTests/WinFormsControlsClassicTests/WinFormsControlsClassicTests.csproj index 938c7f37f2a..26f19f0f795 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/WinFormsControlsClassicTests/WinFormsControlsClassicTests.csproj +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinFormsControlsClassicTests/WinFormsControlsClassicTests.csproj @@ -20,13 +20,11 @@ false - msbuild - - + AnyCPU true @@ -224,6 +222,10 @@ TreeViewTest.Designer.cs TreeViewTest.cs + + UserControls\UserControlWithCollectionEditors.cs + UserControl + UserControls\UserControlWithFontNameEditor.cs UserControl diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.Designer.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.Designer.cs index 2ba025028ae..14d54caa419 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.Designer.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.Designer.cs @@ -50,6 +50,7 @@ private void InitializeComponent() this.ShowExceptionDialogButton = new System.Windows.Forms.Button(); this.flowLayoutPanelUITypeEditors = new System.Windows.Forms.FlowLayoutPanel(); this.fontNameEditor = new System.Windows.Forms.Button(); + this.collectionEditors = new System.Windows.Forms.Button(); this.flowLayoutPanelUITypeEditors.SuspendLayout(); this.SuspendLayout(); // @@ -234,6 +235,7 @@ private void InitializeComponent() this.flowLayoutPanelUITypeEditors.Controls.Add(this.propertyGrid); this.flowLayoutPanelUITypeEditors.Controls.Add(this.listViewButton); this.flowLayoutPanelUITypeEditors.Controls.Add(this.fontNameEditor); + this.flowLayoutPanelUITypeEditors.Controls.Add(this.collectionEditors); this.flowLayoutPanelUITypeEditors.Dock = System.Windows.Forms.DockStyle.Fill; this.flowLayoutPanelUITypeEditors.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; this.flowLayoutPanelUITypeEditors.Location = new System.Drawing.Point(8, 8); @@ -252,6 +254,17 @@ private void InitializeComponent() this.fontNameEditor.UseVisualStyleBackColor = true; this.fontNameEditor.Click += new System.EventHandler(this.FontNameEditor_Click); // + // collectionEditors + // + this.collectionEditors.Location = new System.Drawing.Point(267, 228); + this.collectionEditors.Margin = new System.Windows.Forms.Padding(2); + this.collectionEditors.Name = "collectionEditors"; + this.collectionEditors.Size = new System.Drawing.Size(258, 23); + this.collectionEditors.TabIndex = 16; + this.collectionEditors.Text = "CollectionEditors"; + this.collectionEditors.UseVisualStyleBackColor = true; + this.collectionEditors.Click += new System.EventHandler(this.CollectionEditors_Click); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); @@ -288,6 +301,7 @@ private void InitializeComponent() private System.Windows.Forms.Button ShowExceptionDialogButton; private System.Windows.Forms.FlowLayoutPanel flowLayoutPanelUITypeEditors; private System.Windows.Forms.Button fontNameEditor; + private System.Windows.Forms.Button collectionEditors; } } diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.cs index 8fe14c55447..f1ca3c485bf 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.cs @@ -4,8 +4,8 @@ using System; using System.Windows.Forms; -using WinformsControlsTest.UserControls; using System.Windows.Forms.IntegrationTests.Common; +using WinformsControlsTest.UserControls; namespace WinformsControlsTest { @@ -102,5 +102,10 @@ private void FontNameEditor_Click(object sender, EventArgs e) { new PropertyGrid(new UserControlWithFontNameEditor()).Show(); } + + private void CollectionEditors_Click(object sender, EventArgs e) + { + new PropertyGrid(new UserControlWithCollectionEditors()).Show(); + } } } diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/UserControls/UserControlWithCollectionEditors.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/UserControls/UserControlWithCollectionEditors.cs new file mode 100644 index 00000000000..f647173c9be --- /dev/null +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/UserControls/UserControlWithCollectionEditors.cs @@ -0,0 +1,57 @@ +// 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.Linq; +using System.Windows.Forms; +using System; +#if NETCORE +using System.Drawing.Design; +using System.Windows.Forms.Design; +#endif + +namespace WinformsControlsTest.UserControls +{ + internal class UserControlWithCollectionEditors : UserControl + { + private const string Category = "!CollectionEditors"; + private int[] _intArray = Enumerable.Range(1, 10).ToArray(); + private Array _intLegacyArray = Enumerable.Range(1, 10).ToArray(); + private List _intList = Enumerable.Range(1, 10).ToList(); + + public UserControlWithCollectionEditors() + { + AutoScaleMode = AutoScaleMode.Font; + } + +#if NETCORE + [Editor(typeof(IntegerCollectionEditor), typeof(UITypeEditor))] +#endif + [Browsable(true)] + [EditorBrowsable(EditorBrowsableState.Always)] + [Category(Category)] + public int[] IntArray + { + get => _intArray; + set => _intArray = value; + } + +#if NETCORE + [Editor(typeof(IntegerCollectionEditor), typeof(UITypeEditor))] +#endif + [Browsable(true)] + [EditorBrowsable(EditorBrowsableState.Always)] + [Category(Category)] + public List IntList => _intList; + +#if NETCORE + [Editor(typeof(IntegerCollectionEditor), typeof(UITypeEditor))] +#endif + [Browsable(true)] + [EditorBrowsable(EditorBrowsableState.Always)] + [Category(Category)] + public Array IntLegacyArray => _intLegacyArray; + } +} diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/WinformsControlsTest.csproj b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/WinformsControlsTest.csproj index 9797d6a01c2..c554c05a4fd 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/WinformsControlsTest.csproj +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/WinformsControlsTest.csproj @@ -10,6 +10,10 @@ app1.manifest + + NETCORE + + @@ -71,10 +75,6 @@ - - - - WinformsControlsTest.SmallA.bmp