KEMBAR78
Add OpenFolderDialog v2 by Symbai · Pull Request #4039 · dotnet/wpf · GitHub
Skip to content

Conversation

@Symbai
Copy link
Contributor

@Symbai Symbai commented Jan 20, 2021

Fixes #438, this is mostly a copy of @miloush's work based on the feedback on my previous attempt.

@Symbai Symbai requested a review from a team as a code owner January 20, 2021 21:17
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Jan 20, 2021
@ghost ghost requested review from SamBent, fabiant3 and ryalanms January 20, 2021 21:18
@miloush
Copy link
Contributor

miloush commented Jan 25, 2021

The reason I haven't submitted a PR myself is that I wasn't able to test the code. Did you manage to run it from an app?

It looks like the only thing you changed is the name - I used PickFolderFileDialog because it's a file dialog with a pick folder flag. I think an "open" operation on folder is a bit misleading, what would be the corresponding save folder dialog?

That said, I am not that picky about the name, as long as we get the dialog!

@Symbai
Copy link
Contributor Author

Symbai commented Jan 25, 2021

I think an "open" operation on folder is a bit misleading

Tell this Microsoft, they have chosen "OpenFileDialog" for picking/selecting a file instead of "SelectFileDialog". Thus "OpenFolderDialog" matches the line of "OpenFileDialog". On Winforms its called "FolderBrowserDialog". And on the Windows API Code Pack they called it "CommonOpenFileDialog" allowing setting a property "IsFolderPicker" to true.

So if even Microsoft haven't followed any line, there is no ultimate solution for its name. I for myself think that (existing) "OpenFileDialog" and (new) "OpenFolderDialog" seems quite nice together, while calling one "OpenFileDialog" and the other "FolderBrowserDialog" is not matching at all.

Anyway, we have several ways of calling it and there is no good or bad one. They all make sense, its just a matter of taste. I can rename it if necessary.

@miloush
Copy link
Contributor

miloush commented Jan 25, 2021

@Symbai having open and save file dialogs separate instead a common select file one has some advantages, such as remembering different recent locations for the two tasks separately.

I am sure the team will pick a name they see best fit.

@ryalanms
Copy link
Member

ryalanms commented Feb 8, 2021

Hi @Symbai. We are still establishing an API review process for WPF. @SamBent will likely be the final approver, but I will follow up when we have confirmation. Thanks.

@Symbai
Copy link
Contributor Author

Symbai commented Feb 8, 2021

Thanks for the update, I appreciate that. I can wait, take your time.

@ryalanms
Copy link
Member

Adding @MikeHillberg for API review...

Base automatically changed from master to main March 17, 2021 17:38
@Symbai
Copy link
Contributor Author

Symbai commented Apr 29, 2021

What's the status on this?

/// Represents a common dialog box that allows the user to open one or more file(s).
/// This class cannot be inherited.
/// </summary>
public sealed class OpenFolderDialog : FileDialog

Choose a reason for hiding this comment

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

Can this be a CommonDialog rather than a FileDialog? Making it a FileDialog gives it APIs that don't make sense for a folder, such as CheckFileExists, DefaultExt, SafeFileName, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CommonDialog has no fields and especially no validations, they're all in FileDialog. So either we copy everything except the few APIs you mentioned (which people have criticized on v1), or we just accept the fact that some APIs are irrelevant. Or we make a new base class for both, but that's a deeper change.

FYI: The Windows API Code Pack-Shell also has a FileDialog which becomes a Folder Dialog by setting a property to true. It also has SafeFileName (which will be the folder path then).

Choose a reason for hiding this comment

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

We shouldn't have API that's known to never work though. We want great documentation, but at the same time we want to design easy APIs that don't require outside reading. Basic OOP design is that a subclass add functionality, not remove it.

What makes it difficult is that we also use subclassing for sharing implementations. If the FileDialog code is stable maybe a copy of the relevant parts of it into OpenFolderDialog is OK, and maybe as a separate PR when it's important enough. I think there are also places in code where common functionality has been put into static helpers to provide shared code for cases like this.

@Symbai
Copy link
Contributor Author

Symbai commented May 25, 2021

What's the status on this? Is this ever getting reviewed by someone either merging it or telling me what exactly I have it to change it to so it will be merged?

@Symbai
Copy link
Contributor Author

Symbai commented Jun 11, 2021

Closing as WPF team is unable to review for 5 months and refuses to tell whats the problem. If anyone else wants to do this to themselves, go ahead. I'm giving up on this repo and this team, sorry.

@Symbai Symbai closed this Jun 11, 2021
@nzain
Copy link

nzain commented Jun 12, 2021

What a pity. It seems the WPF team has very little resources or little interest. WPF feels dead to me :(

@fabiant3
Copy link
Contributor

Reopening issue, I left a comment for @Symbai.
We are very much interested in the community PRs, we're just heads down making progress on open sourcing the test repo which is vital for accepting community PRs.

@fabiant3
Copy link
Contributor

Let us know if you'd like to resubmit, looks like your repo PR has been deleted.

@miloush
Copy link
Contributor

miloush commented Jun 16, 2021

I am happy to resubmit if needed, but I think some design discussion should take place first. Is that also waiting for the testing infrastructure?

@fabiant3
Copy link
Contributor

Based on the previous PR I don't believe this change would require the test repo for finalizing it. I'd appreciate if you could bring back the design main points and give us and the community clear options. @MikeHillberg brings some good points, would be good if you could address them. Thanks @miloush!

@miloush
Copy link
Contributor

miloush commented Jun 16, 2021

Right. So, from my point of view there are basically 3 things to decide:

1. Inheritance

The options were:
a) no ancestor
b) inheriting from CommonDialog
c) inheriting from FileDialog

I am against a). It is a common dialog that everyone expects to be shown using ShowDialog, and that will have an owner window, which is basically all that CommaonDialog provides.

From these options, I prefer c). It is a file dialog after all, and there is a lot of code in FileDialog that would need to be duplicated. This includes extracting and validating the paths, hook procedure, OK confirmation event, support for custom places, and some of the flags. As @MikeHillberg pointed out, some of the flags do not apply, and the legacy dialog would need to be overridden if needed. However, if we go for c), the new code is very lightweight and mirrors the Win32 implementation (which is also only a flag on file dialog).

There are other options too. We might not want to do a breaking change moving properties around, but there might be a possibility to split the inheritance chain, that is, OpenFileDialog > FileDialog > something new > CommonDialog. The something new could be for example CommonFileDialog, where most of the FileDialog's internal code would be moved and that would not have the unnecessary properties. Then the new dialog would directly inherit this new intermediate. If this is an option from compatibility point of view, I am all up for it.

2. Naming

The options were:
a) FolderBrowserDialog. This is a name WinForms uses, based on the legacy shell API.
b) PickFolderFileDialog. This was based on the fact that it is a FileDialog with a pick folder flag, for consistency with OpenFileDialog and SaveFileDialog. If we split the inheritance chain, PickFolderDialog would make more sense.
c) OpenFolderDialog. This was to match OpenFileDialog.

I don't see any rationale for a) in a new WPF code. My worry about c) was that there is no "open" operation on folder involved and there would be no corresponding "save" operation/dialog, but as stated above I am quite easy between b) and c).

3. Legacy support

Windows XP which .NET Framework version of WPF supports does not have the common dialog APIs. The options are:

a) throw PlatformNotSupportedException. If this is going to .NET Core only, then this is a valid and easy option.
b) implement fallback using legacy SHBrowseForFolder API. Note that this has a non-trivial amount of native types to include.
c) call the WinForms implementation

If anyone thinks I forgot something, feel free to chime in.

@ThomasGoulet73
Copy link
Contributor

ThomasGoulet73 commented Jun 17, 2021

@miloush That's a great summary of the design discussion required for this PR and I think you've covered everything.

Here's my personal opinion on this discussion:

1. Inheritance
My favorite is inheriting from a new class that inherits from CommonDialog. Both FileDialog and the folder dialog class would inherit from it. I wouldn't move anything public from FileDialog to the new base class. I would only move the private/protected/internal members to the base class and duplicate the public members for compatibility.

If we need full compatiblity and zero API changes to FileDialog (No new base class), we could either use a static class with the shared code or an internal implementation class. By "internal implementation class", I mean a new internal class that contains the shared implementation code from FileDialog and the new folder dialog. The public API would forward their calls to the internal class.

I personally don't like option c). There is a bunch of API that would do nothing and I don't think that it's very developer-friendly.

2. Naming
I always disliked the name FolderBrowserDialog in WinForms because I don't think that it's very intellisense-friendly. Having OpenFolderDialog and OpenFileDialog would make it easier to see the two types of Dialog in intellisense.

3. Legacy support
I wouldn't add any new code to support pre-Vista dialogs. .Net 6 does not support Windows XP and I don't see the team adding it back in a future .Net version. I would just let it fail with an exception that the Win32 API for Vista dialog does not exist if somehow someone was able to run a WPF app on a pre-Vista Windows.

@nzain
Copy link

nzain commented Jun 18, 2021

@fabiant3 You wanted to re-open this PR, right? It looks closed to me :)

What @miloush and @ThomasGoulet73 posted sounds smart to me. On the other side, I'd be happy to have any WPF option at all. This piece is missing for many years. Don't give up on this! 👍

@miloush
Copy link
Contributor

miloush commented Jun 22, 2021

I tried to look more into the splitting inheritance option and I don't think it is that beneficial after all if we can't move around public members - they would have to be defined on both the FileDialog and the new intermediate. If we wanted to keep them non-public on the intermediate, then we would have a public class with no members, which is not great either.

The whole picking folder capability of the file dialog feels like stitched in as an after-thought, and pretending on the WPF side that there is a clean design is a fallacy. I am now actually inclined to just add PickFolders property on the FileDialog and call it a day. That's what the underlying model is anyway.

  • On Windows Vista, the save file dialog supports the pick folders flag, and it lets users to enter a non-existing path, i.e. a folder to be created (this support has been removed on later Windows versions)
  • The Multiselect option kind of works for folders in the sense that the dialog allows you to select multiple things in the UI, however, you are not allowed to confirm such selection.
  • The legacy browse for folder dialog has the ability to display files when selecting a folder. If this feature is added to the new dialog too, then the filter properties become relevant.

These are the current public properties on the FileDialog:

Applicable to folders:

  • CustomPlaces
  • DereferenceLinks - whether links to folders are followed or not allowed
  • FileName - e.g. C:\Users\Thomas
  • FileNames - would always have 1 item at the moment
  • InitialDirectory
  • Options
  • SafeFileName - e.g. Thomas
  • SafeFileNames - would always have 1 item at the moment
  • Tag
  • Title

Doing something, but wouldn't be necessary for folders:

  • AddExtension - internal WPF flag to ensure the file/folder name ends with an extension
  • DefaultExt - the extension to add by default
  • ValidateNames - this one is a red flag, the WPF documentation says "indicating whether the dialog box accepts only valid Win32 file names." which is how the OFN_NOVALIDATE flag works in the legacy file dialogs. However, for the Vista dialogs, the FOS_NOVALIDATE flag means "check for situations that would prevent an application from opening the selected file, such as sharing violations or access denied errors."). In addition to the dialog behavior, WPF uses the flag for adding extensions and prompting for overwriting existing files.

Valid but currently without any effect:

  • CheckFileExists - only existing folders are allowed nowadays
  • CheckPathExists - only existing folders are allowed nowadays
  • RestoreDirectory - applicable to legacy dialogs only, not used in Vista dialogs

Invalid (the native call returns an error):

  • Filter
  • FilterIndex

So in fact @ThomasGoulet73, there isn't that many properties that would do nothing, and all of them would have either worked in the past or might work in the future/on other platform.

As for legacy implementation, I am not quite sure what is the support requirements for running on a supported version of Windows but in a compatibility mode.

@2ji3150
Copy link

2ji3150 commented Sep 28, 2021

This should'nt be closed... MS should fix it...

@ghost ghost locked as resolved and limited conversation to collaborators Apr 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

API Review Requested PR metadata: Label to tag PRs, to facilitate with triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WPF alternative for WinForms FolderBrowserDialog

9 participants