Skip to content

Commit 489689a

Browse files
authored
Merge pull request #2286 from Azaezel/NFD_Update
Nfd update
2 parents e38eb34 + aebbb1e commit 489689a

File tree

7 files changed

+667
-70
lines changed

7 files changed

+667
-70
lines changed

Engine/lib/nativeFileDialogs/README.md

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Native File Dialog #
22

3-
A tiny, neat C library that portably invokes native file open and 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.
3+
A tiny, neat C library that portably invokes native file open, folder select and 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.
44

55
Features:
66

@@ -11,11 +11,12 @@ Features:
1111
- Paid support available.
1212
- Multiple file selection support.
1313
- 64-bit and 32-bit friendly.
14-
- GCC, Clang and Visual Studio supported.
15-
- No third party dependencies.
14+
- GCC, Clang, Xcode, Mingw and Visual Studio supported.
15+
- No third party dependencies for building or linking.
1616
- Support for Vista's modern `IFileDialog` on Windows.
1717
- Support for non-deprecated Cocoa APIs on OS X.
18-
- GTK+3 dialog on Linux.
18+
- GTK3 dialog on Linux.
19+
- Optional Zenity support on Linux to avoid linking GTK.
1920
- Tested, works alongside [http://www.libsdl.org](SDL2) on all platforms, for the game developers out there.
2021

2122
# Example Usage #
@@ -50,47 +51,74 @@ See [NFD.h](src/include/nfd.h) for more options.
5051
5152
# Screenshots #
5253
53-
![Windows 8 rendering an IFileOpenDialog](screens/open_win8.png?raw=true)
54+
![Windows 8 rendering an IFileOpenDialog](screens/open_win.png?raw=true)
5455
![GTK3 on Linux](screens/open_gtk3.png?raw=true)
5556
![Cocoa on Yosemite](screens/open_cocoa.png?raw=true)
5657
58+
## Changelog ##
59+
60+
release | what's new | date
61+
--------|-----------------------------|---------
62+
1.0.0 | initial | oct 2014
63+
1.1.0 | premake5; scons deprecated | aug 2016
64+
1.1.1 | mingw support, build fixes | aug 2016
65+
1.1.2 | test_pickfolder() added | aug 2016
66+
1.1.3 | zenity linux backend added | nov 2017
67+
1.1.3 | fix char type in decls | nov 2017
68+
1.1.4 | fix win32 memleaks | dec 2018
69+
1.1.4 | improve win32 errorhandling | dec 2018
70+
1.1.4 | macos fix focus bug | dec 2018
71+
5772
5873
## Building ##
5974
60-
NFD uses [SCons](http://www.scons.org) for cross-platform builds. After installing SCons, build it with:
75+
NFD uses [Premake5](https://premake.github.io/download.html) generated Makefiles and IDE project files. The generated project files are checked in under `build/` so you don't have to download and use Premake in most cases.
6176
62-
cd src
63-
scons debug=[0,1]
77+
If you need to run Premake5 directly, further [build documentation](docs/build.md) is available.
6478
65-
Alternatively, you can avoid Scons by just including NFD files to your existing project:
79+
Previously, NFD used SCons to build. It still works, but is now deprecated; updates to it are discouraged. Opt to use the native build system where possible.
6680
67-
1. Add all header files in `src/` and `src/include` to your project.
68-
2. Add `src/include` to your include search path or copy it into your existing search path.
69-
3. Add `src/nfd_common.c` to your project.
70-
4. Add `src/nfd_<platform>` to your project, where `<platform>` is the NFD backend for the platform you are fixing to build.
71-
5. On Visual Studio, define `_CRT_SECURE_NO_WARNINGS` to avoid warnings.
81+
`nfd.a` will be built for release builds, and `nfd_d.a` will be built for debug builds.
82+
83+
### Makefiles ###
84+
85+
The makefile offers five options, with `release_x64` as the default.
86+
87+
make config=release_x86
88+
make config=release_x64
89+
make config=debug_x86
90+
make config=debug_x64
7291
7392
### Compiling Your Programs ###
7493
7594
1. Add `src/include` to your include search path.
76-
2. Add `nfd.lib` to the list of list of static libraries to link against.
77-
3. Add `src/` to the library search path.
95+
2. Add `nfd.lib` or `nfd_d.lib` to the list of list of static libraries to link against (for release or debug, respectively).
96+
3. Add `build/<debug|release>/<arch>` to the library search path.
97+
98+
#### Linux GTK ####
99+
`apt-get libgtk-3-dev` installs the gtk dependency for library compilation.
78100
79-
On Linux, you must compile and link against GTK+. Recommend use of `pkg-config --cflags --libs gtk+-3.0`.
101+
On Linux, you have the option of compiling and linking against GTK. If you use it, the recommended way to compile is to include the arguments of `pkg-config --cflags --libs gtk+-3.0`.
80102
81-
On Mac OS X, add `AppKit` to the list of frameworks.
103+
#### Linux Zenity ####
82104
105+
Alternatively, you can use the Zenity backend by running the Makefile in `build/gmake_linux_zenity`. Zenity runs the dialog in its own address space, but requires the user to have Zenity correctly installed and configured on their system.
106+
107+
#### MacOS ####
108+
On Mac OS, add `AppKit` to the list of frameworks.
109+
110+
#### Windows ####
83111
On Windows, ensure you are building against `comctl32.lib`.
84112
85113
## Usage ##
86114
87115
See `NFD.h` for API calls. See `tests/*.c` for example code.
88116
89-
See `tests/SConstruct` for a working build script that compiles on all platforms.
117+
After compiling, `build/bin` contains compiled test programs.
90118
91119
## File Filter Syntax ##
92120
93-
There is a form of file filtering in every file dialog, but no consistent means of supporting it. NFD provides support for filtering files by groups of extensions, providing its own descriptions (where applicable) for the extensions.
121+
There is a form of file filtering in every file dialog API, but no consistent means of supporting it. NFD provides support for filtering files by groups of extensions, providing its own descriptions (where applicable) for the extensions.
94122
95123
A wildcard filter is always added to every dialog.
96124
@@ -113,23 +141,25 @@ See [test_opendialogmultiple.c](test/test_opendialogmultiple.c).
113141
114142
# Known Limitations #
115143
116-
I accept quality code patches, or will resolve these and other matters through support.
144+
I accept quality code patches, or will resolve these and other matters through support. See [submitting pull requests](docs/submitting_pull_requests.md) for details.
117145
118146
- No support for Windows XP's legacy dialogs such as `GetOpenFileName`.
119-
- No support for file filter names -- ex: "Image Files" (*.png, *.jpg). Nameless filters are supported, though.
120-
- No support for selecting folders instead of files.
121-
- On Linux, GTK+ cannot be uninitialized to save memory. Launching a file dialog costs memory. I am open to accepting an alternative `nfd_zenity.c` implementation which uses Zenity and pipes.
147+
- No support for file filter names -- ex: "Image Files" (*.png, *.jpg). Nameless filters are supported, however.
122148
123149
# Copyright and Credit #
124150
125-
Copyright &copy; 2014 [Frogtoss Games](http://www.frogtoss.com), Inc.
151+
Copyright &copy; 2014-2017 [Frogtoss Games](http://www.frogtoss.com), Inc.
126152
File [LICENSE](LICENSE) covers all files in this repo.
127153
128154
Native File Dialog by Michael Labbe
129155
130156
131157
Tomasz Konojacki for [microutf8](http://puszcza.gnu.org.ua/software/microutf8/)
132158
159+
[Denis Kolodin](https://github.com/DenisKolodin) for mingw support.
160+
161+
[Tom Mason](https://github.com/wheybags) for Zenity support.
162+
133163
## Support ##
134164
135165
Directed support for this work is available from the original author under a paid agreement.

Engine/lib/nativeFileDialogs/nfd_cocoa.m

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static nfdresult_t AllocPathSet( NSArray *urls, nfdpathset_t *pathset )
117117
/* public */
118118

119119

120-
nfdresult_t NFD_OpenDialog( const char *filterList,
120+
nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList,
121121
const nfdchar_t *defaultPath,
122122
nfdchar_t **outPath )
123123
{
@@ -146,6 +146,7 @@ nfdresult_t NFD_OpenDialog( const char *filterList,
146146
if ( !*outPath )
147147
{
148148
[pool release];
149+
[keyWindow makeKeyAndOrderFront:nil];
149150
return NFD_ERROR;
150151
}
151152
memcpy( *outPath, utf8Path, len+1 ); /* copy null term */
@@ -163,6 +164,7 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList,
163164
nfdpathset_t *outPaths )
164165
{
165166
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
167+
NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow];
166168

167169
NSOpenPanel *dialog = [NSOpenPanel openPanel];
168170
[dialog setAllowsMultipleSelection:YES];
@@ -181,19 +183,22 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList,
181183
if ( [urls count] == 0 )
182184
{
183185
[pool release];
186+
[keyWindow makeKeyAndOrderFront:nil];
184187
return NFD_CANCEL;
185188
}
186189

187190
if ( AllocPathSet( urls, outPaths ) == NFD_ERROR )
188191
{
189192
[pool release];
193+
[keyWindow makeKeyAndOrderFront:nil];
190194
return NFD_ERROR;
191195
}
192196

193197
nfdResult = NFD_OKAY;
194198
}
195199
[pool release];
196200

201+
[keyWindow makeKeyAndOrderFront:nil];
197202
return nfdResult;
198203
}
199204

@@ -203,7 +208,8 @@ nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
203208
nfdchar_t **outPath )
204209
{
205210
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
206-
211+
NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow];
212+
207213
NSSavePanel *dialog = [NSSavePanel savePanel];
208214
[dialog setExtensionHidden:NO];
209215

@@ -225,14 +231,15 @@ nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
225231
if ( !*outPath )
226232
{
227233
[pool release];
234+
[keyWindow makeKeyAndOrderFront:nil];
228235
return NFD_ERROR;
229236
}
230237
memcpy( *outPath, utf8Path, byteLen );
231238
nfdResult = NFD_OKAY;
232239
}
233240

234241
[pool release];
235-
242+
[keyWindow makeKeyAndOrderFront:nil];
236243
return nfdResult;
237244
}
238245

@@ -241,7 +248,7 @@ nfdresult_t NFD_PickFolder(const nfdchar_t *defaultPath,
241248
{
242249
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
243250

244-
NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow];
251+
NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow];
245252
NSOpenPanel *dialog = [NSOpenPanel openPanel];
246253
[dialog setAllowsMultipleSelection:NO];
247254
[dialog setCanChooseDirectories:YES];
@@ -264,6 +271,7 @@ nfdresult_t NFD_PickFolder(const nfdchar_t *defaultPath,
264271
if ( !*outPath )
265272
{
266273
[pool release];
274+
[keyWindow makeKeyAndOrderFront:nil];
267275
return NFD_ERROR;
268276
}
269277
memcpy( *outPath, utf8Path, len+1 ); /* copy null term */

Engine/lib/nativeFileDialogs/nfd_gtk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static void WaitForCleanup(void)
165165

166166
/* public */
167167

168-
nfdresult_t NFD_OpenDialog( const char *filterList,
168+
nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList,
169169
const nfdchar_t *defaultPath,
170170
nfdchar_t **outPath )
171171
{

0 commit comments

Comments
 (0)