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

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.

Comments
  • 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
  • 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
  • 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.

    linux feature macos 
    opened by CuriousTommy 7
  • Deprecate mingw; support clang on windows instead

    Deprecate mingw; support clang on windows instead

    Mingw via msys2 is in disrepair. A fresh install of their latest (as of 3/6/2019) provides a gcc that fails with nonzero errorlevel and no error messages compiling the source. Numerous unjustifiable issues were encountered building a toolchain that gets to this point including dead wiki links, a totally janky package manager experience and a bunch of other bugs. I didn't have a great time back in 2015 when I set this up, either.

    Mingw via msys2 can still work via makefile, but it would be unsupported (no test builds by the developer, no support in the documentation). I do not want to encourage people to use buggy toolchains. If mingw via msys2 ever gets its act together, it can compile, but I don't want to spend any more time on something that is clearly under maintained, as it creates a hard road for developers to even begin working with NFD.

    Supporting a non-msvc compiler on Windows has value. clang's toolchain on Windows has matured greatly since NFD was first announced. Supporting warnings-free compilation using llvm using the gmake_windows build dir and gnu make is a feasible feature to support, as is using clang inside of msvc via project files.

    The time I spent wrangling msys2 can be used on hooking up asan for the tests.

    If there is a valid reason to continue supporting mingw in addition to llvm, please use this issue to explain the reasons. I will start in on the deprecation path in a few months.

    discuss 
    opened by mlabbe 6
  • 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 bazz1tv 6
  • ShellItem not released on error in Windows implementation

    ShellItem not released on error in Windows implementation

    Hi, The following ShellItem is not released if an error is returned while using it (the function jumps to the end):

    https://github.com/mlabbe/nativefiledialog/blob/5cfe5002eb0fac1e49777a17dec70134147931e2/src/nfd_win.cpp#L403

    Similarly, the file dialog itself is never released.

    Compare it to the official example.

    bug windows maintainer-confirmed 
    opened by demurgos 5
  • Compile dll/so

    Compile dll/so

    Hello,

    For a game project, I need to turn this library into a dll/so file.

    I did some research but none of my attempts worked.

    Can you please put me in the right direction? Thanks.

    opened by Ulydev 5
  • Allow compiling without extra include path

    Allow compiling without extra include path

    As a small change, if the source files of the libraries use relative include path include/nfd.h instead of nfd.h this would allow compiling the library without adding extra include paths in the compiler command-line, which is quite a convenience.

    Encloded the PR with this suggested change.

    e.g. I have a project where we include nfd.h only in 1 place of the whole project so it's also included with relative path e.g. #include "libs/nativefiledialog/include/nfd.h.

    opened by ocornut 4
  • Prevent macro overwrite warning

    Prevent macro overwrite warning

    My system: Windows 10, CLion + MinGW

    When compiling there is a warning that the macro _WIN32_WINNT is being redefined. I simply added a check to undefine it first, which removes the warning makes it work seamlessly on any system.

    Please merge the request soon if everything is good with it. Thank you, this library is awesome!

    opened by HerrNamenlos123 0
  • Add vcpkg installation instructions

    Add vcpkg installation instructions

    nativefiledialog is available as a port in vcpkg, a C++ library manager that simplifies installation for nativefiledialog and other project dependencies. Documenting the install process here will help users get started by providing a single set of commands to build nativefiledialog, ready to be included in their projects.

    We also test whether our library ports build in various configurations (dynamic, static) on various platforms (OSX, Linux, Windows: x86, x64) to keep a wide coverage for users.

    I'm a maintainer for vcpkg, and here is what the port script looks like. We try to keep the library maintained as close as possible to the original library. 😊

    opened by FrankXie05 0
  • Fix modal disable/enable behavior on Win32

    Fix modal disable/enable behavior on Win32

    This PR fixes the modal behavior of native file dialogs on Win32. Previously, opening a native file dialog would leave the calling window enabled. This is not how NFD behaves on macOS, though I do not know how it behaves on Linux.

    More importantly, this issue exposes folks with immediate-mode GUI libraries like Dear ImGui to crashes on Windows. If you use WM_SIZING messages or similar to redraw an immediate mode GUI, but an NFD is open because of a call from the GUI, then a user can break things by resizing the calling window with an NFD still open. Dear ImGui, at least, does not support recursive UI rendering.

    This fix simply passes the calling window handle to fileOpenDialog->Show(), which it gets from GetActiveWindow(). If GetActiveWindow() can't get a handle, it returns NULL anyways, so this change should not negatively impact existing projects. If anyone prefers to avoid disabling the base window when opening an NFD, then I'd argue that should be an API change, because again, this is the default behavior for NFD on macOS.

    I tested this with Clang and MSVC on Win32.

    opened by theOtherMichael 0
  • GTK+ dialogs always crash

    GTK+ dialogs always crash

    Compilation Environment

    • OS (eg: OSX 10.14, Ubuntu 18.04): #1 SMP Debian 5.10.70-1 (2021-09-30)
    • Compiler (eg: GCC, Clang): gcc
    • Compiler Version (eg: MSVC 2017): gcc version 10.2.1 20210110 (Debian 10.2.1-6)
    • Build directory used (eg: build/gmake_linux: included sources
    • Have I attempted to reproduce the problem on the devel branch? No, devel does not compile

    Describe the bug

    GTK+ always crashes on any file dialog operation:

    libpng warning: Image width exceeds user limit in IHDR
    libpng warning: Image height exceeds user limit in IHDR
    libpng error: Invalid IHDR data
    Segmentation fault
    

    Additional context

    Note, the app that uses NFD is using SDL2 only and might be that GTK+ is not initialised. Devel branch does not compile with errors like

    ftg_core.h:13771:12: error: stray ‘\342’ in program
    13771 |     You can’t perform that action at this time.
    

    User Description

    Open source / Individual.

    opened by slajerek 0
  • feature request: set dialog title

    feature request: set dialog title

    Currently, your API does not allow the title of the file dialog to be specified.

    It seems straightforward to support this, because all of the underlying platform APIs provide an option to set the title:

    • IFileDialog::SetTitle on Windows
    • title property of NSSavePanel on MacOS
    • on Gtk and Zenity you are already setting the title to "Open File": https://github.com/mlabbe/nativefiledialog/blob/67345b80ebb429ecc2aeda94c478b3bcc5f7888e/src/nfd_gtk.c#L181 and https://github.com/mlabbe/nativefiledialog/blob/67345b80ebb429ecc2aeda94c478b3bcc5f7888e/src/nfd_zenity.c#L190

    PS. Just got a Julia wrapper for this library (https://github.com/Suavesito-Olimpiada/NativeFileDialog.jl) along with precompiled binaries for many platforms (https://github.com/JuliaBinaryWrappers/NativeFileDialog_jll.jl), thanks to @Suavesito-Olimpiada.

    opened by stevengj 0
Releases(release_116)
Owner
Michael Labbe
I program.
Michael Labbe
OS native dialogs for Windows, MacOS, and Linux

?? nfd2 nfd2 is a Rust binding to the nativefiledialog library, that provides a convenient cross-platform interface to opening file dialogs on Windows

Embark 33 May 15, 2022
Tiny library for handling rust strings in windows.

tinywinstr Tiny library for handling rust strings in windows.

Ed Way 1 Oct 25, 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 10.4k Dec 31, 2022
Cross-platform native Rust menu library

A cross-platform Rust library for managing the native operating system menus.

Mads Marquart 16 Jan 6, 2023
Native Rust library for FastCGI

The FastCGI Rust implementation. Description gfcgi is a native Rust library for FastCGI. This library supports multithreaded socket listeners and HTTP

Andrey Gridchin 9 Aug 7, 2022
Native Maps for Web, Mobile and Desktop

mapr Native Maps for Web, Mobile and Linux A map rendering library written in Rust. Example | Book | API | Chat in Matrix Space Project State This pro

MapLibre 942 Jan 2, 2023
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 8.2k Dec 31, 2022
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 865 Dec 27, 2022
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 627 Jan 5, 2023
Winsafe-examples - Examples of native Windows applications written in Rust with WinSafe.

WinSafe examples This repo contains several examples of native Win32 applications written in Rust with WinSafe. All examples follow the same program s

Rodrigo 40 Dec 14, 2022
Example for Rust Android Native Development

Android console application example project based on rust & cargo-xdk

Zhuo Zhang 4 Mar 17, 2022
Generate Anchor IDL for Native Solana Programs.

Native Solana To Anchor IDL Autogenerate Anchor IDL from programs written in Native Solana. Disclaimer The instructions must follow strict set of rule

acheron 72 Nov 10, 2022
Provides core language-agnostic functionality for LiveView Native across platforms

LiveView Native Core This repository contains an implementation of the LiveView Native core library, which is intended to handle all the details which

LiveView Native 35 Dec 27, 2022
Windows Native Undocumented API for Rust Language 🔥

Windows Native   The Windows-Native Rust library provides a convenient and safe way to access the native Windows undocumented APIs using the Rust prog

null 3 Aug 22, 2023
Crate for simple implementation of Component for Native API 1C:Enterprise written in rust

Гайд по использованию на русском языке можно посмотреть здесь и задать вопросы по использованию, но не оставляйте там комментарии об ошибках, т.к. там

Maxim Kozlov 40 Sep 30, 2023
A Modern, Open Source GTK4 ebook manager powered by Rust.

Bookx An MVP in progress: An ebook reader with .epub support Context menu for each book (delete, rename book, info) On click switch the carousal to th

Anurag Dhadse 12 Dec 28, 2022
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 15 Aug 23, 2022
Szyszka is a simple but powerful and fast bulk file renamer.

Szyszka is a simple but powerful and fast bulk file renamer. Features Written in Rust Available for Linux, Mac and Windows Simple GUI created

Rafał Mikrut 649 Dec 28, 2022
Unsafe bindings and a safe wrapper for gtk4-layer-shell, automatically generated from a .gir file

gtk4-layer-shell: gtk4-layer-shell-sys: gtk4-layer-shell This is the safe wrapper for gtk4-layer-shell, automatically generated from its .gir file. Fo

null 3 Apr 30, 2023