ookii-dialogs / ookii-dialogs-wpf

Awesome dialogs for Windows Desktop applications built with Microsoft .NET (WPF)
BSD 3-Clause "New" or "Revised" License
1.14k stars 85 forks source link

Why ShowDialog for VistaFolderBrowserDialog returns nullable `bool?` #103

Open roman-khazanskii opened 2 years ago

roman-khazanskii commented 2 years ago

Comment states:

        //
        // Summary:
        //     Displays the folder browser dialog.
        //
        // Parameters:
        //   owner:
        //     Handle to the window that owns the dialog.
        //
        // Returns:
        //     If the user clicks the OK button, true is returned; otherwise, false.

Is it even possible to have a null returned from there?

augustoproiete commented 2 years ago

No technical reason... The code was written many years ago so I'd guess that the intent of the original author was to return null in case the VistaFolderBrowserDialog was not supported by the operating system where the app is running, but the code doesn't have that behavior implemented and couldn't return null, so we could change it to a regular bool in a future release

https://github.com/ookii-dialogs/ookii-dialogs-wpf/blob/v5.0.1/src/Ookii.Dialogs.Wpf/VistaFolderBrowserDialog.cs#L250

roman-khazanskii commented 2 years ago

Okay, this is not a real issue, I was just wondering if I should handle null case. Thanks!

SvenGroot commented 1 year ago

I randomly found this issue, and since I'm the original author, I can answer this (if royally late). The various common file dialog classes were designed to have the exact same API as the original WPF OpenFileDialog and SaveFileDialog classes, so they could serve as a drop-in replacement. Although WPF doesn't have a native FolderBrowserDialog, I still wanted to use the same API.

So as you might have guessed, the ShowDialog method of those native classes returns bool?, and therefore so do the Ookii.Dialogs classes, even though they never return null.