Skip to content

Commit 1c01eca

Browse files
committed
New feature: Allow customisation of dialog title, accept label, and cancel label
1 parent 4826ee6 commit 1c01eca

14 files changed

Lines changed: 514 additions & 125 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# VS CMake default output
22
/.vs/
33
/out/
4+
/build/
45
/CMakeSettings.json
56

67
# Mac OS X rubbish

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ typedef struct {
207207
nfdfiltersize_t filterCount;
208208
const nfdu8char_t* defaultPath;
209209
nfdwindowhandle_t parentWindow;
210+
const nfdu8char_t* title;
211+
const nfdu8char_t* acceptLabel;
212+
const nfdu8char_t* cancelLabel;
210213
} nfdopendialogu8args_t;
211214
```
212215

@@ -218,6 +221,9 @@ typedef struct {
218221
const nfdu8char_t* defaultPath;
219222
const nfdu8char_t* defaultName;
220223
nfdwindowhandle_t parentWindow;
224+
const nfdu8char_t* title;
225+
const nfdu8char_t* acceptLabel;
226+
const nfdu8char_t* cancelLabel;
221227
} nfdsavedialogu8args_t;
222228
```
223229

@@ -226,13 +232,19 @@ typedef struct {
226232
typedef struct {
227233
const nfdu8char_t* defaultPath;
228234
nfdwindowhandle_t parentWindow;
235+
const nfdu8char_t* title;
236+
const nfdu8char_t* acceptLabel;
237+
const nfdu8char_t* cancelLabel;
229238
} nfdpickfolderu8args_t;
230239
```
231240

232241
- `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.
233242
- `defaultPath`: Set this to the default folder that the dialog should open to (see the "Platform-specific Quirks" section for more details about the behaviour of this option on Windows).
234243
- `defaultName`: (For SaveDialog only) Set this to the file name that should be pre-filled on the dialog.
235244
- `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.
245+
- `title`: Set this to customize the title of the dialog window. If left unset, the operating system's default title (in the user's language) is used on Windows and macOS, while a hardcoded English title (such as "Open File" or "Save File") is used on Linux (GTK and Portal).
246+
- `acceptLabel`: Set this to customize the text of the accept (confirmation) button, e.g. the "Open" or "Save" button. If left unset, the operating system's default text (in the user's language) is used, except on Linux (GTK), where a hardcoded English label (such as "Open" or "Save") is used.
247+
- `cancelLabel`: Set this to customize the text of the cancel button. If left unset, the operating system's default text (in the user's language) is used, except on Linux (GTK), where the hardcoded English label "Cancel" is used. *This option is supported on Windows (7 and later) and Linux (GTK); it is ignored on macOS and Linux (Portal), where the cancel button text is not customizable.*
236248

237249
## Examples
238250

src/include/nfd.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ typedef struct {
122122
nfdfiltersize_t filterCount;
123123
const nfdu8char_t* defaultPath;
124124
nfdwindowhandle_t parentWindow;
125+
const nfdu8char_t* title;
126+
const nfdu8char_t* acceptLabel;
127+
const nfdu8char_t* cancelLabel;
125128
} nfdopendialogu8args_t;
126129

127130
#ifdef _WIN32
@@ -130,6 +133,9 @@ typedef struct {
130133
nfdfiltersize_t filterCount;
131134
const nfdnchar_t* defaultPath;
132135
nfdwindowhandle_t parentWindow;
136+
const nfdnchar_t* title;
137+
const nfdnchar_t* acceptLabel;
138+
const nfdnchar_t* cancelLabel;
133139
} nfdopendialognargs_t;
134140
#else
135141
typedef nfdopendialogu8args_t nfdopendialognargs_t;
@@ -141,6 +147,9 @@ typedef struct {
141147
const nfdu8char_t* defaultPath;
142148
const nfdu8char_t* defaultName;
143149
nfdwindowhandle_t parentWindow;
150+
const nfdu8char_t* title;
151+
const nfdu8char_t* acceptLabel;
152+
const nfdu8char_t* cancelLabel;
144153
} nfdsavedialogu8args_t;
145154

146155
#ifdef _WIN32
@@ -150,6 +159,9 @@ typedef struct {
150159
const nfdnchar_t* defaultPath;
151160
const nfdnchar_t* defaultName;
152161
nfdwindowhandle_t parentWindow;
162+
const nfdnchar_t* title;
163+
const nfdnchar_t* acceptLabel;
164+
const nfdnchar_t* cancelLabel;
153165
} nfdsavedialognargs_t;
154166
#else
155167
typedef nfdsavedialogu8args_t nfdsavedialognargs_t;
@@ -158,12 +170,18 @@ typedef nfdsavedialogu8args_t nfdsavedialognargs_t;
158170
typedef struct {
159171
const nfdu8char_t* defaultPath;
160172
nfdwindowhandle_t parentWindow;
173+
const nfdu8char_t* title;
174+
const nfdu8char_t* acceptLabel;
175+
const nfdu8char_t* cancelLabel;
161176
} nfdpickfolderu8args_t;
162177

163178
#ifdef _WIN32
164179
typedef struct {
165180
const nfdnchar_t* defaultPath;
166181
nfdwindowhandle_t parentWindow;
182+
const nfdnchar_t* title;
183+
const nfdnchar_t* acceptLabel;
184+
const nfdnchar_t* cancelLabel;
167185
} nfdpickfoldernargs_t;
168186
#else
169187
typedef nfdpickfolderu8args_t nfdpickfoldernargs_t;
@@ -172,7 +190,7 @@ typedef nfdpickfolderu8args_t nfdpickfoldernargs_t;
172190
// This is a unique identifier tagged to all the NFD_*With() function calls, for backward
173191
// compatibility purposes. There is usually no need to use this directly, unless you want to use
174192
// NFD differently depending on the version you're building with.
175-
#define NFD_INTERFACE_VERSION 1
193+
#define NFD_INTERFACE_VERSION 2
176194

177195
/** Free a file path that was returned by the dialogs.
178196
*

src/include/nfd.hpp

Lines changed: 72 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,25 @@ inline nfdresult_t OpenDialog(nfdnchar_t*& outPath,
3838
const nfdnfilteritem_t* filterList = nullptr,
3939
nfdfiltersize_t filterCount = 0,
4040
const nfdnchar_t* defaultPath = nullptr,
41-
nfdwindowhandle_t parentWindow = {}) noexcept {
42-
const nfdopendialognargs_t args{filterList, filterCount, defaultPath, parentWindow};
41+
nfdwindowhandle_t parentWindow = {},
42+
const nfdnchar_t* title = nullptr,
43+
const nfdnchar_t* acceptLabel = nullptr,
44+
const nfdnchar_t* cancelLabel = nullptr) noexcept {
45+
const nfdopendialognargs_t args{
46+
filterList, filterCount, defaultPath, parentWindow, title, acceptLabel, cancelLabel};
4347
return ::NFD_OpenDialogN_With(&outPath, &args);
4448
}
4549

4650
inline nfdresult_t OpenDialogMultiple(const nfdpathset_t*& outPaths,
4751
const nfdnfilteritem_t* filterList = nullptr,
4852
nfdfiltersize_t filterCount = 0,
4953
const nfdnchar_t* defaultPath = nullptr,
50-
nfdwindowhandle_t parentWindow = {}) noexcept {
51-
const nfdopendialognargs_t args{filterList, filterCount, defaultPath, parentWindow};
54+
nfdwindowhandle_t parentWindow = {},
55+
const nfdnchar_t* title = nullptr,
56+
const nfdnchar_t* acceptLabel = nullptr,
57+
const nfdnchar_t* cancelLabel = nullptr) noexcept {
58+
const nfdopendialognargs_t args{
59+
filterList, filterCount, defaultPath, parentWindow, title, acceptLabel, cancelLabel};
5260
return ::NFD_OpenDialogMultipleN_With(&outPaths, &args);
5361
}
5462

@@ -57,23 +65,40 @@ inline nfdresult_t SaveDialog(nfdnchar_t*& outPath,
5765
nfdfiltersize_t filterCount = 0,
5866
const nfdnchar_t* defaultPath = nullptr,
5967
const nfdnchar_t* defaultName = nullptr,
60-
nfdwindowhandle_t parentWindow = {}) noexcept {
61-
const nfdsavedialognargs_t args{
62-
filterList, filterCount, defaultPath, defaultName, parentWindow};
68+
nfdwindowhandle_t parentWindow = {},
69+
const nfdnchar_t* title = nullptr,
70+
const nfdnchar_t* acceptLabel = nullptr,
71+
const nfdnchar_t* cancelLabel = nullptr) noexcept {
72+
const nfdsavedialognargs_t args{filterList,
73+
filterCount,
74+
defaultPath,
75+
defaultName,
76+
parentWindow,
77+
title,
78+
acceptLabel,
79+
cancelLabel};
6380
return ::NFD_SaveDialogN_With(&outPath, &args);
6481
}
6582

6683
inline nfdresult_t PickFolder(nfdnchar_t*& outPath,
6784
const nfdnchar_t* defaultPath = nullptr,
68-
nfdwindowhandle_t parentWindow = {}) noexcept {
69-
const nfdpickfoldernargs_t args{defaultPath, parentWindow};
85+
nfdwindowhandle_t parentWindow = {},
86+
const nfdnchar_t* title = nullptr,
87+
const nfdnchar_t* acceptLabel = nullptr,
88+
const nfdnchar_t* cancelLabel = nullptr) noexcept {
89+
const nfdpickfoldernargs_t args{
90+
defaultPath, parentWindow, title, acceptLabel, cancelLabel};
7091
return ::NFD_PickFolderN_With(&outPath, &args);
7192
}
7293

7394
inline nfdresult_t PickFolderMultiple(const nfdpathset_t*& outPaths,
7495
const nfdnchar_t* defaultPath = nullptr,
75-
nfdwindowhandle_t parentWindow = {}) noexcept {
76-
const nfdpickfoldernargs_t args{defaultPath, parentWindow};
96+
nfdwindowhandle_t parentWindow = {},
97+
const nfdnchar_t* title = nullptr,
98+
const nfdnchar_t* acceptLabel = nullptr,
99+
const nfdnchar_t* cancelLabel = nullptr) noexcept {
100+
const nfdpickfoldernargs_t args{
101+
defaultPath, parentWindow, title, acceptLabel, cancelLabel};
77102
return ::NFD_PickFolderMultipleN_With(&outPaths, &args);
78103
}
79104

@@ -117,17 +142,25 @@ inline nfdresult_t OpenDialog(nfdu8char_t*& outPath,
117142
const nfdu8filteritem_t* filterList = nullptr,
118143
nfdfiltersize_t filterCount = 0,
119144
const nfdu8char_t* defaultPath = nullptr,
120-
nfdwindowhandle_t parentWindow = {}) noexcept {
121-
const nfdopendialogu8args_t args{filterList, filterCount, defaultPath, parentWindow};
145+
nfdwindowhandle_t parentWindow = {},
146+
const nfdu8char_t* title = nullptr,
147+
const nfdu8char_t* acceptLabel = nullptr,
148+
const nfdu8char_t* cancelLabel = nullptr) noexcept {
149+
const nfdopendialogu8args_t args{
150+
filterList, filterCount, defaultPath, parentWindow, title, acceptLabel, cancelLabel};
122151
return ::NFD_OpenDialogU8_With(&outPath, &args);
123152
}
124153

125154
inline nfdresult_t OpenDialogMultiple(const nfdpathset_t*& outPaths,
126155
const nfdu8filteritem_t* filterList = nullptr,
127156
nfdfiltersize_t filterCount = 0,
128157
const nfdu8char_t* defaultPath = nullptr,
129-
nfdwindowhandle_t parentWindow = {}) noexcept {
130-
const nfdopendialogu8args_t args{filterList, filterCount, defaultPath, parentWindow};
158+
nfdwindowhandle_t parentWindow = {},
159+
const nfdu8char_t* title = nullptr,
160+
const nfdu8char_t* acceptLabel = nullptr,
161+
const nfdu8char_t* cancelLabel = nullptr) noexcept {
162+
const nfdopendialogu8args_t args{
163+
filterList, filterCount, defaultPath, parentWindow, title, acceptLabel, cancelLabel};
131164
return ::NFD_OpenDialogMultipleU8_With(&outPaths, &args);
132165
}
133166

@@ -136,23 +169,40 @@ inline nfdresult_t SaveDialog(nfdu8char_t*& outPath,
136169
nfdfiltersize_t filterCount = 0,
137170
const nfdu8char_t* defaultPath = nullptr,
138171
const nfdu8char_t* defaultName = nullptr,
139-
nfdwindowhandle_t parentWindow = {}) noexcept {
140-
const nfdsavedialogu8args_t args{
141-
filterList, filterCount, defaultPath, defaultName, parentWindow};
172+
nfdwindowhandle_t parentWindow = {},
173+
const nfdu8char_t* title = nullptr,
174+
const nfdu8char_t* acceptLabel = nullptr,
175+
const nfdu8char_t* cancelLabel = nullptr) noexcept {
176+
const nfdsavedialogu8args_t args{filterList,
177+
filterCount,
178+
defaultPath,
179+
defaultName,
180+
parentWindow,
181+
title,
182+
acceptLabel,
183+
cancelLabel};
142184
return ::NFD_SaveDialogU8_With(&outPath, &args);
143185
}
144186

145187
inline nfdresult_t PickFolder(nfdu8char_t*& outPath,
146188
const nfdu8char_t* defaultPath = nullptr,
147-
nfdwindowhandle_t parentWindow = {}) noexcept {
148-
const nfdpickfolderu8args_t args{defaultPath, parentWindow};
189+
nfdwindowhandle_t parentWindow = {},
190+
const nfdu8char_t* title = nullptr,
191+
const nfdu8char_t* acceptLabel = nullptr,
192+
const nfdu8char_t* cancelLabel = nullptr) noexcept {
193+
const nfdpickfolderu8args_t args{
194+
defaultPath, parentWindow, title, acceptLabel, cancelLabel};
149195
return ::NFD_PickFolderU8_With(&outPath, &args);
150196
}
151197

152198
inline nfdresult_t PickFolderMultiple(const nfdpathset_t*& outPaths,
153199
const nfdu8char_t* defaultPath = nullptr,
154-
nfdwindowhandle_t parentWindow = {}) noexcept {
155-
const nfdpickfolderu8args_t args{defaultPath, parentWindow};
200+
nfdwindowhandle_t parentWindow = {},
201+
const nfdu8char_t* title = nullptr,
202+
const nfdu8char_t* acceptLabel = nullptr,
203+
const nfdu8char_t* cancelLabel = nullptr) noexcept {
204+
const nfdpickfolderu8args_t args{
205+
defaultPath, parentWindow, title, acceptLabel, cancelLabel};
156206
return ::NFD_PickFolderMultipleU8_With(&outPaths, &args);
157207
}
158208

0 commit comments

Comments
 (0)