btzy / nativefiledialog-extended

Cross platform (Windows, Mac, Linux) native file dialog library with C and C++ bindings, based on mlabbe/nativefiledialog.
zlib License
700 stars 96 forks source link

Provide an option for overriding default folder behavior on Windows #151

Closed dbierek closed 2 months ago

dbierek commented 2 months ago

Issue description:

When a program has multiple file / folder dialogs that are for different purposes (for instance different file types), defaulting to the most recent folder on Windows forces the user to have to manually navigate to different folders, even when the program is manually setting different default paths for each dialog type.

https://github.com/btzy/nativefiledialog-extended/blob/79ebd337d791f260e26e5b3decdff145954c8c5c/src/nfd_win.cpp#L255

Here it mentions that the dialog->SetDefaultFolder call can be changed to dialog->SetFolder to override this behavior, however this change must be manually made to the underlying library code. When pulling in nativefiledialog-extended via vcpkg, this method is unavailable, and the code must be manually imported and modified.

Suggested Change:

I think it would be beneficial to allow an option to allow overriding this default behavior, either in the args structs or in functions as an optional parameter. Maybe something like bool overrideRecentPathWithDefault.

dbierek commented 2 months ago

Screenshot showing the issue in NavKit: Screenshot 2024-09-20 000142

In this case, the Hitman 3 button opens a file dialog with a default path of C:\Program Files (x86)\Steam\steamapps\common\HITMAN 3, but the most recent folder opened was D:\workspace\NavKit\output, so it is defaulting to that folder instead of the HITMAN 3 folder, making it so the user must manually select the desired folder.

btzy commented 2 months ago

Yes, I agree that a way to use IFileDialog::SetFolder will be useful.

Note that the "correct" way to have dialogs for different purposes on Windows is to call IFileDialog::SetClientGuid though. This will persist separate last used folders for each GUID. I'm not sure if there's a way to do something similar on macOS and GTK though.

dbierek commented 2 months ago

Note that the "correct" way to have dialogs for different purposes on Windows is to call IFileDialog::SetClientGuid though. This will persist separate last used folders for each GUID.

Interesting, I wasn't aware of this option. Perhaps that can be exposed through the library as a way for at least each Windows dialog to maintain its own recent folder.

btzy commented 2 months ago

I kinda think that if we are to expose setting the GUID for Windows only, then NFDe users will likely end up writing extra macOS- and Linux-specific code to do it manually on those platforms, since if they really need per-GUID recent folders on Windows, then they probably can't live with the default behaviour on macOS and Linux either. So I think NFDe will likely have to come with a manual implementation on those platforms.

btzy commented 2 months ago

Closed by #152.