#file-dialog #ui #macos #build

deprecated nfd2

Please use https://crates.io/crates/rfd instead

8 releases

0.3.1 Feb 4, 2022
0.3.0 Mar 26, 2021
0.2.3 Oct 22, 2020
0.2.2 Sep 27, 2020
0.1.1 Mar 19, 2020

#18 in #file-dialog

Download history 16/week @ 2023-11-20 62/week @ 2023-11-27 14/week @ 2023-12-04 92/week @ 2023-12-11 73/week @ 2023-12-18 3/week @ 2023-12-25 5/week @ 2024-01-01 19/week @ 2024-01-08 2/week @ 2024-01-15 42/week @ 2024-01-22 5/week @ 2024-01-29 6/week @ 2024-02-05 32/week @ 2024-02-12 107/week @ 2024-02-19 100/week @ 2024-02-26 71/week @ 2024-03-04

311 downloads per month
Used in propdayscov

MIT AND Zlib

74KB
2K SLoC

C 658 SLoC // 0.1% comments C++ 542 SLoC // 0.1% comments Rust 329 SLoC // 0.2% comments Objective-C 225 SLoC // 0.1% comments

💾 nfd2

Build Status Crates.io Docs Contributor Covenant Embark

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

This is a fork!

The original nfd-rs crate appears essentially unmaintained by now, so we have made this fork with the intent of making sure that it is at least maintained and that bugs stay fixed so we can have something to rely on.

That being said, our ultimate goal with this crate is to eventually make it pure Rust, without a need for external C code or a build script at all.

Dependencies

Since this crate currently depends on nativefiledialog, you must have the dependencies for that project installed. See Compiling Your Programs in the README.md file for nativefiledialog for more information on the requirements for each platform.

Linux

Linux requires the GTK3 development package(s) to be installed before building:

  • Debian/Ubuntu: apt-get install libgtk-3-dev
  • Fedora: dnf install gtk3-devel

Other

Other platforms do not require additional installation.

Usage

Single File Dialog

use nfd2::Response;

fn main() {
    match nfd2::open_file_dialog(None, None).expect("oh no") {
        Response::Okay(file_path) => println!("File path = {:?}", file_path),
        Response::OkayMultiple(files) => println!("Files {:?}", files),
        Response::Cancel => println!("User canceled"),
    }
}

Multiple File Dialog

use nfd2::Response;

fn main() {
    /// Only show .jpg files
    let result = nfd2::dialog_multiple().filter("jpg").open().expect("oh no");

    match result {
        Response::Okay(file_path) => println!("File path = {:?}", file_path),
        Response::OkayMultiple(files) => println!("Files {:?}", files),
        Response::Cancel => println!("User canceled"),
    }
}

Contributing

We welcome community contributions to this project.

Please read our Contributor Guide for more information on how to get started.

License

MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) AND Zlib (Zlib or https://opensource.org/licenses/Zlib)

No runtime deps

~170KB