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 @@ -49,10 +49,12 @@
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.PrintDialogDesigner))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.RadioButtonDesigner))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.RichTextBoxDesigner))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.SaveFileDialogDesigner))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.SplitContainerDesigner))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.SplitterPanelDesigner))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.SplitterDesigner))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.FlowLayoutPanelDesigner))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.FolderBrowserDialogDesigner))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.TabControlDesigner))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.TableLayoutPanelDesigner))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.TabPageDesigner))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
virtual System.ComponentModel.Design.ComponentDesigner.SetTextualDefaultProperty.get -> bool
*REMOVED*System.ComponentModel.Design.DesignerActionListCollection.AddRange(System.ComponentModel.Design.DesignerActionList?[]! value) -> void
*REMOVED*~System.Windows.Forms.Design.Behavior.BehaviorServiceAdornerCollection.AddRange(System.Windows.Forms.Design.Behavior.Adorner[] value) -> void
*REMOVED*~System.Windows.Forms.Design.Behavior.GlyphCollection.AddRange(System.Windows.Forms.Design.Behavior.Glyph[] value) -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ public partial class ComponentDesigner : ITreeDesigner, IDesignerFilter, ICompon
/// </summary>
public virtual ICollection AssociatedComponents => Array.Empty<IComponent>();

private protected virtual void UpdateTextualDefaultProperty()
{
var component = Component;
if (component?.Site is { } site)
{
PropertyDescriptor defaultProperty = TypeDescriptor.GetDefaultProperty(component);
if (!(defaultProperty is not null && defaultProperty.PropertyType.Equals(typeof(string))))
{
return;
}

if (defaultProperty.GetValue(component) is string currentValue && string.IsNullOrEmpty(currentValue))
{
defaultProperty.SetValue(component, site.Name);
}
}
}

internal virtual bool CanBeAssociatedWith(IDesigner parentDesigner) => true;

/// <summary>
Expand Down Expand Up @@ -125,6 +143,15 @@ public virtual void InitializeNewComponent(IDictionary defaultValues)
{
// execute legacy code
InitializeNonDefault();

// Note: This was originally an obsoleted API called OnSetComponentDefaults(). The
// default behavior of this API was to set the the default property to the component's
// site name, if the property was a string and null or empty. We've removed the API
// but preserved the same behavior, now controlled by SetTextualDefaultProperty.
if (SetTextualDefaultProperty)
{
UpdateTextualDefaultProperty();
}
}

void IDesignerFilter.PostFilterAttributes(IDictionary attributes) => PostFilterAttributes(attributes);
Expand All @@ -149,6 +176,12 @@ public virtual void InitializeNewComponent(IDictionary defaultValues)
/// </summary>
public virtual DesignerVerbCollection Verbs => _verbs ??= new DesignerVerbCollection();

/// <summary>
/// Controls whether the default property of <see cref="Component"/> is automatically set
/// to <see cref="ISite.Name"/> on creation. The default is <see langword="true"/>.
/// </summary>
protected virtual bool SetTextualDefaultProperty => true;

ICollection ITreeDesigner.Children
{
get
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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;

namespace System.Windows.Forms.Design;

internal class FolderBrowserDialogDesigner : ComponentDesigner
{
// Overridden to avoid setting the default property ("SelectedPath")
// to the Site.Name (i.e. folderBrowserDialog1).
protected override bool SetTextualDefaultProperty => false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public unsafe DialogResult ShowDialog(IWin32Window? owner)
}

// Retrieve the path from the IDList.
PWSTR selectedPath = default;
PWSTR selectedPath = pDisplayName;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this change for?

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.

I don't know why the value was set to "default" before, but the default value always points to "0", and when I set the property value, such as FolderBrowerDialog's SelectedPath, an exception occurs.
image

Compare with the code with NexFx, the selectedPath should use pDisplayName pointer.

PInvoke.SHGetPathFromIDList(browseHandle, selectedPath);
DirectoryPath = new string((char*)selectedPath);
return DialogResult.OK;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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;

namespace System.Windows.Forms.Design;

internal class SaveFileDialogDesigner : ComponentDesigner
{
// Overridden to avoid setting the default property ("FileName")
// to the Site.Name (i.e. saveFileDialog1).
protected override bool SetTextualDefaultProperty => false;
}
Loading