diff --git a/README.md b/README.md index 218eacd..b542032 100644 --- a/README.md +++ b/README.md @@ -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)). @@ -200,6 +200,7 @@ typedef struct { nfdfiltersize_t filterCount; const nfdu8char_t* defaultPath; nfdwindowhandle_t parentWindow; + int overrideRecentWithDefault; } nfdopendialogu8args_t; ``` @@ -211,6 +212,7 @@ typedef struct { const nfdu8char_t* defaultPath; const nfdu8char_t* defaultName; nfdwindowhandle_t parentWindow; + int overrideRecentWithDefault; } nfdsavedialogu8args_t; ``` @@ -219,13 +221,15 @@ typedef struct { typedef struct { const nfdu8char_t* defaultPath; nfdwindowhandle_t parentWindow; + int overrideRecentWithDefault; } nfdpickfolderu8args_t; ``` - `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 `overrideRecentWithDefault `value is set to 1). - `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. +- `overrideRecentWithDefault`: Set this to 1 to use the `defaultPath` instead of the most recent folder on Windows. ## Examples @@ -257,7 +261,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 overrideRecentWithDefault 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.* ## Iterating Over PathSets diff --git a/src/include/nfd.h b/src/include/nfd.h index adb1c81..dd72a97 100644 --- a/src/include/nfd.h +++ b/src/include/nfd.h @@ -121,6 +121,7 @@ typedef struct { nfdfiltersize_t filterCount; const nfdu8char_t* defaultPath; nfdwindowhandle_t parentWindow; + int overrideRecentWithDefault; } nfdopendialogu8args_t; #ifdef _WIN32 @@ -129,6 +130,7 @@ typedef struct { nfdfiltersize_t filterCount; const nfdnchar_t* defaultPath; nfdwindowhandle_t parentWindow; + int overrideRecentWithDefault; } nfdopendialognargs_t; #else typedef nfdopendialogu8args_t nfdopendialognargs_t; @@ -140,6 +142,7 @@ typedef struct { const nfdu8char_t* defaultPath; const nfdu8char_t* defaultName; nfdwindowhandle_t parentWindow; + int overrideRecentWithDefault; } nfdsavedialogu8args_t; #ifdef _WIN32 @@ -149,6 +152,7 @@ typedef struct { const nfdnchar_t* defaultPath; const nfdnchar_t* defaultName; nfdwindowhandle_t parentWindow; + int overrideRecentWithDefault; } nfdsavedialognargs_t; #else typedef nfdsavedialogu8args_t nfdsavedialognargs_t; @@ -157,12 +161,14 @@ typedef nfdsavedialogu8args_t nfdsavedialognargs_t; typedef struct { const nfdu8char_t* defaultPath; nfdwindowhandle_t parentWindow; + int overrideRecentWithDefault; } nfdpickfolderu8args_t; #ifdef _WIN32 typedef struct { const nfdnchar_t* defaultPath; nfdwindowhandle_t parentWindow; + int overrideRecentWithDefault; } nfdpickfoldernargs_t; #else typedef nfdpickfolderu8args_t nfdpickfoldernargs_t; @@ -196,11 +202,13 @@ NFD_API void NFD_Quit(void); * NFD_OKAY. * @param[out] outPath * @param filterCount If zero, filterList is ignored (you can use null). - * @param defaultPath If null, the operating system will decide. */ + * @param defaultPath If null, the operating system will decide. + * @param overrideRecentWithDefault If 1, use defaultPath instead of the recent path on Windows. */ NFD_API nfdresult_t NFD_OpenDialogN(nfdnchar_t** outPath, const nfdnfilteritem_t* filterList, nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath); + const nfdnchar_t* defaultPath, + int overrideRecentWithDefault); /** Single file open dialog * @@ -208,11 +216,13 @@ NFD_API nfdresult_t NFD_OpenDialogN(nfdnchar_t** outPath, * returns NFD_OKAY. * @param[out] outPath * @param filterCount If zero, filterList is ignored (you can use null). - * @param defaultPath If null, the operating system will decide. */ + * @param defaultPath If null, the operating system will decide. + * @param overrideRecentWithDefault If 1, use defaultPath instead of the recent path on Windows. */ NFD_API nfdresult_t NFD_OpenDialogU8(nfdu8char_t** outPath, const nfdu8filteritem_t* filterList, nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath); + const nfdu8char_t* defaultPath, + int overrideRecentWithDefault); /** This function is a library implementation detail. Please use NFD_OpenDialogN_With() instead. */ NFD_API nfdresult_t NFD_OpenDialogN_With_Impl(nfdversion_t version, @@ -249,11 +259,13 @@ NFD_INLINE nfdresult_t NFD_OpenDialogU8_With(nfdu8char_t** outPath, * returns NFD_OKAY. * @param[out] outPaths * @param filterCount If zero, filterList is ignored (you can use null). - * @param defaultPath If null, the operating system will decide. */ + * @param defaultPath If null, the operating system will decide. + * @param overrideRecentWithDefault If 1, use defaultPath instead of the recent path on Windows. */ NFD_API nfdresult_t NFD_OpenDialogMultipleN(const nfdpathset_t** outPaths, const nfdnfilteritem_t* filterList, nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath); + const nfdnchar_t* defaultPath, + int overrideRecentWithDefault); /** Multiple file open dialog * @@ -261,11 +273,13 @@ NFD_API nfdresult_t NFD_OpenDialogMultipleN(const nfdpathset_t** outPaths, * returns NFD_OKAY. * @param[out] outPaths * @param filterCount If zero, filterList is ignored (you can use null). - * @param defaultPath If null, the operating system will decide. */ + * @param defaultPath If null, the operating system will decide. + * @param overrideRecentWithDefault If 1, use defaultPath instead of the recent path on Windows. */ NFD_API nfdresult_t NFD_OpenDialogMultipleU8(const nfdpathset_t** outPaths, const nfdu8filteritem_t* filterList, nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath); + const nfdu8char_t* defaultPath, + int overrideRecentWithDefault); /** This function is a library implementation detail. Please use NFD_OpenDialogMultipleN_With() * instead. */ @@ -303,12 +317,14 @@ NFD_INLINE nfdresult_t NFD_OpenDialogMultipleU8_With(const nfdpathset_t** outPat * NFD_OKAY. * @param[out] outPath * @param filterCount If zero, filterList is ignored (you can use null). - * @param defaultPath If null, the operating system will decide. */ + * @param defaultPath If null, the operating system will decide. + * @param overrideRecentWithDefault If 1, use defaultPath instead of the recent path on Windows. */ NFD_API nfdresult_t NFD_SaveDialogN(nfdnchar_t** outPath, const nfdnfilteritem_t* filterList, nfdfiltersize_t filterCount, const nfdnchar_t* defaultPath, - const nfdnchar_t* defaultName); + const nfdnchar_t* defaultName, + int overrideRecentWithDefault); /** Save dialog * @@ -316,12 +332,14 @@ NFD_API nfdresult_t NFD_SaveDialogN(nfdnchar_t** outPath, * returns NFD_OKAY. * @param[out] outPath * @param filterCount If zero, filterList is ignored (you can use null). - * @param defaultPath If null, the operating system will decide. */ + * @param defaultPath If null, the operating system will decide. + * @param overrideRecentWithDefault If 1, use defaultPath instead of the recent path on Windows. */ NFD_API nfdresult_t NFD_SaveDialogU8(nfdu8char_t** outPath, const nfdu8filteritem_t* filterList, nfdfiltersize_t filterCount, const nfdu8char_t* defaultPath, - const nfdu8char_t* defaultName); + const nfdu8char_t* defaultName, + int overrideRecentWithDefault); /** This function is a library implementation detail. Please use NFD_SaveDialogN_With() instead. */ NFD_API nfdresult_t NFD_SaveDialogN_With_Impl(nfdversion_t version, @@ -357,16 +375,22 @@ NFD_INLINE nfdresult_t NFD_SaveDialogU8_With(nfdu8char_t** outPath, * It is the caller's responsibility to free `outPath` via NFD_FreePathN() if this function returns * NFD_OKAY. * @param[out] outPath - * @param defaultPath If null, the operating system will decide. */ -NFD_API nfdresult_t NFD_PickFolderN(nfdnchar_t** outPath, const nfdnchar_t* defaultPath); + * @param defaultPath If null, the operating system will decide. + * @param overrideRecentWithDefault If 1, use defaultPath instead of the recent path on Windows. */ +NFD_API nfdresult_t NFD_PickFolderN(nfdnchar_t** outPath, + const nfdnchar_t* defaultPath, + int overrideRecentWithDefault); /** Select single folder dialog * * It is the caller's responsibility to free `outPath` via NFD_FreePathU8() if this function * returns NFD_OKAY. * @param[out] outPath - * @param defaultPath If null, the operating system will decide. */ -NFD_API nfdresult_t NFD_PickFolderU8(nfdu8char_t** outPath, const nfdu8char_t* defaultPath); + * @param defaultPath If null, the operating system will decide. + * @param overrideRecentWithDefault If 1, use defaultPath instead of the recent path on Windows. */ +NFD_API nfdresult_t NFD_PickFolderU8(nfdu8char_t** outPath, + const nfdu8char_t* defaultPath, + int overrideRecentWithDefault); /** This function is a library implementation detail. Please use NFD_PickFolderN_With() instead. */ NFD_API nfdresult_t NFD_PickFolderN_With_Impl(nfdversion_t version, @@ -402,18 +426,22 @@ NFD_INLINE nfdresult_t NFD_PickFolderU8_With(nfdu8char_t** outPath, * It is the caller's responsibility to free `outPaths` via NFD_PathSet_FreeN() if this function * returns NFD_OKAY. * @param[out] outPaths - * @param defaultPath If null, the operating system will decide. */ + * @param defaultPath If null, the operating system will decide. + * @param overrideRecentWithDefault If 1, use defaultPath instead of the recent path on Windows. */ NFD_API nfdresult_t NFD_PickFolderMultipleN(const nfdpathset_t** outPaths, - const nfdnchar_t* defaultPath); + const nfdnchar_t* defaultPath, + int overrideRecentWithDefault); /** Select multiple folder dialog * * It is the caller's responsibility to free `outPaths` via NFD_PathSet_FreeU8() if this function * returns NFD_OKAY. * @param[out] outPaths - * @param defaultPath If null, the operating system will decide. */ + * @param defaultPath If null, the operating system will decide. + * @param overrideRecentWithDefault If 1, use defaultPath instead of the recent path on Windows. */ NFD_API nfdresult_t NFD_PickFolderMultipleU8(const nfdpathset_t** outPaths, - const nfdu8char_t* defaultPath); + const nfdu8char_t* defaultPath, + int overrideRecentWithDefault); /** This function is a library implementation detail. Please use NFD_PickFolderMultipleN_With() * instead. */ diff --git a/src/include/nfd.hpp b/src/include/nfd.hpp index da232ae..b98c6de 100644 --- a/src/include/nfd.hpp +++ b/src/include/nfd.hpp @@ -38,8 +38,9 @@ inline nfdresult_t OpenDialog(nfdnchar_t*& outPath, const nfdnfilteritem_t* filterList = nullptr, nfdfiltersize_t filterCount = 0, const nfdnchar_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdopendialognargs_t args{filterList, filterCount, defaultPath, parentWindow}; + nfdwindowhandle_t parentWindow = {}, + int overrideRecentWithDefault = 0) noexcept { + const nfdopendialognargs_t args{filterList, filterCount, defaultPath, parentWindow, overrideRecentWithDefault}; return ::NFD_OpenDialogN_With(&outPath, &args); } @@ -47,8 +48,9 @@ inline nfdresult_t OpenDialogMultiple(const nfdpathset_t*& outPaths, const nfdnfilteritem_t* filterList = nullptr, nfdfiltersize_t filterCount = 0, const nfdnchar_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdopendialognargs_t args{filterList, filterCount, defaultPath, parentWindow}; + nfdwindowhandle_t parentWindow = {}, + int overrideRecentWithDefault = 0) noexcept { + const nfdopendialognargs_t args{filterList, filterCount, defaultPath, parentWindow, overrideRecentWithDefault}; return ::NFD_OpenDialogMultipleN_With(&outPaths, &args); } @@ -57,7 +59,8 @@ inline nfdresult_t SaveDialog(nfdnchar_t*& outPath, nfdfiltersize_t filterCount = 0, const nfdnchar_t* defaultPath = nullptr, const nfdnchar_t* defaultName = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { + nfdwindowhandle_t parentWindow = {}, + int overrideRecentWithDefault = 0) noexcept { const nfdsavedialognargs_t args{ filterList, filterCount, defaultPath, defaultName, parentWindow}; return ::NFD_SaveDialogN_With(&outPath, &args); @@ -65,15 +68,17 @@ inline nfdresult_t SaveDialog(nfdnchar_t*& outPath, inline nfdresult_t PickFolder(nfdnchar_t*& outPath, const nfdnchar_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdpickfoldernargs_t args{defaultPath, parentWindow}; + nfdwindowhandle_t parentWindow = {}, + int overrideRecentWithDefault = 0) noexcept { + const nfdpickfoldernargs_t args{defaultPath, parentWindow, overrideRecentWithDefault}; return ::NFD_PickFolderN_With(&outPath, &args); } inline nfdresult_t PickFolderMultiple(const nfdpathset_t*& outPaths, const nfdnchar_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdpickfoldernargs_t args{defaultPath, parentWindow}; + nfdwindowhandle_t parentWindow = {}, + int overrideRecentWithDefault = 0) noexcept { + const nfdpickfoldernargs_t args{defaultPath, parentWindow, overrideRecentWithDefault}; return ::NFD_PickFolderMultipleN_With(&outPaths, &args); } @@ -117,7 +122,8 @@ inline nfdresult_t OpenDialog(nfdu8char_t*& outPath, const nfdu8filteritem_t* filterList = nullptr, nfdfiltersize_t filterCount = 0, const nfdu8char_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { + nfdwindowhandle_t parentWindow = {}, + int overrideRecentWithDefault = 0) noexcept { const nfdopendialogu8args_t args{filterList, filterCount, defaultPath, parentWindow}; return ::NFD_OpenDialogU8_With(&outPath, &args); } @@ -126,8 +132,9 @@ inline nfdresult_t OpenDialogMultiple(const nfdpathset_t*& outPaths, const nfdu8filteritem_t* filterList = nullptr, nfdfiltersize_t filterCount = 0, const nfdu8char_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdopendialogu8args_t args{filterList, filterCount, defaultPath, parentWindow}; + nfdwindowhandle_t parentWindow = {}, + int overrideRecentWithDefault = 0) noexcept { + const nfdopendialogu8args_t args{filterList, filterCount, defaultPath, parentWindow, overrideRecentWithDefault}; return ::NFD_OpenDialogMultipleU8_With(&outPaths, &args); } @@ -136,23 +143,26 @@ inline nfdresult_t SaveDialog(nfdu8char_t*& outPath, nfdfiltersize_t filterCount = 0, const nfdu8char_t* defaultPath = nullptr, const nfdu8char_t* defaultName = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { + nfdwindowhandle_t parentWindow = {}, + int overrideRecentWithDefault = 0) noexcept { const nfdsavedialogu8args_t args{ - filterList, filterCount, defaultPath, defaultName, parentWindow}; + filterList, filterCount, defaultPath, defaultName, parentWindow, overrideRecentWithDefault}; return ::NFD_SaveDialogU8_With(&outPath, &args); } inline nfdresult_t PickFolder(nfdu8char_t*& outPath, const nfdu8char_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdpickfolderu8args_t args{defaultPath, parentWindow}; + nfdwindowhandle_t parentWindow = {}, + int overrideRecentWithDefault = 0) noexcept { + const nfdpickfolderu8args_t args{defaultPath, parentWindow, overrideRecentWithDefault}; return ::NFD_PickFolderU8_With(&outPath, &args); } inline nfdresult_t PickFolderMultiple(const nfdpathset_t*& outPaths, const nfdu8char_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdpickfolderu8args_t args{defaultPath, parentWindow}; + nfdwindowhandle_t parentWindow = {}, + int overrideRecentWithDefault = 0) noexcept { + const nfdpickfolderu8args_t args{defaultPath, parentWindow, overrideRecentWithDefault}; return ::NFD_PickFolderMultipleU8_With(&outPaths, &args); } @@ -218,9 +228,10 @@ inline nfdresult_t OpenDialog(UniquePathN& outPath, const nfdnfilteritem_t* filterList = nullptr, nfdfiltersize_t filterCount = 0, const nfdnchar_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { + nfdwindowhandle_t parentWindow = {}, + int overrideRecentWithDefault = 0) noexcept { nfdnchar_t* out; - nfdresult_t res = OpenDialog(out, filterList, filterCount, defaultPath, parentWindow); + nfdresult_t res = OpenDialog(out, filterList, filterCount, defaultPath, parentWindow, overrideRecentWithDefault); if (res == NFD_OKAY) { outPath.reset(out); } @@ -231,9 +242,10 @@ inline nfdresult_t OpenDialogMultiple(UniquePathSet& outPaths, const nfdnfilteritem_t* filterList = nullptr, nfdfiltersize_t filterCount = 0, const nfdnchar_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { + nfdwindowhandle_t parentWindow = {}, + int overrideRecentWithDefault = 0) noexcept { const nfdpathset_t* out; - nfdresult_t res = OpenDialogMultiple(out, filterList, filterCount, defaultPath, parentWindow); + nfdresult_t res = OpenDialogMultiple(out, filterList, filterCount, defaultPath, parentWindow, overrideRecentWithDefault); if (res == NFD_OKAY) { outPaths.reset(out); } @@ -245,10 +257,11 @@ inline nfdresult_t SaveDialog(UniquePathN& outPath, nfdfiltersize_t filterCount = 0, const nfdnchar_t* defaultPath = nullptr, const nfdnchar_t* defaultName = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { + nfdwindowhandle_t parentWindow = {}, + int overrideRecentWithDefault = 0) noexcept { nfdnchar_t* out; nfdresult_t res = - SaveDialog(out, filterList, filterCount, defaultPath, defaultName, parentWindow); + SaveDialog(out, filterList, filterCount, defaultPath, defaultName, parentWindow, overrideRecentWithDefault); if (res == NFD_OKAY) { outPath.reset(out); } @@ -257,9 +270,10 @@ inline nfdresult_t SaveDialog(UniquePathN& outPath, inline nfdresult_t PickFolder(UniquePathN& outPath, const nfdnchar_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { + nfdwindowhandle_t parentWindow = {}, + int overrideRecentWithDefault = 0) noexcept { nfdnchar_t* out; - nfdresult_t res = PickFolder(out, defaultPath, parentWindow); + nfdresult_t res = PickFolder(out, defaultPath, parentWindow, overrideRecentWithDefault); if (res == NFD_OKAY) { outPath.reset(out); } @@ -268,9 +282,10 @@ inline nfdresult_t PickFolder(UniquePathN& outPath, inline nfdresult_t PickFolderMultiple(UniquePathSet& outPaths, const nfdnchar_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { + nfdwindowhandle_t parentWindow = {}, + int overrideRecentWithDefault = 0) noexcept { const nfdpathset_t* out; - nfdresult_t res = PickFolderMultiple(out, defaultPath, parentWindow); + nfdresult_t res = PickFolderMultiple(out, defaultPath, parentWindow, overrideRecentWithDefault); if (res == NFD_OKAY) { outPaths.reset(out); } @@ -282,9 +297,10 @@ inline nfdresult_t OpenDialog(UniquePathU8& outPath, const nfdu8filteritem_t* filterList = nullptr, nfdfiltersize_t filterCount = 0, const nfdu8char_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { + nfdwindowhandle_t parentWindow = {}, + int overrideRecentWithDefault = 0) noexcept { nfdu8char_t* out; - nfdresult_t res = OpenDialog(out, filterList, filterCount, defaultPath, parentWindow); + nfdresult_t res = OpenDialog(out, filterList, filterCount, defaultPath, parentWindow, overrideRecentWithDefault); if (res == NFD_OKAY) { outPath.reset(out); } @@ -295,9 +311,10 @@ inline nfdresult_t OpenDialogMultiple(UniquePathSet& outPaths, const nfdu8filteritem_t* filterList = nullptr, nfdfiltersize_t filterCount = 0, const nfdu8char_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { + nfdwindowhandle_t parentWindow = {}, + int overrideRecentWithDefault = 0) noexcept { const nfdpathset_t* out; - nfdresult_t res = OpenDialogMultiple(out, filterList, filterCount, defaultPath, parentWindow); + nfdresult_t res = OpenDialogMultiple(out, filterList, filterCount, defaultPath, parentWindow, overrideRecentWithDefault); if (res == NFD_OKAY) { outPaths.reset(out); } @@ -309,10 +326,11 @@ inline nfdresult_t SaveDialog(UniquePathU8& outPath, nfdfiltersize_t filterCount = 0, const nfdu8char_t* defaultPath = nullptr, const nfdu8char_t* defaultName = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { + nfdwindowhandle_t parentWindow = {}, + int overrideRecentWithDefault = 0) noexcept { nfdu8char_t* out; nfdresult_t res = - SaveDialog(out, filterList, filterCount, defaultPath, defaultName, parentWindow); + SaveDialog(out, filterList, filterCount, defaultPath, defaultName, parentWindow, overrideRecentWithDefault); if (res == NFD_OKAY) { outPath.reset(out); } @@ -321,9 +339,10 @@ inline nfdresult_t SaveDialog(UniquePathU8& outPath, inline nfdresult_t PickFolder(UniquePathU8& outPath, const nfdu8char_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { + nfdwindowhandle_t parentWindow = {}, + int overrideRecentWithDefault = 0) noexcept { nfdu8char_t* out; - nfdresult_t res = PickFolder(out, defaultPath, parentWindow); + nfdresult_t res = PickFolder(out, defaultPath, parentWindow, overrideRecentWithDefault); if (res == NFD_OKAY) { outPath.reset(out); } @@ -332,9 +351,10 @@ inline nfdresult_t PickFolder(UniquePathU8& outPath, inline nfdresult_t PickFolderMultiple(UniquePathSet& outPaths, const nfdu8char_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { + nfdwindowhandle_t parentWindow = {}, + int overrideRecentWithDefault = 0) noexcept { const nfdpathset_t* out; - nfdresult_t res = PickFolderMultiple(out, defaultPath, parentWindow); + nfdresult_t res = PickFolderMultiple(out, defaultPath, parentWindow, overrideRecentWithDefault); if (res == NFD_OKAY) { outPaths.reset(out); } diff --git a/src/nfd_cocoa.m b/src/nfd_cocoa.m index 4bcea22..4fb7b27 100644 --- a/src/nfd_cocoa.m +++ b/src/nfd_cocoa.m @@ -221,7 +221,8 @@ void NFD_Quit(void) { nfdresult_t NFD_OpenDialogN(nfdnchar_t** outPath, const nfdnfilteritem_t* filterList, nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath) { + const nfdnchar_t* defaultPath, + int overrideRecentWithDefault = 0) { nfdopendialognargs_t args = {0}; args.filterList = filterList; args.filterCount = filterCount; @@ -268,7 +269,8 @@ nfdresult_t NFD_OpenDialogN_With_Impl(nfdversion_t version, nfdresult_t NFD_OpenDialogU8(nfdu8char_t** outPath, const nfdu8filteritem_t* filterList, nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath) { + const nfdu8char_t* defaultPath, + int overrideRecentWithDefault = 0) { return NFD_OpenDialogN(outPath, filterList, filterCount, defaultPath); } @@ -281,7 +283,8 @@ nfdresult_t NFD_OpenDialogU8_With_Impl(nfdversion_t version, nfdresult_t NFD_OpenDialogMultipleN(const nfdpathset_t** outPaths, const nfdnfilteritem_t* filterList, nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath) { + const nfdnchar_t* defaultPath, + int overrideRecentWithDefault = 0) { nfdopendialognargs_t args = {0}; args.filterList = filterList; args.filterCount = filterCount; @@ -333,8 +336,10 @@ nfdresult_t NFD_OpenDialogMultipleN_With_Impl(nfdversion_t version, nfdresult_t NFD_OpenDialogMultipleU8(const nfdpathset_t** outPaths, const nfdu8filteritem_t* filterList, nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath) { - return NFD_OpenDialogMultipleN(outPaths, filterList, filterCount, defaultPath); + const nfdu8char_t* defaultPath, + int overrideRecentWithDefault = 0) { + return NFD_OpenDialogMultipleN(outPaths, filterList, filterCount, defaultPath, + int overrideRecentWithDefault = 0); } nfdresult_t NFD_OpenDialogMultipleU8_With_Impl(nfdversion_t version, @@ -347,7 +352,8 @@ nfdresult_t NFD_SaveDialogN(nfdnchar_t** outPath, const nfdnfilteritem_t* filterList, nfdfiltersize_t filterCount, const nfdnchar_t* defaultPath, - const nfdnchar_t* defaultName) { + const nfdnchar_t* defaultName, + int overrideRecentWithDefault = 0) { nfdsavedialognargs_t args = {0}; args.filterList = filterList; args.filterCount = filterCount; @@ -402,7 +408,8 @@ nfdresult_t NFD_SaveDialogU8(nfdu8char_t** outPath, const nfdu8filteritem_t* filterList, nfdfiltersize_t filterCount, const nfdu8char_t* defaultPath, - const nfdu8char_t* defaultName) { + const nfdu8char_t* defaultName, + int overrideRecentWithDefault = 0) { return NFD_SaveDialogN(outPath, filterList, filterCount, defaultPath, defaultName); } @@ -412,7 +419,9 @@ nfdresult_t NFD_SaveDialogU8_With_Impl(nfdversion_t version, return NFD_SaveDialogN_With_Impl(version, outPath, args); } -nfdresult_t NFD_PickFolderN(nfdnchar_t** outPath, const nfdnchar_t* defaultPath) { +nfdresult_t NFD_PickFolderN(nfdnchar_t** outPath, + const nfdnchar_t* defaultPath, + int overrideRecentWithDefault = 0) { nfdpickfoldernargs_t args = {0}; args.defaultPath = defaultPath; return NFD_PickFolderN_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); @@ -454,7 +463,9 @@ nfdresult_t NFD_PickFolderN_With_Impl(nfdversion_t version, return result; } -nfdresult_t NFD_PickFolderU8(nfdu8char_t** outPath, const nfdu8char_t* defaultPath) { +nfdresult_t NFD_PickFolderU8(nfdu8char_t** outPath, + const nfdu8char_t* defaultPath, + int overrideRecentWithDefault = 0) { return NFD_PickFolderN(outPath, defaultPath); } @@ -464,7 +475,9 @@ nfdresult_t NFD_PickFolderU8_With_Impl(nfdversion_t version, return NFD_PickFolderN_With_Impl(version, outPath, args); } -nfdresult_t NFD_PickFolderMultipleN(const nfdpathset_t** outPaths, const nfdnchar_t* defaultPath) { +nfdresult_t NFD_PickFolderMultipleN(const nfdpathset_t** outPaths, + const nfdnchar_t* defaultPath, + int overrideRecentWithDefault = 0) { nfdpickfoldernargs_t args = {0}; args.defaultPath = defaultPath; return NFD_PickFolderMultipleN_With_Impl(NFD_INTERFACE_VERSION, outPaths, &args); @@ -512,7 +525,8 @@ nfdresult_t NFD_PickFolderMultipleN_With_Impl(nfdversion_t version, } nfdresult_t NFD_PickFolderMultipleU8(const nfdpathset_t** outPaths, - const nfdu8char_t* defaultPath) { + const nfdu8char_t* defaultPath, + int overrideRecentWithDefault = 0) { return NFD_PickFolderMultipleN(outPaths, defaultPath); } diff --git a/src/nfd_gtk.cpp b/src/nfd_gtk.cpp index bdb6292..4ad6407 100644 --- a/src/nfd_gtk.cpp +++ b/src/nfd_gtk.cpp @@ -507,7 +507,8 @@ void NFD_FreePathU8(nfdu8char_t* filePath) __attribute__((alias("NFD_FreePathN") nfdresult_t NFD_OpenDialogN(nfdnchar_t** outPath, const nfdnfilteritem_t* filterList, nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath) { + const nfdnchar_t* defaultPath, + int overrideRecentWithDefault = 0) { nfdopendialognargs_t args{}; args.filterList = filterList; args.filterCount = filterCount; @@ -561,7 +562,8 @@ nfdresult_t NFD_OpenDialogN_With_Impl(nfdversion_t version, nfdresult_t NFD_OpenDialogU8(nfdu8char_t** outPath, const nfdu8filteritem_t* filterList, nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath) + const nfdu8char_t* defaultPath, + int overrideRecentWithDefault = 0) __attribute__((alias("NFD_OpenDialogN"))); nfdresult_t NFD_OpenDialogU8_With_Impl(nfdversion_t version, @@ -630,7 +632,8 @@ nfdresult_t NFD_OpenDialogMultipleN_With_Impl(nfdversion_t version, nfdresult_t NFD_OpenDialogMultipleU8(const nfdpathset_t** outPaths, const nfdu8filteritem_t* filterList, nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath) + const nfdu8char_t* defaultPath, + int overrideRecentWithDefault = 0) __attribute__((alias("NFD_OpenDialogMultipleN"))); nfdresult_t NFD_OpenDialogMultipleU8_With_Impl(nfdversion_t version, @@ -719,7 +722,8 @@ nfdresult_t NFD_SaveDialogU8(nfdu8char_t** outPath, const nfdu8filteritem_t* filterList, nfdfiltersize_t filterCount, const nfdu8char_t* defaultPath, - const nfdu8char_t* defaultName) + const nfdu8char_t* defaultName, + int overrideRecentWithDefault = 0) __attribute__((alias("NFD_SaveDialogN"))); nfdresult_t NFD_SaveDialogU8_With_Impl(nfdversion_t version, @@ -773,7 +777,9 @@ nfdresult_t NFD_PickFolderN_With_Impl(nfdversion_t version, } } -nfdresult_t NFD_PickFolderU8(nfdu8char_t** outPath, const nfdu8char_t* defaultPath) +nfdresult_t NFD_PickFolderU8(nfdu8char_t** outPath, + const nfdu8char_t* defaultPath, + int overrideRecentWithDefault = 0) __attribute__((alias("NFD_PickFolderN"))); nfdresult_t NFD_PickFolderU8_With_Impl(nfdversion_t version, @@ -828,7 +834,9 @@ nfdresult_t NFD_PickFolderMultipleN_With_Impl(nfdversion_t version, } } -nfdresult_t NFD_PickFolderMultipleU8(const nfdpathset_t** outPaths, const nfdu8char_t* defaultPath) +nfdresult_t NFD_PickFolderMultipleU8(const nfdpathset_t** outPaths, + const nfdu8char_t* defaultPath, + int overrideRecentWithDefault = 0) __attribute__((alias("NFD_PickFolderMultipleN"))); nfdresult_t NFD_PickFolderMultipleU8_With_Impl(nfdversion_t version, diff --git a/src/nfd_portal.cpp b/src/nfd_portal.cpp index 684c502..5a5199a 100644 --- a/src/nfd_portal.cpp +++ b/src/nfd_portal.cpp @@ -1429,7 +1429,8 @@ void NFD_FreePathU8(nfdu8char_t* filePath) __attribute__((alias("NFD_FreePathN") nfdresult_t NFD_OpenDialogN(nfdnchar_t** outPath, const nfdnfilteritem_t* filterList, nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath) { + const nfdnchar_t* defaultPath, + int overrideRecentWithDefault = 0) { nfdopendialognargs_t args{}; args.filterList = filterList; args.filterCount = filterCount; @@ -1467,7 +1468,8 @@ nfdresult_t NFD_OpenDialogN_With_Impl(nfdversion_t version, nfdresult_t NFD_OpenDialogU8(nfdu8char_t** outPath, const nfdu8filteritem_t* filterList, nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath) + const nfdu8char_t* defaultPath, + int overrideRecentWithDefault = 0) __attribute__((alias("NFD_OpenDialogN"))); nfdresult_t NFD_OpenDialogU8_With_Impl(nfdversion_t version, @@ -1515,7 +1517,8 @@ nfdresult_t NFD_OpenDialogMultipleN_With_Impl(nfdversion_t version, nfdresult_t NFD_OpenDialogMultipleU8(const nfdpathset_t** outPaths, const nfdu8filteritem_t* filterList, nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath) + const nfdu8char_t* defaultPath, + int overrideRecentWithDefault = 0) __attribute__((alias("NFD_OpenDialogMultipleN"))); nfdresult_t NFD_OpenDialogMultipleU8_With_Impl(nfdversion_t version, @@ -1584,7 +1587,8 @@ nfdresult_t NFD_SaveDialogU8(nfdu8char_t** outPath, const nfdu8filteritem_t* filterList, nfdfiltersize_t filterCount, const nfdu8char_t* defaultPath, - const nfdu8char_t* defaultName) + const nfdu8char_t* defaultName, + int overrideRecentWithDefault = 0) __attribute__((alias("NFD_SaveDialogN"))); nfdresult_t NFD_SaveDialogU8_With_Impl(nfdversion_t version, @@ -1641,7 +1645,9 @@ nfdresult_t NFD_PickFolderN_With_Impl(nfdversion_t version, return AllocAndCopyFilePath(uri, *outPath); } -nfdresult_t NFD_PickFolderU8(nfdu8char_t** outPath, const nfdu8char_t* defaultPath) +nfdresult_t NFD_PickFolderU8(nfdu8char_t** outPath, + const nfdu8char_t* defaultPath, + int overrideRecentWithDefault = 0) __attribute__((alias("NFD_PickFolderN"))); nfdresult_t NFD_PickFolderU8_With_Impl(nfdversion_t version, @@ -1697,7 +1703,9 @@ nfdresult_t NFD_PickFolderMultipleN_With_Impl(nfdversion_t version, return NFD_OKAY; } -nfdresult_t NFD_PickFolderMultipleU8(const nfdpathset_t** outPaths, const nfdu8char_t* defaultPath) +nfdresult_t NFD_PickFolderMultipleU8(const nfdpathset_t** outPaths, + const nfdu8char_t* defaultPath, + int overrideRecentWithDefault = 0) __attribute__((alias("NFD_PickFolderMultipleN"))); nfdresult_t NFD_PickFolderMultipleU8_With_Impl(nfdversion_t version, diff --git a/src/nfd_win.cpp b/src/nfd_win.cpp index 4bf07e2..7d7264d 100644 --- a/src/nfd_win.cpp +++ b/src/nfd_win.cpp @@ -231,7 +231,9 @@ nfdresult_t SetDefaultExtension(::IFileDialog* fileOpenDialog, return NFD_OKAY; } -nfdresult_t SetDefaultPath(IFileDialog* dialog, const nfdnchar_t* defaultPath) { +nfdresult_t SetDefaultPath(IFileDialog* dialog, + const nfdnchar_t* defaultPath, + int overrideRecentWithDefault = 0) { if (!defaultPath || !*defaultPath) return NFD_OKAY; IShellItem* folder; @@ -249,13 +251,19 @@ nfdresult_t SetDefaultPath(IFileDialog* dialog, const nfdnchar_t* defaultPath) { } Release_Guard 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 - if (!SUCCEEDED(dialog->SetDefaultFolder(folder))) { - NFDi_SetError("Failed to set default path."); - return NFD_ERROR; + if (overrideRecentWithDefault == 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; + } } return NFD_OKAY; @@ -340,11 +348,14 @@ void NFD_FreePathN(nfdnchar_t* filePath) { nfdresult_t NFD_OpenDialogN(nfdnchar_t** outPath, const nfdnfilteritem_t* filterList, nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath) { + const nfdnchar_t* defaultPath, + int overrideRecentWithDefault = 0) { nfdopendialognargs_t args{}; args.filterList = filterList; args.filterCount = filterCount; args.defaultPath = defaultPath; + args.overrideRecentWithDefault = overrideRecentWithDefault; + return NFD_OpenDialogN_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); } @@ -382,7 +393,7 @@ nfdresult_t NFD_OpenDialogN_With_Impl(nfdversion_t version, } // Set the default path - if (!SetDefaultPath(fileOpenDialog, args->defaultPath)) { + if (!SetDefaultPath(fileOpenDialog, args->defaultPath, args->overrideRecentWithDefault)) { return NFD_ERROR; } @@ -424,11 +435,13 @@ nfdresult_t NFD_OpenDialogN_With_Impl(nfdversion_t version, nfdresult_t NFD_OpenDialogMultipleN(const nfdpathset_t** outPaths, const nfdnfilteritem_t* filterList, nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath) { + const nfdnchar_t* defaultPath, + int overrideRecentWithDefault = 0) { nfdopendialognargs_t args{}; args.filterList = filterList; args.filterCount = filterCount; args.defaultPath = defaultPath; + args.overrideRecentWithDefault = overrideRecentWithDefault; return NFD_OpenDialogMultipleN_With_Impl(NFD_INTERFACE_VERSION, outPaths, &args); } @@ -466,7 +479,7 @@ nfdresult_t NFD_OpenDialogMultipleN_With_Impl(nfdversion_t version, } // Set the default path - if (!SetDefaultPath(fileOpenDialog, args->defaultPath)) { + if (!SetDefaultPath(fileOpenDialog, args->defaultPath, args->overrideRecentWithDefault)) { return NFD_ERROR; } @@ -501,12 +514,14 @@ nfdresult_t NFD_SaveDialogN(nfdnchar_t** outPath, const nfdnfilteritem_t* filterList, nfdfiltersize_t filterCount, const nfdnchar_t* defaultPath, - const nfdnchar_t* defaultName) { + const nfdnchar_t* defaultName, + int overrideRecentWithDefault = 0) { nfdsavedialognargs_t args{}; args.filterList = filterList; args.filterCount = filterCount; args.defaultPath = defaultPath; args.defaultName = defaultName; + args.overrideRecentWithDefault = overrideRecentWithDefault; return NFD_SaveDialogN_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); } @@ -544,7 +559,7 @@ nfdresult_t NFD_SaveDialogN_With_Impl(nfdversion_t version, } // Set the default path - if (!SetDefaultPath(fileSaveDialog, args->defaultPath)) { + if (!SetDefaultPath(fileSaveDialog, args->defaultPath, args->overrideRecentWithDefault)) { return NFD_ERROR; } @@ -588,9 +603,12 @@ nfdresult_t NFD_SaveDialogN_With_Impl(nfdversion_t version, } } -nfdresult_t NFD_PickFolderN(nfdnchar_t** outPath, const nfdnchar_t* defaultPath) { +nfdresult_t NFD_PickFolderN(nfdnchar_t** outPath, + const nfdnchar_t* defaultPath, + int overrideRecentWithDefault = 0) { nfdpickfoldernargs_t args{}; args.defaultPath = defaultPath; + args.overrideRecentWithDefault = overrideRecentWithDefault; return NFD_PickFolderN_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); } @@ -615,7 +633,7 @@ nfdresult_t NFD_PickFolderN_With_Impl(nfdversion_t version, Release_Guard<::IFileOpenDialog> fileOpenDialogGuard(fileOpenDialog); // Set the default path - if (!SetDefaultPath(fileOpenDialog, args->defaultPath)) { + if (!SetDefaultPath(fileOpenDialog, args->defaultPath, args->overrideRecentWithDefault)) { return NFD_ERROR; } @@ -654,9 +672,12 @@ nfdresult_t NFD_PickFolderN_With_Impl(nfdversion_t version, return NFD_OKAY; } -nfdresult_t NFD_PickFolderMultipleN(const nfdpathset_t** outPaths, const nfdnchar_t* defaultPath) { +nfdresult_t NFD_PickFolderMultipleN(const nfdpathset_t** outPaths, + const nfdnchar_t* defaultPath, + int overrideRecentWithDefault = 0) { nfdpickfoldernargs_t args{}; args.defaultPath = defaultPath; + args.overrideRecentWithDefault = overrideRecentWithDefault; return NFD_PickFolderMultipleN_With_Impl(NFD_INTERFACE_VERSION, outPaths, &args); } @@ -681,7 +702,7 @@ nfdresult_t NFD_PickFolderMultipleN_With_Impl(nfdversion_t version, Release_Guard<::IFileOpenDialog> fileOpenDialogGuard(fileOpenDialog); // Set the default path - if (!SetDefaultPath(fileOpenDialog, args->defaultPath)) { + if (!SetDefaultPath(fileOpenDialog, args->defaultPath, args->overrideRecentWithDefault)) { return NFD_ERROR; } @@ -927,11 +948,13 @@ void NFD_FreePathU8(nfdu8char_t* outPath) { nfdresult_t NFD_OpenDialogU8(nfdu8char_t** outPath, const nfdu8filteritem_t* filterList, nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath) { + const nfdu8char_t* defaultPath, + int overrideRecentWithDefault = 0) { nfdopendialogu8args_t args{}; args.filterList = filterList; args.filterCount = filterCount; args.defaultPath = defaultPath; + args.overrideRecentWithDefault = overrideRecentWithDefault; return NFD_OpenDialogU8_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); } @@ -955,7 +978,7 @@ nfdresult_t NFD_OpenDialogU8_With_Impl(nfdversion_t version, // call the native function nfdnchar_t* outPathN; const nfdopendialognargs_t argsN{ - filterItemsNGuard.data, args->filterCount, defaultPathNGuard.data, args->parentWindow}; + filterItemsNGuard.data, args->filterCount, defaultPathNGuard.data, args->parentWindow, args->overrideRecentWithDefault}; nfdresult_t res = NFD_OpenDialogN_With_Impl(NFD_INTERFACE_VERSION, &outPathN, &argsN); if (res != NFD_OKAY) { @@ -976,11 +999,13 @@ nfdresult_t NFD_OpenDialogU8_With_Impl(nfdversion_t version, nfdresult_t NFD_OpenDialogMultipleU8(const nfdpathset_t** outPaths, const nfdu8filteritem_t* filterList, nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath) { + const nfdu8char_t* defaultPath, + int overrideRecentWithDefault = 0) { nfdopendialogu8args_t args{}; args.filterList = filterList; args.filterCount = filterCount; args.defaultPath = defaultPath; + args.overrideRecentWithDefault = overrideRecentWithDefault; return NFD_OpenDialogMultipleU8_With_Impl(NFD_INTERFACE_VERSION, outPaths, &args); } @@ -1003,7 +1028,7 @@ nfdresult_t NFD_OpenDialogMultipleU8_With_Impl(nfdversion_t version, // call the native function const nfdopendialognargs_t argsN{ - filterItemsNGuard.data, args->filterCount, defaultPathNGuard.data, args->parentWindow}; + filterItemsNGuard.data, args->filterCount, defaultPathNGuard.data, args->parentWindow, args->overrideRecentWithDefault}; return NFD_OpenDialogMultipleN_With_Impl(NFD_INTERFACE_VERSION, outPaths, &argsN); } @@ -1014,12 +1039,14 @@ nfdresult_t NFD_SaveDialogU8(nfdu8char_t** outPath, const nfdu8filteritem_t* filterList, nfdfiltersize_t filterCount, const nfdu8char_t* defaultPath, - const nfdu8char_t* defaultName) { + const nfdu8char_t* defaultName, + int overrideRecentWithDefault = 0) { nfdsavedialogu8args_t args{}; args.filterList = filterList; args.filterCount = filterCount; args.defaultPath = defaultPath; args.defaultName = defaultName; + args.overrideRecentWithDefault = overrideRecentWithDefault; return NFD_SaveDialogU8_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); } @@ -1050,7 +1077,8 @@ nfdresult_t NFD_SaveDialogU8_With_Impl(nfdversion_t version, args->filterCount, defaultPathNGuard.data, defaultNameNGuard.data, - args->parentWindow}; + args->parentWindow, + args->overrideRecentWithDefault}; nfdresult_t res = NFD_SaveDialogN_With_Impl(NFD_INTERFACE_VERSION, &outPathN, &argsN); if (res != NFD_OKAY) { @@ -1068,9 +1096,12 @@ nfdresult_t NFD_SaveDialogU8_With_Impl(nfdversion_t version, /* select folder dialog */ /* It is the caller's responsibility to free `outPath` via NFD_FreePathU8() if this function returns * NFD_OKAY */ -nfdresult_t NFD_PickFolderU8(nfdu8char_t** outPath, const nfdu8char_t* defaultPath) { +nfdresult_t NFD_PickFolderU8(nfdu8char_t** outPath, + const nfdu8char_t* defaultPath, + int overrideRecentWithDefault = 0) { nfdpickfolderu8args_t args{}; args.defaultPath = defaultPath; + args.overrideRecentWithDefault = overrideRecentWithDefault; return NFD_PickFolderU8_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); } @@ -1087,7 +1118,7 @@ nfdresult_t NFD_PickFolderU8_With_Impl(nfdversion_t version, // call the native function nfdnchar_t* outPathN; - const nfdpickfoldernargs_t argsN{defaultPathNGuard.data, args->parentWindow}; + const nfdpickfoldernargs_t argsN{defaultPathNGuard.data, args->parentWindow, args->overrideRecentWithDefault}; nfdresult_t res = NFD_PickFolderN_With_Impl(NFD_INTERFACE_VERSION, &outPathN, &argsN); if (res != NFD_OKAY) { @@ -1106,9 +1137,11 @@ nfdresult_t NFD_PickFolderU8_With_Impl(nfdversion_t version, /* It is the caller's responsibility to free `outPaths` via NFD_PathSet_FreeU8() if this function * returns NFD_OKAY. */ nfdresult_t NFD_PickFolderMultipleU8(const nfdpathset_t** outPaths, - const nfdu8char_t* defaultPath) { + const nfdu8char_t* defaultPath, + int overrideRecentWithDefault = 0) { nfdpickfolderu8args_t args{}; args.defaultPath = defaultPath; + args.overrideRecentWithDefault = overrideRecentWithDefault; return NFD_PickFolderMultipleU8_With_Impl(NFD_INTERFACE_VERSION, outPaths, &args); } @@ -1124,7 +1157,7 @@ nfdresult_t NFD_PickFolderMultipleU8_With_Impl(nfdversion_t version, NormalizePathSeparator(defaultPathNGuard.data); // call the native function - const nfdpickfoldernargs_t argsN{defaultPathNGuard.data, args->parentWindow}; + const nfdpickfoldernargs_t argsN{defaultPathNGuard.data, args->parentWindow, args->overrideRecentWithDefault}; return NFD_PickFolderMultipleN_With_Impl(NFD_INTERFACE_VERSION, outPaths, &argsN); } diff --git a/test/test_opendialog.c b/test/test_opendialog.c index 412d019..f6c6203 100644 --- a/test/test_opendialog.c +++ b/test/test_opendialog.c @@ -17,7 +17,7 @@ int main(void) { nfdfilteritem_t filterItem[2] = {{"Source code", "c,cpp,cc"}, {"Headers", "h,hpp"}}; // show the dialog - nfdresult_t result = NFD_OpenDialog(&outPath, filterItem, 2, NULL); + nfdresult_t result = NFD_OpenDialog(&outPath, filterItem, 2, NULL, 0); if (result == NFD_OKAY) { puts("Success!"); puts(outPath); diff --git a/test/test_opendialog_native.c b/test/test_opendialog_native.c index e600b73..9bba340 100644 --- a/test/test_opendialog_native.c +++ b/test/test_opendialog_native.c @@ -22,7 +22,7 @@ int main(void) { #endif // show the dialog - nfdresult_t result = NFD_OpenDialog(&outPath, filterItem, 2, NULL); + nfdresult_t result = NFD_OpenDialog(&outPath, filterItem, 2, NULL, 0); if (result == NFD_OKAY) { puts("Success!"); #ifdef _WIN32 diff --git a/test/test_opendialogmultiple.c b/test/test_opendialogmultiple.c index 6b1d189..addeec2 100644 --- a/test/test_opendialogmultiple.c +++ b/test/test_opendialogmultiple.c @@ -17,7 +17,7 @@ int main(void) { nfdfilteritem_t filterItem[2] = {{"Source code", "c,cpp,cc"}, {"Headers", "h,hpp"}}; // show the dialog - nfdresult_t result = NFD_OpenDialogMultiple(&outPaths, filterItem, 2, NULL); + nfdresult_t result = NFD_OpenDialogMultiple(&outPaths, filterItem, 2, NULL, 0); if (result == NFD_OKAY) { puts("Success!"); diff --git a/test/test_opendialogmultiple_enum.c b/test/test_opendialogmultiple_enum.c index 827029c..89c3b21 100644 --- a/test/test_opendialogmultiple_enum.c +++ b/test/test_opendialogmultiple_enum.c @@ -17,7 +17,7 @@ int main(void) { nfdfilteritem_t filterItem[2] = {{"Source code", "c,cpp,cc"}, {"Headers", "h,hpp"}}; // show the dialog - nfdresult_t result = NFD_OpenDialogMultiple(&outPaths, filterItem, 2, NULL); + nfdresult_t result = NFD_OpenDialogMultiple(&outPaths, filterItem, 2, NULL, 0); if (result == NFD_OKAY) { puts("Success!"); diff --git a/test/test_opendialogmultiple_enum_native.c b/test/test_opendialogmultiple_enum_native.c index 01802bc..5ada021 100644 --- a/test/test_opendialogmultiple_enum_native.c +++ b/test/test_opendialogmultiple_enum_native.c @@ -22,7 +22,7 @@ int main(void) { #endif // show the dialog - nfdresult_t result = NFD_OpenDialogMultiple(&outPaths, filterItem, 2, NULL); + nfdresult_t result = NFD_OpenDialogMultiple(&outPaths, filterItem, 2, NULL, 0); if (result == NFD_OKAY) { puts("Success!"); diff --git a/test/test_opendialogmultiple_native.c b/test/test_opendialogmultiple_native.c index b52ba27..619e929 100644 --- a/test/test_opendialogmultiple_native.c +++ b/test/test_opendialogmultiple_native.c @@ -22,7 +22,7 @@ int main(void) { #endif // show the dialog - nfdresult_t result = NFD_OpenDialogMultiple(&outPaths, filterItem, 2, NULL); + nfdresult_t result = NFD_OpenDialogMultiple(&outPaths, filterItem, 2, NULL, 0); if (result == NFD_OKAY) { puts("Success!"); diff --git a/test/test_pickfolder.c b/test/test_pickfolder.c index 12df199..4958d80 100644 --- a/test/test_pickfolder.c +++ b/test/test_pickfolder.c @@ -14,7 +14,7 @@ int main(void) { nfdchar_t* outPath; // show the dialog - nfdresult_t result = NFD_PickFolder(&outPath, NULL); + nfdresult_t result = NFD_PickFolder(&outPath, NULL, 0); if (result == NFD_OKAY) { puts("Success!"); puts(outPath); diff --git a/test/test_pickfolder_native.c b/test/test_pickfolder_native.c index e311acc..b119dba 100644 --- a/test/test_pickfolder_native.c +++ b/test/test_pickfolder_native.c @@ -15,7 +15,7 @@ int main(void) { nfdchar_t* outPath; // show the dialog - nfdresult_t result = NFD_PickFolder(&outPath, NULL); + nfdresult_t result = NFD_PickFolder(&outPath, NULL, 0); if (result == NFD_OKAY) { puts("Success!"); #ifdef _WIN32 diff --git a/test/test_pickfoldermultiple.c b/test/test_pickfoldermultiple.c index 23ad4db..7d024fe 100644 --- a/test/test_pickfoldermultiple.c +++ b/test/test_pickfoldermultiple.c @@ -14,7 +14,7 @@ int main(void) { const nfdpathset_t* outPaths; // show the dialog - nfdresult_t result = NFD_PickFolderMultiple(&outPaths, NULL); + nfdresult_t result = NFD_PickFolderMultiple(&outPaths, NULL, 0); if (result == NFD_OKAY) { puts("Success!"); diff --git a/test/test_pickfoldermultiple_native.c b/test/test_pickfoldermultiple_native.c index 93c1449..79363cc 100644 --- a/test/test_pickfoldermultiple_native.c +++ b/test/test_pickfoldermultiple_native.c @@ -15,7 +15,7 @@ int main(void) { const nfdpathset_t* outPaths; // show the dialog - nfdresult_t result = NFD_PickFolderMultiple(&outPaths, NULL); + nfdresult_t result = NFD_PickFolderMultiple(&outPaths, NULL, 0); if (result == NFD_OKAY) { puts("Success!"); diff --git a/test/test_savedialog.c b/test/test_savedialog.c index 42ff595..b3051e5 100644 --- a/test/test_savedialog.c +++ b/test/test_savedialog.c @@ -17,7 +17,7 @@ int main(void) { nfdfilteritem_t filterItem[2] = {{"Source code", "c,cpp,cc"}, {"Header", "h,hpp"}}; // show the dialog - nfdresult_t result = NFD_SaveDialog(&savePath, filterItem, 2, NULL, "Untitled.c"); + nfdresult_t result = NFD_SaveDialog(&savePath, filterItem, 2, NULL, "Untitled.c", 0); if (result == NFD_OKAY) { puts("Success!"); puts(savePath); diff --git a/test/test_savedialog_native.c b/test/test_savedialog_native.c index d1ee09d..8b5b5e7 100644 --- a/test/test_savedialog_native.c +++ b/test/test_savedialog_native.c @@ -28,7 +28,7 @@ int main(void) { #endif // show the dialog - nfdresult_t result = NFD_SaveDialog(&savePath, filterItem, 2, NULL, defaultPath); + nfdresult_t result = NFD_SaveDialog(&savePath, filterItem, 2, NULL, defaultPath, 0); if (result == NFD_OKAY) { puts("Success!"); #ifdef _WIN32