From 02ba8b18bca3237fdfe5071f6ccb10d894a377d0 Mon Sep 17 00:00:00 2001 From: "Leaf Shi (BEYONDSOFT CONSULTING INC)" Date: Fri, 7 Feb 2025 18:21:35 +0800 Subject: [PATCH 1/5] Port ToolStripCollectionEditor to the Runtime --- .../src/System.Design.Forwards.cs | 1 + .../src/Resources/SR.resx | 6 + .../System/WinForms/Design/blank.bmp | Bin 0 -> 94 bytes .../Resources/ToolStripItemEditorForm.resx | 630 ++++++++ .../src/Resources/xlf/SR.cs.xlf | 10 + .../src/Resources/xlf/SR.de.xlf | 10 + .../src/Resources/xlf/SR.es.xlf | 10 + .../src/Resources/xlf/SR.fr.xlf | 10 + .../src/Resources/xlf/SR.it.xlf | 10 + .../src/Resources/xlf/SR.ja.xlf | 10 + .../src/Resources/xlf/SR.ko.xlf | 10 + .../src/Resources/xlf/SR.pl.xlf | 10 + .../src/Resources/xlf/SR.pt-BR.xlf | 10 + .../src/Resources/xlf/SR.ru.xlf | 10 + .../src/Resources/xlf/SR.tr.xlf | 10 + .../src/Resources/xlf/SR.zh-Hans.xlf | 10 + .../src/Resources/xlf/SR.zh-Hant.xlf | 10 + .../xlf/ToolStripItemEditorForm.cs.xlf | 72 + .../xlf/ToolStripItemEditorForm.de.xlf | 72 + .../xlf/ToolStripItemEditorForm.es.xlf | 72 + .../xlf/ToolStripItemEditorForm.fr.xlf | 72 + .../xlf/ToolStripItemEditorForm.it.xlf | 72 + .../xlf/ToolStripItemEditorForm.ja.xlf | 72 + .../xlf/ToolStripItemEditorForm.ko.xlf | 72 + .../xlf/ToolStripItemEditorForm.pl.xlf | 72 + .../xlf/ToolStripItemEditorForm.pt-BR.xlf | 72 + .../xlf/ToolStripItemEditorForm.ru.xlf | 72 + .../xlf/ToolStripItemEditorForm.tr.xlf | 72 + .../xlf/ToolStripItemEditorForm.zh-Hans.xlf | 72 + .../xlf/ToolStripItemEditorForm.zh-Hant.xlf | 72 + .../src/System.Windows.Forms.Design.csproj | 6 + ...ollectionEditor.ToolStripItemEditorForm.cs | 1363 +++++++++++++++++ .../Forms/Design/ToolStripCollectionEditor.cs | 94 ++ .../Design/ToolStripCustomTypeDescriptor.cs | 98 ++ .../DesignSurface/DemoConsole/MainForm.cs | 12 +- 35 files changed, 3273 insertions(+), 3 deletions(-) create mode 100644 src/System.Windows.Forms.Design/src/Resources/System/WinForms/Design/blank.bmp create mode 100644 src/System.Windows.Forms.Design/src/Resources/ToolStripItemEditorForm.resx create mode 100644 src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.cs.xlf create mode 100644 src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.de.xlf create mode 100644 src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.es.xlf create mode 100644 src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.fr.xlf create mode 100644 src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.it.xlf create mode 100644 src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.ja.xlf create mode 100644 src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.ko.xlf create mode 100644 src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.pl.xlf create mode 100644 src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.pt-BR.xlf create mode 100644 src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.ru.xlf create mode 100644 src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.tr.xlf create mode 100644 src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.zh-Hans.xlf create mode 100644 src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.zh-Hant.xlf create mode 100644 src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.ToolStripItemEditorForm.cs create mode 100644 src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.cs create mode 100644 src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCustomTypeDescriptor.cs diff --git a/src/System.Design/src/System.Design.Forwards.cs b/src/System.Design/src/System.Design.Forwards.cs index a36c7c11be3..f2905f6b951 100644 --- a/src/System.Design/src/System.Design.Forwards.cs +++ b/src/System.Design/src/System.Design.Forwards.cs @@ -81,6 +81,7 @@ [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ToolStripMenuItemDesigner))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.TrackBarDesigner))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.TreeViewDesigner))] +[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ToolStripCollectionEditor))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.UpDownBaseDesigner))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.UserControlDocumentDesigner))] diff --git a/src/System.Windows.Forms.Design/src/Resources/SR.resx b/src/System.Windows.Forms.Design/src/Resources/SR.resx index 189892d8d15..1ff3988b4b2 100644 --- a/src/System.Windows.Forms.Design/src/Resources/SR.resx +++ b/src/System.Windows.Forms.Design/src/Resources/SR.resx @@ -1476,6 +1476,12 @@ Press Ctrl+Enter to accept Text. TableLayoutPanel cannot expand to contain the control, because the panel's GrowStyle property is set to 'FixedSize'. + + (&None) + + + (&Multiple Items) + Opens the Images collection editor diff --git a/src/System.Windows.Forms.Design/src/Resources/System/WinForms/Design/blank.bmp b/src/System.Windows.Forms.Design/src/Resources/System/WinForms/Design/blank.bmp new file mode 100644 index 0000000000000000000000000000000000000000..4be33cd7ab31198addb990b8c3f44ac5a392d712 GIT binary patch literal 94 mcmZ?rjbnfSJ0PV2#2iq}$iN7ePymyd#Q*>Q8U6!>@nHaa?+kkY literal 0 HcmV?d00001 diff --git a/src/System.Windows.Forms.Design/src/Resources/ToolStripItemEditorForm.resx b/src/System.Windows.Forms.Design/src/Resources/ToolStripItemEditorForm.resx new file mode 100644 index 00000000000..0b0f7db6fac --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/ToolStripItemEditorForm.resx @@ -0,0 +1,630 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + Left, Right + + + + Left, Right + + + + True + + + NoControl + + + + 84, 3 + + + 75, 23 + + + 1 + + + Cancel + + + btnCancel + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + okCancelTableLayoutPanel + + + 1 + + + Left, Right + + + True + + + None + + + NoControl + + + 3, 3 + + + No + + + 75, 23 + + + 0 + + + OK + + + btnOK + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + okCancelTableLayoutPanel + + + 0 + + + Top, Bottom, Left, Right + + + 3 + + + Left, Right + + + 2 + + + Left, Right + + + True + + + NoControl + + + 199, 3 + + + 69, 23 + + + 1 + + + &Add + + + btnAddNew + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + addTableLayoutPanel + + + 0 + + + Left, Right + + + False + + + 3, 4 + + + 190, 21 + + + 0 + + + newItemTypes + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + addTableLayoutPanel + + + 1 + + + 3, 17 + + + 1 + + + 271, 23 + + + 1 + + + addTableLayoutPanel + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="btnAddNew" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="newItemTypes" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="AutoSize,0,Percent,100" /><Rows Styles="AutoSize,0" /></TableLayoutSettings> + + + Right + + + True + + + 2 + + + 453, 310 + + + 1 + + + 162, 29 + + + 9 + + + okCancelTableLayoutPanel + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel + + + 1 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="btnOK" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="btnCancel" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /></Controls><Columns Styles="Percent,50,Percent,50" /><Rows Styles="AutoSize,0" /></TableLayoutSettings> + + + Bottom, Left + + + True + + + NoControl + + + 3, 1 + + + 162, 13 + + + 0 + + + &Select item and add to list below: + + + lblItems + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel + + + 2 + + + Bottom, Left, Right + + + NoControl + + + 312, 0 + + + 303, 14 + + + 7 + + + toolStrip1 + + + selectedItemName + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel + + + 3 + + + Fill + + + False + + + 312, 17 + + + 303, 287 + + + 8 + + + selectedItemProps + + + System.Windows.Forms.PropertyGrid, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel + + + 4 + + + True + + + 3, 43 + + + 53, 13 + + + 2 + + + &Members: + + + lblMembers + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel + + + 5 + + + Fill + + + 3, 59 + + + 271, 245 + + + 3 + + + listBoxItems + + + System.Windows.Forms.ListBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel + + + 6 + + + Move the selected item up in the list + + + Move Up + + + Left + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAEdJREFUOE9jYBj0 + 4MCBA//JdiRU83+yDIFpBtoOcgFphqBrJskQXJqJMoSQZqIMgYU4RWEAMmQYGADzBsgrZCUkspMv3TUC + AGYzbEaI9u+YAAAAAElFTkSuQmCC + + + + NoControl + + + 280, 59 + + + 26, 23 + + + 4 + + + btnMoveUp + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel + + + 7 + + + Move the selected item down in the list + + + Move Down + + + Left + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAElJREFUOE9jYBje + 4MCBA/9hmGSfgjQCNcExlE+8OUPUAHRnI4cB0eFByBCiAhOXIURphsUTxbEAMghmCEk2o6cUijQTn+wo + UAkAY/VsRlvaylwAAAAASUVORK5CYII= + + + + NoControl + + + 280, 88 + + + 26, 23 + + + 5 + + + btnMoveDown + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel + + + 8 + + + Remove the selected item from the list + + + Remove + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAHdJREFUOE+tU1sO + wCAI8/434nRbMGPrFGldZsKHWkp5tfbHMbMjTOFz7I27Lv7Q7fU5sEGQBzcSrEgQNwVhJKVzqER5mI7k + jKlmalhtpsLvFJY6K90pWyrXoJJNSZScA7M9A1mHPo+yk6U7s5SXbBZLRVnGriKAJ50T5KPzn8IEAAAA + AElFTkSuQmCC + + + + NoControl + + + 280, 117 + + + 26, 23 + + + 6 + + + btnRemove + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel + + + 9 + + + 12, 12 + + + 7 + + + 618, 342 + + + 0 + + + tableLayoutPanel + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="addTableLayoutPanel" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="okCancelTableLayoutPanel" Row="6" RowSpan="1" Column="0" ColumnSpan="3" /><Control Name="lblItems" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="selectedItemName" Row="0" RowSpan="1" Column="2" ColumnSpan="1" /><Control Name="selectedItemProps" Row="1" RowSpan="5" Column="2" ColumnSpan="1" /><Control Name="lblMembers" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="listBoxItems" Row="3" RowSpan="3" Column="0" ColumnSpan="1" /><Control Name="btnMoveUp" Row="3" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="btnMoveDown" Row="4" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="btnRemove" Row="5" RowSpan="1" Column="1" ColumnSpan="1" /></Controls><Columns Styles="AutoSize,0,AutoSize,0,Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,Percent,100,AutoSize,0" /></TableLayoutSettings> + + + True + + + 6, 13 + + + 642, 366 + + + 600, 400 + + + No + + + CenterScreen + + + Items Collection Editor + + + ToolStripItemEditorForm + + + System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 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 77fd803b2d9..9298f3c8b39 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 @@ -2332,6 +2332,16 @@ Stisknutím kombinace kláves Ctrl+Enter text přijměte. Vložení třídy MenuItem prvku ToolStrip v transakci prvku DropDown + + (&Multiple Items) + (&Multiple Items) + + + + (&None) + (&None) + + &Edit Items... &Upravit položky... 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 b51861be88c..17bc9da74a6 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 @@ -2332,6 +2332,16 @@ Drücken Sie STRG+EINGABETASTE, um Text zu übernehmen. "ToolStrip MenuItem Insert" in DropDown-Transaktion. + + (&Multiple Items) + (&Multiple Items) + + + + (&None) + (&None) + + &Edit Items... Einträge &bearbeiten... 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 e26bb16d7dd..d5bc259e7e8 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 @@ -2332,6 +2332,16 @@ Presione Ctrl+Entrar para aceptar el texto. Inserción de MenuItem de ToolStrip en transacción DropDown. + + (&Multiple Items) + (&Multiple Items) + + + + (&None) + (&None) + + &Edit Items... &Editar elementos... 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 0877bf6b61b..32eddbc9003 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 @@ -2332,6 +2332,16 @@ Appuyez sur Ctrl+Entrée pour valider le texte. Transaction Insertion d'un MenuItem ToolStrip dans DropDown. + + (&Multiple Items) + (&Multiple Items) + + + + (&None) + (&None) + + &Edit Items... &Modifier les éléments... 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 095f10d87b7..7ad3cc86c98 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 @@ -2332,6 +2332,16 @@ Per accettare testo premere CTRL+INVIO. Inserisci elemento MenuItem di un controllo ToolStrip in transazione DropDown + + (&Multiple Items) + (&Multiple Items) + + + + (&None) + (&None) + + &Edit Items... &Modifica elementi... 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 324f9f64a17..3cd6ef705be 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 @@ -2332,6 +2332,16 @@ Press Ctrl+Enter to accept Text. DropDown での ToolStrip MenuItem の挿入トランザクションです。 + + (&Multiple Items) + (&Multiple Items) + + + + (&None) + (&None) + + &Edit Items... 項目の編集(&E)... 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 c2c50494d2c..bd5462043ce 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 @@ -2332,6 +2332,16 @@ Press Ctrl+Enter to accept Text. DropDown 트랜잭션의 ToolStrip MenuItem 삽입입니다. + + (&Multiple Items) + (&Multiple Items) + + + + (&None) + (&None) + + &Edit Items... 항목 편집(&E)... 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 6c21ff24aa1..871106fd044 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 @@ -2332,6 +2332,16 @@ Naciśnij klawisze Ctrl+Enter, aby zaakceptować tekst. Operacja ToolStrip MenuItem Insert w DropDown. + + (&Multiple Items) + (&Multiple Items) + + + + (&None) + (&None) + + &Edit Items... &Edytuj elementy... 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 5e68b54cc33..e3aec7eadd4 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 @@ -2332,6 +2332,16 @@ Pressione Ctrl+Enter para aceitar Texto. Inserção de ToolStrip MenuItem na Transação DropDown. + + (&Multiple Items) + (&Multiple Items) + + + + (&None) + (&None) + + &Edit Items... &Editar Itens... 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 c30a933cb51..ed82a0938f3 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 @@ -2332,6 +2332,16 @@ Press Ctrl+Enter to accept Text. Вставка элементов меню ToolStrip в транзакцию DropDown. + + (&Multiple Items) + (&Multiple Items) + + + + (&None) + (&None) + + &Edit Items... &Правка элементов… 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 aae519a3e45..d7095490bae 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 @@ -2332,6 +2332,16 @@ Metni kabul etmek için Ctrl+Enter tuşlarına basın. DropDown İşleminde ToolStrip MenuItem Ekleme. + + (&Multiple Items) + (&Multiple Items) + + + + (&None) + (&None) + + &Edit Items... &Öğeleri Düzenle... 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 8fa9d2b9ee0..c8c4d5dbd47 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 @@ -2332,6 +2332,16 @@ Press Ctrl+Enter to accept Text. DropDown 事务中的“ToolStrip 菜单项插入”。 + + (&Multiple Items) + (&Multiple Items) + + + + (&None) + (&None) + + &Edit Items... 编辑项(&E)... 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 f8695a54e27..f851232ba62 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 @@ -2332,6 +2332,16 @@ Press Ctrl+Enter to accept Text. DropDown 異動中的 ToolStrip MenuItem 插入。 + + (&Multiple Items) + (&Multiple Items) + + + + (&None) + (&None) + + &Edit Items... 編輯項目(&E)... diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.cs.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.cs.xlf new file mode 100644 index 00000000000..3d3b633a0a7 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.cs.xlf @@ -0,0 +1,72 @@ + + + + + + Items Collection Editor + Items Collection Editor + + + + &Add + &Add + + + + Cancel + Cancel + + + + Move the selected item down in the list + Move the selected item down in the list + + + + Move Down + Move Down + + + + Move the selected item up in the list + Move the selected item up in the list + + + + Move Up + Move Up + + + + OK + OK + + + + Remove the selected item from the list + Remove the selected item from the list + + + + Remove + Remove + + + + &Select item and add to list below: + &Select item and add to list below: + + + + &Members: + &Members: + + + + toolStrip1 + toolStrip1 + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.de.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.de.xlf new file mode 100644 index 00000000000..c71e8e9c80f --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.de.xlf @@ -0,0 +1,72 @@ + + + + + + Items Collection Editor + Items Collection Editor + + + + &Add + &Add + + + + Cancel + Cancel + + + + Move the selected item down in the list + Move the selected item down in the list + + + + Move Down + Move Down + + + + Move the selected item up in the list + Move the selected item up in the list + + + + Move Up + Move Up + + + + OK + OK + + + + Remove the selected item from the list + Remove the selected item from the list + + + + Remove + Remove + + + + &Select item and add to list below: + &Select item and add to list below: + + + + &Members: + &Members: + + + + toolStrip1 + toolStrip1 + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.es.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.es.xlf new file mode 100644 index 00000000000..dd316cb5f07 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.es.xlf @@ -0,0 +1,72 @@ + + + + + + Items Collection Editor + Items Collection Editor + + + + &Add + &Add + + + + Cancel + Cancel + + + + Move the selected item down in the list + Move the selected item down in the list + + + + Move Down + Move Down + + + + Move the selected item up in the list + Move the selected item up in the list + + + + Move Up + Move Up + + + + OK + OK + + + + Remove the selected item from the list + Remove the selected item from the list + + + + Remove + Remove + + + + &Select item and add to list below: + &Select item and add to list below: + + + + &Members: + &Members: + + + + toolStrip1 + toolStrip1 + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.fr.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.fr.xlf new file mode 100644 index 00000000000..96e0489f6eb --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.fr.xlf @@ -0,0 +1,72 @@ + + + + + + Items Collection Editor + Items Collection Editor + + + + &Add + &Add + + + + Cancel + Cancel + + + + Move the selected item down in the list + Move the selected item down in the list + + + + Move Down + Move Down + + + + Move the selected item up in the list + Move the selected item up in the list + + + + Move Up + Move Up + + + + OK + OK + + + + Remove the selected item from the list + Remove the selected item from the list + + + + Remove + Remove + + + + &Select item and add to list below: + &Select item and add to list below: + + + + &Members: + &Members: + + + + toolStrip1 + toolStrip1 + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.it.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.it.xlf new file mode 100644 index 00000000000..673a526d906 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.it.xlf @@ -0,0 +1,72 @@ + + + + + + Items Collection Editor + Items Collection Editor + + + + &Add + &Add + + + + Cancel + Cancel + + + + Move the selected item down in the list + Move the selected item down in the list + + + + Move Down + Move Down + + + + Move the selected item up in the list + Move the selected item up in the list + + + + Move Up + Move Up + + + + OK + OK + + + + Remove the selected item from the list + Remove the selected item from the list + + + + Remove + Remove + + + + &Select item and add to list below: + &Select item and add to list below: + + + + &Members: + &Members: + + + + toolStrip1 + toolStrip1 + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.ja.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.ja.xlf new file mode 100644 index 00000000000..ab035685d5d --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.ja.xlf @@ -0,0 +1,72 @@ + + + + + + Items Collection Editor + Items Collection Editor + + + + &Add + &Add + + + + Cancel + Cancel + + + + Move the selected item down in the list + Move the selected item down in the list + + + + Move Down + Move Down + + + + Move the selected item up in the list + Move the selected item up in the list + + + + Move Up + Move Up + + + + OK + OK + + + + Remove the selected item from the list + Remove the selected item from the list + + + + Remove + Remove + + + + &Select item and add to list below: + &Select item and add to list below: + + + + &Members: + &Members: + + + + toolStrip1 + toolStrip1 + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.ko.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.ko.xlf new file mode 100644 index 00000000000..27f689bd56a --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.ko.xlf @@ -0,0 +1,72 @@ + + + + + + Items Collection Editor + Items Collection Editor + + + + &Add + &Add + + + + Cancel + Cancel + + + + Move the selected item down in the list + Move the selected item down in the list + + + + Move Down + Move Down + + + + Move the selected item up in the list + Move the selected item up in the list + + + + Move Up + Move Up + + + + OK + OK + + + + Remove the selected item from the list + Remove the selected item from the list + + + + Remove + Remove + + + + &Select item and add to list below: + &Select item and add to list below: + + + + &Members: + &Members: + + + + toolStrip1 + toolStrip1 + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.pl.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.pl.xlf new file mode 100644 index 00000000000..a4ffbebf02d --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.pl.xlf @@ -0,0 +1,72 @@ + + + + + + Items Collection Editor + Items Collection Editor + + + + &Add + &Add + + + + Cancel + Cancel + + + + Move the selected item down in the list + Move the selected item down in the list + + + + Move Down + Move Down + + + + Move the selected item up in the list + Move the selected item up in the list + + + + Move Up + Move Up + + + + OK + OK + + + + Remove the selected item from the list + Remove the selected item from the list + + + + Remove + Remove + + + + &Select item and add to list below: + &Select item and add to list below: + + + + &Members: + &Members: + + + + toolStrip1 + toolStrip1 + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.pt-BR.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.pt-BR.xlf new file mode 100644 index 00000000000..be7cc966588 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.pt-BR.xlf @@ -0,0 +1,72 @@ + + + + + + Items Collection Editor + Items Collection Editor + + + + &Add + &Add + + + + Cancel + Cancel + + + + Move the selected item down in the list + Move the selected item down in the list + + + + Move Down + Move Down + + + + Move the selected item up in the list + Move the selected item up in the list + + + + Move Up + Move Up + + + + OK + OK + + + + Remove the selected item from the list + Remove the selected item from the list + + + + Remove + Remove + + + + &Select item and add to list below: + &Select item and add to list below: + + + + &Members: + &Members: + + + + toolStrip1 + toolStrip1 + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.ru.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.ru.xlf new file mode 100644 index 00000000000..a7997f459d1 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.ru.xlf @@ -0,0 +1,72 @@ + + + + + + Items Collection Editor + Items Collection Editor + + + + &Add + &Add + + + + Cancel + Cancel + + + + Move the selected item down in the list + Move the selected item down in the list + + + + Move Down + Move Down + + + + Move the selected item up in the list + Move the selected item up in the list + + + + Move Up + Move Up + + + + OK + OK + + + + Remove the selected item from the list + Remove the selected item from the list + + + + Remove + Remove + + + + &Select item and add to list below: + &Select item and add to list below: + + + + &Members: + &Members: + + + + toolStrip1 + toolStrip1 + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.tr.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.tr.xlf new file mode 100644 index 00000000000..9e00071bcec --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.tr.xlf @@ -0,0 +1,72 @@ + + + + + + Items Collection Editor + Items Collection Editor + + + + &Add + &Add + + + + Cancel + Cancel + + + + Move the selected item down in the list + Move the selected item down in the list + + + + Move Down + Move Down + + + + Move the selected item up in the list + Move the selected item up in the list + + + + Move Up + Move Up + + + + OK + OK + + + + Remove the selected item from the list + Remove the selected item from the list + + + + Remove + Remove + + + + &Select item and add to list below: + &Select item and add to list below: + + + + &Members: + &Members: + + + + toolStrip1 + toolStrip1 + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.zh-Hans.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.zh-Hans.xlf new file mode 100644 index 00000000000..4eb3c5edb63 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.zh-Hans.xlf @@ -0,0 +1,72 @@ + + + + + + Items Collection Editor + Items Collection Editor + + + + &Add + &Add + + + + Cancel + Cancel + + + + Move the selected item down in the list + Move the selected item down in the list + + + + Move Down + Move Down + + + + Move the selected item up in the list + Move the selected item up in the list + + + + Move Up + Move Up + + + + OK + OK + + + + Remove the selected item from the list + Remove the selected item from the list + + + + Remove + Remove + + + + &Select item and add to list below: + &Select item and add to list below: + + + + &Members: + &Members: + + + + toolStrip1 + toolStrip1 + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.zh-Hant.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.zh-Hant.xlf new file mode 100644 index 00000000000..b4409ee1c8b --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.zh-Hant.xlf @@ -0,0 +1,72 @@ + + + + + + Items Collection Editor + Items Collection Editor + + + + &Add + &Add + + + + Cancel + Cancel + + + + Move the selected item down in the list + Move the selected item down in the list + + + + Move Down + Move Down + + + + Move the selected item up in the list + Move the selected item up in the list + + + + Move Up + Move Up + + + + OK + OK + + + + Remove the selected item from the list + Remove the selected item from the list + + + + Remove + Remove + + + + &Select item and add to list below: + &Select item and add to list below: + + + + &Members: + &Members: + + + + toolStrip1 + toolStrip1 + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/System.Windows.Forms.Design.csproj b/src/System.Windows.Forms.Design/src/System.Windows.Forms.Design.csproj index 74ac5d4b609..7be4bb0bf1f 100644 --- a/src/System.Windows.Forms.Design/src/System.Windows.Forms.Design.csproj +++ b/src/System.Windows.Forms.Design/src/System.Windows.Forms.Design.csproj @@ -52,6 +52,12 @@ System.ComponentModel.Design + + System.Windows.Forms.Design + + + System.Windows.Forms.Design + colordlg.data diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.ToolStripItemEditorForm.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.ToolStripItemEditorForm.cs new file mode 100644 index 00000000000..52198bfbac2 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.ToolStripItemEditorForm.cs @@ -0,0 +1,1363 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Drawing; + +#nullable disable + +namespace System.Windows.Forms.Design; + +internal partial class ToolStripCollectionEditor +{ + protected class ToolStripItemEditorForm : CollectionForm + { + private readonly ToolStripCollectionEditor _editor; + private const int ICON_DIMENSION = 16; + private const int SEPARATOR_HEIGHT = 4; + private const int TEXT_IMAGE_SPACING = 6; + private const int INDENT_SPACING = 4; + private const int IMAGE_PADDING = 1; + + private static bool s_isScalingInitialized; + private static int s_iconHeight = ICON_DIMENSION; + private static int s_iconWidth = ICON_DIMENSION; + private static int s_separatorHeight = SEPARATOR_HEIGHT; + private static int s_textImageSpacing = TEXT_IMAGE_SPACING; + private static int s_indentSpacing = INDENT_SPACING; + private static int s_imagePaddingX = IMAGE_PADDING; + private static int s_imagePaddingY = IMAGE_PADDING; + + private ToolStripCustomTypeDescriptor _toolStripCustomTypeDescriptor; + + /// + /// The amount of fudgespace we use when GDI+ returns us a string length. + /// + private const int GdiPlusFudge = 5; + + /// + /// The collection we're actually editing. + /// + private ToolStripItemCollection _targetToolStripCollection; + + /// + /// Our list of items that we're editing. + /// + private EditorItemCollection _itemList; + + /// + /// The start index of custom items in the new toolStripDropDownItem type dropdown. + /// + private int _customItemIndex = -1; + + /// + /// All our control instance variables. + /// + private TableLayoutPanel _tableLayoutPanel; + private TableLayoutPanel _addTableLayoutPanel; + private TableLayoutPanel _okCancelTableLayoutPanel; + private Button _btnCancel; + private Button _btnOK; + private Button _btnMoveUp; + private Button _btnMoveDown; + private Label _lblItems; + private ImageComboBox _newItemTypes; + private Button _btnAddNew; + private FilterListBox _listBoxItems; + private Label _selectedItemName; + private Button _btnRemove; + private VsPropertyGrid _selectedItemProps; + private Label _lblMembers; + + private IComponentChangeService _componentChangeSvc; + private readonly string _originalText; + + /// + /// Create the form and set it up. + /// + /// The collection editor that spawned us. + internal ToolStripItemEditorForm(CollectionEditor parent) : base(parent) + { + if (!s_isScalingInitialized) + { + if (ScaleHelper.IsScalingRequired) + { + s_iconHeight = ICON_DIMENSION; + s_iconWidth = ScaleHelper.ScaleToInitialSystemDpi(ICON_DIMENSION); + s_separatorHeight = ScaleHelper.ScaleToInitialSystemDpi(SEPARATOR_HEIGHT); + s_textImageSpacing = ScaleHelper.ScaleToInitialSystemDpi(TEXT_IMAGE_SPACING); + s_indentSpacing = ScaleHelper.ScaleToInitialSystemDpi(INDENT_SPACING); + s_imagePaddingX = ScaleHelper.ScaleToInitialSystemDpi(IMAGE_PADDING); + s_imagePaddingY = ScaleHelper.ScaleToInitialSystemDpi(IMAGE_PADDING); + } + + s_isScalingInitialized = true; + } + + _editor = (ToolStripCollectionEditor)parent; + InitializeComponent(); + if (ScaleHelper.IsScalingRequired) + { + ScaleButtonImageLogicalToDevice(_btnMoveUp); + ScaleButtonImageLogicalToDevice(_btnMoveDown); + ScaleButtonImageLogicalToDevice(_btnRemove); + } + + ActiveControl = _listBoxItems; + _originalText = Text; + SetStyle(ControlStyles.ResizeRedraw, true); + } + + /// + /// The collection that we're editing. Setting this causes us to sync our contents with that collection. + /// + internal ToolStripItemCollection Collection + { + set + { + if (value != _targetToolStripCollection) + { + // clear our existing list of items. + // + _itemList?.Clear(); + + // add any existing items to our list. + // + if (value is not null) + { + if (Context is not null) + { + // create a new list around the new value. + // + _itemList = new EditorItemCollection(this, _listBoxItems.Items, value); + + ToolStrip realToolStrip = ToolStripFromObject(Context.Instance); + _itemList.Add(realToolStrip); + + ToolStripItem itemInstance = Context.Instance as ToolStripItem; + if (itemInstance is not null && itemInstance.Site is not null) + { + Text = _originalText + " (" + itemInstance.Site.Name + "." + Context.PropertyDescriptor.Name + ")"; + } + + foreach (ToolStripItem item in value) + { + if (item is DesignerToolStripControlHost) + { + continue; + } + + _itemList.Add(item); + } + + IComponentChangeService changeSvc = (IComponentChangeService)Context.GetService(typeof(IComponentChangeService)); + if (changeSvc is not null) + { + changeSvc.ComponentChanged += new ComponentChangedEventHandler(OnComponentChanged); + } + + _selectedItemProps.Site = new PropertyGridSite(Context, _selectedItemProps); + } + } + else + { + if (_componentChangeSvc is not null) + { + _componentChangeSvc.ComponentChanged -= new ComponentChangedEventHandler(OnComponentChanged); + } + + _componentChangeSvc = null; + _selectedItemProps.Site = null; + } + + _targetToolStripCollection = value; + } + } + } + + #region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + ComponentResourceManager resources = new ComponentResourceManager(typeof(ToolStripItemEditorForm)); + _btnCancel = new Button(); + _btnOK = new Button(); + _tableLayoutPanel = new TableLayoutPanel(); + _addTableLayoutPanel = new TableLayoutPanel(); + _btnAddNew = new Button(); + _newItemTypes = new ImageComboBox(); + _okCancelTableLayoutPanel = new TableLayoutPanel(); + _lblItems = new Label(); + _selectedItemName = new Label(); + _selectedItemProps = new VsPropertyGrid(); + _lblMembers = new Label(); + _listBoxItems = new FilterListBox(); + _btnMoveUp = new Button(); + _btnMoveDown = new Button(); + _btnRemove = new Button(); + _tableLayoutPanel.SuspendLayout(); + _addTableLayoutPanel.SuspendLayout(); + _okCancelTableLayoutPanel.SuspendLayout(); + SuspendLayout(); + // + // btnCancel + // + resources.ApplyResources(_btnCancel, "btnCancel"); + _btnCancel.DialogResult = DialogResult.Cancel; + _btnCancel.Margin = new Padding(3, 0, 0, 0); + _btnCancel.Name = "btnCancel"; + // + // btnOK + // + resources.ApplyResources(_btnOK, "btnOK"); + _btnOK.Margin = new Padding(0, 0, 3, 0); + _btnOK.Name = "btnOK"; + // + // tableLayoutPanel + // + resources.ApplyResources(_tableLayoutPanel, "tableLayoutPanel"); + _tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 274F)); + _tableLayoutPanel.ColumnStyles.Add(new ColumnStyle()); + _tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); + _tableLayoutPanel.Controls.Add(_addTableLayoutPanel, 0, 1); + _tableLayoutPanel.Controls.Add(_okCancelTableLayoutPanel, 0, 6); + _tableLayoutPanel.Controls.Add(_lblItems, 0, 0); + _tableLayoutPanel.Controls.Add(_selectedItemName, 2, 0); + _tableLayoutPanel.Controls.Add(_selectedItemProps, 2, 1); + _tableLayoutPanel.Controls.Add(_lblMembers, 0, 2); + _tableLayoutPanel.Controls.Add(_listBoxItems, 0, 3); + _tableLayoutPanel.Controls.Add(_btnMoveUp, 1, 3); + _tableLayoutPanel.Controls.Add(_btnMoveDown, 1, 4); + _tableLayoutPanel.Controls.Add(_btnRemove, 1, 5); + _tableLayoutPanel.Name = "tableLayoutPanel"; + _tableLayoutPanel.RowStyles.Add(new RowStyle()); + _tableLayoutPanel.RowStyles.Add(new RowStyle()); + _tableLayoutPanel.RowStyles.Add(new RowStyle()); + _tableLayoutPanel.RowStyles.Add(new RowStyle()); + _tableLayoutPanel.RowStyles.Add(new RowStyle()); + _tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); + _tableLayoutPanel.RowStyles.Add(new RowStyle()); + // + // addTableLayoutPanel + // + resources.ApplyResources(_addTableLayoutPanel, "addTableLayoutPanel"); + _addTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); + _addTableLayoutPanel.ColumnStyles.Add(new ColumnStyle()); + _addTableLayoutPanel.Controls.Add(_btnAddNew, 1, 0); + _addTableLayoutPanel.Controls.Add(_newItemTypes, 0, 0); + _addTableLayoutPanel.Margin = new Padding(0, 3, 3, 3); + _addTableLayoutPanel.Name = "addTableLayoutPanel"; + _addTableLayoutPanel.AutoSize = true; + _addTableLayoutPanel.RowStyles.Add(new RowStyle()); + // + // btnAddNew + // + resources.ApplyResources(_btnAddNew, "btnAddNew"); + _btnAddNew.Margin = new Padding(3, 0, 0, 0); + _btnAddNew.Name = "btnAddNew"; + // + // newItemTypes + // + resources.ApplyResources(_newItemTypes, "newItemTypes"); + _newItemTypes.DropDownStyle = ComboBoxStyle.DropDownList; + _newItemTypes.FormattingEnabled = true; + _newItemTypes.Margin = new Padding(0, 0, 3, 0); + _newItemTypes.Name = "newItemTypes"; + _newItemTypes.DrawMode = DrawMode.OwnerDrawVariable; + + // + // okCancelTableLayoutPanel + // + resources.ApplyResources(_okCancelTableLayoutPanel, "okCancelTableLayoutPanel"); + _tableLayoutPanel.SetColumnSpan(_okCancelTableLayoutPanel, 3); + _okCancelTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); + _okCancelTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); + _okCancelTableLayoutPanel.Controls.Add(_btnOK, 0, 0); + _okCancelTableLayoutPanel.Controls.Add(_btnCancel, 1, 0); + _okCancelTableLayoutPanel.Margin = new Padding(3, 6, 0, 0); + _okCancelTableLayoutPanel.Name = "okCancelTableLayoutPanel"; + _okCancelTableLayoutPanel.RowStyles.Add(new RowStyle()); + // + // lblItems + // + resources.ApplyResources(_lblItems, "lblItems"); + _lblItems.Margin = new Padding(0, 3, 3, 0); + _lblItems.Name = "lblItems"; + // + // selectedItemName + // + resources.ApplyResources(_selectedItemName, "selectedItemName"); + _selectedItemName.Margin = new Padding(3, 3, 3, 0); + _selectedItemName.Name = "selectedItemName"; + // + // selectedItemProps + // + _selectedItemProps.CommandsVisibleIfAvailable = false; + resources.ApplyResources(_selectedItemProps, "selectedItemProps"); + _selectedItemProps.Margin = new Padding(3, 3, 0, 3); + _selectedItemProps.Name = "selectedItemProps"; + _tableLayoutPanel.SetRowSpan(_selectedItemProps, 5); + // + // lblMembers + // + resources.ApplyResources(_lblMembers, "lblMembers"); + _lblMembers.Margin = new Padding(0, 3, 3, 0); + _lblMembers.Name = "lblMembers"; + // + // listBoxItems + // + resources.ApplyResources(_listBoxItems, "listBoxItems"); + _listBoxItems.DrawMode = DrawMode.OwnerDrawVariable; + _listBoxItems.FormattingEnabled = true; + _listBoxItems.Margin = new Padding(0, 3, 3, 3); + _listBoxItems.Name = "listBoxItems"; + _tableLayoutPanel.SetRowSpan(_listBoxItems, 3); + _listBoxItems.SelectionMode = SelectionMode.MultiExtended; + // + // btnMoveUp + // + resources.ApplyResources(_btnMoveUp, "btnMoveUp"); + _btnMoveUp.Margin = new Padding(3, 3, 18, 0); + _btnMoveUp.Name = "btnMoveUp"; + // + // btnMoveDown + // + resources.ApplyResources(_btnMoveDown, "btnMoveDown"); + _btnMoveDown.Margin = new Padding(3, 1, 18, 3); + _btnMoveDown.Name = "btnMoveDown"; + // + // btnRemove + // + resources.ApplyResources(_btnRemove, "btnRemove"); + _btnRemove.Margin = new Padding(3, 3, 18, 3); + _btnRemove.Name = "btnRemove"; + // + // ToolStripCollectionEditor + // + AutoScaleMode = AutoScaleMode.Font; + AcceptButton = _btnOK; + resources.ApplyResources(this, "$this"); + CancelButton = _btnCancel; + Controls.Add(_tableLayoutPanel); + HelpButton = true; + MaximizeBox = false; + MinimizeBox = false; + Name = "ToolStripCollectionEditor"; + Padding = new Padding(9); + ShowIcon = false; + ShowInTaskbar = false; + SizeGripStyle = SizeGripStyle.Show; + _tableLayoutPanel.ResumeLayout(false); + _tableLayoutPanel.PerformLayout(); + _addTableLayoutPanel.ResumeLayout(false); + _addTableLayoutPanel.PerformLayout(); + _okCancelTableLayoutPanel.ResumeLayout(false); + _okCancelTableLayoutPanel.PerformLayout(); + ResumeLayout(false); + + // events + HelpButtonClicked += new CancelEventHandler(ToolStripCollectionEditor_HelpButtonClicked); + _newItemTypes.DropDown += new EventHandler(OnnewItemTypes_DropDown); + _newItemTypes.HandleCreated += new EventHandler(OnComboHandleCreated); + _newItemTypes.SelectedIndexChanged += new EventHandler(OnnewItemTypes_SelectedIndexChanged); + _btnAddNew.Click += new EventHandler(OnnewItemTypes_SelectionChangeCommitted); + _btnMoveUp.Click += new EventHandler(OnbtnMoveUp_Click); + _btnMoveDown.Click += new EventHandler(OnbtnMoveDown_Click); + _btnRemove.Click += new EventHandler(OnbtnRemove_Click); + _btnOK.Click += new EventHandler(OnbtnOK_Click); + _selectedItemName.Paint += new PaintEventHandler(OnselectedItemName_Paint); + _listBoxItems.SelectedIndexChanged += new EventHandler(OnlistBoxItems_SelectedIndexChanged); + _listBoxItems.DrawItem += new DrawItemEventHandler(OnlistBoxItems_DrawItem); + _listBoxItems.MeasureItem += new MeasureItemEventHandler(OnlistBoxItems_MeasureItem); + + _selectedItemProps.PropertyValueChanged += new PropertyValueChangedEventHandler(PropertyGrid_propertyValueChanged); + Load += new EventHandler(OnFormLoad); + } + #endregion + + /// + /// Create a new button bitmap scaled for the device units. + /// Note: original image might be disposed. + /// + /// button with an image, image size is defined in logical units + private static void ScaleButtonImageLogicalToDevice(Button button) + { + if (button?.Image is not Bitmap buttonBitmap) + { + return; + } + + button.Image = ScaleHelper.ScaleToDpi(buttonBitmap, ScaleHelper.InitialSystemDpi, disposeBitmap: true); + } + + private void OnComboHandleCreated(object sender, EventArgs e) + { + // BUGBUG: syncing the MeasureItem event forces handle creation. + _newItemTypes.HandleCreated -= new EventHandler(OnComboHandleCreated); + + _newItemTypes.MeasureItem += new MeasureItemEventHandler(OnlistBoxItems_MeasureItem); + _newItemTypes.DrawItem += new DrawItemEventHandler(OnlistBoxItems_DrawItem); + } + + /// + /// Add a new toolStripDropDownItem to our list. This will add a preview toolStripDropDownItem + /// and a list box toolStripDropDownItem as well. + /// + /// The toolStripDropDownItem we're adding + /// The index to add it at, or -1 to add it at the end. + private void AddItem(ToolStripItem newItem, int index) + { + if (index == -1) + { + _itemList.Add(newItem); + } + else + { + // make sure we're legit. + // + if (index < 0 || index >= _itemList.Count) + { + return; + } + + _itemList.Insert(index, newItem); + } + + ToolStrip ownerToolStrip = (Context is not null) ? ToolStripFromObject(Context!.Instance) : null; + // set the owner to be the real windows bar + ownerToolStrip?.Items.Add(newItem); + + // clear the current selection and set a new one. + _listBoxItems.ClearSelected(); + _listBoxItems.SelectedItem = newItem; + } + + /// + /// Move an toolStripDropDownItem from one index to the other. + /// + private void MoveItem(int fromIndex, int toIndex) + { + _itemList.Move(fromIndex, toIndex); + } + + private void OnComponentChanged(object sender, ComponentChangedEventArgs e) + { + if (e.Component is ToolStripItem && e.Member is PropertyDescriptor && e.Member.Name == "Name") + { + _lblItems.Invalidate(); + } + } + + /// + /// Pick up the new collection value. + /// + protected override void OnEditValueChanged() + { + _selectedItemProps.SelectedObjects = null; + Collection = (ToolStripItemCollection)EditValue; + } + + /// + /// Called when the form loads...add the types from the list into the combo box. + /// + /// + /// + private void OnFormLoad(object sender, EventArgs e) + { + // Set the font as appropriate. + _newItemTypes.ItemHeight = Math.Max(s_iconHeight, Font.Height); + + Component component = Context.Instance as Component; + Debug.Assert(component is not null, "why isn't the editor instance a component?"); + if (component is not null) + { + Type[] newToolStripItemTypes = ToolStripDesignerUtils.GetStandardItemTypes(component); + + _newItemTypes.Items.Clear(); + foreach (Type t in newToolStripItemTypes) + { + _newItemTypes.Items.Add(new TypeListItem(t)); + } + + _newItemTypes.SelectedIndex = 0; + + _customItemIndex = -1; + + newToolStripItemTypes = ToolStripDesignerUtils.GetCustomItemTypes(component, component.Site); + if (newToolStripItemTypes.Length > 0) + { + _customItemIndex = _newItemTypes.Items.Count; + foreach (Type t in newToolStripItemTypes) + { + _newItemTypes.Items.Add(new TypeListItem(t)); + } + } + + if (_listBoxItems.Items.Count > 0) + { + _listBoxItems.SelectedIndex = 0; + } + } + } + + /// + /// Handle a click of the OK button. + /// + /// + /// + private void OnbtnOK_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.OK; + } + + private void ToolStripCollectionEditor_HelpButtonClicked(object sender, CancelEventArgs e) + { + e.Cancel = true; + _editor.ShowHelp(); + } + + /// + /// Remove all the selected items. + /// + private void OnbtnRemove_Click(object sender, EventArgs e) + { + // Move the selected items into an array so it doesn't change as we remove from it. + // + ToolStripItem[] items = new ToolStripItem[_listBoxItems.SelectedItems.Count]; + _listBoxItems.SelectedItems.CopyTo(items, 0); + + // now remove each of the items. + // + for (int i = 0; i < items.Length; i++) + { + RemoveItem(items[i]); + } + } + + /// + /// Move the selected toolStripDropDownItem down one notch in the list. + /// + private void OnbtnMoveDown_Click(object sender, EventArgs e) + { + ToolStripItem currentItem = (ToolStripItem)_listBoxItems.SelectedItem; + int currentIndex = _listBoxItems.Items.IndexOf(currentItem); + MoveItem(currentIndex, ++currentIndex); + _listBoxItems.SelectedIndex = currentIndex; + } + + /// + /// Move the selected toolStripDropDownItem up one notch in the list. + /// + private void OnbtnMoveUp_Click(object sender, EventArgs e) + { + ToolStripItem currentItem = (ToolStripItem)_listBoxItems.SelectedItem; + int currentIndex = _listBoxItems.Items.IndexOf(currentItem); + if (currentIndex > 1) + { + MoveItem(currentIndex, --currentIndex); + _listBoxItems.SelectedIndex = currentIndex; + } + } + + /// + /// When we drop the combo, make sure it's wide enough to show the + /// full text from all the items. + /// + private void OnnewItemTypes_DropDown(object sender, EventArgs e) + { + if (_newItemTypes.Tag is null || !(bool)_newItemTypes.Tag) + { + int itemWidth = _newItemTypes.ItemHeight; + int dropDownHeight = 0; + + // walk the items and get the widest one. + // + using (Graphics g = _newItemTypes.CreateGraphics()) + { + foreach (TypeListItem item in _newItemTypes.Items) + { + itemWidth = (int)Math.Max(itemWidth, _newItemTypes.ItemHeight + 1 + g.MeasureString(item.Type.Name, _newItemTypes.Font).Width + GdiPlusFudge); + dropDownHeight += (Font.Height + s_separatorHeight) + 2 * s_imagePaddingY; + } + } + + _newItemTypes.DropDownWidth = itemWidth; + _newItemTypes.DropDownHeight = dropDownHeight; + + // store that we've already done this work. + _newItemTypes.Tag = true; + } + } + + /// + /// When the user makes an actual selection change, add an toolStripDropDownItem to the windows bar. + /// + /// + /// + // Okay to not catch non-CLS compliant exceptions + private void OnnewItemTypes_SelectionChangeCommitted(object sender, EventArgs e) + { + // Get the toolStripDropDownItem type + if (_newItemTypes.SelectedItem is not TypeListItem typeItem) + { + return; + } + + // Create the toolStripDropDownItem + ToolStripItem newItem = (ToolStripItem)CreateInstance(typeItem.Type); + // Set the Image property and DisplayStyle. + if (newItem is ToolStripButton or ToolStripSplitButton or ToolStripDropDownButton) + { + Image image; + try + { + image = new Bitmap(typeof(ToolStripItemEditorForm), "blank.bmp"); + } + catch (Exception) + { + throw; + } + + PropertyDescriptor imageProperty = TypeDescriptor.GetProperties(newItem)["Image"]; + + if (imageProperty is not null && image is not null) + { + imageProperty.SetValue(newItem, image); + } + + PropertyDescriptor displayProperty = TypeDescriptor.GetProperties(newItem)["DisplayStyle"]; + displayProperty?.SetValue(newItem, ToolStripItemDisplayStyle.Image); + + PropertyDescriptor imageTransProperty = TypeDescriptor.GetProperties(newItem)["ImageTransparentColor"]; + imageTransProperty?.SetValue(newItem, Color.Magenta); + } + + // Add it. + AddItem(newItem, -1); + _listBoxItems.Focus(); + } + + /// + /// Just invalidate the combo on a selection change. + /// + private void OnnewItemTypes_SelectedIndexChanged(object sender, EventArgs e) + { + _newItemTypes.Invalidate(); + } + + /// + /// Custom measureItem for the ListBox items... + /// + private void OnlistBoxItems_MeasureItem(object sender, MeasureItemEventArgs e) + { + int separator = 0; + if (sender is ComboBox) + { + bool drawSeparator = e.Index == _customItemIndex; + + if (e.Index >= 0 && drawSeparator) + { + separator = s_separatorHeight; + } + } + + Font measureFont = Font; + e.ItemHeight = Math.Max(s_iconHeight + separator, measureFont.Height + separator) + 2 * s_imagePaddingY; + } + + /// + /// Custom draw the list box toolStripDropDownItem with the icon and the text. We actually share this code b/t the list box and the combo box. + /// + private void OnlistBoxItems_DrawItem(object sender, DrawItemEventArgs e) + { + if (e.Index == -1) + { + return; + } + + // fish out the toolStripDropDownItem type. we're so cool we can share this code + // with just this difference. + Type itemType; + string itemText; + bool indentItem = false; + bool drawSeparator = false; + bool isComboEditBox = ((e.State & DrawItemState.ComboBoxEdit) == DrawItemState.ComboBoxEdit); + + if (sender is ListBox) + { + ListBox listBox = sender as ListBox; + + // the list box has the items directly. + if (listBox.Items[e.Index] is not Component item) + { + Debug.Fail("Unexpected list box toolStripDropDownItem painted!"); + return; + } + + if (item is ToolStripItem) + { + indentItem = true; + } + + itemType = item.GetType(); + itemText = (item.Site is not null) ? item.Site.Name : itemType.Name; + } + else if (sender is ComboBox box) + { + // the combo box has just the types. + // + drawSeparator = ((e.Index == _customItemIndex) && !isComboEditBox); // never draw the separator in the edit box, even if it is the selected index. + if (box.Items[e.Index] is not TypeListItem typeListItem) + { + Debug.Fail("Unexpected combo box toolStripDropDownItem!"); + return; + } + + itemType = typeListItem.Type; + itemText = typeListItem.ToString(); + } + else + { + Debug.Fail("Unexpected sender calling DrawItem"); + return; + } + + // okay, we've got ourselves an toolStripDropDownItem type. draw it. + // + if (itemType is not null) + { + if (drawSeparator) + { + e.Graphics.DrawLine(SystemPens.ControlDark, e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Right - 2, e.Bounds.Y + 2); + } + + // Get the toolbox bitmap, draw it, and then draw the text. We just + // draw the bitmap as a square based on the height of this line toolStripDropDownItem. + // + + // calculate the image rect + Rectangle imageBounds = e.Bounds; + imageBounds.Size = new Size(s_iconWidth, s_iconHeight); + int xOffset = isComboEditBox ? 0 : s_imagePaddingX * 2; + imageBounds.Offset(xOffset, s_imagePaddingX); + + if (drawSeparator) + { + imageBounds.Offset(0, s_separatorHeight); + } + + if (indentItem) + { + imageBounds.X += s_iconWidth + s_indentSpacing; + } + + // make sure after all this we still are within bounds and are square. + if (!isComboEditBox) + { + imageBounds.Intersect(e.Bounds); + } + + // draw the image if it's there + Bitmap tbxBitmap = ToolStripDesignerUtils.GetToolboxBitmap(itemType); + if (tbxBitmap is not null) + { + if (isComboEditBox) + { + // Paint the icon of the combo's textbox area. + e.Graphics.DrawImage(tbxBitmap, e.Bounds.X, e.Bounds.Y, s_iconWidth, s_iconHeight); + } + else + { + e.Graphics.FillRectangle(SystemBrushes.Window, imageBounds); + e.Graphics.DrawImage(tbxBitmap, imageBounds); + } + } + + // calculate the text rect + Rectangle textBounds = e.Bounds; + textBounds.X = imageBounds.Right + s_textImageSpacing; + textBounds.Y = imageBounds.Top - s_imagePaddingY; + if (!isComboEditBox) + { + textBounds.Y += s_imagePaddingY * 2; + } + + textBounds.Intersect(e.Bounds); + + // draw the background as necessary. + Rectangle fillBounds = e.Bounds; + fillBounds.X = textBounds.X - 2; + + if (drawSeparator) + { + fillBounds.Y += s_separatorHeight; + fillBounds.Height -= s_separatorHeight; + } + + Color textColor; + if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) + { + textColor = SystemColors.HighlightText; + e.Graphics.FillRectangle(SystemBrushes.Highlight, fillBounds); + } + else + { + textColor = SystemColors.WindowText; + e.Graphics.FillRectangle(SystemBrushes.Window, fillBounds); + } + + // render the text + if (!string.IsNullOrEmpty(itemText)) + { + TextFormatFlags format = TextFormatFlags.Top | TextFormatFlags.Left; + TextRenderer.DrawText(e.Graphics, itemText, Font, textBounds, textColor, format); + } + + // finally, draw the focus rect. + if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) + { + fillBounds.Width -= 1; + ControlPaint.DrawFocusRectangle(e.Graphics, fillBounds, e.ForeColor, e.BackColor); + } + } + } + + /// + /// Push the selected items into the property grid. + /// + /// + /// + private void OnlistBoxItems_SelectedIndexChanged(object sender, EventArgs e) + { + // push the items into the grid. + // + object[] objList = new object[_listBoxItems.SelectedItems.Count]; + if (objList.Length > 0) + { + _listBoxItems.SelectedItems.CopyTo(objList, 0); + } + + // ToolStrip is selected ... remove the items property + if (objList.Length == 1 && objList[0] is ToolStrip toolStrip) + { + ToolStrip parentStrip = toolStrip; + if (parentStrip is not null && parentStrip.Site is not null) + { + _toolStripCustomTypeDescriptor ??= new ToolStripCustomTypeDescriptor(toolStrip); + + _selectedItemProps.SelectedObjects = [_toolStripCustomTypeDescriptor]; + } + else + { + // if null parentStrip or non sited then don't show the properties. + _selectedItemProps.SelectedObjects = null; + } + } + else + { + _selectedItemProps.SelectedObjects = objList; + } + + // enable the up/down button and the remove button based on the items. + // + _btnMoveUp.Enabled = (_listBoxItems.SelectedItems.Count == 1) && (_listBoxItems.SelectedIndex > 1); + _btnMoveDown.Enabled = (_listBoxItems.SelectedItems.Count == 1) && (_listBoxItems.SelectedIndex < _listBoxItems.Items.Count - 1); + _btnRemove.Enabled = objList.Length > 0; + + // Cannot remove a Win bar thru this CollectionEditor. + foreach (object obj in _listBoxItems.SelectedItems) + { + if (obj is ToolStrip) + { + _btnRemove.Enabled = _btnMoveUp.Enabled = _btnMoveDown.Enabled = false; + break; + } + } + + // Invalidate the list box and the label above the grid. + _listBoxItems.Invalidate(); + _selectedItemName.Invalidate(); + } + + /// + /// Invalidate the ListBox and the SelectedItemName Label on top of the propertyGrid + /// + private void PropertyGrid_propertyValueChanged(object sender, PropertyValueChangedEventArgs e) + { + // Invalidate the list box and the label above the grid. + _listBoxItems.Invalidate(); + _selectedItemName.Invalidate(); + } + + /// + /// Paint the name and type of the currently selected items in the label above the property grid. + /// + private void OnselectedItemName_Paint(object sender, PaintEventArgs e) + { + // make the bolded font for the type name. + // + using Font boldFont = new Font(_selectedItemName.Font, FontStyle.Bold); + Label label = sender as Label; + Rectangle bounds = label.ClientRectangle; + StringFormat stringFormat = null; + + bool rightToLeft = (label.RightToLeft == RightToLeft.Yes); + + if (rightToLeft) + { + stringFormat = new StringFormat(StringFormatFlags.DirectionRightToLeft); + } + else + { + stringFormat = new StringFormat(); + } + + stringFormat.HotkeyPrefix = Drawing.Text.HotkeyPrefix.Show; + + // Based on the count, just paint the name, (Multiple Items), or (None) + switch (_listBoxItems.SelectedItems.Count) + { + case 1: + // for a single toolStripDropDownItem, we paint it's class name in bold, then the toolStripDropDownItem name. + Component selectedItem = null; + if (_listBoxItems.SelectedItem is ToolStrip strip) + { + selectedItem = strip; + } + else + { + selectedItem = (ToolStripItem)_listBoxItems.SelectedItem; + } + + string className = "&" + selectedItem.GetType().Name; + if (selectedItem.Site is not null) + { + // Erase background + e.Graphics.FillRectangle(SystemBrushes.Control, bounds); + string itemName = selectedItem.Site.Name; + + if (label is not null) + { + label.Text = className + itemName; + } + + int classWidth = 0; + classWidth = (int)e.Graphics.MeasureString(className, boldFont).Width; + e.Graphics.DrawString(className, boldFont, SystemBrushes.WindowText, bounds, stringFormat); + int itemTextWidth = (int)e.Graphics.MeasureString(itemName, _selectedItemName.Font).Width; + Rectangle textRect = new Rectangle(classWidth + GdiPlusFudge, 0, bounds.Width - (classWidth + GdiPlusFudge), bounds.Height); + label.AutoEllipsis = itemTextWidth > textRect.Width; + + TextFormatFlags flags = TextFormatFlags.EndEllipsis; + if (rightToLeft) + { + flags |= TextFormatFlags.RightToLeft; + } + + TextRenderer.DrawText(e.Graphics, itemName, _selectedItemName.Font, textRect, SystemColors.WindowText, flags); + } + + break; + case 0: + e.Graphics.FillRectangle(SystemBrushes.Control, bounds); // erase background + if (label is not null) + { + label.Text = SR.ToolStripItemCollectionEditorLabelNone; + } + + e.Graphics.DrawString(SR.ToolStripItemCollectionEditorLabelNone, boldFont, SystemBrushes.WindowText, bounds, stringFormat); + break; + default: + e.Graphics.FillRectangle(SystemBrushes.Control, bounds); // erase background + if (label is not null) + { + label.Text = SR.ToolStripItemCollectionEditorLabelMultipleItems; + } + + e.Graphics.DrawString(SR.ToolStripItemCollectionEditorLabelMultipleItems, boldFont, SystemBrushes.WindowText, bounds, stringFormat); + break; + } + + stringFormat.Dispose(); + } + + /// + /// Removes an toolStripDropDownItem from the list and the preview windows bar + /// + /// + private void RemoveItem(ToolStripItem item) + { + int index; + try + { + // remove the toolStripDropDownItem from the list. + // + index = _itemList.IndexOf(item); + _itemList.Remove(item); + + // destroy the toolStripDropDownItem. This will remove it from the designer as well. + // + } + finally + { + item.Dispose(); + } + + // now set up our selection + // + if (_itemList.Count > 0) + { + _listBoxItems.ClearSelected(); + index = Math.Max(0, Math.Min(index, _listBoxItems.Items.Count - 1)); + _listBoxItems.SelectedIndex = index; + } + } + + /// + /// Fishes out the ToolStrip from the object - which can be a ToolStrip or a ToolStripDropDownItem + /// + internal static ToolStrip ToolStripFromObject(object instance) + { + ToolStrip currentToolStrip = null; + + if (instance is not null) + { + currentToolStrip = instance is ToolStripDropDownItem toolStripDropDownItem ? toolStripDropDownItem.DropDown : instance as ToolStrip; + } + + return currentToolStrip; + } + + private class ImageComboBox : ComboBox + { + public ImageComboBox() + { + } + + private Rectangle ImageRect + { + get + { + // Need to add padding for RTL combo box. + return RightToLeft == RightToLeft.Yes + ? new Rectangle(4 + SystemInformation.HorizontalScrollBarThumbWidth, 3, s_iconWidth, s_iconHeight) + : new Rectangle(3, 3, s_iconWidth, s_iconHeight); + } + } + + protected override void OnDropDownClosed(EventArgs e) + { + base.OnDropDownClosed(e); + Invalidate(ImageRect); + } + + protected override void OnSelectedIndexChanged(EventArgs e) + { + base.OnSelectedIndexChanged(e); + Invalidate(ImageRect); + } + + protected override void WndProc(ref Message m) + { + base.WndProc(ref m); + switch (m.MsgInternal) + { + case PInvokeCore.WM_SETFOCUS: + case PInvokeCore.WM_KILLFOCUS: + Invalidate(ImageRect); + break; + } + } + } + + /// + /// This is a magic collection. It's job is to keep the preview windows bar and the list box in sync and manage both sets of items. + /// It contains a list of EditorItem objects, which whole the information for each toolStripDropDownItem, and a reference to the real ToolStripItem component, + /// the and the preview ToolStripItem. The order and contents of this combo box always match that of the real collection, the list box, and the preview windows bar. + /// It operates generically on three ILists: the list box.Items collection, the previewToolStrip.Items collection, and the actual ToolStripItemCollection being designed. + /// + private class EditorItemCollection : CollectionBase + { + // the ListBox.Items collection + private readonly IList _listBoxList; + // the real deal target collection + private readonly IList _targetCollectionList; + // the owner form that created this collection. + private readonly ToolStripItemEditorForm _owner; + + /// + /// Setup the collection's variables. + /// + internal EditorItemCollection(ToolStripItemEditorForm owner, IList displayList, IList componentList) + { + _owner = owner; + _listBoxList = displayList; + _targetCollectionList = componentList; + } + + /// + /// Add a new win bar item. See OnInsertComplete for the actual add operation. + /// + /// + public void Add(object item) + { + List.Add(new EditorItem(item)); + } + + /// + /// This is a little tricky, since our list doesn't actually contain + /// ToolStripItems, but rather EditorItems, we have to walk those. No bother, + /// this list is always pretty short. + /// + public int IndexOf(ToolStripItem item) + { + for (int i = 0; i < List.Count; i++) + { + EditorItem editorItem = (EditorItem)List[i]!; + if (editorItem.Component == item) + { + return i; + } + } + + return -1; + } + + /// + /// Insert an toolStripDropDownItem into the list somewhere. See OnInsertComplete for the real meaty stuff. + /// + /// + /// + public void Insert(int index, ToolStripItem item) + { + List.Insert(index, new EditorItem(item)); + } + + /// + /// Move an toolStripDropDownItem from one array position to another. + /// + public void Move(int fromIndex, int toIndex) + { + if (toIndex == fromIndex) + { + return; + } + + EditorItem editorItem = (EditorItem)List[fromIndex]!; + if (editorItem.Host is not null) + { + return; + } + + try + { + _owner.Context?.OnComponentChanging(); + + // yank 'em all outate there. + // + _listBoxList.Remove(editorItem.Component); + _targetCollectionList.Remove(editorItem.Component); + + InnerList.Remove(editorItem); + + // put 'em all back in. + _listBoxList.Insert(toIndex, editorItem.Component); + // since ToolStrip is also an toolStripDropDownItem of the listBoxItems + // Lets decrement the counter by one. + + // ToolStrip is Always the TOP toolStripDropDownItem + // so it is SAFE to assume that + // the index that we want is always currentIndex - 1. + + // This is required as the _targetList doesn't contain the ToolStrip. + _targetCollectionList.Insert(toIndex - 1, editorItem.Component); + + InnerList.Insert(toIndex, editorItem); + } + finally + { + _owner.Context?.OnComponentChanged(); + } + } + + /// + /// Clear has a different semantic than remove. Clear simply dumps all the items + /// out of the list box and the preview and zero's this collection. Remove is more + /// destructive in that it affects the target collection. + /// + protected override void OnClear() + { + _listBoxList.Clear(); + foreach (EditorItem item in List) + { + item.Dispose(); + } + + // We don't do sync target list here. + base.OnClear(); + } + + /// + /// After an toolStripDropDownItem is inserted into the collection, we do the work + /// to make sure that we sync up the three lists. + /// + /// + /// + protected override void OnInsertComplete(int index, object value) + { + if (value is null) + { + return; + } + + EditorItem item = (EditorItem)value; + if (item.Host is not null) + { + // Insert into the list box. + _listBoxList.Insert(index, item.Host); + base.OnInsertComplete(index, value); + return; + } + + // check the target collection first, if it's already there, + // chill. Otherwise we need to push it in. In the case that we're + // sync'ing to an existing list, we don't want to be re-adding + // everything. + // + if (!_targetCollectionList.Contains(item.Component)) + { + try + { + _owner.Context?.OnComponentChanging(); + _targetCollectionList.Insert(index - 1, item.Component); + } + finally + { + _owner.Context?.OnComponentChanged(); + } + } + + // insert into the list box and into the preview + // + _listBoxList.Insert(index, item.Component); + base.OnInsertComplete(index, value); + } + + /// + /// Really remove an toolStripDropDownItem from the collections. + /// + /// + /// + protected override void OnRemove(int index, object value) + { + object item = List[index]; + if (item is null) + { + return; + } + + EditorItem editorItem = (EditorItem)item!; + + // pull it from the list box and preview + // + _listBoxList.RemoveAt(index); + + // yank it from the collection. The code that calls this + // collection is responsible for disposing it to destroy + // it in the designer. + // + try + { + _owner.Context?.OnComponentChanging(); + _targetCollectionList.RemoveAt(index - 1); + } + finally + { + _owner.Context?.OnComponentChanged(); + } + + // finally dispose the editor toolStripDropDownItem which cleanup the preview toolStripDropDownItem. + editorItem?.Dispose(); + base.OnRemove(index, value); + } + + /// + /// Remove an toolStripDropDownItem. See OnRemove for the gory details. + /// + /// + public void Remove(ToolStripItem item) + { + int index = IndexOf(item); + List.RemoveAt(index); + } + + /// + /// This class keeps track of the mapping between a win bar item in the designer, in the + /// preview windows bar, and in the list box. + /// + private class EditorItem + { + // The real deal toolStripDropDownItem in the designer. + public ToolStripItem _component; + public ToolStrip _host; + + internal EditorItem(object componentItem) + { + if (componentItem is ToolStrip toolStrip) + { + _host = toolStrip; + } + else + { + _component = (ToolStripItem)componentItem; + } + } + + /// + /// The toolStripDropDownItem that's actually being created in the designer. + /// + public ToolStripItem Component => _component; + + /// + /// The ToolStrip that's actually being created in the designer. + /// + public ToolStrip Host + { + get + { + return _host; + } + } + + /// + /// Cleanup our mess. + /// + public void Dispose() + { + GC.SuppressFinalize(this); + _component = null; + } + } + } + + private class TypeListItem + { + public readonly Type Type; + + public TypeListItem(Type type) + { + Type = type; + } + + public override string ToString() + { + return ToolStripDesignerUtils.GetToolboxDescription(Type); + } + } + } +} diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.cs new file mode 100644 index 00000000000..edd1a8ad422 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.cs @@ -0,0 +1,94 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; +using System.ComponentModel.Design; + +namespace System.Windows.Forms.Design +{ + internal partial class ToolStripCollectionEditor : CollectionEditor + { + /// + /// Default constructor. + /// + public ToolStripCollectionEditor() : base(typeof(ToolStripItemCollection)) + { + } + + /// + /// Overridden to reaction our editor form instead of the standard collection editor form. + /// + /// An instance of a ToolStripItemEditorForm + protected override CollectionForm CreateCollectionForm() => new ToolStripItemEditorForm(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.ToolStripCollectionEditor"; + } + } + + /// + /// Check the owner. + /// + public override object? EditValue(ITypeDescriptorContext? context, IServiceProvider provider, object? value) + { + if (provider is null) + { + return null; + } + + // get ahold of the designer for the component that is launching this editor. + // If it is a win bar, then we want to let it know this editor is up. + ToolStripDesigner? designer = null; + + // see if the selected component is a windows bar or windows bar toolStripDropDownItem that is directly on the form. + ISelectionService? selectionService = provider.GetService(); + if (selectionService is not null) + { + object? primarySelection = selectionService.PrimarySelection; + + // if it's a drop down toolStripDropDownItem, just pop up to it's owner. + if (primarySelection is ToolStripDropDownItem toolStripDropDownItem) + { + primarySelection = toolStripDropDownItem.Owner; + } + + // Now get the designer. + if (primarySelection is ToolStrip) + { + IDesignerHost? host = provider.GetService(); + if (host is not null) + { + designer = host.GetDesigner((IComponent)primarySelection) as ToolStripDesigner; + } + } + } + + try + { + if (designer is not null) + { + designer.EditingCollection = true; + } + + using (ScaleHelper.EnterDpiAwarenessScope(DPI_AWARENESS_CONTEXT.DPI_AWARENESS_CONTEXT_SYSTEM_AWARE)) + { + return base.EditValue(context, provider, value); + } + } + finally + { + if (designer is not null) + { + designer.EditingCollection = false; + } + } + } + } +} diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCustomTypeDescriptor.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCustomTypeDescriptor.cs new file mode 100644 index 00000000000..37aa5643ee6 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCustomTypeDescriptor.cs @@ -0,0 +1,98 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; + +namespace System.Windows.Forms.Design; + +internal class ToolStripCustomTypeDescriptor : CustomTypeDescriptor +{ + private readonly ToolStrip _instance; + private PropertyDescriptor? _propItems; + private PropertyDescriptorCollection? _collection; + + public ToolStripCustomTypeDescriptor(ToolStrip instance) : base() + { + _instance = instance; + } + + /// + /// The GetPropertyOwner method returns an instance of an object that + /// owns the given property for the object this type descriptor is representing. + /// An optional attribute array may be provided to filter the collection that is + /// returned. Returning null from this method causes the TypeDescriptor object + /// to use its default type description services. + /// + /// PropertyDescriptor + /// + public override object GetPropertyOwner(PropertyDescriptor? pd) + { + return _instance; + } + + /// + /// The GetProperties method returns a collection of property descriptors + /// for the object this type descriptor is representing. An optional + /// attribute array may be provided to filter the collection that is returned + /// If no parent is provided,this will return an empty + /// property collection. + /// + /// + public override PropertyDescriptorCollection GetProperties() + { + if (_instance is not null && _collection is null) + { + PropertyDescriptorCollection retColl = TypeDescriptor.GetProperties(_instance); + PropertyDescriptor[] propArray = new PropertyDescriptor[retColl.Count]; + + retColl.CopyTo(propArray, 0); + + _collection = new PropertyDescriptorCollection(propArray, false); + } + + if (_collection?.Count > 0) + { + _propItems = _collection["Items"]; + if (_propItems is not null) + { + _collection.Remove(_propItems); + } + } + + return _collection!; + } + + /// + /// The GetProperties method returns a collection of property descriptors + /// for the object this type descriptor is representing. An optional + /// attribute array may be provided to filter the collection that is returned. + /// If no parent is provided,this will return an empty + /// property collection. + /// Here we will pass the "collection without the "items" property. + /// + /// + /// + public override PropertyDescriptorCollection GetProperties(Attribute[]? attributes) + { + if (_instance is not null && _collection is null) + { + PropertyDescriptorCollection retColl = TypeDescriptor.GetProperties(_instance); + PropertyDescriptor[] propArray = new PropertyDescriptor[retColl.Count]; + + retColl.CopyTo(propArray, 0); + + _collection = new PropertyDescriptorCollection(propArray, false); + } + + if (_collection?.Count > 0) + { + _propItems = _collection["Items"]; + if (_propItems is not null) + { + _collection.Remove(_propItems); + } + } + + return _collection!; + } +} diff --git a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.cs b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.cs index d309900bc3c..8d6913589d6 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.cs @@ -293,11 +293,17 @@ private void CreateDesignSurface(int n) rootComponent.BackColor = Color.Pink; rootComponent.Text = "Root Component hosted by the DesignSurface N.6"; - ToolStripContainer toolStripContainer = surface.CreateControl(new Size(800, 200), new Point(0, 0)); + ToolStripContainer toolStripContainer = surface.CreateControl(new Size(800, 200), new Point(0, 60)); toolStripContainer.Dock = DockStyle.Fill; - MenuStrip menuStrip1 = new(); - MenuStrip menuStrip2 = new(); + ToolStrip toolStrip1 = surface.CreateControl(new Size(400, 50), new Point(0, 0)); + ToolStripButton toolStripButton1 = new("toolStripButton1"); + ToolStripDropDownButton toolStripDropDownButton1 = new("toolStripDropDownButton1"); + toolStrip1.Items.Add(toolStripButton1); + toolStrip1.Items.Add(toolStripDropDownButton1); + + MenuStrip menuStrip1 = surface.CreateControl(new Size(400, 50), new Point(0, 60)); + MenuStrip menuStrip2 = surface.CreateControl(new Size(400, 50), new Point(0, 150)); ToolStripMenuItem toolStripMenuItem1 = new("TopMenuItem1"); ToolStripMenuItem toolStripMenuItem2 = new("TopMenuItem2"); From e20f8cab66027f060bce91b243b0e9e428255415 Mon Sep 17 00:00:00 2001 From: "Leaf Shi (BEYONDSOFT CONSULTING INC)" Date: Sat, 8 Feb 2025 17:04:25 +0800 Subject: [PATCH 2/5] Update blank.bmp and move ToolStripEditorFrom.resx to loc project --- .../System/WinForms/Design/BlankToolstrip.bmp | Bin 0 -> 1078 bytes .../System/WinForms/Design/blank.bmp | Bin 94 -> 0 bytes .../src/System.Windows.Forms.Design.csproj | 10 +- ...ollectionEditor.ToolStripItemEditorForm.cs | 4 +- .../Design}/ToolStripItemEditorForm.resx | 217 ++++++++++-------- .../xlf/ToolStripItemEditorForm.cs.xlf | 0 .../xlf/ToolStripItemEditorForm.de.xlf | 0 .../xlf/ToolStripItemEditorForm.es.xlf | 0 .../xlf/ToolStripItemEditorForm.fr.xlf | 0 .../xlf/ToolStripItemEditorForm.it.xlf | 0 .../xlf/ToolStripItemEditorForm.ja.xlf | 0 .../xlf/ToolStripItemEditorForm.ko.xlf | 0 .../xlf/ToolStripItemEditorForm.pl.xlf | 0 .../xlf/ToolStripItemEditorForm.pt-BR.xlf | 0 .../xlf/ToolStripItemEditorForm.ru.xlf | 0 .../xlf/ToolStripItemEditorForm.tr.xlf | 0 .../xlf/ToolStripItemEditorForm.zh-Hans.xlf | 0 .../xlf/ToolStripItemEditorForm.zh-Hant.xlf | 0 18 files changed, 122 insertions(+), 109 deletions(-) create mode 100644 src/System.Windows.Forms.Design/src/Resources/System/WinForms/Design/BlankToolstrip.bmp delete mode 100644 src/System.Windows.Forms.Design/src/Resources/System/WinForms/Design/blank.bmp rename src/System.Windows.Forms.Design/src/{Resources => System/Windows/Forms/Design}/ToolStripItemEditorForm.resx (80%) rename src/System.Windows.Forms.Design/src/{Resources => System/Windows/Forms/Design}/xlf/ToolStripItemEditorForm.cs.xlf (100%) rename src/System.Windows.Forms.Design/src/{Resources => System/Windows/Forms/Design}/xlf/ToolStripItemEditorForm.de.xlf (100%) rename src/System.Windows.Forms.Design/src/{Resources => System/Windows/Forms/Design}/xlf/ToolStripItemEditorForm.es.xlf (100%) rename src/System.Windows.Forms.Design/src/{Resources => System/Windows/Forms/Design}/xlf/ToolStripItemEditorForm.fr.xlf (100%) rename src/System.Windows.Forms.Design/src/{Resources => System/Windows/Forms/Design}/xlf/ToolStripItemEditorForm.it.xlf (100%) rename src/System.Windows.Forms.Design/src/{Resources => System/Windows/Forms/Design}/xlf/ToolStripItemEditorForm.ja.xlf (100%) rename src/System.Windows.Forms.Design/src/{Resources => System/Windows/Forms/Design}/xlf/ToolStripItemEditorForm.ko.xlf (100%) rename src/System.Windows.Forms.Design/src/{Resources => System/Windows/Forms/Design}/xlf/ToolStripItemEditorForm.pl.xlf (100%) rename src/System.Windows.Forms.Design/src/{Resources => System/Windows/Forms/Design}/xlf/ToolStripItemEditorForm.pt-BR.xlf (100%) rename src/System.Windows.Forms.Design/src/{Resources => System/Windows/Forms/Design}/xlf/ToolStripItemEditorForm.ru.xlf (100%) rename src/System.Windows.Forms.Design/src/{Resources => System/Windows/Forms/Design}/xlf/ToolStripItemEditorForm.tr.xlf (100%) rename src/System.Windows.Forms.Design/src/{Resources => System/Windows/Forms/Design}/xlf/ToolStripItemEditorForm.zh-Hans.xlf (100%) rename src/System.Windows.Forms.Design/src/{Resources => System/Windows/Forms/Design}/xlf/ToolStripItemEditorForm.zh-Hant.xlf (100%) diff --git a/src/System.Windows.Forms.Design/src/Resources/System/WinForms/Design/BlankToolstrip.bmp b/src/System.Windows.Forms.Design/src/Resources/System/WinForms/Design/BlankToolstrip.bmp new file mode 100644 index 0000000000000000000000000000000000000000..3788cf1e87e08b63c730f966734f59a72e1a08c8 GIT binary patch literal 1078 zcmZ?rHDh4_12Z700mK4O%*dbsWI@0YJ_ZI5hJpVK|Nm2hzkU1mpHlp2q4a-pFw9Q8U6!>@nHaa?+kkY diff --git a/src/System.Windows.Forms.Design/src/System.Windows.Forms.Design.csproj b/src/System.Windows.Forms.Design/src/System.Windows.Forms.Design.csproj index 7be4bb0bf1f..d90c206de40 100644 --- a/src/System.Windows.Forms.Design/src/System.Windows.Forms.Design.csproj +++ b/src/System.Windows.Forms.Design/src/System.Windows.Forms.Design.csproj @@ -52,10 +52,8 @@ System.ComponentModel.Design - - System.Windows.Forms.Design - - + + ToolStripCollectionEditor.ToolStripItemEditorForm.cs System.Windows.Forms.Design @@ -79,7 +77,7 @@ - + @@ -98,7 +96,7 @@ System.Windows.Forms.Design.Behavior.%(FileName) - + True diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.ToolStripItemEditorForm.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.ToolStripItemEditorForm.cs index 52198bfbac2..d5fc13c4c50 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.ToolStripItemEditorForm.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.ToolStripItemEditorForm.cs @@ -616,7 +616,7 @@ private void OnnewItemTypes_SelectionChangeCommitted(object sender, EventArgs e) Image image; try { - image = new Bitmap(typeof(ToolStripItemEditorForm), "blank.bmp"); + image = new Bitmap(typeof(ToolStripItemEditorForm), "BlankToolstrip.bmp"); } catch (Exception) { @@ -953,7 +953,7 @@ private void OnselectedItemName_Paint(object sender, PaintEventArgs e) Rectangle textRect = new Rectangle(classWidth + GdiPlusFudge, 0, bounds.Width - (classWidth + GdiPlusFudge), bounds.Height); label.AutoEllipsis = itemTextWidth > textRect.Width; - TextFormatFlags flags = TextFormatFlags.EndEllipsis; + TextFormatFlags flags = TextFormatFlags.EndEllipsis | TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping; if (rightToLeft) { flags |= TextFormatFlags.RightToLeft; diff --git a/src/System.Windows.Forms.Design/src/Resources/ToolStripItemEditorForm.resx b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripItemEditorForm.resx similarity index 80% rename from src/System.Windows.Forms.Design/src/Resources/ToolStripItemEditorForm.resx rename to src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripItemEditorForm.resx index 0b0f7db6fac..bf2513abf03 100644 --- a/src/System.Windows.Forms.Design/src/Resources/ToolStripItemEditorForm.resx +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripItemEditorForm.resx @@ -1,107 +1,122 @@  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 - - - Left, Right - - + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + Left, Right diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.cs.xlf b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.cs.xlf similarity index 100% rename from src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.cs.xlf rename to src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.cs.xlf diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.de.xlf b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.de.xlf similarity index 100% rename from src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.de.xlf rename to src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.de.xlf diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.es.xlf b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.es.xlf similarity index 100% rename from src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.es.xlf rename to src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.es.xlf diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.fr.xlf b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.fr.xlf similarity index 100% rename from src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.fr.xlf rename to src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.fr.xlf diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.it.xlf b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.it.xlf similarity index 100% rename from src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.it.xlf rename to src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.it.xlf diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.ja.xlf b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.ja.xlf similarity index 100% rename from src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.ja.xlf rename to src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.ja.xlf diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.ko.xlf b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.ko.xlf similarity index 100% rename from src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.ko.xlf rename to src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.ko.xlf diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.pl.xlf b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.pl.xlf similarity index 100% rename from src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.pl.xlf rename to src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.pl.xlf diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.pt-BR.xlf b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.pt-BR.xlf similarity index 100% rename from src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.pt-BR.xlf rename to src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.pt-BR.xlf diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.ru.xlf b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.ru.xlf similarity index 100% rename from src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.ru.xlf rename to src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.ru.xlf diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.tr.xlf b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.tr.xlf similarity index 100% rename from src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.tr.xlf rename to src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.tr.xlf diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.zh-Hans.xlf b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.zh-Hans.xlf similarity index 100% rename from src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.zh-Hans.xlf rename to src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.zh-Hans.xlf diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.zh-Hant.xlf b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.zh-Hant.xlf similarity index 100% rename from src/System.Windows.Forms.Design/src/Resources/xlf/ToolStripItemEditorForm.zh-Hant.xlf rename to src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/xlf/ToolStripItemEditorForm.zh-Hant.xlf From e9a0b611c594d1b4421b3a1ec05238f586f548a8 Mon Sep 17 00:00:00 2001 From: "Leaf Shi (BEYONDSOFT CONSULTING INC)" Date: Sat, 8 Feb 2025 18:36:38 +0800 Subject: [PATCH 3/5] Update test cases --- .../System/Windows/Forms/Design/EmbeddedResourceTests.cs | 2 ++ .../IntegrationTests/DesignSurface/DemoConsole/MainForm.cs | 2 ++ .../System/Windows/Forms/Design/DesignerAttributeTests.cs | 1 - 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/EmbeddedResourceTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/EmbeddedResourceTests.cs index 15a280c0c04..c3cc94f1e9b 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/EmbeddedResourceTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/EmbeddedResourceTests.cs @@ -123,6 +123,8 @@ public void EmbeddedResource_ResourcesExist_Bitmap(string resourceName) System.Windows.Forms.Design.ShortcutKeysEditor.resources System.Windows.Forms.Design.StringCollectionEditor.resources System.Windows.Forms.Design.StyleCollectionEditor.resources + System.Windows.Forms.Design.ToolStripItemEditorForm.resources + System.Windows.Forms.Design.BlankToolstrip.bmp """; [Fact] diff --git a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.cs b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.cs index 8d6913589d6..17b8c9a2149 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.cs @@ -299,8 +299,10 @@ private void CreateDesignSurface(int n) ToolStrip toolStrip1 = surface.CreateControl(new Size(400, 50), new Point(0, 0)); ToolStripButton toolStripButton1 = new("toolStripButton1"); ToolStripDropDownButton toolStripDropDownButton1 = new("toolStripDropDownButton1"); + ToolStripTextBox toolStripTextBox= new("toolStripTextBox"); toolStrip1.Items.Add(toolStripButton1); toolStrip1.Items.Add(toolStripDropDownButton1); + toolStrip1.Items.Add(toolStripTextBox); MenuStrip menuStrip1 = surface.CreateControl(new Size(400, 50), new Point(0, 60)); MenuStrip menuStrip2 = surface.CreateControl(new Size(400, 50), new Point(0, 150)); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Design/DesignerAttributeTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Design/DesignerAttributeTests.cs index 04eed97b21d..1ff089a64d9 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Design/DesignerAttributeTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Design/DesignerAttributeTests.cs @@ -32,7 +32,6 @@ public class DesignerAttributeTests $"System.Windows.Forms.Design.StatusBarDesigner, {Assemblies.SystemDesign}", $"System.Windows.Forms.Design.ToolBarButtonDesigner, {Assemblies.SystemDesign}", $"System.Windows.Forms.Design.ToolBarDesigner, {Assemblies.SystemDesign}", - $"System.Windows.Forms.Design.ToolStripCollectionEditor, {Assemblies.SystemDesign}", $"System.Windows.Forms.Design.ToolStripImageIndexEditor, {Assemblies.SystemDesign}", $"System.Windows.Forms.Design.WebBrowserDesigner, {Assemblies.SystemDesign}", ]; From a4964508cd09a7d7771902c806244ac25736971d Mon Sep 17 00:00:00 2001 From: "Leaf Shi (BEYONDSOFT CONSULTING INC)" Date: Tue, 11 Feb 2025 18:45:52 +0800 Subject: [PATCH 4/5] Update some code according to comment --- ...ollectionEditor.ToolStripItemEditorForm.cs | 505 ++++++++---------- .../Forms/Design/ToolStripCollectionEditor.cs | 3 - .../Design/ToolStripCustomTypeDescriptor.cs | 5 +- 3 files changed, 228 insertions(+), 285 deletions(-) diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.ToolStripItemEditorForm.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.ToolStripItemEditorForm.cs index d5fc13c4c50..da4dc6b0e70 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.ToolStripItemEditorForm.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.ToolStripItemEditorForm.cs @@ -12,6 +12,9 @@ namespace System.Windows.Forms.Design; internal partial class ToolStripCollectionEditor { + /// + /// Our internal form UI for the . + /// protected class ToolStripItemEditorForm : CollectionForm { private readonly ToolStripCollectionEditor _editor; @@ -33,9 +36,9 @@ protected class ToolStripItemEditorForm : CollectionForm private ToolStripCustomTypeDescriptor _toolStripCustomTypeDescriptor; /// - /// The amount of fudgespace we use when GDI+ returns us a string length. + /// The amount of space we use when GDI+ returns us a string length. /// - private const int GdiPlusFudge = 5; + private const int GdiPlusExtraSpace = 5; /// /// The collection we're actually editing. @@ -43,17 +46,17 @@ protected class ToolStripItemEditorForm : CollectionForm private ToolStripItemCollection _targetToolStripCollection; /// - /// Our list of items that we're editing. + /// Our list of items that we're editing. /// private EditorItemCollection _itemList; /// - /// The start index of custom items in the new toolStripDropDownItem type dropdown. + /// The start index of custom items in the new type dropdown. /// private int _customItemIndex = -1; /// - /// All our control instance variables. + /// All our control instance variables. /// private TableLayoutPanel _tableLayoutPanel; private TableLayoutPanel _addTableLayoutPanel; @@ -75,7 +78,7 @@ protected class ToolStripItemEditorForm : CollectionForm private readonly string _originalText; /// - /// Create the form and set it up. + /// Create the form and set it up. /// /// The collection editor that spawned us. internal ToolStripItemEditorForm(CollectionEditor parent) : base(parent) @@ -84,13 +87,13 @@ internal ToolStripItemEditorForm(CollectionEditor parent) : base(parent) { if (ScaleHelper.IsScalingRequired) { - s_iconHeight = ICON_DIMENSION; - s_iconWidth = ScaleHelper.ScaleToInitialSystemDpi(ICON_DIMENSION); - s_separatorHeight = ScaleHelper.ScaleToInitialSystemDpi(SEPARATOR_HEIGHT); - s_textImageSpacing = ScaleHelper.ScaleToInitialSystemDpi(TEXT_IMAGE_SPACING); - s_indentSpacing = ScaleHelper.ScaleToInitialSystemDpi(INDENT_SPACING); - s_imagePaddingX = ScaleHelper.ScaleToInitialSystemDpi(IMAGE_PADDING); - s_imagePaddingY = ScaleHelper.ScaleToInitialSystemDpi(IMAGE_PADDING); + s_iconHeight = LogicalToDeviceUnits(ICON_DIMENSION); + s_iconWidth = LogicalToDeviceUnits(ICON_DIMENSION); + s_separatorHeight = LogicalToDeviceUnits(SEPARATOR_HEIGHT); + s_textImageSpacing = LogicalToDeviceUnits(TEXT_IMAGE_SPACING); + s_indentSpacing = LogicalToDeviceUnits(INDENT_SPACING); + s_imagePaddingX = LogicalToDeviceUnits(IMAGE_PADDING); + s_imagePaddingY = LogicalToDeviceUnits(IMAGE_PADDING); } s_isScalingInitialized = true; @@ -111,7 +114,7 @@ internal ToolStripItemEditorForm(CollectionEditor parent) : base(parent) } /// - /// The collection that we're editing. Setting this causes us to sync our contents with that collection. + /// The collection that we're editing. Setting this causes us to sync our contents with that collection. /// internal ToolStripItemCollection Collection { @@ -119,27 +122,23 @@ internal ToolStripItemCollection Collection { if (value != _targetToolStripCollection) { - // clear our existing list of items. - // + // Clear our existing list of items. _itemList?.Clear(); - // add any existing items to our list. - // + // Add any existing items to our list. if (value is not null) { if (Context is not null) { - // create a new list around the new value. - // - _itemList = new EditorItemCollection(this, _listBoxItems.Items, value); + // Create a new list around the new value. + _itemList = new(this, _listBoxItems.Items, value); ToolStrip realToolStrip = ToolStripFromObject(Context.Instance); _itemList.Add(realToolStrip); - ToolStripItem itemInstance = Context.Instance as ToolStripItem; - if (itemInstance is not null && itemInstance.Site is not null) + if (Context.Instance is ToolStripItem itemInstance && itemInstance.Site is not null) { - Text = _originalText + " (" + itemInstance.Site.Name + "." + Context.PropertyDescriptor.Name + ")"; + Text = $"{_originalText} ({itemInstance.Site.Name}.{Context.PropertyDescriptor.Name})"; } foreach (ToolStripItem item in value) @@ -152,10 +151,9 @@ internal ToolStripItemCollection Collection _itemList.Add(item); } - IComponentChangeService changeSvc = (IComponentChangeService)Context.GetService(typeof(IComponentChangeService)); - if (changeSvc is not null) + if (Context.GetService() is IComponentChangeService changeService) { - changeSvc.ComponentChanged += new ComponentChangedEventHandler(OnComponentChanged); + changeService.ComponentChanged += OnComponentChanged; } _selectedItemProps.Site = new PropertyGridSite(Context, _selectedItemProps); @@ -165,7 +163,7 @@ internal ToolStripItemCollection Collection { if (_componentChangeSvc is not null) { - _componentChangeSvc.ComponentChanged -= new ComponentChangedEventHandler(OnComponentChanged); + _componentChangeSvc.ComponentChanged -= OnComponentChanged; } _componentChangeSvc = null; @@ -179,51 +177,45 @@ internal ToolStripItemCollection Collection #region Windows Form Designer generated code /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. /// private void InitializeComponent() { - ComponentResourceManager resources = new ComponentResourceManager(typeof(ToolStripItemEditorForm)); - _btnCancel = new Button(); - _btnOK = new Button(); - _tableLayoutPanel = new TableLayoutPanel(); - _addTableLayoutPanel = new TableLayoutPanel(); - _btnAddNew = new Button(); - _newItemTypes = new ImageComboBox(); - _okCancelTableLayoutPanel = new TableLayoutPanel(); - _lblItems = new Label(); - _selectedItemName = new Label(); - _selectedItemProps = new VsPropertyGrid(); - _lblMembers = new Label(); - _listBoxItems = new FilterListBox(); - _btnMoveUp = new Button(); - _btnMoveDown = new Button(); - _btnRemove = new Button(); + ComponentResourceManager resources = new(typeof(ToolStripItemEditorForm)); + _btnCancel = new(); + _btnOK = new(); + _tableLayoutPanel = new(); + _addTableLayoutPanel = new(); + _btnAddNew = new(); + _newItemTypes = new(); + _okCancelTableLayoutPanel = new(); + _lblItems = new(); + _selectedItemName = new(); + _selectedItemProps = new(); + _lblMembers = new(); + _listBoxItems = new(); + _btnMoveUp = new(); + _btnMoveDown = new(); + _btnRemove = new(); _tableLayoutPanel.SuspendLayout(); _addTableLayoutPanel.SuspendLayout(); _okCancelTableLayoutPanel.SuspendLayout(); SuspendLayout(); - // // btnCancel - // resources.ApplyResources(_btnCancel, "btnCancel"); _btnCancel.DialogResult = DialogResult.Cancel; - _btnCancel.Margin = new Padding(3, 0, 0, 0); + _btnCancel.Margin = new(3, 0, 0, 0); _btnCancel.Name = "btnCancel"; - // // btnOK - // resources.ApplyResources(_btnOK, "btnOK"); - _btnOK.Margin = new Padding(0, 0, 3, 0); + _btnOK.Margin = new(0, 0, 3, 0); _btnOK.Name = "btnOK"; - // // tableLayoutPanel - // resources.ApplyResources(_tableLayoutPanel, "tableLayoutPanel"); - _tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 274F)); - _tableLayoutPanel.ColumnStyles.Add(new ColumnStyle()); - _tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); + _tableLayoutPanel.ColumnStyles.Add(new(SizeType.Absolute, 274F)); + _tableLayoutPanel.ColumnStyles.Add(new()); + _tableLayoutPanel.ColumnStyles.Add(new(SizeType.Percent, 100F)); _tableLayoutPanel.Controls.Add(_addTableLayoutPanel, 0, 1); _tableLayoutPanel.Controls.Add(_okCancelTableLayoutPanel, 0, 6); _tableLayoutPanel.Controls.Add(_lblItems, 0, 0); @@ -235,110 +227,84 @@ private void InitializeComponent() _tableLayoutPanel.Controls.Add(_btnMoveDown, 1, 4); _tableLayoutPanel.Controls.Add(_btnRemove, 1, 5); _tableLayoutPanel.Name = "tableLayoutPanel"; - _tableLayoutPanel.RowStyles.Add(new RowStyle()); - _tableLayoutPanel.RowStyles.Add(new RowStyle()); - _tableLayoutPanel.RowStyles.Add(new RowStyle()); - _tableLayoutPanel.RowStyles.Add(new RowStyle()); - _tableLayoutPanel.RowStyles.Add(new RowStyle()); - _tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); - _tableLayoutPanel.RowStyles.Add(new RowStyle()); - // + _tableLayoutPanel.RowStyles.Add(new()); + _tableLayoutPanel.RowStyles.Add(new()); + _tableLayoutPanel.RowStyles.Add(new()); + _tableLayoutPanel.RowStyles.Add(new()); + _tableLayoutPanel.RowStyles.Add(new()); + _tableLayoutPanel.RowStyles.Add(new(SizeType.Percent, 100F)); + _tableLayoutPanel.RowStyles.Add(new()); // addTableLayoutPanel - // resources.ApplyResources(_addTableLayoutPanel, "addTableLayoutPanel"); - _addTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); - _addTableLayoutPanel.ColumnStyles.Add(new ColumnStyle()); + _addTableLayoutPanel.ColumnStyles.Add(new(SizeType.Percent, 100F)); + _addTableLayoutPanel.ColumnStyles.Add(new()); _addTableLayoutPanel.Controls.Add(_btnAddNew, 1, 0); _addTableLayoutPanel.Controls.Add(_newItemTypes, 0, 0); - _addTableLayoutPanel.Margin = new Padding(0, 3, 3, 3); + _addTableLayoutPanel.Margin = new(0, 3, 3, 3); _addTableLayoutPanel.Name = "addTableLayoutPanel"; _addTableLayoutPanel.AutoSize = true; - _addTableLayoutPanel.RowStyles.Add(new RowStyle()); - // + _addTableLayoutPanel.RowStyles.Add(new()); // btnAddNew - // resources.ApplyResources(_btnAddNew, "btnAddNew"); - _btnAddNew.Margin = new Padding(3, 0, 0, 0); + _btnAddNew.Margin = new(3, 0, 0, 0); _btnAddNew.Name = "btnAddNew"; - // // newItemTypes - // resources.ApplyResources(_newItemTypes, "newItemTypes"); _newItemTypes.DropDownStyle = ComboBoxStyle.DropDownList; _newItemTypes.FormattingEnabled = true; - _newItemTypes.Margin = new Padding(0, 0, 3, 0); + _newItemTypes.Margin = new(0, 0, 3, 0); _newItemTypes.Name = "newItemTypes"; _newItemTypes.DrawMode = DrawMode.OwnerDrawVariable; - // // okCancelTableLayoutPanel - // resources.ApplyResources(_okCancelTableLayoutPanel, "okCancelTableLayoutPanel"); _tableLayoutPanel.SetColumnSpan(_okCancelTableLayoutPanel, 3); - _okCancelTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); - _okCancelTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); + _okCancelTableLayoutPanel.ColumnStyles.Add(new(SizeType.Percent, 50F)); + _okCancelTableLayoutPanel.ColumnStyles.Add(new(SizeType.Percent, 50F)); _okCancelTableLayoutPanel.Controls.Add(_btnOK, 0, 0); _okCancelTableLayoutPanel.Controls.Add(_btnCancel, 1, 0); - _okCancelTableLayoutPanel.Margin = new Padding(3, 6, 0, 0); + _okCancelTableLayoutPanel.Margin = new(3, 6, 0, 0); _okCancelTableLayoutPanel.Name = "okCancelTableLayoutPanel"; - _okCancelTableLayoutPanel.RowStyles.Add(new RowStyle()); - // + _okCancelTableLayoutPanel.RowStyles.Add(new()); // lblItems - // resources.ApplyResources(_lblItems, "lblItems"); - _lblItems.Margin = new Padding(0, 3, 3, 0); + _lblItems.Margin = new(0, 3, 3, 0); _lblItems.Name = "lblItems"; - // // selectedItemName - // resources.ApplyResources(_selectedItemName, "selectedItemName"); - _selectedItemName.Margin = new Padding(3, 3, 3, 0); + _selectedItemName.Margin = new(3, 3, 3, 0); _selectedItemName.Name = "selectedItemName"; - // // selectedItemProps - // _selectedItemProps.CommandsVisibleIfAvailable = false; resources.ApplyResources(_selectedItemProps, "selectedItemProps"); - _selectedItemProps.Margin = new Padding(3, 3, 0, 3); + _selectedItemProps.Margin = new(3, 3, 0, 3); _selectedItemProps.Name = "selectedItemProps"; _tableLayoutPanel.SetRowSpan(_selectedItemProps, 5); - // // lblMembers - // resources.ApplyResources(_lblMembers, "lblMembers"); - _lblMembers.Margin = new Padding(0, 3, 3, 0); + _lblMembers.Margin = new(0, 3, 3, 0); _lblMembers.Name = "lblMembers"; - // // listBoxItems - // resources.ApplyResources(_listBoxItems, "listBoxItems"); _listBoxItems.DrawMode = DrawMode.OwnerDrawVariable; _listBoxItems.FormattingEnabled = true; - _listBoxItems.Margin = new Padding(0, 3, 3, 3); + _listBoxItems.Margin = new(0, 3, 3, 3); _listBoxItems.Name = "listBoxItems"; _tableLayoutPanel.SetRowSpan(_listBoxItems, 3); _listBoxItems.SelectionMode = SelectionMode.MultiExtended; - // // btnMoveUp - // resources.ApplyResources(_btnMoveUp, "btnMoveUp"); - _btnMoveUp.Margin = new Padding(3, 3, 18, 0); + _btnMoveUp.Margin = new(3, 3, 18, 0); _btnMoveUp.Name = "btnMoveUp"; - // // btnMoveDown - // resources.ApplyResources(_btnMoveDown, "btnMoveDown"); - _btnMoveDown.Margin = new Padding(3, 1, 18, 3); + _btnMoveDown.Margin = new(3, 1, 18, 3); _btnMoveDown.Name = "btnMoveDown"; - // // btnRemove - // resources.ApplyResources(_btnRemove, "btnRemove"); - _btnRemove.Margin = new Padding(3, 3, 18, 3); + _btnRemove.Margin = new(3, 3, 18, 3); _btnRemove.Name = "btnRemove"; - // // ToolStripCollectionEditor - // AutoScaleMode = AutoScaleMode.Font; AcceptButton = _btnOK; resources.ApplyResources(this, "$this"); @@ -348,7 +314,7 @@ private void InitializeComponent() MaximizeBox = false; MinimizeBox = false; Name = "ToolStripCollectionEditor"; - Padding = new Padding(9); + Padding = new(9); ShowIcon = false; ShowInTaskbar = false; SizeGripStyle = SizeGripStyle.Show; @@ -360,23 +326,23 @@ private void InitializeComponent() _okCancelTableLayoutPanel.PerformLayout(); ResumeLayout(false); - // events - HelpButtonClicked += new CancelEventHandler(ToolStripCollectionEditor_HelpButtonClicked); - _newItemTypes.DropDown += new EventHandler(OnnewItemTypes_DropDown); - _newItemTypes.HandleCreated += new EventHandler(OnComboHandleCreated); - _newItemTypes.SelectedIndexChanged += new EventHandler(OnnewItemTypes_SelectedIndexChanged); - _btnAddNew.Click += new EventHandler(OnnewItemTypes_SelectionChangeCommitted); - _btnMoveUp.Click += new EventHandler(OnbtnMoveUp_Click); - _btnMoveDown.Click += new EventHandler(OnbtnMoveDown_Click); - _btnRemove.Click += new EventHandler(OnbtnRemove_Click); - _btnOK.Click += new EventHandler(OnbtnOK_Click); - _selectedItemName.Paint += new PaintEventHandler(OnselectedItemName_Paint); - _listBoxItems.SelectedIndexChanged += new EventHandler(OnlistBoxItems_SelectedIndexChanged); - _listBoxItems.DrawItem += new DrawItemEventHandler(OnlistBoxItems_DrawItem); - _listBoxItems.MeasureItem += new MeasureItemEventHandler(OnlistBoxItems_MeasureItem); - - _selectedItemProps.PropertyValueChanged += new PropertyValueChangedEventHandler(PropertyGrid_propertyValueChanged); - Load += new EventHandler(OnFormLoad); + // Events + HelpButtonClicked += ToolStripCollectionEditor_HelpButtonClicked; + _newItemTypes.DropDown += OnNewItemTypes_DropDown; + _newItemTypes.HandleCreated += OnComboHandleCreated; + _newItemTypes.SelectedIndexChanged += OnNewItemTypes_SelectedIndexChanged; + _btnAddNew.Click += OnNewItemTypes_SelectionChangeCommitted; + _btnMoveUp.Click += OnBtnMoveUp_Click; + _btnMoveDown.Click += OnBtnMoveDown_Click; + _btnRemove.Click += OnBtnRemove_Click; + _btnOK.Click += OnBtnOK_Click; + _selectedItemName.Paint += OnSelectedItemName_Paint; + _listBoxItems.SelectedIndexChanged += OnListBoxItems_SelectedIndexChanged; + _listBoxItems.DrawItem += OnListBoxItems_DrawItem; + _listBoxItems.MeasureItem += OnlistBoxItems_MeasureItem; + + _selectedItemProps.PropertyValueChanged += PropertyGrid_propertyValueChanged; + Load += OnFormLoad; } #endregion @@ -398,17 +364,18 @@ private static void ScaleButtonImageLogicalToDevice(Button button) private void OnComboHandleCreated(object sender, EventArgs e) { // BUGBUG: syncing the MeasureItem event forces handle creation. - _newItemTypes.HandleCreated -= new EventHandler(OnComboHandleCreated); + _newItemTypes.HandleCreated -= OnComboHandleCreated; - _newItemTypes.MeasureItem += new MeasureItemEventHandler(OnlistBoxItems_MeasureItem); - _newItemTypes.DrawItem += new DrawItemEventHandler(OnlistBoxItems_DrawItem); + _newItemTypes.MeasureItem += OnlistBoxItems_MeasureItem; + _newItemTypes.DrawItem += OnListBoxItems_DrawItem; } /// - /// Add a new toolStripDropDownItem to our list. This will add a preview toolStripDropDownItem - /// and a list box toolStripDropDownItem as well. + /// Add a new to our list. + /// This will add a preview + /// and a list box as well. /// - /// The toolStripDropDownItem we're adding + /// The we're adding /// The index to add it at, or -1 to add it at the end. private void AddItem(ToolStripItem newItem, int index) { @@ -418,8 +385,7 @@ private void AddItem(ToolStripItem newItem, int index) } else { - // make sure we're legit. - // + // Make sure we're legit. if (index < 0 || index >= _itemList.Count) { return; @@ -428,17 +394,20 @@ private void AddItem(ToolStripItem newItem, int index) _itemList.Insert(index, newItem); } - ToolStrip ownerToolStrip = (Context is not null) ? ToolStripFromObject(Context!.Instance) : null; - // set the owner to be the real windows bar + ToolStrip ownerToolStrip = Context is { Instance: not null } contextInstance + ? ToolStripFromObject(contextInstance) + : null; + + // Set the owner to be the real ToolStrip ownerToolStrip?.Items.Add(newItem); - // clear the current selection and set a new one. + // Clear the current selection and set a new one. _listBoxItems.ClearSelected(); _listBoxItems.SelectedItem = newItem; } /// - /// Move an toolStripDropDownItem from one index to the other. + /// Move an from one index to the other. /// private void MoveItem(int fromIndex, int toIndex) { @@ -454,7 +423,7 @@ private void OnComponentChanged(object sender, ComponentChangedEventArgs e) } /// - /// Pick up the new collection value. + /// Pick up the new collection value. /// protected override void OnEditValueChanged() { @@ -463,7 +432,7 @@ protected override void OnEditValueChanged() } /// - /// Called when the form loads...add the types from the list into the combo box. + /// Called when the form loads...add the types from the list into the combo box. /// /// /// @@ -472,45 +441,45 @@ private void OnFormLoad(object sender, EventArgs e) // Set the font as appropriate. _newItemTypes.ItemHeight = Math.Max(s_iconHeight, Font.Height); - Component component = Context.Instance as Component; - Debug.Assert(component is not null, "why isn't the editor instance a component?"); - if (component is not null) + if (Context.Instance is not Component component) { - Type[] newToolStripItemTypes = ToolStripDesignerUtils.GetStandardItemTypes(component); + return; + } - _newItemTypes.Items.Clear(); - foreach (Type t in newToolStripItemTypes) - { - _newItemTypes.Items.Add(new TypeListItem(t)); - } + Type[] newToolStripItemTypes = ToolStripDesignerUtils.GetStandardItemTypes(component); - _newItemTypes.SelectedIndex = 0; + _newItemTypes.Items.Clear(); + foreach (Type t in newToolStripItemTypes) + { + _newItemTypes.Items.Add(new TypeListItem(t)); + } - _customItemIndex = -1; + _newItemTypes.SelectedIndex = 0; - newToolStripItemTypes = ToolStripDesignerUtils.GetCustomItemTypes(component, component.Site); - if (newToolStripItemTypes.Length > 0) - { - _customItemIndex = _newItemTypes.Items.Count; - foreach (Type t in newToolStripItemTypes) - { - _newItemTypes.Items.Add(new TypeListItem(t)); - } - } + _customItemIndex = -1; - if (_listBoxItems.Items.Count > 0) + newToolStripItemTypes = ToolStripDesignerUtils.GetCustomItemTypes(component, component.Site); + if (newToolStripItemTypes.Length > 0) + { + _customItemIndex = _newItemTypes.Items.Count; + foreach (Type t in newToolStripItemTypes) { - _listBoxItems.SelectedIndex = 0; + _newItemTypes.Items.Add(new TypeListItem(t)); } } + + if (_listBoxItems.Items.Count > 0) + { + _listBoxItems.SelectedIndex = 0; + } } /// - /// Handle a click of the OK button. + /// Handle a click of the OK button. /// /// /// - private void OnbtnOK_Click(object sender, EventArgs e) + private void OnBtnOK_Click(object sender, EventArgs e) { DialogResult = DialogResult.OK; } @@ -522,17 +491,15 @@ private void ToolStripCollectionEditor_HelpButtonClicked(object sender, CancelEv } /// - /// Remove all the selected items. + /// Remove all the selected items. /// - private void OnbtnRemove_Click(object sender, EventArgs e) + private void OnBtnRemove_Click(object sender, EventArgs e) { // Move the selected items into an array so it doesn't change as we remove from it. - // ToolStripItem[] items = new ToolStripItem[_listBoxItems.SelectedItems.Count]; _listBoxItems.SelectedItems.CopyTo(items, 0); - // now remove each of the items. - // + // Now remove each of the items. for (int i = 0; i < items.Length; i++) { RemoveItem(items[i]); @@ -540,9 +507,11 @@ private void OnbtnRemove_Click(object sender, EventArgs e) } /// - /// Move the selected toolStripDropDownItem down one notch in the list. + /// Move the selected down one notch in the list. /// - private void OnbtnMoveDown_Click(object sender, EventArgs e) + /// + /// + private void OnBtnMoveDown_Click(object sender, EventArgs e) { ToolStripItem currentItem = (ToolStripItem)_listBoxItems.SelectedItem; int currentIndex = _listBoxItems.Items.IndexOf(currentItem); @@ -551,9 +520,9 @@ private void OnbtnMoveDown_Click(object sender, EventArgs e) } /// - /// Move the selected toolStripDropDownItem up one notch in the list. + /// Move the selected up one notch in the list. /// - private void OnbtnMoveUp_Click(object sender, EventArgs e) + private void OnBtnMoveUp_Click(object sender, EventArgs e) { ToolStripItem currentItem = (ToolStripItem)_listBoxItems.SelectedItem; int currentIndex = _listBoxItems.Items.IndexOf(currentItem); @@ -565,23 +534,22 @@ private void OnbtnMoveUp_Click(object sender, EventArgs e) } /// - /// When we drop the combo, make sure it's wide enough to show the - /// full text from all the items. + /// When we drop the combo, make sure it's wide enough to show the + /// full text from all the items. /// - private void OnnewItemTypes_DropDown(object sender, EventArgs e) + private void OnNewItemTypes_DropDown(object sender, EventArgs e) { if (_newItemTypes.Tag is null || !(bool)_newItemTypes.Tag) { int itemWidth = _newItemTypes.ItemHeight; int dropDownHeight = 0; - // walk the items and get the widest one. - // + // Walk the items and get the widest one. using (Graphics g = _newItemTypes.CreateGraphics()) { foreach (TypeListItem item in _newItemTypes.Items) { - itemWidth = (int)Math.Max(itemWidth, _newItemTypes.ItemHeight + 1 + g.MeasureString(item.Type.Name, _newItemTypes.Font).Width + GdiPlusFudge); + itemWidth = (int)Math.Max(itemWidth, _newItemTypes.ItemHeight + 1 + g.MeasureString(item.Type.Name, _newItemTypes.Font).Width + GdiPlusExtraSpace); dropDownHeight += (Font.Height + s_separatorHeight) + 2 * s_imagePaddingY; } } @@ -589,26 +557,26 @@ private void OnnewItemTypes_DropDown(object sender, EventArgs e) _newItemTypes.DropDownWidth = itemWidth; _newItemTypes.DropDownHeight = dropDownHeight; - // store that we've already done this work. + // Store that we've already done this work. _newItemTypes.Tag = true; } } /// - /// When the user makes an actual selection change, add an toolStripDropDownItem to the windows bar. + /// When the user makes an actual selection change, add an to the ToolStrip. /// /// /// // Okay to not catch non-CLS compliant exceptions - private void OnnewItemTypes_SelectionChangeCommitted(object sender, EventArgs e) + private void OnNewItemTypes_SelectionChangeCommitted(object sender, EventArgs e) { - // Get the toolStripDropDownItem type + // Get the item type. if (_newItemTypes.SelectedItem is not TypeListItem typeItem) { return; } - // Create the toolStripDropDownItem + // Create the ToolStripItem. ToolStripItem newItem = (ToolStripItem)CreateInstance(typeItem.Type); // Set the Image property and DisplayStyle. if (newItem is ToolStripButton or ToolStripSplitButton or ToolStripDropDownButton) @@ -623,7 +591,7 @@ private void OnnewItemTypes_SelectionChangeCommitted(object sender, EventArgs e) throw; } - PropertyDescriptor imageProperty = TypeDescriptor.GetProperties(newItem)["Image"]; + PropertyDescriptor imageProperty = TypeDescriptor.GetProperties(newItem)[nameof(Image)]; if (imageProperty is not null && image is not null) { @@ -643,15 +611,15 @@ private void OnnewItemTypes_SelectionChangeCommitted(object sender, EventArgs e) } /// - /// Just invalidate the combo on a selection change. + /// Just invalidate the combo on a selection change. /// - private void OnnewItemTypes_SelectedIndexChanged(object sender, EventArgs e) + private void OnNewItemTypes_SelectedIndexChanged(object sender, EventArgs e) { _newItemTypes.Invalidate(); } /// - /// Custom measureItem for the ListBox items... + /// Custom measureItem for the ListBox items... /// private void OnlistBoxItems_MeasureItem(object sender, MeasureItemEventArgs e) { @@ -671,31 +639,30 @@ private void OnlistBoxItems_MeasureItem(object sender, MeasureItemEventArgs e) } /// - /// Custom draw the list box toolStripDropDownItem with the icon and the text. We actually share this code b/t the list box and the combo box. + /// Custom draw the list box item with the icon and the text. + /// We actually share this code between the list box and the combo box. /// - private void OnlistBoxItems_DrawItem(object sender, DrawItemEventArgs e) + private void OnListBoxItems_DrawItem(object sender, DrawItemEventArgs e) { if (e.Index == -1) { return; } - // fish out the toolStripDropDownItem type. we're so cool we can share this code + // Fish out the item type. we're so cool we can share this code // with just this difference. Type itemType; string itemText; bool indentItem = false; bool drawSeparator = false; - bool isComboEditBox = ((e.State & DrawItemState.ComboBoxEdit) == DrawItemState.ComboBoxEdit); + bool isComboEditBox = (e.State & DrawItemState.ComboBoxEdit) == DrawItemState.ComboBoxEdit; - if (sender is ListBox) + if (sender is ListBox listBox) { - ListBox listBox = sender as ListBox; - - // the list box has the items directly. + // The list box has the items directly. if (listBox.Items[e.Index] is not Component item) { - Debug.Fail("Unexpected list box toolStripDropDownItem painted!"); + Debug.Fail("Unexpected list box item painted!"); return; } @@ -709,12 +676,12 @@ private void OnlistBoxItems_DrawItem(object sender, DrawItemEventArgs e) } else if (sender is ComboBox box) { - // the combo box has just the types. - // - drawSeparator = ((e.Index == _customItemIndex) && !isComboEditBox); // never draw the separator in the edit box, even if it is the selected index. + // The combo box has just the types. + // Never draw the separator in the edit box, even if it is the selected index. + drawSeparator = (e.Index == _customItemIndex) && !isComboEditBox; if (box.Items[e.Index] is not TypeListItem typeListItem) { - Debug.Fail("Unexpected combo box toolStripDropDownItem!"); + Debug.Fail("Unexpected combo box item!"); return; } @@ -727,8 +694,7 @@ private void OnlistBoxItems_DrawItem(object sender, DrawItemEventArgs e) return; } - // okay, we've got ourselves an toolStripDropDownItem type. draw it. - // + // Okay, we've got ourselves an item type. draw it. if (itemType is not null) { if (drawSeparator) @@ -738,11 +704,9 @@ private void OnlistBoxItems_DrawItem(object sender, DrawItemEventArgs e) // Get the toolbox bitmap, draw it, and then draw the text. We just // draw the bitmap as a square based on the height of this line toolStripDropDownItem. - // - - // calculate the image rect + // Calculate the image rect Rectangle imageBounds = e.Bounds; - imageBounds.Size = new Size(s_iconWidth, s_iconHeight); + imageBounds.Size = new(s_iconWidth, s_iconHeight); int xOffset = isComboEditBox ? 0 : s_imagePaddingX * 2; imageBounds.Offset(xOffset, s_imagePaddingX); @@ -756,13 +720,13 @@ private void OnlistBoxItems_DrawItem(object sender, DrawItemEventArgs e) imageBounds.X += s_iconWidth + s_indentSpacing; } - // make sure after all this we still are within bounds and are square. + // Make sure after all this we still are within bounds and are square. if (!isComboEditBox) { imageBounds.Intersect(e.Bounds); } - // draw the image if it's there + // Draw the image if it's there Bitmap tbxBitmap = ToolStripDesignerUtils.GetToolboxBitmap(itemType); if (tbxBitmap is not null) { @@ -778,7 +742,7 @@ private void OnlistBoxItems_DrawItem(object sender, DrawItemEventArgs e) } } - // calculate the text rect + // Calculate the text rect Rectangle textBounds = e.Bounds; textBounds.X = imageBounds.Right + s_textImageSpacing; textBounds.Y = imageBounds.Top - s_imagePaddingY; @@ -789,7 +753,7 @@ private void OnlistBoxItems_DrawItem(object sender, DrawItemEventArgs e) textBounds.Intersect(e.Bounds); - // draw the background as necessary. + // Draw the background as necessary. Rectangle fillBounds = e.Bounds; fillBounds.X = textBounds.X - 2; @@ -811,14 +775,14 @@ private void OnlistBoxItems_DrawItem(object sender, DrawItemEventArgs e) e.Graphics.FillRectangle(SystemBrushes.Window, fillBounds); } - // render the text + // Render the text if (!string.IsNullOrEmpty(itemText)) { TextFormatFlags format = TextFormatFlags.Top | TextFormatFlags.Left; TextRenderer.DrawText(e.Graphics, itemText, Font, textBounds, textColor, format); } - // finally, draw the focus rect. + // Finally, draw the focus rect. if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) { fillBounds.Width -= 1; @@ -828,15 +792,14 @@ private void OnlistBoxItems_DrawItem(object sender, DrawItemEventArgs e) } /// - /// Push the selected items into the property grid. + /// Push the selected items into the property grid. /// /// /// - private void OnlistBoxItems_SelectedIndexChanged(object sender, EventArgs e) + private void OnListBoxItems_SelectedIndexChanged(object sender, EventArgs e) { - // push the items into the grid. - // - object[] objList = new object[_listBoxItems.SelectedItems.Count]; + // Push the items into the grid. + object[] objList = [_listBoxItems.SelectedItems.Count]; if (objList.Length > 0) { _listBoxItems.SelectedItems.CopyTo(objList, 0); @@ -848,13 +811,13 @@ private void OnlistBoxItems_SelectedIndexChanged(object sender, EventArgs e) ToolStrip parentStrip = toolStrip; if (parentStrip is not null && parentStrip.Site is not null) { - _toolStripCustomTypeDescriptor ??= new ToolStripCustomTypeDescriptor(toolStrip); + _toolStripCustomTypeDescriptor ??= new(toolStrip); _selectedItemProps.SelectedObjects = [_toolStripCustomTypeDescriptor]; } else { - // if null parentStrip or non sited then don't show the properties. + // If null parentStrip or non sited then don't show the properties. _selectedItemProps.SelectedObjects = null; } } @@ -863,13 +826,12 @@ private void OnlistBoxItems_SelectedIndexChanged(object sender, EventArgs e) _selectedItemProps.SelectedObjects = objList; } - // enable the up/down button and the remove button based on the items. - // + // Enable the up/down button and the remove button based on the items. _btnMoveUp.Enabled = (_listBoxItems.SelectedItems.Count == 1) && (_listBoxItems.SelectedIndex > 1); _btnMoveDown.Enabled = (_listBoxItems.SelectedItems.Count == 1) && (_listBoxItems.SelectedIndex < _listBoxItems.Items.Count - 1); _btnRemove.Enabled = objList.Length > 0; - // Cannot remove a Win bar thru this CollectionEditor. + // Cannot remove a ToolStrip through this CollectionEditor. foreach (object obj in _listBoxItems.SelectedItems) { if (obj is ToolStrip) @@ -885,7 +847,7 @@ private void OnlistBoxItems_SelectedIndexChanged(object sender, EventArgs e) } /// - /// Invalidate the ListBox and the SelectedItemName Label on top of the propertyGrid + /// Invalidate the and the SelectedItemName Label on top of the propertyGrid. /// private void PropertyGrid_propertyValueChanged(object sender, PropertyValueChangedEventArgs e) { @@ -897,11 +859,10 @@ private void PropertyGrid_propertyValueChanged(object sender, PropertyValueChang /// /// Paint the name and type of the currently selected items in the label above the property grid. /// - private void OnselectedItemName_Paint(object sender, PaintEventArgs e) + private void OnSelectedItemName_Paint(object sender, PaintEventArgs e) { - // make the bolded font for the type name. - // - using Font boldFont = new Font(_selectedItemName.Font, FontStyle.Bold); + // Make the bolded font for the type name. + using Font boldFont = new(_selectedItemName.Font, FontStyle.Bold); Label label = sender as Label; Rectangle bounds = label.ClientRectangle; StringFormat stringFormat = null; @@ -910,11 +871,11 @@ private void OnselectedItemName_Paint(object sender, PaintEventArgs e) if (rightToLeft) { - stringFormat = new StringFormat(StringFormatFlags.DirectionRightToLeft); + stringFormat = new(StringFormatFlags.DirectionRightToLeft); } else { - stringFormat = new StringFormat(); + stringFormat = new(); } stringFormat.HotkeyPrefix = Drawing.Text.HotkeyPrefix.Show; @@ -923,7 +884,7 @@ private void OnselectedItemName_Paint(object sender, PaintEventArgs e) switch (_listBoxItems.SelectedItems.Count) { case 1: - // for a single toolStripDropDownItem, we paint it's class name in bold, then the toolStripDropDownItem name. + // For a single toolStripDropDownItem, we paint it's class name in bold, then the toolStripDropDownItem name. Component selectedItem = null; if (_listBoxItems.SelectedItem is ToolStrip strip) { @@ -950,7 +911,7 @@ private void OnselectedItemName_Paint(object sender, PaintEventArgs e) classWidth = (int)e.Graphics.MeasureString(className, boldFont).Width; e.Graphics.DrawString(className, boldFont, SystemBrushes.WindowText, bounds, stringFormat); int itemTextWidth = (int)e.Graphics.MeasureString(itemName, _selectedItemName.Font).Width; - Rectangle textRect = new Rectangle(classWidth + GdiPlusFudge, 0, bounds.Width - (classWidth + GdiPlusFudge), bounds.Height); + Rectangle textRect = new(classWidth + GdiPlusExtraSpace, 0, bounds.Width - (classWidth + GdiPlusExtraSpace), bounds.Height); label.AutoEllipsis = itemTextWidth > textRect.Width; TextFormatFlags flags = TextFormatFlags.EndEllipsis | TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping; @@ -987,7 +948,7 @@ private void OnselectedItemName_Paint(object sender, PaintEventArgs e) } /// - /// Removes an toolStripDropDownItem from the list and the preview windows bar + /// Removes an from the list and the preview ToolStrip /// /// private void RemoveItem(ToolStripItem item) @@ -995,21 +956,16 @@ private void RemoveItem(ToolStripItem item) int index; try { - // remove the toolStripDropDownItem from the list. - // + // Remove the toolStripDropDownItem from the list. index = _itemList.IndexOf(item); _itemList.Remove(item); - - // destroy the toolStripDropDownItem. This will remove it from the designer as well. - // } finally { item.Dispose(); } - // now set up our selection - // + // Now set up our selection if (_itemList.Count > 0) { _listBoxItems.ClearSelected(); @@ -1019,7 +975,7 @@ private void RemoveItem(ToolStripItem item) } /// - /// Fishes out the ToolStrip from the object - which can be a ToolStrip or a ToolStripDropDownItem + /// Fishes out the ToolStrip from the object - which can be a ToolStrip or a /// internal static ToolStrip ToolStripFromObject(object instance) { @@ -1045,8 +1001,8 @@ private Rectangle ImageRect { // Need to add padding for RTL combo box. return RightToLeft == RightToLeft.Yes - ? new Rectangle(4 + SystemInformation.HorizontalScrollBarThumbWidth, 3, s_iconWidth, s_iconHeight) - : new Rectangle(3, 3, s_iconWidth, s_iconHeight); + ? new(4 + SystemInformation.HorizontalScrollBarThumbWidth, 3, s_iconWidth, s_iconHeight) + : new(3, 3, s_iconWidth, s_iconHeight); } } @@ -1076,18 +1032,18 @@ protected override void WndProc(ref Message m) } /// - /// This is a magic collection. It's job is to keep the preview windows bar and the list box in sync and manage both sets of items. - /// It contains a list of EditorItem objects, which whole the information for each toolStripDropDownItem, and a reference to the real ToolStripItem component, - /// the and the preview ToolStripItem. The order and contents of this combo box always match that of the real collection, the list box, and the preview windows bar. - /// It operates generically on three ILists: the list box.Items collection, the previewToolStrip.Items collection, and the actual ToolStripItemCollection being designed. + /// This is a magic collection. It's job is to keep the preview ToolStrip and the list box in sync and manage both sets of items. + /// It contains a list of EditorItem objects, which whole the information for each , and a reference to the real ToolStripItem component, + /// the and the preview ToolStripItem. The order and contents of this combo box always match that of the real collection, the list box, and the preview ToolStrip. + /// It operates generically on three ILists: the list box.Items collection, the previewToolStrip.Items collection, and the actual ToolStripItemCollection being designed. /// private class EditorItemCollection : CollectionBase { - // the ListBox.Items collection + // The ListBox.Items collection private readonly IList _listBoxList; - // the real deal target collection + // The real deal target collection private readonly IList _targetCollectionList; - // the owner form that created this collection. + // The owner form that created this collection. private readonly ToolStripItemEditorForm _owner; /// @@ -1101,7 +1057,7 @@ internal EditorItemCollection(ToolStripItemEditorForm owner, IList displayList, } /// - /// Add a new win bar item. See OnInsertComplete for the actual add operation. + /// Add a new ToolStrip item. See OnInsertComplete for the actual add operation. /// /// public void Add(object item) @@ -1129,7 +1085,7 @@ public int IndexOf(ToolStripItem item) } /// - /// Insert an toolStripDropDownItem into the list somewhere. See OnInsertComplete for the real meaty stuff. + /// Insert an into the list somewhere. See OnInsertComplete for the real meaty stuff. /// /// /// @@ -1139,7 +1095,7 @@ public void Insert(int index, ToolStripItem item) } /// - /// Move an toolStripDropDownItem from one array position to another. + /// Move an from one array position to another. /// public void Move(int fromIndex, int toIndex) { @@ -1158,16 +1114,15 @@ public void Move(int fromIndex, int toIndex) { _owner.Context?.OnComponentChanging(); - // yank 'em all outate there. - // + // Yank 'em all outate there. _listBoxList.Remove(editorItem.Component); _targetCollectionList.Remove(editorItem.Component); InnerList.Remove(editorItem); - // put 'em all back in. + // Put 'em all back in. _listBoxList.Insert(toIndex, editorItem.Component); - // since ToolStrip is also an toolStripDropDownItem of the listBoxItems + // Since ToolStrip is also an toolStripDropDownItem of the listBoxItems // Lets decrement the counter by one. // ToolStrip is Always the TOP toolStripDropDownItem @@ -1203,7 +1158,7 @@ protected override void OnClear() } /// - /// After an toolStripDropDownItem is inserted into the collection, we do the work + /// After an is inserted into the collection, we do the work /// to make sure that we sync up the three lists. /// /// @@ -1224,11 +1179,9 @@ protected override void OnInsertComplete(int index, object value) return; } - // check the target collection first, if it's already there, + // Check the target collection first, if it's already there, // chill. Otherwise we need to push it in. In the case that we're - // sync'ing to an existing list, we don't want to be re-adding - // everything. - // + // sync'ing to an existing list, we don't want to be re-adding everything. if (!_targetCollectionList.Contains(item.Component)) { try @@ -1242,17 +1195,14 @@ protected override void OnInsertComplete(int index, object value) } } - // insert into the list box and into the preview - // + // Insert into the list box and into the preview _listBoxList.Insert(index, item.Component); base.OnInsertComplete(index, value); } /// - /// Really remove an toolStripDropDownItem from the collections. + /// Really remove an from the collections. /// - /// - /// protected override void OnRemove(int index, object value) { object item = List[index]; @@ -1263,14 +1213,12 @@ protected override void OnRemove(int index, object value) EditorItem editorItem = (EditorItem)item!; - // pull it from the list box and preview - // + // Pull it from the list box and preview _listBoxList.RemoveAt(index); - // yank it from the collection. The code that calls this + // Yank it from the collection. The code that calls this // collection is responsible for disposing it to destroy // it in the designer. - // try { _owner.Context?.OnComponentChanging(); @@ -1281,13 +1229,14 @@ protected override void OnRemove(int index, object value) _owner.Context?.OnComponentChanged(); } - // finally dispose the editor toolStripDropDownItem which cleanup the preview toolStripDropDownItem. + // Finally dispose the editor toolStripDropDownItem which cleanup the preview toolStripDropDownItem. editorItem?.Dispose(); base.OnRemove(index, value); } /// - /// Remove an toolStripDropDownItem. See OnRemove for the gory details. + /// Remove an + /// See OnRemove for the gory details. /// /// public void Remove(ToolStripItem item) @@ -1297,8 +1246,8 @@ public void Remove(ToolStripItem item) } /// - /// This class keeps track of the mapping between a win bar item in the designer, in the - /// preview windows bar, and in the list box. + /// This class keeps track of the mapping between a ToolStrip item in the designer, in the + /// preview ToolStrip, and in the list box. /// private class EditorItem { @@ -1319,12 +1268,12 @@ internal EditorItem(object componentItem) } /// - /// The toolStripDropDownItem that's actually being created in the designer. + /// The that's actually being created in the designer. /// public ToolStripItem Component => _component; /// - /// The ToolStrip that's actually being created in the designer. + /// The ToolStrip that's actually being created in the designer. /// public ToolStrip Host { @@ -1335,7 +1284,7 @@ public ToolStrip Host } /// - /// Cleanup our mess. + /// Cleanup our mess. /// public void Dispose() { diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.cs index edd1a8ad422..336e42e22fa 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.cs @@ -8,9 +8,6 @@ namespace System.Windows.Forms.Design { internal partial class ToolStripCollectionEditor : CollectionEditor { - /// - /// Default constructor. - /// public ToolStripCollectionEditor() : base(typeof(ToolStripItemCollection)) { } diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCustomTypeDescriptor.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCustomTypeDescriptor.cs index 37aa5643ee6..6fb5583222a 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCustomTypeDescriptor.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCustomTypeDescriptor.cs @@ -25,10 +25,7 @@ public ToolStripCustomTypeDescriptor(ToolStrip instance) : base() /// /// PropertyDescriptor /// - public override object GetPropertyOwner(PropertyDescriptor? pd) - { - return _instance; - } + public override object GetPropertyOwner(PropertyDescriptor? pd) => _instance; /// /// The GetProperties method returns a collection of property descriptors From 8b1915eb3b3228a1e39a325c3176f6bd53c873ea Mon Sep 17 00:00:00 2001 From: "Leaf Shi (BEYONDSOFT CONSULTING INC)" Date: Wed, 12 Feb 2025 15:05:38 +0800 Subject: [PATCH 5/5] Update all wrong text "toolStripDropDownItem" and rebase to main --- ...ollectionEditor.ToolStripItemEditorForm.cs | 128 ++++++++---------- .../Forms/Design/ToolStripCollectionEditor.cs | 8 +- 2 files changed, 57 insertions(+), 79 deletions(-) diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.ToolStripItemEditorForm.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.ToolStripItemEditorForm.cs index da4dc6b0e70..2437d9c70f4 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.ToolStripItemEditorForm.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.ToolStripItemEditorForm.cs @@ -51,7 +51,7 @@ protected class ToolStripItemEditorForm : CollectionForm private EditorItemCollection _itemList; /// - /// The start index of custom items in the new type dropdown. + /// The start index of custom items in the new item type dropdown. /// private int _customItemIndex = -1; @@ -114,7 +114,7 @@ internal ToolStripItemEditorForm(CollectionEditor parent) : base(parent) } /// - /// The collection that we're editing. Setting this causes us to sync our contents with that collection. + /// The collection that we're editing. Setting this causes us to sync our contents with that collection. /// internal ToolStripItemCollection Collection { @@ -339,7 +339,7 @@ private void InitializeComponent() _selectedItemName.Paint += OnSelectedItemName_Paint; _listBoxItems.SelectedIndexChanged += OnListBoxItems_SelectedIndexChanged; _listBoxItems.DrawItem += OnListBoxItems_DrawItem; - _listBoxItems.MeasureItem += OnlistBoxItems_MeasureItem; + _listBoxItems.MeasureItem += OnListBoxItems_MeasureItem; _selectedItemProps.PropertyValueChanged += PropertyGrid_propertyValueChanged; Load += OnFormLoad; @@ -366,16 +366,15 @@ private void OnComboHandleCreated(object sender, EventArgs e) // BUGBUG: syncing the MeasureItem event forces handle creation. _newItemTypes.HandleCreated -= OnComboHandleCreated; - _newItemTypes.MeasureItem += OnlistBoxItems_MeasureItem; + _newItemTypes.MeasureItem += OnListBoxItems_MeasureItem; _newItemTypes.DrawItem += OnListBoxItems_DrawItem; } /// - /// Add a new to our list. - /// This will add a preview - /// and a list box as well. + /// Add a new item to our list. This will add a preview item + /// and a list box item as well. /// - /// The we're adding + /// The item we're adding /// The index to add it at, or -1 to add it at the end. private void AddItem(ToolStripItem newItem, int index) { @@ -407,7 +406,7 @@ private void AddItem(ToolStripItem newItem, int index) } /// - /// Move an from one index to the other. + /// Move an item from one index to the other. /// private void MoveItem(int fromIndex, int toIndex) { @@ -507,7 +506,7 @@ private void OnBtnRemove_Click(object sender, EventArgs e) } /// - /// Move the selected down one notch in the list. + /// Move the selected item down one notch in the list. /// /// /// @@ -520,7 +519,7 @@ private void OnBtnMoveDown_Click(object sender, EventArgs e) } /// - /// Move the selected up one notch in the list. + /// Move the selected item up one notch in the list. /// private void OnBtnMoveUp_Click(object sender, EventArgs e) { @@ -549,7 +548,8 @@ private void OnNewItemTypes_DropDown(object sender, EventArgs e) { foreach (TypeListItem item in _newItemTypes.Items) { - itemWidth = (int)Math.Max(itemWidth, _newItemTypes.ItemHeight + 1 + g.MeasureString(item.Type.Name, _newItemTypes.Font).Width + GdiPlusExtraSpace); + itemWidth = (int)Math.Max(itemWidth, _newItemTypes.ItemHeight + 1 + + g.MeasureString(item.Type.Name, _newItemTypes.Font).Width + GdiPlusExtraSpace); dropDownHeight += (Font.Height + s_separatorHeight) + 2 * s_imagePaddingY; } } @@ -563,7 +563,7 @@ private void OnNewItemTypes_DropDown(object sender, EventArgs e) } /// - /// When the user makes an actual selection change, add an to the ToolStrip. + /// When the user makes an actual selection change, add an item to the ToolStrip. /// /// /// @@ -581,15 +581,18 @@ private void OnNewItemTypes_SelectionChangeCommitted(object sender, EventArgs e) // Set the Image property and DisplayStyle. if (newItem is ToolStripButton or ToolStripSplitButton or ToolStripDropDownButton) { - Image image; + Image image = null; try { image = new Bitmap(typeof(ToolStripItemEditorForm), "BlankToolstrip.bmp"); } - catch (Exception) + catch (Exception ex) { + if (ex.IsCriticalException()) + { throw; } + } PropertyDescriptor imageProperty = TypeDescriptor.GetProperties(newItem)[nameof(Image)]; @@ -621,7 +624,7 @@ private void OnNewItemTypes_SelectedIndexChanged(object sender, EventArgs e) /// /// Custom measureItem for the ListBox items... /// - private void OnlistBoxItems_MeasureItem(object sender, MeasureItemEventArgs e) + private void OnListBoxItems_MeasureItem(object sender, MeasureItemEventArgs e) { int separator = 0; if (sender is ComboBox) @@ -694,7 +697,7 @@ private void OnListBoxItems_DrawItem(object sender, DrawItemEventArgs e) return; } - // Okay, we've got ourselves an item type. draw it. + // We've got ourselves an item type. draw it. if (itemType is not null) { if (drawSeparator) @@ -703,7 +706,7 @@ private void OnListBoxItems_DrawItem(object sender, DrawItemEventArgs e) } // Get the toolbox bitmap, draw it, and then draw the text. We just - // draw the bitmap as a square based on the height of this line toolStripDropDownItem. + // draw the bitmap as a square based on the height of this line item. // Calculate the image rect Rectangle imageBounds = e.Bounds; imageBounds.Size = new(s_iconWidth, s_iconHeight); @@ -726,7 +729,7 @@ private void OnListBoxItems_DrawItem(object sender, DrawItemEventArgs e) imageBounds.Intersect(e.Bounds); } - // Draw the image if it's there + // Draw the image if it's there. Bitmap tbxBitmap = ToolStripDesignerUtils.GetToolboxBitmap(itemType); if (tbxBitmap is not null) { @@ -775,7 +778,7 @@ private void OnListBoxItems_DrawItem(object sender, DrawItemEventArgs e) e.Graphics.FillRectangle(SystemBrushes.Window, fillBounds); } - // Render the text + // Render the text. if (!string.IsNullOrEmpty(itemText)) { TextFormatFlags format = TextFormatFlags.Top | TextFormatFlags.Left; @@ -799,14 +802,14 @@ private void OnListBoxItems_DrawItem(object sender, DrawItemEventArgs e) private void OnListBoxItems_SelectedIndexChanged(object sender, EventArgs e) { // Push the items into the grid. - object[] objList = [_listBoxItems.SelectedItems.Count]; - if (objList.Length > 0) + object[] selectedItems = [_listBoxItems.SelectedItems.Count]; + if (selectedItems.Length > 0) { - _listBoxItems.SelectedItems.CopyTo(objList, 0); + _listBoxItems.SelectedItems.CopyTo(selectedItems, 0); } - // ToolStrip is selected ... remove the items property - if (objList.Length == 1 && objList[0] is ToolStrip toolStrip) + // ToolStrip is selected. Remove the items property. + if (selectedItems.Length == 1 && selectedItems[0] is ToolStrip toolStrip) { ToolStrip parentStrip = toolStrip; if (parentStrip is not null && parentStrip.Site is not null) @@ -823,13 +826,13 @@ private void OnListBoxItems_SelectedIndexChanged(object sender, EventArgs e) } else { - _selectedItemProps.SelectedObjects = objList; + _selectedItemProps.SelectedObjects = selectedItems; } // Enable the up/down button and the remove button based on the items. _btnMoveUp.Enabled = (_listBoxItems.SelectedItems.Count == 1) && (_listBoxItems.SelectedIndex > 1); _btnMoveDown.Enabled = (_listBoxItems.SelectedItems.Count == 1) && (_listBoxItems.SelectedIndex < _listBoxItems.Items.Count - 1); - _btnRemove.Enabled = objList.Length > 0; + _btnRemove.Enabled = selectedItems.Length > 0; // Cannot remove a ToolStrip through this CollectionEditor. foreach (object obj in _listBoxItems.SelectedItems) @@ -867,33 +870,19 @@ private void OnSelectedItemName_Paint(object sender, PaintEventArgs e) Rectangle bounds = label.ClientRectangle; StringFormat stringFormat = null; - bool rightToLeft = (label.RightToLeft == RightToLeft.Yes); + bool rightToLeft = label.RightToLeft == RightToLeft.Yes; - if (rightToLeft) - { - stringFormat = new(StringFormatFlags.DirectionRightToLeft); - } - else - { - stringFormat = new(); - } + stringFormat = rightToLeft ? new(StringFormatFlags.DirectionRightToLeft) : new(); stringFormat.HotkeyPrefix = Drawing.Text.HotkeyPrefix.Show; - // Based on the count, just paint the name, (Multiple Items), or (None) + // Based on the count, just paint the name, (Multiple Items), or (None). switch (_listBoxItems.SelectedItems.Count) { case 1: - // For a single toolStripDropDownItem, we paint it's class name in bold, then the toolStripDropDownItem name. + // For a single item, we paint it's class name in bold, then the item name. Component selectedItem = null; - if (_listBoxItems.SelectedItem is ToolStrip strip) - { - selectedItem = strip; - } - else - { - selectedItem = (ToolStripItem)_listBoxItems.SelectedItem; - } + selectedItem = _listBoxItems.SelectedItem is ToolStrip strip ? strip : (ToolStripItem)_listBoxItems.SelectedItem; string className = "&" + selectedItem.GetType().Name; if (selectedItem.Site is not null) @@ -925,7 +914,8 @@ private void OnSelectedItemName_Paint(object sender, PaintEventArgs e) break; case 0: - e.Graphics.FillRectangle(SystemBrushes.Control, bounds); // erase background + // Erase background. + e.Graphics.FillRectangle(SystemBrushes.Control, bounds); if (label is not null) { label.Text = SR.ToolStripItemCollectionEditorLabelNone; @@ -934,7 +924,8 @@ private void OnSelectedItemName_Paint(object sender, PaintEventArgs e) e.Graphics.DrawString(SR.ToolStripItemCollectionEditorLabelNone, boldFont, SystemBrushes.WindowText, bounds, stringFormat); break; default: - e.Graphics.FillRectangle(SystemBrushes.Control, bounds); // erase background + // Erase background. + e.Graphics.FillRectangle(SystemBrushes.Control, bounds); if (label is not null) { label.Text = SR.ToolStripItemCollectionEditorLabelMultipleItems; @@ -948,7 +939,7 @@ private void OnSelectedItemName_Paint(object sender, PaintEventArgs e) } /// - /// Removes an from the list and the preview ToolStrip + /// Removes an item from the list and the preview ToolStrip /// /// private void RemoveItem(ToolStripItem item) @@ -956,7 +947,7 @@ private void RemoveItem(ToolStripItem item) int index; try { - // Remove the toolStripDropDownItem from the list. + // Remove the item from the list. index = _itemList.IndexOf(item); _itemList.Remove(item); } @@ -965,7 +956,7 @@ private void RemoveItem(ToolStripItem item) item.Dispose(); } - // Now set up our selection + // Now set up our selection. if (_itemList.Count > 0) { _listBoxItems.ClearSelected(); @@ -1033,15 +1024,15 @@ protected override void WndProc(ref Message m) /// /// This is a magic collection. It's job is to keep the preview ToolStrip and the list box in sync and manage both sets of items. - /// It contains a list of EditorItem objects, which whole the information for each , and a reference to the real ToolStripItem component, + /// It contains a list of EditorItem objects, which whole the information for each item, and a reference to the real ToolStripItem component, /// the and the preview ToolStripItem. The order and contents of this combo box always match that of the real collection, the list box, and the preview ToolStrip. /// It operates generically on three ILists: the list box.Items collection, the previewToolStrip.Items collection, and the actual ToolStripItemCollection being designed. /// private class EditorItemCollection : CollectionBase { - // The ListBox.Items collection + // The ListBox.Items collection. private readonly IList _listBoxList; - // The real deal target collection + // The real deal target collection. private readonly IList _targetCollectionList; // The owner form that created this collection. private readonly ToolStripItemEditorForm _owner; @@ -1085,7 +1076,7 @@ public int IndexOf(ToolStripItem item) } /// - /// Insert an into the list somewhere. See OnInsertComplete for the real meaty stuff. + /// Insert an item into the list somewhere. See OnInsertComplete for the real meaty stuff. /// /// /// @@ -1095,7 +1086,7 @@ public void Insert(int index, ToolStripItem item) } /// - /// Move an from one array position to another. + /// Move an item from one array position to another. /// public void Move(int fromIndex, int toIndex) { @@ -1122,10 +1113,10 @@ public void Move(int fromIndex, int toIndex) // Put 'em all back in. _listBoxList.Insert(toIndex, editorItem.Component); - // Since ToolStrip is also an toolStripDropDownItem of the listBoxItems + // Since ToolStrip is also an item of the listBoxItems // Lets decrement the counter by one. - // ToolStrip is Always the TOP toolStripDropDownItem + // ToolStrip is Always the TOP item // so it is SAFE to assume that // the index that we want is always currentIndex - 1. @@ -1158,7 +1149,7 @@ protected override void OnClear() } /// - /// After an is inserted into the collection, we do the work + /// After an item is inserted into the collection, we do the work /// to make sure that we sync up the three lists. /// /// @@ -1201,7 +1192,7 @@ protected override void OnInsertComplete(int index, object value) } /// - /// Really remove an from the collections. + /// Really remove an item from the collections. /// protected override void OnRemove(int index, object value) { @@ -1229,14 +1220,13 @@ protected override void OnRemove(int index, object value) _owner.Context?.OnComponentChanged(); } - // Finally dispose the editor toolStripDropDownItem which cleanup the preview toolStripDropDownItem. + // Finally dispose the editor item which cleanup the preview item. editorItem?.Dispose(); base.OnRemove(index, value); } /// - /// Remove an - /// See OnRemove for the gory details. + /// Remove an item.See OnRemove for details. /// /// public void Remove(ToolStripItem item) @@ -1251,7 +1241,7 @@ public void Remove(ToolStripItem item) /// private class EditorItem { - // The real deal toolStripDropDownItem in the designer. + // The real deal item in the designer. public ToolStripItem _component; public ToolStrip _host; @@ -1268,20 +1258,14 @@ internal EditorItem(object componentItem) } /// - /// The that's actually being created in the designer. + /// The item that's actually being created in the designer. /// public ToolStripItem Component => _component; /// /// The ToolStrip that's actually being created in the designer. /// - public ToolStrip Host - { - get - { - return _host; - } - } + public ToolStrip Host => _host; /// /// Cleanup our mess. diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.cs index 336e42e22fa..3b20702de56 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.cs @@ -22,13 +22,7 @@ public ToolStripCollectionEditor() : base(typeof(ToolStripItemCollection)) /// 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.ToolStripCollectionEditor"; - } - } + protected override string HelpTopic => "net.ComponentModel.ToolStripCollectionEditor"; /// /// Check the owner.