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/).
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. It does not have any non-Rust
59//! build dependencies, however it requires the user to have either the
60//! [GTK](https://github.com/flatpak/xdg-desktop-portal-gtk),
61//! [GNOME](https://gitlab.gnome.org/GNOME/xdg-desktop-portal-gnome), or
62//! [KDE](https://invent.kde.org/plasma/xdg-desktop-portal-kde/) XDG Desktop Portal backend installed
63//! at runtime. These are typically installed by the distribution together with the desktop environment.
64//! If you are packaging an application that uses RFD, ensure either one of these is installed
65//! with the package. The
66//! [wlroots portal backend](https://github.com/emersion/xdg-desktop-portal-wlr) does not implement the
67//! D-Bus API that RFD requires (it does not interfere with the other portal implementations;
68//! they can all be installed simultaneously).
69//!
70//! The XDG Desktop Portal has no API for message dialogs, so the [MessageDialog] and
71//! [AsyncMessageDialog] structs will not build with this backend.
72//!
73//! # macOS non-windowed applications, async, and threading
74//!
75//! macOS async dialogs require an `NSApplication` instance, so the dialog is only truly async when
76//! opened in windowed environment like `winit` or `SDL2`. Otherwise, it will fallback to sync dialog.
77//! It is also recommended to spawn dialogs on your main thread. RFD can run dialogs from any thread
78//! but it is only possible in a windowed app and it adds a little bit of overhead. So it is recommended
79//! to [spawn on main and await in other thread](https://github.com/PolyMeilex/rfd/blob/master/examples/async.rs).
80//! Non-windowed apps will never be able to spawn async dialogs or from threads other than the main thread.
81//!
82//! # Customize button texts of message dialog in Windows
83//!
84//! `TaskDialogIndirect` API is used for showing message dialog which can have customized button texts.
85//! It is only provided by ComCtl32.dll v6 but Windows use v5 by default.
86//! If you want to customize button texts or just need a modern dialog style (aka *visual styles*), you will need to:
87//!
88//! 1. Enable cargo feature `common-controls-v6`.
89//! 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)
90//!
91//!
92//! 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/).
93//!
94//! # Cargo features
95//! * `gtk3`: Uses GTK for dialogs on Linux & BSDs; has no effect on Windows and macOS
96//! * `xdg-portal`: Uses XDG Desktop Portal instead of GTK on Linux & BSDs
97//! * `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.
98//!
99//! # State
100//!
101//! | API Stability |
102//! | ------------- |
103//! | 🚧 |
104//!
105//! | Feature | Linux | Windows | MacOS | Wasm32 |
106//! | ------------ | ----- | ------- | --------- | ------ |
107//! | SingleFile | ✔ | ✔ | ✔ | ✔ |
108//! | MultipleFile | ✔ | ✔ | ✔ | ✔ |
109//! | PickFolder | ✔ | ✔ | ✔ | ✖ |
110//! | SaveFile | ✔ | ✔ | ✔ | ✖ |
111//! | | | | | |
112//! | Filters | ✔ ([GTK only](https://github.com/PolyMeilex/rfd/issues/42)) | ✔ | ✔ | ✔ |
113//! | StartingPath | ✔ | ✔ | ✔ | ✖ |
114//! | Async | ✔ | ✔ | ✔ | ✔ |
115//!
116//! # rfd-extras
117//!
118//! AKA features that are not file related
119//!
120//! | Feature | Linux | Windows | MacOS | Wasm32 |
121//! | ------------- | ----- | ------- | ----- | ------ |
122//! | MessageDialog | ✔ (GTK only) | ✔ | ✔ | ✔ |
123//! | PromptDialog | | | | |
124//! | ColorPicker | | | | |
125
126mod backend;
127
128mod file_handle;
129pub use file_handle::FileHandle;
130
131mod file_dialog;
132#[cfg(target_os = "macos")]
133mod oneshot;
134
135#[cfg(not(target_arch = "wasm32"))]
136pub use file_dialog::FileDialog;
137
138pub use file_dialog::AsyncFileDialog;
139
140mod message_dialog;
141pub use message_dialog::{
142 AsyncMessageDialog, MessageButtons, MessageDialog, MessageDialogResult, MessageLevel,
143};