A tiny, neat C library that portably invokes native file open and save dialogs.

Related tags

c windows macos linux gui dialog
Overview

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:

  • Lean C API, static library -- no ObjC, no C++, no STL.
  • Zlib licensed.
  • Consistent UTF-8 support on all platforms.
  • Simple universal file filter syntax.
  • Paid support available.
  • Multiple file selection support.
  • 64-bit and 32-bit friendly.
  • GCC, Clang, Xcode, Mingw and Visual Studio supported.
  • No third party dependencies for building or linking.
  • Support for Vista's modern IFileDialog on Windows.
  • Support for non-deprecated Cocoa APIs on OS X.
  • GTK3 dialog on Linux.
  • Optional Zenity support on Linux to avoid linking GTK.
  • Tested, works alongside http://www.libsdl.org on all platforms, for the game developers out there.

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

  • Major version increments denote API or ABI departure.
  • Minor version increments denote build or trivial departures.
  • Micro version increments just recompile and drop-in.
release what's new date
1.0.0 initial oct 2014
1.1.0 premake5; scons deprecated aug 2016
1.1.1 mingw support, build fixes aug 2016
1.1.2 test_pickfolder() added aug 2016
1.1.3 zenity linux backend added nov 2017
fix char type in decls nov 2017
1.1.4 fix win32 memleaks dec 2018
improve win32 errorhandling dec 2018
macos fix focus bug dec 2018
1.1.5 win32 fix com reinitialize aug 2019
1.1.6 fix osx filter bug aug 2019
remove deprecated scons aug 2019
fix mingw compilation aug 2019
-Wextra warning cleanup aug 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

  • ; Begin a new filter.
  • , Add a separate type to the filter.

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.

  • No support for Windows XP's legacy dialogs such as GetOpenFileName.
  • No support for file filter names -- ex: "Image Files" (*.png, *.jpg). Nameless filters are supported, however.
  • GTK Zenity implementation's process exec error handling does not gracefully handle numerous error cases, choosing to abort rather than cleanup and return.
  • GTK 3 spams one warning per dialog created.

Copyright and Credit

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

Native File Dialog by Michael Labbe [email protected]

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.

Issues
  • Add mingw/msys support

    Add mingw/msys support

    This PR makes similar what #10 does, but with premakes and offered to devel branch.

    I've implemented MinGW/MSYS support. It builds:

    $ cd build/gmake_windows
    $ make
    ==== Building nfd (release_x64) ====
    Creating ../lib/Release/x64
    Creating ../obj/x64/Release/nfd
    nfd_common.c
    nfd_win.cpp
    Linking nfd
    ==== Building test_opendialog (release_x64) ====
    Creating ../bin
    Creating ../obj/x64/Release/test_opendialog
    test_opendialog.c
    Linking test_opendialog
    ==== Building test_opendialogmultiple (release_x64) ====
    Creating ../obj/x64/Release/test_opendialogmultiple
    test_opendialogmultiple.c
    Linking test_opendialogmultiple
    ==== Building test_savedialog (release_x64) ====
    Creating ../obj/x64/Release/test_savedialog
    test_savedialog.c
    Linking test_savedialog
    

    I've checked all tests, It works!

    P.S. I made changes with linux, but checked it with windows+msys.

    opened by DenisKolodin 18
  • GTK+3: Dialog does not disappear

    GTK+3: Dialog does not disappear

    When using NFD from SDL, I noticed that the dialog never disappears after clicking Cancel or OK. It freezes and control is returned to the application as expected, but still remains in the foreground of the application. I can then call the window to the background and continue work. On the next call, the window appears as expected, but predictably shows the same behavior.

    I would expect that the dialog disappears and focus is returned to the previous window.

    opened by paniq 12
  • Support for compiling with MSYS

    Support for compiling with MSYS

    This pull request includes support for compiling NFD using the MSYS/MinGW environment.

    opened by rafalcieslak 11
  • Screen does no longer update after dismissing the open dialog on OSX using SDL

    Screen does no longer update after dismissing the open dialog on OSX using SDL

    I seem to have a bit of trouble with NFD_OpenDialog on OSX that calls NSOpenPanel which changes the glContext. The same problem occurs with NFD_SaveDialog if you browse more files and then dismiss the dialog.

    I've tried various workarounds like this: http://stackoverflow.com/questions/13987148/nsopenpanel-breaks-my-sdl-opengl-app but I can't get anything to work. Am I missing something? Using SDL version 2.0.3.

    / Harry

    opened by lundstroem 10
  • add zenity backend

    add zenity backend

    Hey, I'd like to use this and don't want to pull in all of gtk as a dependency, so I added a zenity backend, as you suggested in your readme.

    opened by wheybags 10
  • Select Directory Support

    Select Directory Support

    Hi,

    I wonder if there are any plans on supporting the ability to select a directory?

    opened by emoon 9
  • Focus for Mac Window

    Focus for Mac Window

    Hi,

    first of all thanks for the great work on the Native File Requester. We use it on www.visualgraphics.tv for multi os file requesters for the Desktops.

    We have one issue which may not be yours. Under Mac / Cocoa we never succeed in setting the focus back to the SDL2 OpenGL Window after a Dialog was open. Resulting that the user has to select the main window once before being able to continue work.

    Did you see this behavior too ?

    Thanks again,

    Markus

    opened by markusmoenig 8
  • About Adding In ARM64 Support

    About Adding In ARM64 Support

    Hello,

    I noticed that nativefiledialog does not have support for ARM64. I added in the changes needed to build nativefiledialog on ARM64 Linux (and Windows in theory, but I haven't test building on Windows).

    But before I make a PR, I want to ask a question about one of your bullet points:

    Do not submit anything I can't verify or maintain.

    Do you have the ability to verify ARM64 builds? I'm worried that you might reject my PR if you don't have any ARM64 hardware to test the ARM64 builds.

    feature linux macos 
    opened by CuriousTommy 7
  • Fix MinGW requiring fpermissive to compile

    Fix MinGW requiring fpermissive to compile

    This is the error I get otherwise:

    ../../src/nfd_win.cpp: In function 'nfdresult_t NFD_OpenDialog(const nfdchar_t*, const nfdchar_t*, nfdchar_t**)':
    ../../src/nfd_win.cpp:448:1: error: jump to label 'end' [-fpermissive]
     end:
     ^~~
    ../../src/nfd_win.cpp:379:14: note:   from here
             goto end;
                  ^~~
    ../../src/nfd_win.cpp:383:13: note:   crosses initialization of 'HRESULT result'
         HRESULT result = ::CoCreateInstance(::CLSID_FileOpenDialog, NULL,
                 ^~~~~~
    
    opened by ncruces 6
  • [OSX] File Extensions filters < 3 chars not working

    [OSX] File Extensions filters < 3 chars not working

    I originally wanted to add a file extension for 7-zip files (7z) but it would not work.. After some experimenting, I found that "e7" also did not work but "e7e" did work... I also could not get "7z " or " 7z" to work..

    I could not find any NFD code that alluded to constraining the file extension to 3-chars, making me wonder if this is a different issue outside of NFD.. here are the relevant functions regarding the filter list:

    NFD_OpenDialogMultiple AddFilterListToDialog BuildAllowedFileTypes

    I am not skilled with OBJC so I'm not sure how to fix the problem.

    opened by bazzinotti 6
  • Added a CMakeLists file

    Added a CMakeLists file

    Added a CMakeLists file for anyone using cmake like me.

    opened by AlvaroBarua 0
  • Zenity: add --confirm-overwrite for save dialog

    Zenity: add --confirm-overwrite for save dialog

    Zenity: The save dialog now prompts the user for confirmation if the selected path already exists.

    opened by jorio 0
  • Memory leak in AddFiltersToDialog on Windows (nfd_win.cpp)

    Memory leak in AddFiltersToDialog on Windows (nfd_win.cpp)

    Compilation Environment

    • OS: Windows
    • Compiler: MSVC
    • Compiler Version: MSVC 1928
    • Build directory used: vs2010
    • Have I attempted to reproduce the problem on the devel branch? Yes

    Memory leak in AddFiltersToDialog when deallocating COMDLG_FILTERSPEC

    Before the function returns in AddFiltersToDialog, the code frees the allocated memory for specList and its members, but it only does it for the pszSpec but not the pszName. In the for loop there should also be a line for NFDi_Free( (void*)specList[i].pszName );.

    opened by KaiH0717 0
  • Zenity does not append extensions from filterlist onto return value

    Zenity does not append extensions from filterlist onto return value

    As of c0e491055bba7b6e0326e2d94566b65e6aebc014, the GTK build adds an extension to the returned value. This is done to match the behaviour of the other platforms. This affects the dialogs that return filenames.

    The extension is derived from the first filter in the selected list. For example, if the user passes in png,jpg;pdf, then the three extensions that will be presented are:

    • png, jpg
    • pdf
    • *.*

    If the user enters some_file with the first filter selected, then some_file.png is returned. If the user enters some_file with the second filter selected, then some_file.pdf is returned. With the third filter selected, some_file is returned.

    It appears to not be possible to query which filter was selected when Zenity returns, so this functionality cannot be added to Native File Dialog. As a result, it always returns some_file. If anyone knows a way to get the selected filter from Zenity or a way to provide parity, please update this bug.

    opened by mlabbe 1
  • nfd_win_legacy.c

    nfd_win_legacy.c

    Tested against all tests in the tests folder on 32-bit MinGW. I tested by building the source files directly instead of using the Makefile, so I unfortunately cannot provide an updated Makefile. I was wondering what kind of ideas you have for making an application capable of using either nfd_win or nfd_win_legacy based on what functions are available in the operating system. Let me know if there are any additional changes needed and I'll see what I can do. Thank you for your work on Native File Dialog!

    opened by NuklearBomb 2
  • Remove + from GTK+ in documentation when gtk4 ships

    Remove + from GTK+ in documentation when gtk4 ships

    https://mail.gnome.org/archives/gtk-devel-list/2019-February/msg00000.html

    opened by mlabbe 0
  • Add Haiku support

    Add Haiku support

    This fixes and upstreams a port by @puckipedia done some years ago.

    Didn't check the premake stuff yet (it seems we have a recipe for 4.4 but not 5 yet), but the Scons-built test do work.

    opened by mmuman 14
  • KDE support

    KDE support

    Hi, I'd like to integrate your library in my project but it does not seem to support KDE. It instead uses the Gnome file picker which is a very suboptimal experience with a KDE setup. Beyond the different interface, it does not integrate with favorite locations or lacks many navigation controls.

    Would it be possible to add KDE support?

    feature help wanted linux 
    opened by demurgos 9
Releases(release_116)
Owner
Michael Labbe
I program.
Michael Labbe
Truly cross platform, truly native. multiple backend GUI for rust

WIP: Sauron-native a rust UI library that conquers all platforms ranging from desktop to mobile devices. An attempt to create a truly native, truly cr

Jovansonlee Cesar 596 Jun 10, 2021
OS-native file dialogs on Linux, OS X and Windows

nfd-rs nfd-rs is a Rust binding to the library nativefiledialog, that provides a convenient cross-platform interface to opening file dialogs on Linux,

Saurav Sachidanand 129 Jun 9, 2021
Simple and portable (but not inflexible) GUI library in C that uses the native GUI technologies of each platform it supports.

libui: a portable GUI library for C This README is being written. Status It has come to my attention that I have not been particularly clear about how

Pietro Gagliardi 9.9k Jun 15, 2021
Rust bindings to the minimalist, native, cross-platform UI toolkit `libui`

Improved User Interface A cross-platform UI toolkit for Rust based on libui iui: ui-sys: iui is a simple (about 4 kLOC of Rust), small (about 800kb, i

Rust Native UI Group 749 Jun 13, 2021
Rust bindings for the FLTK GUI library.

fltk-rs Rust bindings for the FLTK Graphical User Interface library. The FLTK crate is a crossplatform lightweight gui library which can be statically

Mohammed Alyousef 317 Jun 13, 2021
A data-first Rust-native UI design toolkit.

Druid A data-first Rust-native UI toolkit. Druid is an experimental Rust-native UI toolkit. Its main goal is to offer a polished user experience. Ther

null 3.8k Jun 13, 2021
The Rust UI-Toolkit.

The Orbital Widget Toolkit is a cross-platform (G)UI toolkit for building scalable user interfaces with the programming language Rust. It's based on t

Redox OS 3.2k Jun 13, 2021
Rust bindings for Sciter

Rust bindings for Sciter Check this page for other language bindings (Delphi / D / Go / .NET / Python / Rust). Introduction Sciter is an embeddable mu

Terra Informatica Software, Inc 544 Jun 15, 2021
Build smaller, faster, and more secure desktop applications with a web frontend.

TAURI Tauri Apps footprint: minuscule performance: ludicrous flexibility: gymnastic security: hardened Current Releases Component Descrip

Tauri 17.3k Jun 13, 2021
A simple UI framework for Rust built on top of IUP (http://webserver2.tecgraf.puc-rio.br/iup/)

KISS-UI A UI framework for Rust based on the KISS (Keep It Simple, Stupid!) philosophy. Powered by the IUP GUI library for C by Tecgraf, via the bindi

null 342 Jun 10, 2021
Experimental embedder for Flutter

NativeShell (Experimental embedder for Flutter) Features Leverages existing Flutter desktop embedder on each platform Unlike Flutter desktop embedders

NativeShell 204 Jun 18, 2021
File system enumerator and monitor for Android.

File system enumerator and file monitor for Android. Built to be compatible with other command line utilties! This tool was created to somewhat automa

Kyle Benac 10 Jan 25, 2021
Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies

Dear ImGui (This library is available under a free and permissive license, but needs financial support to sustain its continued improvements. In addit

omar 30k Jun 15, 2021
A cross-platform GUI library for Rust, inspired by Elm

Iced A cross-platform GUI library for Rust focused on simplicity and type-safety. Inspired by Elm. Features Simple, easy-to-use, batteries-included AP

Héctor Ramón 9.6k Jun 13, 2021