OS-native file dialogs on Linux, OS X and Windows

Overview

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, OS X and Windows.

This crate has been tested on Mac, Window and Linux (Ubuntu 14.04) and supports single/mutliple and save dialogs, notice APIs may break with newer versions.

Usage

  • Add the dependency nfd in your Cargo.toml

    [dependencies]
    nfd = "0.0.4"
  • Open a single file dialog

    extern crate nfd;
    
    use nfd::Response;
    
    fn main() {
    
      let result = nfd::open_file_dialog(None, None).unwrap_or_else(|e| {
      	panic!(e);
      });
    
      match result {
          Response::Okay(file_path) => println!("File path = {:?}", file_path),
          Response::OkayMultiple(files) => println!("Files {:?}", files),
          Response::Cancel => println!("User canceled"),
      }
    }
  • Open a multi file dialog using builder with jpg files as filter

    extern crate nfd;
    
    use nfd::Response;
    
    fn main() {
    
      let result = nfd::dialog_multiple().filter("jpg").open().unwrap_or_else(|e| {
      	panic!(e);
      });
    
      match result {
          Response::Okay(file_path) => println!("File path = {:?}", file_path),
          Response::OkayMultiple(files) => println!("Files {:?}", files),
          Response::Cancel => println!("User canceled"),
      }
    }

Screenshot

Cocoa on El Capitan

Comments
  • Big refactor

    Big refactor

    • Added proper Result type
    • No unwrapping inside the open dialog functions. It now returns a correct restult type instead
    • Added the nfd sources that is built using the gcc crate instead of having the user compile the code manually
    • Added DialogBuilder to make it nicer to construct dialogs with filters and paths
    • Added builder_open_jpg example which uses the builder code and only allows for opening of jpg files
    • Fixed issue focus issue for Mac dialogs: Outlined here https://github.com/mlabbe/nativefiledialog/issues/7
    • Support for multi open + example
    opened by emoon 23
  • Add nativefiledialog as a git submodule

    Add nativefiledialog as a git submodule

    This PR uses nativefiledialog as submodule. I keep build.rs. But use devel branch. It's in active development. I'll change dependency to master when devel will be merged, because it's one still contains changes we need.

    We can use devel or wait for master. Any option available. But PR is ready to check.

    opened by DenisKolodin 10
  • Fix bug with Save Dialog

    Fix bug with Save Dialog

    I've found a bug with a save dialog:

    This application has requested the Runtime to terminate it in an unusual way.
    Please contact the application's support team for more information.
    Assertion failed!
    
    Program: C:\kode\kode-simulator\target\debug\simulator.exe
    File: nativefiledialog/src/nfd_common.c, Line 55
    
    Expression: ptr
    

    Multiple files were expected on save, but that's wrong. No pointer to multiple files struct, that's why it fails on free assert inside nfd_common.c.

    With this PR save dialog works fine.

    opened by DenisKolodin 6
  • nativefiledialog as submodule

    nativefiledialog as submodule

    PR https://github.com/mlabbe/nativefiledialog/pull/19 was merged. It makes possible to use it as submodule.

    @saurvs @emoon Let's consider to use it mentioned way.

    Now nativefiledialog (devel branch) uses premake 5 and have Makefiles to popular OS. I offer:

    • [x] Use nativefiledialog as git submodule
    • [x] Remove nfd folder with local version (and stop to maintain it)
    • [x] Update and still use build.rs script

    Any ideas? Caveats?

    opened by DenisKolodin 3
  • Building example fails on OSX 10.11

    Building example fails on OSX 10.11

        Updating registry `https://github.com/rust-lang/crates.io-index`
       Compiling gcc v0.3.51
       Compiling nfd v0.0.4 (file:///Users/matthew/Documents/nfd-rs)
    error: failed to run custom build command for `nfd v0.0.4 (file:///Users/matthew/Documents/nfd-rs)`
    process didn't exit successfully: `/Users/matthew/Documents/nfd-rs/target/debug/build/nfd-fadd152c4e7e2b1e/build-script-build` (exit code: 101)
    --- stdout
    TARGET = Some("x86_64-apple-darwin")
    OPT_LEVEL = Some("0")
    TARGET = Some("x86_64-apple-darwin")
    HOST = Some("x86_64-apple-darwin")
    TARGET = Some("x86_64-apple-darwin")
    TARGET = Some("x86_64-apple-darwin")
    HOST = Some("x86_64-apple-darwin")
    CC_x86_64-apple-darwin = None
    CC_x86_64_apple_darwin = None
    HOST_CC = None
    CC = None
    HOST = Some("x86_64-apple-darwin")
    TARGET = Some("x86_64-apple-darwin")
    HOST = Some("x86_64-apple-darwin")
    CFLAGS_x86_64-apple-darwin = None
    CFLAGS_x86_64_apple_darwin = None
    HOST_CFLAGS = None
    CFLAGS = None
    PROFILE = Some("debug")
    running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-m64" "-I" "nativefiledialog/src/include" "-o" "/Users/matthew/Documents/nfd-rs/target/debug/build/nfd-2d1f6f190beb9ef3/out/nativefiledialog/src/nfd_common.o" "-c" "nativefiledialog/src/nfd_common.c"
    cargo:warning=clang: error: no such file or directory: 'nativefiledialog/src/nfd_common.c'
    cargo:warning=clang: error: no input files
    exit code: 1
    
    
    command did not execute successfully, got: exit code: 1
    
    
    
    --- stderr
    thread 'main' panicked at 'explicit panic', /Users/matthew/.cargo/registry/src/github.com-1ecc6299db9ec823/gcc-0.3.51/src/lib.rs:1239
    note: Run with `RUST_BACKTRACE=1` for a backtrace.
    
    opened by BookOwl 2
  • Publish 0.0.4 version

    Publish 0.0.4 version

    @saurvs Could you publish 0.0.4 version to crates.io? I use git version now, it's stable. But I need access it from crates.io to publish own library depends on your crate.

    opened by DenisKolodin 2
  • Linkerror on windows

    Linkerror on windows

    With this code

    fn main() {
        let t = nfd::open_file_dialog(None, Some("")).unwrap();
    }
    

    rust panics in the build-phase because of the following error:

    error: linking with `link.exe` failed: exit code: 1120
    ...
    = note: Non-UTF-8 output: libnfd-2d582c35cd8355e4.rlib(nfd_win.o) : error LNK2019: Reference to unresolved external symbol \"__imp_SHCreateItemFromParsingName\" in function \"\"enum nfdresult_t __cdecl SetDefaultPath(struct IFileDialog *,char const *)\" (?SetDefaultPath@@YA?AW4nfdresult_t@@PEAUIFileDialog@@PEBD@Z)\".\r\nD:\\dev\\repositories\\rust-playground\\target\\debug\\deps\\rust_playground.exe 
    : fatal error LNK1120: 1 not resoved extern
    
    opened by Septias 1
  • Cant navigate in filesystem

    Cant navigate in filesystem

    When I open the system dialog with open_file_dialog I can't navigate between the folders :

    let result = nfd::open_file_dialog(Some("png"), Some("~/Pictures")).unwrap_or_else(|e| {
           panic!(e);
    });
    

    The buttons event on the sidebar are disabled, and I don't land on the Pictures folder

    opened by ctaque 1
  • Link error on Windows with Rust 1.33.0

    Link error on Windows with Rust 1.33.0

    Thanks for this useful crate.

    After upgrading Rust to 1.33.0 I get the following link error from nfd when building Cinter:

    libnfd-ec2bb1b08ec0519c.rlib(nfd_win.o) : error LNK2019: unresolved external symbol __imp_SHCreateItemFromParsingName referenced in function "enum nfdresult_t __cdecl SetDefaultPath(struct IFileDialog *,char const *)" (?SetDefaultPath@@YA?AW4nfdresult_t@@PEAUIFileDialog@@PEBD@Z)
    

    1.32.0 works fine.

    I'm on Windows 10 with Visual Studio 2017.

    opened by askeksa 1
  • Failed to build. Debian 9.5

    Failed to build. Debian 9.5

    error: failed to run custom build command for `nfd v0.0.4`
    process didn't exit successfully: `/target/debug/build/nfd-dff4fe53caa6791a/build-script-build` (exit code: 101)
    
    thread 'main' panicked at '
    
    Internal error occurred: Command "aarch64-linux-gnu-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-I" "nativefiledialog/src/include" "-Wall" "-Wextra" "-o" "/target/aarch64-unknown-linux-gnu/debug/build/nfd-cc59041a1d0b08c3/out/nativefiledialog/src/nfd_gtk.o" "-c" "nativefiledialog/src/nfd_gtk.c" with args "aarch64-linux-gnu-gcc" did not execute successfully (status code exit code: 1).
    
    ', /cargo/registry/src/github.com-1ecc6299db9ec823/gcc-0.3.54/src/lib.rs:1670:5
    note: Run with `RUST_BACKTRACE=1` for a backtrace.
    
    warning: build failed, waiting for other jobs to finish...
    error: build failed
    

    Kernel: x86_64 Linux 4.9.0-3-amd64

    opened by lalabuy948 1
  • Customtitle

    Customtitle

    I have a feature that you may like. However, it needs a modification on submodule nativefiledialog. The feature allows the user to replace the default dialog title ("Open File" or "Select folder" etc.) with a dialog title that can serve as a prompt. I have a pull request pending at nativefiledialog, but I am far from sure it will be accepted. I am not sure how to approach this problem. Anyway: here is my two cents

    opened by LenRemmerswaal 1
  • mremap_chunk(): invalid pointer

    mremap_chunk(): invalid pointer

    I don't know if it's an issue with these bindings, or the original library, or if I'm doing something terrible... My application crashed in a very rare case when I was in the folder selector opened with nfd::open_pick_folder. And gave output:

    mremap_chunk(): invalid pointer
    munmap_chunk(): invalid pointer
    

    The code: https://github.com/Ploppz/bup/blob/main/src/path.rs

    opened by Ploppz 0
  • Change OkayMultiple into a tuple?

    Change OkayMultiple into a tuple?

    I may be missing something but I am not aware of any OS where the file chooser lets you pick multiple files in different folders.

    Assuming this is the case, the path of all files returned by OkayMultiple will always be the same for all elements of the Vec.

    Would it then not make sense to change the return value to a tuple (String, Vec<String>) that returns the path in the first string and just the file names or folders, omitting the path, in the Vec<String>?

    opened by virtualritz 0
  • Update to current version of nativefiledialog?

    Update to current version of nativefiledialog?

    It looks like nativefiledialog has some significant updates since 2016, particularly for win32 and osx. Would it be fairly easy to use the latest source files from that project? Thank you.

    opened by sdicker8 0
  • Update 3 year old nativefiledialog to latest

    Update 3 year old nativefiledialog to latest

    This updates from using nativefiledialog C library from 2016-08-25 to latest master, version 1.1.6 from 2019-09-30.

    No code changes required!

    Would be great to publish a new version of this crate with this to include the 3 years of fixes and updates

    opened by repi 0
  • Support for stable-x86_64-pc-windows-gnu toolchain?

    Support for stable-x86_64-pc-windows-gnu toolchain?

    I'm trying to build using the stable-x86_64-pc-windows-gnu toolchain and I'm getting this error:

    cargo:warning=nativefiledialog/src/nfd_win.cpp:118:24: error: 'sprintf_s' was not declared in this scope
    

    Is this because nfd assumes you'll be building using MSVC and sprintf_s is Microsoft-specific? Building against stable-x86_64-pc-windows-msvc works fine.

    opened by ben-wallis 0
Owner
Saurav Sachidanand
Interned at HackerRank '19, previously at GSoC '18 with CERN and '17 with Performance Co-Pilot
Saurav Sachidanand
A tiny, neat C library that portably invokes native file open and save dialogs.

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 p

Michael Labbe 1.5k Dec 28, 2022
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
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
A cross-platform Mod Manager for RimWorld intended to work with macOS, linux and Windows

TODOs are available here. Discussions, PRs and Issues are open for anyone who is willing to contribute. rrm Inspired by Spoons rmm. This is a cross-pl

Alejandro Osornio 7 Sep 5, 2022
Send Windows 10 styled notifications on Windows 7.

win7-notifications Send Windows 10 styled notifications on Windows 7. Note: This crate requires a win32 event loop to be running, otherwise the notifi

Tauri 9 Aug 29, 2022
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
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
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
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
Crate for simple implementation of Component for Native API 1C:Enterprise written in rust

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

Maxim Kozlov 40 Sep 30, 2023
Unofficial Linux QQ client, based on GTK4 and libadwaita, developed with Rust and Relm4.

GTK QQ (WIP) Unofficial Linux QQ client, based on GTK4 and libadwaita, developed with Rust and Relm4. Screenshots Light Dark Note The two screenshots

Lomírus 198 Dec 24, 2022
A powerful desktop widget app for windows, built with Vue and Tauri.

DashboardX Widgets A powerful desktop widget app for windows, built with Vue and Tauri. Still in development Currently only runs on windows (uses nati

DashboardX Widgets 3 Oct 25, 2023
A GUI for NordVPN on Linux that maintains feature parity with the official clients, written with Rust and GTK.

Viking for NordVPN This project aims to provide a fully usable and feature-complete graphical interface for NordVPN on Linux. While it attempts to clo

Jacob Birkett 2 Oct 23, 2022