diff --git a/README.md b/README.md index 4f7fe31..20bc85b 100644 --- a/README.md +++ b/README.md @@ -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, unless the `NFD_OVERRIDE_RECENT_WITH_DEFAULT` flag is set to 1). +- `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` flag 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. @@ -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, unless the `NFD_OVERRIDE_RECENT_WITH_DEFAULT` flag is set to 1. 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` flag 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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 740b484..f80ba39 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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" ON) +if (NFD_OVERRIDE_RECENT_WITH_DEFAULT) + target_compile_definitions(${TARGET_NAME} PRIVATE nfd_OVERRIDE_RECENT_WITH_DEFAULT) +endif() diff --git a/src/include/nfd.h b/src/include/nfd.h index 39fde47..adb1c81 100644 --- a/src/include/nfd.h +++ b/src/include/nfd.h @@ -34,9 +34,6 @@ extern "C" { #define NFD_INLINE static inline #endif // __cplusplus -// If 1, use defaultPath instead of the recent path on Windows. -extern int NFD_OVERRIDE_RECENT_WITH_DEFAULT; - #include typedef char nfdu8char_t; diff --git a/src/nfd_win.cpp b/src/nfd_win.cpp index 1ea2f2a..2d4fa6a 100644 --- a/src/nfd_win.cpp +++ b/src/nfd_win.cpp @@ -30,8 +30,6 @@ struct IUnknown; // Workaround for "combaseapi.h(229): error C2187: syntax erro #include #include "nfd.h" -int NFD_OVERRIDE_RECENT_WITH_DEFAULT = 1; - namespace { /* current error */ @@ -252,20 +250,20 @@ nfdresult_t SetDefaultPath(IFileDialog* dialog, const nfdnchar_t* defaultPath) { Release_Guard folderGuard(folder); - if (NFD_OVERRIDE_RECENT_WITH_DEFAULT == 1) { - // 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; - } +#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; }