rfd/
lib.rs

1//! Rusty File Dialogs is a cross platform library for using native file open/save dialogs.
2//! It provides both asynchronous and synchronous APIs. Supported platforms:
3//!
4//!   * Windows
5//!   * macOS
6//!   * Linux & BSDs (GTK3 or XDG Desktop Portal)
7//!   * WASM32 (async only)
8//!
9//! # Examples
10//!
11//! ## Synchronous
12//! ```no_run
13//! use rfd::FileDialog;
14//!
15//! let files = FileDialog::new()
16//!     .add_filter("text", &["txt", "rs"])
17//!     .add_filter("rust", &["rs", "toml"])
18//!     .set_directory("/")
19//!     .pick_file();
20//! ```
21//!
22//! ## Asynchronous
23//! ```no_run
24//! use rfd::AsyncFileDialog;
25//!
26//! let future = async {
27//!     let file = AsyncFileDialog::new()
28//!         .add_filter("text", &["txt", "rs"])
29//!         .add_filter("rust", &["rs", "toml"])
30//!         .set_directory("/")
31//!         .pick_file()
32//!         .await;
33//!
34//!     let data = file.unwrap().read().await;
35//! };
36//! ```
37//!
38//! # Linux & BSD backends
39//!
40//! On Linux & BSDs, two backends are available, one using the [GTK3 Rust bindings](https://gtk-rs.org/)
41//! and the other using the [XDG Desktop Portal](https://github.com/flatpak/xdg-desktop-portal)
42//! D-Bus API through [ashpd](https://github.com/bilelmoussaoui/ashpd),
43//! [zbus](https://gitlab.freedesktop.org/dbus/zbus/) and [zenity](https://gitlab.gnome.org/GNOME/zenity).
44//!
45//! ## GTK backend
46//! The GTK backend is used when the `xdg-portal` feature is disabled with the [`default-features = false`](https://doc.rust-lang.org/cargo/reference/features.html#dependency-features), and `gtk3` is enabled instead. The GTK3
47//! backend requires the C library and development headers to be installed to build RFD. The package
48//! names on various distributions are:
49//!
50//! | Distribution    | Installation Command |
51//! | --------------- | ------------ |
52//! | Fedora          | dnf install gtk3-devel   |
53//! | Arch            | pacman -S gtk3         |
54//! | Debian & Ubuntu | apt install libgtk-3-dev |
55//!
56//! ## XDG Desktop Portal backend
57//! The XDG Desktop Portal backend is used with the `xdg-portal` Cargo feature which is enabled by default. Either the `tokio` or `async-std` feature must be enabled. This backend will use either the GTK or KDE file dialog depending on the desktop environment
58//! in use at runtime.
59//!
60//! It does not have any non-Rust
61//! build dependencies, however it requires the user to have either the
62//! [GTK](https://github.com/flatpak/xdg-desktop-portal-gtk),
63//! [GNOME](https://gitlab.gnome.org/GNOME/xdg-desktop-portal-gnome), or
64//! [KDE](https://invent.kde.org/plasma/xdg-desktop-portal-kde/) XDG Desktop Portal backend installed
65//! at runtime. These are typically installed by the distribution together with the desktop environment.
66//!
67//! The
68//! [wlroots portal backend](https://github.com/emersion/xdg-desktop-portal-wlr) does not implement the
69//! D-Bus API that RFD requires (it does not interfere with the other portal implementations;
70//! they can all be installed simultaneously).
71//!
72//! [Zenity](https://gitlab.gnome.org/GNOME/zenity) is also required to display message dialogs,
73//! and is used for file dialogs if [ashpd] cannot.
74//!
75//! If you are packaging an application that uses RFD, ensure that both a supported portal backend and
76//! Zenity are installed with the package.
77//!
78//! # macOS non-windowed applications, async, and threading
79//!
80//! macOS async dialogs require an `NSApplication` instance, so the dialog is only truly async when
81//! opened in windowed environment like `winit` or `SDL2`. Otherwise, it will fallback to sync dialog.
82//! It is also recommended to spawn dialogs on your main thread. RFD can run dialogs from any thread
83//! but it is only possible in a windowed app and it adds a little bit of overhead. So it is recommended
84//! to [spawn on main and await in other thread](https://github.com/PolyMeilex/rfd/blob/master/examples/async.rs).
85//! Non-windowed apps will never be able to spawn async dialogs or from threads other than the main thread.
86//!
87//! # Customize button texts of message dialog in Windows
88//!
89//! `TaskDialogIndirect` API is used for showing message dialog which can have customized button texts.
90//! It is only provided by ComCtl32.dll v6 but Windows use v5 by default.
91//! If you want to customize button texts or just need a modern dialog style (aka *visual styles*), you will need to:
92//!
93//! 1. Enable cargo feature `common-controls-v6`.
94//! 2. Add an application manifest to use ComCtl32.dll v5. See [Windows Controls / Enabling Visual Styles](https://docs.microsoft.com/en-us/windows/win32/controls/cookbook-overview)
95//!
96//!
97//! Here is an [example](https://github.com/PolyMeilex/rfd/tree/master/examples/message-custom-buttons) using [embed-resource](https://docs.rs/embed-resource/latest/embed_resource/).
98//!
99//! # Cargo features
100//!  * `gtk3`: Uses GTK for dialogs on Linux & BSDs; has no effect on Windows and macOS
101//!  * `xdg-portal`: Uses XDG Desktop Portal instead of GTK on Linux & BSDs
102//!  * `common-controls-v6`: Use `TaskDialogIndirect` API from ComCtl32.dll v6 for showing message dialog. This is necessary if you need to customize dialog button texts.
103//!
104//! # State
105//!
106//! | API Stability |
107//! | ------------- |
108//! | 🚧            |
109//!
110//! | Feature      | Linux | Windows | MacOS     | Wasm32 |
111//! | ------------ | ----- | ------- | --------- | ------ |
112//! | SingleFile   | ✔     | ✔       | ✔         | ✔      |
113//! | MultipleFile | ✔     | ✔       | ✔         | ✔      |
114//! | PickFolder   | ✔     | ✔       | ✔         | ✖      |
115//! | SaveFile     | ✔     | ✔       | ✔         | ✖      |
116//! | Filters      | ✔     | ✔       | ✔         | ✔      |
117//! | StartingPath | ✔     | ✔       | ✔         | ✖      |
118//! | Async        | ✔     | ✔       | ✔         | ✔      |
119//!
120//! # rfd-extras
121//!
122//! AKA features that are not file related
123//!
124//! | Feature       | Linux        | Windows | MacOS | Wasm32 |
125//! | ------------- | -----        | ------- | ----- | ------ |
126//! | MessageDialog | ✔            | ✔       | ✔     | ✔      |
127//! | PromptDialog  |              |         |       |        |
128//! | ColorPicker   |              |         |       |        |
129
130mod backend;
131
132mod file_handle;
133pub use file_handle::FileHandle;
134
135mod file_dialog;
136#[cfg(target_os = "macos")]
137mod oneshot;
138
139#[cfg(not(target_arch = "wasm32"))]
140pub use file_dialog::FileDialog;
141
142pub use file_dialog::AsyncFileDialog;
143
144mod message_dialog;
145pub use message_dialog::{
146    AsyncMessageDialog, MessageButtons, MessageDialog, MessageDialogResult, MessageLevel,
147};