Home

Awesome

Native File Dialog

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.

Features:

Example Usage

#include <nfd.h>
#include <stdio.h>
#include <stdlib.h>

int main( void )
{
    nfdchar_t *outPath = NULL;
    nfdresult_t result = NFD_OpenDialog( NULL, NULL, &outPath );
        
    if ( result == NFD_OKAY ) {
        puts("Success!");
        puts(outPath);
        free(outPath);
    }
    else if ( result == NFD_CANCEL ) {
        puts("User pressed cancel.");
    }
    else {
        printf("Error: %s\n", NFD_GetError() );
    }

    return 0;
}

See self-documenting API NFD.h for more options.

Screenshots

Windows rendering a dialog GTK3 on Linux rendering a dialog Cocoa on MacOS rendering a dialog

Changelog

releasewhat's newdate
1.0.0initialoct 2014
1.1.0premake5; scons deprecatedaug 2016
1.1.1mingw support, build fixesaug 2016
1.1.2test_pickfolder() addedaug 2016
1.1.3zenity linux backend addednov 2017
<i></i>fix char type in declsnov 2017
1.1.4fix win32 memleaksdec 2018
<i></i>improve win32 errorhandlingdec 2018
<i></i>macos fix focus bugdec 2018
1.1.5win32 fix com reinitializeaug 2019
1.1.6fix osx filter bugaug 2019
<i></i>remove deprecated sconsaug 2019
<i></i>fix mingw compilationaug 2019
<i></i>-Wextra warning cleanupaug 2019

Building

NFD uses Premake5 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.

If you need to run Premake5 directly, further build documentation is available.

Previously, NFD used SCons to build. As of 1.1.6, SCons support has been removed entirely.

nfd.a will be built for release builds, and nfd_d.a will be built for debug builds.

Makefiles

The makefile offers up to four options, with release_x64 as the default.

make config=release_x86
make config=release_x64
make config=debug_x86
make config=debug_x64

Compiling Your Programs

  1. Add src/include to your include search path.
  2. Add nfd.lib or nfd_d.lib to the list of list of static libraries to link against (for release or debug, respectively).
  3. Add build/<debug|release>/<arch> to the library search path.

Linux GTK

apt-get libgtk-3-dev installs the gtk dependency for library compilation.

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.

Linux Zenity

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.

MacOS

On Mac OS, add AppKit to the list of frameworks.

Windows

On Windows, ensure you are linking against comctl32.lib.

Usage

See NFD.h for API calls. See tests/*.c for example code.

After compiling, build/bin contains compiled test programs. The appropriate subdirectory under build/lib contains the built library.

File Filter Syntax

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.

A wildcard filter is always added to every dialog.

Separators

Examples

txt The default filter is for text files. There is a wildcard option in a dropdown.

png,jpg;psd The default filter is for png and jpg files. A second filter is available for psd files. There is a wildcard option in a dropdown.

NULL Wildcard only.

Iterating Over PathSets

See test_opendialogmultiple.c.

Known Limitations

I accept quality code patches, or will resolve these and other matters through support. See contributing for details.

Copyright and Credit

Copyright © 2014-2019 Frogtoss Games, Inc. File LICENSE covers all files in this repo.

Native File Dialog by Michael Labbe mike@frogtoss.com

Tomasz Konojacki for microutf8

Denis Kolodin for mingw support.

Tom Mason for Zenity support.

Support

Directed support for this work is available from the original author under a paid agreement.

Contact Frogtoss Games.