Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/System.Design/src/System.Design.Forwards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Runtime.CompilerServices;

// internal UITypeEditors
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.BindingNavigatorDesigner))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.BindingSourceDesigner))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ColumnHeaderCollectionEditor))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.DataMemberFieldConverter))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.DataGridViewCellStyleEditor))]
Expand Down
43 changes: 42 additions & 1 deletion src/System.Windows.Forms.Design/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,45 @@ virtual System.ComponentModel.Design.ComponentDesigner.SetTextualDefaultProperty
*REMOVED*~System.Windows.Forms.Design.Behavior.GlyphCollection.AddRange(System.Windows.Forms.Design.Behavior.Glyph[] value) -> void
System.ComponentModel.Design.DesignerActionListCollection.AddRange(params System.ComponentModel.Design.DesignerActionList?[]! value) -> void
~System.Windows.Forms.Design.Behavior.BehaviorServiceAdornerCollection.AddRange(params System.Windows.Forms.Design.Behavior.Adorner[] value) -> void
~System.Windows.Forms.Design.Behavior.GlyphCollection.AddRange(params System.Windows.Forms.Design.Behavior.Glyph[] value) -> void
~System.Windows.Forms.Design.Behavior.GlyphCollection.AddRange(params System.Windows.Forms.Design.Behavior.Glyph[] value) -> void
abstract System.ComponentModel.Design.DataSourceDescriptor.Image.get -> System.Drawing.Bitmap!
abstract System.ComponentModel.Design.DataSourceDescriptor.IsDesignable.get -> bool
abstract System.ComponentModel.Design.DataSourceDescriptor.Name.get -> string!
abstract System.ComponentModel.Design.DataSourceDescriptor.TypeName.get -> string!
abstract System.ComponentModel.Design.DataSourceGroup.DataSources.get -> System.ComponentModel.Design.DataSourceDescriptorCollection!
abstract System.ComponentModel.Design.DataSourceGroup.Image.get -> System.Drawing.Bitmap!
abstract System.ComponentModel.Design.DataSourceGroup.IsDefault.get -> bool
abstract System.ComponentModel.Design.DataSourceGroup.Name.get -> string!
abstract System.ComponentModel.Design.DataSourceProviderService.AddDataSourceInstance(System.ComponentModel.Design.IDesignerHost! host, System.ComponentModel.Design.DataSourceDescriptor! dataSourceDescriptor) -> object!
abstract System.ComponentModel.Design.DataSourceProviderService.GetDataSources() -> System.ComponentModel.Design.DataSourceGroupCollection!
abstract System.ComponentModel.Design.DataSourceProviderService.InvokeAddNewDataSource(System.Windows.Forms.IWin32Window! parentWindow, System.Windows.Forms.FormStartPosition startPosition) -> System.ComponentModel.Design.DataSourceGroup!
abstract System.ComponentModel.Design.DataSourceProviderService.InvokeConfigureDataSource(System.Windows.Forms.IWin32Window! parentWindow, System.Windows.Forms.FormStartPosition startPosition, System.ComponentModel.Design.DataSourceDescriptor! dataSourceDescriptor) -> bool
abstract System.ComponentModel.Design.DataSourceProviderService.NotifyDataSourceComponentAdded(object! dsc) -> void
abstract System.ComponentModel.Design.DataSourceProviderService.SupportsAddNewDataSource.get -> bool
abstract System.ComponentModel.Design.DataSourceProviderService.SupportsConfigureDataSource.get -> bool
System.ComponentModel.Design.DataSourceDescriptor
System.ComponentModel.Design.DataSourceDescriptor.DataSourceDescriptor() -> void
System.ComponentModel.Design.DataSourceDescriptorCollection
System.ComponentModel.Design.DataSourceDescriptorCollection.Add(System.ComponentModel.Design.DataSourceDescriptor! value) -> int
System.ComponentModel.Design.DataSourceDescriptorCollection.Contains(System.ComponentModel.Design.DataSourceDescriptor! value) -> bool
System.ComponentModel.Design.DataSourceDescriptorCollection.CopyTo(System.ComponentModel.Design.DataSourceDescriptor![]! array, int index) -> void
System.ComponentModel.Design.DataSourceDescriptorCollection.DataSourceDescriptorCollection() -> void
System.ComponentModel.Design.DataSourceDescriptorCollection.IndexOf(System.ComponentModel.Design.DataSourceDescriptor! value) -> int
System.ComponentModel.Design.DataSourceDescriptorCollection.Insert(int index, System.ComponentModel.Design.DataSourceDescriptor! value) -> void
System.ComponentModel.Design.DataSourceDescriptorCollection.Remove(System.ComponentModel.Design.DataSourceDescriptor! value) -> void
System.ComponentModel.Design.DataSourceDescriptorCollection.this[int index].get -> System.ComponentModel.Design.DataSourceDescriptor?
System.ComponentModel.Design.DataSourceDescriptorCollection.this[int index].set -> void
System.ComponentModel.Design.DataSourceGroup
System.ComponentModel.Design.DataSourceGroup.DataSourceGroup() -> void
System.ComponentModel.Design.DataSourceGroupCollection
System.ComponentModel.Design.DataSourceGroupCollection.Add(System.ComponentModel.Design.DataSourceGroup! value) -> int
System.ComponentModel.Design.DataSourceGroupCollection.Contains(System.ComponentModel.Design.DataSourceGroup! value) -> bool
System.ComponentModel.Design.DataSourceGroupCollection.CopyTo(System.ComponentModel.Design.DataSourceGroup![]! array, int index) -> void
System.ComponentModel.Design.DataSourceGroupCollection.DataSourceGroupCollection() -> void
System.ComponentModel.Design.DataSourceGroupCollection.IndexOf(System.ComponentModel.Design.DataSourceGroup! value) -> int
System.ComponentModel.Design.DataSourceGroupCollection.Insert(int index, System.ComponentModel.Design.DataSourceGroup! value) -> void
System.ComponentModel.Design.DataSourceGroupCollection.Remove(System.ComponentModel.Design.DataSourceGroup! value) -> void
System.ComponentModel.Design.DataSourceGroupCollection.this[int index].get -> System.ComponentModel.Design.DataSourceGroup?
System.ComponentModel.Design.DataSourceGroupCollection.this[int index].set -> void
System.ComponentModel.Design.DataSourceProviderService
System.ComponentModel.Design.DataSourceProviderService.DataSourceProviderService() -> void
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; }
}
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;
}
}
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; }
}
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;
}
}
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);
}
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)
Copy link
Copy Markdown
Contributor

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 switch

Copy link
Copy Markdown
Member Author

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.

{
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;
}
}
}
Loading