Skip to content

Commit

Permalink
Merge branch 'master' of github.com:btzy/nativefiledialog-extended
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Oct 6, 2024
2 parents 2c22a11 + 388549a commit ed19b3c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

![GitHub Actions](https://github.com/btzy/nativefiledialog-extended/workflows/build/badge.svg)

A small C library with that portably invokes native file open, folder select and file save dialogs. Write dialog code once and have it pop up native dialogs on all supported platforms. Avoid linking large dependencies like wxWidgets and Qt.
A small C library that portably invokes native file open, folder select and file save dialogs. Write dialog code once and have it pop up native dialogs on all supported platforms. Avoid linking large dependencies like wxWidgets and Qt.

This library is based on Michael Labbe's Native File Dialog ([mlabbe/nativefiledialog](https://github.com/mlabbe/nativefiledialog)).

Expand Down Expand Up @@ -223,7 +223,7 @@ typedef struct {
```

- `filterList` and `filterCount`: Set these to customize the file filter (it appears as a dropdown menu on Windows and Linux, but simply hides files on macOS). Set `filterList` to a pointer to the start of the array of filter items and `filterCount` to the number of filter items in that array. See the "File Filter Syntax" section below for details.
- `defaultPath`: Set this to the default folder that the dialog should open to (on Windows, if there is a recently used folder, it opens to that folder instead of the folder you pass).
- `defaultPath`: Set this to the default folder that the dialog should open to (on Windows, if there is a recently used folder, it opens to that folder instead of the folder you pass, unless the `NFD_OVERRIDE_RECENT_WITH_DEFAULT` build option is set to ON).
- `defaultName`: (For SaveDialog only) Set this to the file name that should be pre-filled on the dialog.
- `parentWindow`: Set this to the native window handle of the parent of this dialog. See the "Usage with a Platform Abstraction Framework" section for details. It is also possible to pass a handle even if you do not use a platform abstraction framework.

Expand Down Expand Up @@ -257,7 +257,7 @@ A wildcard filter is always added to every dialog.
*Note 3: On Linux, the file extension is appended (if missing) when the user presses down the "Save" button. The appended file extension will remain visible to the user, even if an overwrite prompt is shown and the user then presses "Cancel".*
*Note 4: On Windows, the default folder parameter is only used if there is no recently used folder available. Otherwise, the default folder will be the folder that was last used. Internally, the Windows implementation calls [IFileDialog::SetDefaultFolder(IShellItem)](https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifiledialog-setdefaultfolder). This is usual Windows behaviour and users expect it.*
*Note 4: On Windows, the default folder parameter is only used if there is no recently used folder available, unless the `NFD_OVERRIDE_RECENT_WITH_DEFAULT` build option is set to ON. Otherwise, the default folder will be the folder that was last used. Internally, the Windows implementation calls [IFileDialog::SetDefaultFolder(IShellItem)](https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifiledialog-setdefaultfolder). This is usual Windows behaviour and users expect it.*
## Iterating Over PathSets
Expand Down
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,8 @@ if (NFD_INSTALL)
FILE ${TARGET_NAME}-config.cmake
)
endif()

option(NFD_OVERRIDE_RECENT_WITH_DEFAULT "Use defaultPath instead of recent folder on Windows" OFF)
if (NFD_OVERRIDE_RECENT_WITH_DEFAULT)
target_compile_definitions(${TARGET_NAME} PRIVATE NFD_OVERRIDE_RECENT_WITH_DEFAULT)
endif()
3 changes: 1 addition & 2 deletions src/nfd_gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,7 @@ void RealizedSignalHandler(GtkWidget* window, void* userdata) {
}

struct NativeWindowParenter {
NativeWindowParenter(GtkWidget* widget, const nfdwindowhandle_t& parentWindow) noexcept
: widget(widget) {
NativeWindowParenter(GtkWidget* w, const nfdwindowhandle_t& parentWindow) noexcept : widget(w) {
parent = GetAllocNativeWindowHandle(parentWindow);

if (parent) {
Expand Down
16 changes: 8 additions & 8 deletions src/nfd_portal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1605,17 +1605,17 @@ nfdresult_t NFD_PickFolderN_With_Impl(nfdversion_t version,
(void)version;

{
dbus_uint32_t version;
const nfdresult_t res = NFD_DBus_GetVersion(version);
dbus_uint32_t portal_version;
const nfdresult_t res = NFD_DBus_GetVersion(portal_version);
if (res != NFD_OKAY) {
return res;
}
if (version < 3) {
if (portal_version < 3) {
NFDi_SetFormattedError(
"The xdg-desktop-portal installed on this system does not support a folder picker; "
"at least version 3 of the org.freedesktop.portal.FileChooser interface is "
"required but the installed interface version is %u.",
version);
portal_version);
return NFD_ERROR;
}
}
Expand Down Expand Up @@ -1662,17 +1662,17 @@ nfdresult_t NFD_PickFolderMultipleN_With_Impl(nfdversion_t version,
(void)version;

{
dbus_uint32_t version;
const nfdresult_t res = NFD_DBus_GetVersion(version);
dbus_uint32_t portal_version;
const nfdresult_t res = NFD_DBus_GetVersion(portal_version);
if (res != NFD_OKAY) {
return res;
}
if (version < 3) {
if (portal_version < 3) {
NFDi_SetFormattedError(
"The xdg-desktop-portal installed on this system does not support a folder picker; "
"at least version 3 of the org.freedesktop.portal.FileChooser interface is "
"required but the installed interface version is %u.",
version);
portal_version);
return NFD_ERROR;
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/nfd_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,20 @@ nfdresult_t SetDefaultPath(IFileDialog* dialog, const nfdnchar_t* defaultPath) {

Release_Guard<IShellItem> folderGuard(folder);

// SetDefaultFolder() might use another recently used folder if available, so the user doesn't
// need to keep navigating back to the default folder (recommended by Windows). change to
// SetFolder() if you always want to use the default folder
#ifdef NFD_OVERRIDE_RECENT_WITH_DEFAULT
// Use SetFolder() if you always want to use the default folder
if (!SUCCEEDED(dialog->SetFolder(folder))) {
NFDi_SetError("Failed to set default path.");
return NFD_ERROR;
}
#else
// SetDefaultFolder() might use another recently used folder if available, so the user
// doesn't need to keep navigating back to the default folder (recommended by Windows).
if (!SUCCEEDED(dialog->SetDefaultFolder(folder))) {
NFDi_SetError("Failed to set default path.");
return NFD_ERROR;
}
#endif

return NFD_OKAY;
}
Expand Down

0 comments on commit ed19b3c

Please sign in to comment.