-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Port ColumnHeaderCollectionEditor #2345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5eca7ef
Added ColumnHeaderCollectionEditor
JuditRose 9d7e0f1
cleanup
JuditRose fe11672
Merge branch 'master' into jvrozsa/ColumnHeaderCollectionEditor
JuditRose 495e675
added unit test for column header collection editor
JuditRose 88f33d9
Merge branch 'master' into jvrozsa/ColumnHeaderCollectionEditor
JuditRose e89d9d0
add type forwarding
JuditRose File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...dows.Forms.Design.Editors/src/System/Windows/Forms/Design/ColumnHeaderCollectionEditor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System.ComponentModel; | ||
| using System.ComponentModel.Design; | ||
|
|
||
| namespace System.Windows.Forms.Design | ||
| { | ||
| internal class ColumnHeaderCollectionEditor : CollectionEditor | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref='System.Windows.Forms.Design.ImageCollectionEditor'/> class. | ||
| /// </summary> | ||
| public ColumnHeaderCollectionEditor(Type type) : base(type) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the help topic to display for the dialog help button or pressing F1. Override to display a different help topic. | ||
| /// </summary> | ||
| protected override string HelpTopic | ||
| { | ||
| get => "net.ComponentModel.ColumnHeaderCollectionEditor"; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Sets the specified collection to have the specified array of items. | ||
| /// </summary> | ||
| protected override object SetItems(object editValue, object[] value) | ||
| { | ||
| if (editValue is ListView.ColumnHeaderCollection list) | ||
JuditRose marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| list.Clear(); | ||
| ColumnHeader[] colHeaders = new ColumnHeader[value.Length]; | ||
| Array.Copy(value, 0, colHeaders, 0, value.Length); | ||
| list.AddRange(colHeaders); | ||
| } | ||
| return editValue; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Removes the item from listview column header collection | ||
| /// </summary> | ||
| internal override void OnItemRemoving(object item) | ||
| { | ||
| if (!(Context.Instance is ListView listview)) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (item is ColumnHeader column) | ||
JuditRose marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| IComponentChangeService cs = GetService(typeof(IComponentChangeService)) as IComponentChangeService; | ||
| PropertyDescriptor itemsProp = null; | ||
| if (cs != null) | ||
| { | ||
| itemsProp = TypeDescriptor.GetProperties(Context.Instance)["Columns"]; | ||
| cs.OnComponentChanging(Context.Instance, itemsProp); | ||
| } | ||
| listview.Columns.Remove(column); | ||
|
|
||
| if (cs != null && itemsProp != null) | ||
| { | ||
| cs.OnComponentChanged(Context.Instance, itemsProp, null, null); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
27 changes: 27 additions & 0 deletions
27
...Editors/tests/UnitTests/System/Windows/Forms/Design/ColumnHeaderCollectionEditorTests .cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using Xunit; | ||
|
|
||
| namespace System.Windows.Forms.Design.Tests | ||
| { | ||
| public class ColumnHeaderCollectionEditorTests | ||
| { | ||
| [Fact] | ||
| public void ColumnHeaderCollectionEditor_Ctor_Default() | ||
| { | ||
| var editor = new ColumnHeaderCollectionEditor(typeof(string)); | ||
| Assert.False(editor.IsDropDownResizable); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ColumnHeaderCollectionEditor_EditValue_ReturnsValue() | ||
| { | ||
| var editor = new ColumnHeaderCollectionEditor(typeof(string)); | ||
| string[] value = new string[] { "asdf", "qwer", "zxcv" }; | ||
|
|
||
| Assert.Same(value, editor.EditValue(null, value)); | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.