Skip to content

Fix issue 14624: [PropertyGrid] FolderNameEditor does not use the modern FolderBrowserDialog#14635

Open
SimonZhao888 wants to merge 1 commit into
dotnet:mainfrom
SimonZhao888:Fix_Issue_14624
Open

Fix issue 14624: [PropertyGrid] FolderNameEditor does not use the modern FolderBrowserDialog#14635
SimonZhao888 wants to merge 1 commit into
dotnet:mainfrom
SimonZhao888:Fix_Issue_14624

Conversation

@SimonZhao888

Copy link
Copy Markdown
Member

Fixes #14624

Proposed changes

  • Update InitializeDialog(FolderBrowser) → InitializeDialog(FolderBrowserDialog)
  • Refactoring Unit Tests - FolderNameEditorTests.cs

Customer Impact

  • [PropertyGrid] FolderNameEditor use the modern FolderBrowserDialog

Regression?

  • No

Risk

  • Mini

Screenshots

Before

14624-before.mp4

After

14624.mp4

Test methodology

  • Manual testing

Test environment(s)

  • 11.0.100-preview.5.26227.104

Copilot AI left a comment

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.

Pull request overview

This PR updates the WinForms design-time FolderNameEditor used by PropertyGrid so it uses System.Windows.Forms.FolderBrowserDialog (which supports the modern/Vista-style folder picker when AutoUpgradeEnabled is enabled), and adjusts related design-time editors and tests accordingly.

Changes:

  • Replaced the legacy FolderNameEditor.FolderBrowser usage with FolderBrowserDialog, and updated returned path handling to use SelectedPath.
  • Updated SelectedPathEditor / InitialDirectoryEditor overrides to match the new InitializeDialog signature.
  • Refactored/updated unit + UI integration tests and adjusted shipped public API text for the signature change.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/FolderNameEditor.cs Switches the editor implementation to FolderBrowserDialog and updates InitializeDialog signature.
src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/SelectedPathEditor.cs Updates override to configure the new dialog type.
src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/InitialDirectoryEditor.cs Updates override to configure the new dialog type.
src/System.Windows.Forms.Design/src/PublicAPI.Shipped.txt Updates the shipped API entry for FolderNameEditor.InitializeDialog.
src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/FolderNameEditorTests.cs Refactors unit tests around the new dialog type/signature.
src/test/integration/UIIntegrationTests/FolderNameEditorTests.cs Updates UI integration test to use FolderBrowserDialog / SelectedPath.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 38 to 43
/// <summary>
/// Initializes the folder browser dialog when it is created. This gives you an opportunity
/// to configure the dialog as you please. The default implementation provides a generic folder browser.
/// </summary>
protected virtual void InitializeDialog(FolderBrowser folderBrowser)
protected virtual void InitializeDialog(FolderBrowserDialog folderBrowserDialog)
{
private class TestFolderNameEditor : FolderNameEditor
{
private FolderBrowser? _folderBrowser;
private FolderBrowserDialog? _folderBrowser;

@LeafShi1 LeafShi1 left a comment

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.

Thanks for the PR! I have a few concerns — see inline comments.

virtual System.Windows.Forms.Design.DesignerOptions.UseSnapLines.set -> void
virtual System.Windows.Forms.Design.FileNameEditor.InitializeDialog(System.Windows.Forms.OpenFileDialog! openFileDialog) -> void
virtual System.Windows.Forms.Design.FolderNameEditor.InitializeDialog(System.Windows.Forms.Design.FolderNameEditor.FolderBrowser! folderBrowser) -> void
virtual System.Windows.Forms.Design.FolderNameEditor.InitializeDialog(System.Windows.Forms.FolderBrowserDialog! folderBrowserDialog) -> void

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.

This is a binary-breaking change to a shipped public API. Any downstream code that overrides InitializeDialog(FolderBrowser) will fail at both compile time and runtime after this change.

Typically for shipped APIs in dotnet, the old method signature should be kept (marked [Obsolete] or [EditorBrowsable(Never)]) and a new overload with the FolderBrowserDialog parameter should be introduced. The old entry should remain in PublicAPI.Shipped.txt and the new one added to PublicAPI.Unshipped.txt.

Alternatively, if the team has decided this breaking change is acceptable, it should be tracked in the breaking-changes documentation.

private FolderBrowserDialog? _folderBrowserDialog;

public override object? EditValue(ITypeDescriptorContext? context, IServiceProvider provider, object? value)
{

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.

FolderBrowserDialog implements IDisposable (inherits from CommonDialogComponent). Since _folderBrowserDialog is cached as a field but FolderNameEditor does not implement IDisposable, this dialog will never be disposed, leaking native handles.

Consider either:

  1. Making FolderNameEditor implement IDisposable to clean up the dialog, or
  2. Creating the dialog locally in EditValue (inside a using block) instead of caching it as a field — this also avoids stale state between invocations.

{
return _folderBrowser.DirectoryPath;
return _folderBrowser.SelectedPath;
}

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.

The integration test's TestFolderNameEditor diverges from the updated base class — it doesn't set SelectedPath from the incoming value before calling ShowDialog. The base class now does:
csharp _folderBrowserDialog.SelectedPath = value as string ?? string.Empty;
Should this override replicate that behavior so it tests the same flow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[PropertyGrid] FolderNameEditor does not use the modern FolderBrowserDialog

3 participants