Skip to content

Commit

Permalink
Remove extern int and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
dbierek committed Sep 24, 2024
1 parent a9f57d7 commit 5df9fda
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
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, 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.

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, 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
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" ON)
if (NFD_OVERRIDE_RECENT_WITH_DEFAULT)
target_compile_definitions(${TARGET_NAME} PRIVATE nfd_OVERRIDE_RECENT_WITH_DEFAULT)
endif()
3 changes: 0 additions & 3 deletions src/include/nfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stddef.h>

typedef char nfdu8char_t;
Expand Down
28 changes: 13 additions & 15 deletions src/nfd_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ struct IUnknown; // Workaround for "combaseapi.h(229): error C2187: syntax erro
#include <windows.h>
#include "nfd.h"

int NFD_OVERRIDE_RECENT_WITH_DEFAULT = 1;

namespace {

/* current error */
Expand Down Expand Up @@ -252,20 +250,20 @@ nfdresult_t SetDefaultPath(IFileDialog* dialog, const nfdnchar_t* defaultPath) {

Release_Guard<IShellItem> 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;
}
Expand Down

0 comments on commit 5df9fda

Please sign in to comment.