-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Port BindingSourceDesigner, BindingNavigatorDesigner to runtime #9749
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
SimonZhao888
merged 5 commits into
dotnet:main
from
SimonZhao888:Issue_4908_Port_BindingNavigatorDesignerAndBindingSourceDesigner
Aug 28, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
28af1e2
Port BindingSourceDesigner, BindingNavigatorDesigner to runtime
0b5f3b7
Update BindingSource control localtion in DemoConsole app
9448c02
Update code style.
72a3336
Update code style
366da42
update the code style in DemoConsole project
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
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
17 changes: 17 additions & 0 deletions
17
src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DataSourceDescriptor.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,17 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Drawing; | ||
|
|
||
| namespace System.ComponentModel.Design; | ||
|
|
||
| public abstract class DataSourceDescriptor | ||
| { | ||
| public abstract string Name { get; } | ||
|
|
||
| public abstract Bitmap Image { get; } | ||
|
|
||
| public abstract string TypeName { get; } | ||
|
|
||
| public abstract bool IsDesignable { get; } | ||
| } |
31 changes: 31 additions & 0 deletions
31
...m.Windows.Forms.Design/src/System/ComponentModel/Design/DataSourceDescriptorCollection.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,31 @@ | ||
| // 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; | ||
|
|
||
| namespace System.ComponentModel.Design; | ||
|
|
||
| public class DataSourceDescriptorCollection : CollectionBase | ||
| { | ||
| public DataSourceDescriptorCollection() : base() | ||
| { | ||
| } | ||
|
|
||
| public int Add(DataSourceDescriptor value) => List.Add(value); | ||
|
|
||
| public int IndexOf(DataSourceDescriptor value) => List.IndexOf(value); | ||
|
|
||
| public void Insert(int index, DataSourceDescriptor value) => List.Insert(index, value); | ||
|
|
||
| public bool Contains(DataSourceDescriptor value) => List.Contains(value); | ||
|
|
||
| public void CopyTo(DataSourceDescriptor[] array, int index) => List.CopyTo(array, index); | ||
|
|
||
| public void Remove(DataSourceDescriptor value) => List.Remove(value); | ||
|
|
||
| public DataSourceDescriptor? this[int index] | ||
| { | ||
| get => List[index] as DataSourceDescriptor; | ||
| set => List[index] = value; | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DataSourceGroup.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,17 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Drawing; | ||
|
|
||
| namespace System.ComponentModel.Design; | ||
|
|
||
| public abstract class DataSourceGroup | ||
| { | ||
| public abstract string Name { get; } | ||
|
|
||
| public abstract Bitmap Image { get; } | ||
|
|
||
| public abstract DataSourceDescriptorCollection DataSources { get; } | ||
|
|
||
| public abstract bool IsDefault { get; } | ||
| } |
32 changes: 32 additions & 0 deletions
32
...System.Windows.Forms.Design/src/System/ComponentModel/Design/DataSourceGroupCollection.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,32 @@ | ||
| // 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; | ||
|
|
||
| namespace System.ComponentModel.Design; | ||
|
|
||
| public class DataSourceGroupCollection : CollectionBase | ||
| { | ||
| public DataSourceGroupCollection() : base() | ||
| { | ||
| } | ||
|
|
||
| public int Add(DataSourceGroup value) => List.Add(value); | ||
|
|
||
| public int IndexOf(DataSourceGroup value) => List.IndexOf(value); | ||
|
|
||
| public void Insert(int index, DataSourceGroup value) => List.Insert(index, value); | ||
|
|
||
| public bool Contains(DataSourceGroup value) => List.Contains(value); | ||
|
|
||
| public void CopyTo(DataSourceGroup[] array, int index) => List.CopyTo(array, index); | ||
|
|
||
| public void Remove(DataSourceGroup value) => List.Remove(value); | ||
|
|
||
| public DataSourceGroup? this[int index] | ||
| { | ||
| get => List[index] as DataSourceGroup; | ||
|
|
||
| set => List[index] = value; | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
...System.Windows.Forms.Design/src/System/ComponentModel/Design/DataSourceProviderService.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,25 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Runtime.InteropServices; | ||
| using System.Windows.Forms; | ||
|
|
||
| namespace System.ComponentModel.Design; | ||
|
|
||
| [Guid("ABE5C1F0-C96E-40c4-A22D-4A5CEC899BDC")] | ||
| public abstract class DataSourceProviderService | ||
| { | ||
| public abstract bool SupportsAddNewDataSource { get; } | ||
|
|
||
| public abstract bool SupportsConfigureDataSource { get; } | ||
|
|
||
| public abstract DataSourceGroupCollection GetDataSources(); | ||
|
|
||
| public abstract DataSourceGroup InvokeAddNewDataSource(IWin32Window parentWindow, FormStartPosition startPosition); | ||
|
|
||
| public abstract bool InvokeConfigureDataSource(IWin32Window parentWindow, FormStartPosition startPosition, DataSourceDescriptor dataSourceDescriptor); | ||
|
|
||
| public abstract object AddDataSourceInstance(IDesignerHost host, DataSourceDescriptor dataSourceDescriptor); | ||
|
|
||
| public abstract void NotifyDataSourceComponentAdded(object dsc); | ||
| } |
180 changes: 180 additions & 0 deletions
180
src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/BindingNavigatorDesigner.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,180 @@ | ||
| // 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.Design; | ||
| using System.ComponentModel; | ||
| using System.Collections; | ||
|
|
||
| namespace System.Windows.Forms.Design; | ||
|
|
||
| internal class BindingNavigatorDesigner : ToolStripDesigner | ||
| { | ||
| private static readonly string[] s_itemNames = | ||
| [ | ||
| "MovePreviousItem", | ||
| "MoveFirstItem", | ||
| "MoveNextItem", | ||
| "MoveLastItem", | ||
| "AddNewItem", | ||
| "DeleteItem", | ||
| "PositionItem", | ||
| "CountItem" | ||
| ]; | ||
|
|
||
| public override void Initialize(IComponent component) | ||
| { | ||
| base.Initialize(component); | ||
|
|
||
| IComponentChangeService componentChangeService = GetService<IComponentChangeService>(); | ||
| if (componentChangeService is not null) | ||
| { | ||
| componentChangeService.ComponentRemoved += ComponentChangeService_ComponentRemoved; | ||
| componentChangeService.ComponentChanged += ComponentChangeService_ComponentChanged; | ||
| } | ||
| } | ||
|
|
||
| protected override void Dispose(bool disposing) | ||
| { | ||
| if (disposing) | ||
| { | ||
| IComponentChangeService componentChangeService = GetService<IComponentChangeService>(); | ||
| if (componentChangeService is not null) | ||
| { | ||
| componentChangeService.ComponentRemoved -= ComponentChangeService_ComponentRemoved; | ||
| componentChangeService.ComponentChanged -= ComponentChangeService_ComponentChanged; | ||
| } | ||
| } | ||
|
|
||
| base.Dispose(disposing); | ||
| } | ||
|
|
||
| public override void InitializeNewComponent(IDictionary defaultValues) | ||
| { | ||
| base.InitializeNewComponent(defaultValues); | ||
|
|
||
| BindingNavigator navigator = (BindingNavigator)Component; | ||
| IDesignerHost? host = Component?.Site?.GetService<IDesignerHost>(); | ||
|
|
||
| try | ||
| { | ||
| s_autoAddNewItems = false; // Temporarily suppress "new items go to the selected strip" behavior | ||
| navigator.SuspendLayout(); // Turn off layout while adding items | ||
| navigator.AddStandardItems(); // Let the control add its standard items (user overridable) | ||
| SiteItems(host: host, items: navigator.Items); // Recursively site and name all the items on the strip | ||
| RaiseItemsChanged(); // Make designer Undo engine aware of the newly added and sited items | ||
| navigator.ResumeLayout(); // Allow strip to lay out now | ||
| navigator.ShowItemToolTips = true; // Non-default property setting for ShowToolTips | ||
| } | ||
| finally | ||
| { | ||
| s_autoAddNewItems = true; | ||
| } | ||
| } | ||
|
|
||
| private void RaiseItemsChanged() | ||
| { | ||
| BindingNavigator navigator = (BindingNavigator)Component; | ||
| IComponentChangeService componentChangeService = GetService<IComponentChangeService>(); | ||
|
|
||
| if (componentChangeService is not null) | ||
| { | ||
| MemberDescriptor? memberDescriptor = TypeDescriptor.GetProperties(navigator)["Items"]; | ||
| componentChangeService.OnComponentChanging(component: navigator, member: memberDescriptor); | ||
| componentChangeService.OnComponentChanged(component: navigator, member: memberDescriptor, oldValue: null, newValue: null); | ||
|
|
||
| foreach (string itemName in s_itemNames) | ||
| { | ||
| PropertyDescriptor? propertyDescriptor = TypeDescriptor.GetProperties(navigator)[itemName]; | ||
|
|
||
| if (propertyDescriptor is not null) | ||
| { | ||
| componentChangeService.OnComponentChanging(component: navigator, member: propertyDescriptor); | ||
| componentChangeService.OnComponentChanged(component: navigator, member: propertyDescriptor, oldValue: null, newValue: null); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void SiteItem(IDesignerHost? host, ToolStripItem item) | ||
| { | ||
| // Skip any controls added for design-time use only | ||
| if (item is DesignerToolStripControlHost) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| // Site the item in the container, giving it a unique site name based on its initial Name property | ||
| host?.Container.Add(item, DesignerUtils.GetUniqueSiteName(host, item.Name)); | ||
|
|
||
| // Update the item's Name property to reflect the unique site name that it was actually given | ||
| item.Name = item?.Site?.Name; | ||
|
|
||
| // Site any sub-items of this item | ||
| ToolStripDropDownItem? dropDownItem = item as ToolStripDropDownItem; | ||
| if (dropDownItem is not null && dropDownItem.HasDropDownItems) | ||
| { | ||
| SiteItems(host: host, items: dropDownItem.DropDownItems); | ||
| } | ||
| } | ||
|
|
||
| private void SiteItems(IDesignerHost? host, ToolStripItemCollection items) | ||
| { | ||
| foreach (ToolStripItem item in items) | ||
| { | ||
| SiteItem(host, item); | ||
| } | ||
| } | ||
|
|
||
| private void ComponentChangeService_ComponentRemoved(object? sender, ComponentEventArgs e) | ||
| { | ||
| ToolStripItem? item = e.Component as ToolStripItem; | ||
|
|
||
| if (item is not null) | ||
| { | ||
| BindingNavigator navigator = (BindingNavigator)Component; | ||
|
|
||
| if (item == navigator.MoveFirstItem) | ||
| { | ||
| navigator.MoveFirstItem = null; | ||
| } | ||
| else if (item == navigator.MovePreviousItem) | ||
| { | ||
| navigator.MovePreviousItem = null; | ||
| } | ||
| else if (item == navigator.MoveNextItem) | ||
| { | ||
| navigator.MoveNextItem = null; | ||
| } | ||
| else if (item == navigator.MoveLastItem) | ||
| { | ||
| navigator.MoveLastItem = null; | ||
| } | ||
| else if (item == navigator.PositionItem) | ||
| { | ||
| navigator.PositionItem = null; | ||
| } | ||
| else if (item == navigator.CountItem) | ||
| { | ||
| navigator.CountItem = null; | ||
| } | ||
| else if (item == navigator.AddNewItem) | ||
| { | ||
| navigator.AddNewItem = null; | ||
| } | ||
| else if (item == navigator.DeleteItem) | ||
| { | ||
| navigator.DeleteItem = null; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void ComponentChangeService_ComponentChanged(object? sender, ComponentChangedEventArgs e) | ||
| { | ||
| BindingNavigator navigator = (BindingNavigator)Component; | ||
|
|
||
| if (e.Component is not null && e.Component == navigator.CountItem && e.Member is not null && e.Member.Name == "Text") | ||
| { | ||
| navigator.CountItemFormat = navigator.CountItem.Text ?? string.Empty; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code would be more readable if you used a
switchThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since navigator.MoveFirstItem etc. are not constants, switch cannot be used here.