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 `libdbus` or [zenity](https://gitlab.gnome.org/GNOME/zenity).
43//!
44//! ## GTK backend
45//! 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
46//! backend requires the C library and development headers to be installed to build RFD. The package
47//! names on various distributions are:
48//!
49//! | Distribution    | Installation Command |
50//! | --------------- | ------------ |
51//! | Fedora          | dnf install gtk3-devel   |
52//! | Arch            | pacman -S gtk3         |
53//! | Debian & Ubuntu | apt install libgtk-3-dev |
54//!
55//! ## XDG Desktop Portal backend
56//! The XDG Desktop Portal backend is used with the `xdg-portal` Cargo feature which is enabled by default. This backend will use either the GTK or KDE file dialog depending on the desktop environment
57//! in use at runtime.
58//!
59//! It requires the user to have `libdbus` system liblary (should be available on any systemd
60//! distro), if the liblary is not found `zenity` will be used instead.
61//!
62//! It requires the user to also have either the
63//! [GTK](https://github.com/flatpak/xdg-desktop-portal-gtk),
64//! [GNOME](https://gitlab.gnome.org/GNOME/xdg-desktop-portal-gnome), or
65//! [KDE](https://invent.kde.org/plasma/xdg-desktop-portal-kde/) XDG Desktop Portal backend installed
66//! at runtime. These are typically installed by the distribution together with the desktop environment.
67//!
68//! The
69//! [wlroots portal backend](https://github.com/emersion/xdg-desktop-portal-wlr) does not implement the
70//! D-Bus API that RFD requires (it does not interfere with the other portal implementations;
71//! they can all be installed simultaneously).
72//!
73//! [Zenity](https://gitlab.gnome.org/GNOME/zenity) is also required to display message dialogs,
74//! and is used for file dialogs if xdg portal fails.
75//!
76//! If you are packaging an application that uses RFD, ensure that both a supported portal backend and
77//! Zenity are installed with the package.
78//!
79//! # macOS non-windowed applications, async, and threading
80//!
81//! macOS async dialogs require an `NSApplication` instance, so the dialog is only truly async when
82//! opened in windowed environment like `winit` or `SDL2`. Otherwise, it will fallback to sync dialog.
83//! It is also recommended to spawn dialogs on your main thread. RFD can run dialogs from any thread
84//! but it is only possible in a windowed app and it adds a little bit of overhead. So it is recommended
85//! to [spawn on main and await in other thread](https://github.com/PolyMeilex/rfd/blob/master/examples/async.rs).
86//! Non-windowed apps will never be able to spawn async dialogs or from threads other than the main thread.
87//!
88//! # Customize button texts of message dialog in Windows
89//!
90//! `TaskDialogIndirect` API is used for showing message dialog which can have customized button texts.
91//! It is only provided by ComCtl32.dll v6 but Windows use v5 by default.
92//! If you want to customize button texts or just need a modern dialog style (aka *visual styles*), you will need to:
93//!
94//! 1. Enable cargo feature `common-controls-v6`.
95//! 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)
96//!
97//!
98//! 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/).
99//!
100//! # Cargo features
101//!  * `gtk3`: Uses GTK for dialogs on Linux & BSDs; has no effect on Windows and macOS
102//!  * `xdg-portal`: Uses XDG Desktop Portal instead of GTK on Linux & BSDs
103//!  * `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.
104//!
105//! # State
106//!
107//! | API Stability |
108//! | ------------- |
109//! | 🚧            |
110//!
111//! | Feature      | Linux | Windows | MacOS     | Wasm32 |
112//! | ------------ | ----- | ------- | --------- | ------ |
113//! | SingleFile   | ✔     | ✔       | ✔         | ✔      |
114//! | MultipleFile | ✔     | ✔       | ✔         | ✔      |
115//! | PickFolder   | ✔     | ✔       | ✔         | ✖      |
116//! | SaveFile     | ✔     | ✔       | ✔         | ✖      |
117//! | Filters      | ✔     | ✔       | ✔         | ✔      |
118//! | StartingPath | ✔     | ✔       | ✔         | ✖      |
119//! | Async        | ✔     | ✔       | ✔         | ✔      |
120//!
121//! # rfd-extras
122//!
123//! AKA features that are not file related
124//!
125//! | Feature       | Linux        | Windows | MacOS | Wasm32 |
126//! | ------------- | -----        | ------- | ----- | ------ |
127//! | MessageDialog | ✔            | ✔       | ✔     | ✔      |
128//! | PromptDialog  |              |         |       |        |
129//! | ColorPicker   |              |         |       |        |
130
131mod backend;
132
133mod file_handle;
134pub use file_handle::FileHandle;
135
136mod file_dialog;
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};