egui_file_dialog/lib.rs
1//! # egui-file-dialog
2//!
3//! An easy-to-use and customizable file dialog (a.k.a. file explorer, file picker) for
4//! [egui](https://github.com/emilk/egui).
5//!
6//! Read more about the project: <https://github.com/jannistpl/egui-file-dialog>
7//!
8//! ### Features
9//!
10//! - Pick a file or a directory
11//! - Save a file (Prompt user for a destination path)
12//! - Dialog to ask the user if the existing file should be overwritten
13//! - Pick multiple files and folders at once
14//! (ctrl/shift + click on linux/windows and cmd/shift + click on macOS)
15//! - Open the dialog in a normal or modal window
16//! - Create a new folder
17//! - Keyboard navigation
18//! - Option to show or hide hidden files and folders
19//! - Option to show or hide system files
20//! - Navigation buttons to open the parent or previous directories
21//! - Search for items in a directory
22//! - Add file filters the user can select from a dropdown
23//! - Shortcut for user directories (Home, Documents, ...) and system disks
24//! - Pin folders to the left sidebar
25//! - Manually edit the path via text
26//! - Virtual file system support
27//! - Customization highlights:
28//! - Customize which areas and functions of the dialog are visible
29//! - Customize the text labels used by the dialog to enable multilingual support
30//! - Customize file and folder icons
31//! - Add custom quick access sections to the left sidebar
32//! - Customize keybindings used by the file dialog
33//! - Add a right panel with custom UI
34//! (An optional information panel to display file previews is included)
35//!
36//! ## Example
37//!
38//! Detailed examples that can be run can be found in the
39//! [examples](https://github.com/jannistpl/egui-file-dialog/tree/develop/examples) folder.
40//!
41//! The following example shows the basic use of the file dialog with
42//! [eframe](https://github.com/emilk/egui/tree/master/crates/eframe) to select a file.
43//!
44//! ```no_run
45//! use std::path::PathBuf;
46//!
47//! use eframe::egui;
48//! use egui_file_dialog::FileDialog;
49//!
50//! struct MyApp {
51//! file_dialog: FileDialog,
52//! picked_file: Option<PathBuf>,
53//! }
54//!
55//! impl MyApp {
56//! pub fn new(_cc: &eframe::CreationContext) -> Self {
57//! Self {
58//! // Create a new file dialog object
59//! file_dialog: FileDialog::new(),
60//! picked_file: None,
61//! }
62//! }
63//! }
64//!
65//! impl eframe::App for MyApp {
66//! fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
67//! egui::CentralPanel::default().show_inside(ui, |ui| {
68//! if ui.button("Pick file").clicked() {
69//! // Open the file dialog to pick a file.
70//! self.file_dialog.pick_file();
71//! }
72//!
73//! ui.label(format!("Picked file: {:?}", self.picked_file));
74//!
75//! // Update the dialog
76//! self.file_dialog.update(ui);
77//!
78//! // Check if the user picked a file.
79//! if let Some(path) = self.file_dialog.take_picked() {
80//! self.picked_file = Some(path.to_path_buf());
81//! }
82//! });
83//! }
84//! }
85//!
86//! fn main() -> eframe::Result<()> {
87//! eframe::run_native(
88//! "File dialog demo",
89//! eframe::NativeOptions::default(),
90//! Box::new(|ctx| Ok(Box::new(MyApp::new(ctx)))),
91//! )
92//! }
93//! ```
94//!
95//! ### Customization
96//! Many things can be customized so that the dialog can be used in different situations. \
97//! A few highlights of the customization are listed below. For all possible customization
98//! options, see the documentation on
99//! [docs.rs](https://docs.rs/egui-file-dialog/latest/egui_file_dialog/struct.FileDialog.html).
100//!
101//! - Set which areas and functions of the dialog are visible using `FileDialog::show_*` methods
102//! - Update the text labels that the dialog uses. See [Multilingual support](#multilingual-support)
103//! - Customize file and folder icons using `FileDialog::set_file_icon`
104//! (Currently only unicode is supported)
105//! - Customize keybindings used by the file dialog using `FileDialog::keybindings`.
106//! See [Keybindings](#keybindings)
107//! - Add a right panel with custom UI using `FileDialog::update_with_right_panel_ui`
108//!
109//! Since the dialog uses the egui style to look like the rest of the application,
110//! the appearance can be customized with `egui::Style` and `egui::Context::set_style`.
111//!
112//! The following example shows how a single file dialog can be customized. \
113//! If you need to configure multiple file dialog objects with the same or almost the same
114//! options, it is a good idea to use `FileDialogConfig` and `FileDialog::with_config`
115//! (See `FileDialogConfig` on [docs.rs](
116//! https://docs.rs/egui-file-dialog/latest/egui_file_dialog/struct.FileDialogConfig.html)).
117//!
118//! ```rust
119//! use std::path::PathBuf;
120//!
121//! use egui_file_dialog::{FileDialog, Filter};
122//!
123//! FileDialog::new()
124//! .initial_directory(PathBuf::from("/path/to/app"))
125//! .default_file_name("app.cfg")
126//! .default_size([600.0, 400.0])
127//! .resizable(false)
128//! .show_new_folder_button(false)
129//! .show_search(false)
130//! .show_path_edit_button(false)
131//! // Add a new quick access section to the left sidebar
132//! .add_quick_access("Project", |s| {
133//! s.add_path("โ Examples", "examples");
134//! s.add_path("๐ท Media", "media");
135//! s.add_path("๐ Source", "src");
136//! })
137//! // Markdown files should use the "document with text (U+1F5B9)" icon
138//! .set_file_icon(
139//! "๐น",
140//! Filter::new(|path: &std::path::Path| path.extension().unwrap_or_default() == "md"),
141//! )
142//! // .gitignore files should use the "web-github (U+E624)" icon
143//! .set_file_icon(
144//! "",
145//! Filter::new(|path: &std::path::Path| path.file_name().unwrap_or_default() == ".gitignore"),
146//! )
147//! // Add file filters the user can select in the bottom right
148//! .add_file_filter(
149//! "PNG files",
150//! Filter::new(|p: &std::path::Path| p.extension().unwrap_or_default() == "png"),
151//! )
152//! .add_file_filter(
153//! "Rust source files",
154//! Filter::new(|p: &std::path::Path| p.extension().unwrap_or_default() == "rs"),
155//! );
156//! ```
157//!
158//! ### Multilingual support
159//! For desktop applications it is often necessary to offer different languages.
160//! While the dialog currently only offers English labels by default, the labels are
161//! fully customizable. This makes it possible to adapt the labels to different languages.
162//!
163//! The following example shows how the labels can be changed to display the file dialog in
164//! English or German. Checkout `examples/multilingual` for the full example.
165//!
166//! ```
167//! use egui_file_dialog::{FileDialog, FileDialogLabels};
168//!
169//! enum Language {
170//! English,
171//! German,
172//! }
173//!
174//! fn get_labels_german() -> FileDialogLabels {
175//! FileDialogLabels {
176//! title_select_directory: "๐ Ordner รffnen".to_string(),
177//! title_select_file: "๐ Datei รffnen".to_string(),
178//! title_save_file: "๐ฅ Datei Speichern".to_string(),
179//!
180//! // ... See examples/multilingual for the other labels
181//!
182//! ..Default::default()
183//! }
184//! }
185//!
186//! /// Updates the labels of the file dialog.
187//! /// Should be called every time the user selects a different language.
188//! fn update_labels(language: &Language, file_dialog: &mut FileDialog) {
189//! *file_dialog.labels_mut() = match language {
190//! // English labels are used by default
191//! Language::English => FileDialogLabels::default(),
192//! // Use custom labels for German
193//! Language::German => get_labels_german(),
194//! };
195//! }
196//! ```
197//!
198//! ### Persistent data
199//! The file dialog currently requires the following persistent data to be stored across
200//! multiple file dialog objects:
201//!
202//! - Folders the user pinned to the left sidebar (`FileDialog::show_pinned_folders`)
203//! - If hidden files and folders should be visible (`FileDialog::show_hidden_option`)
204//! - If system files should be visible (`FileDialog::show_system_files_option`)
205//!
206//! If one of the above feature is activated, the data should be saved by the application.
207//! Otherwise, frustrating situations could arise for the user and the features would not
208//! offer much added value.
209//!
210//! All data that needs to be stored permanently is contained in the `FileDialogStorage` struct.
211//! This struct can be accessed using `FileDialog::storage` or `FileDialog::storage_mut` to save or
212//! load the persistent data. \
213//! By default the feature `serde` is enabled, which implements `serde::Serialize` and
214//! `serde::Deserialize` for the objects to be saved. However, the objects can also be
215//! accessed without the feature enabled.
216//!
217//! Checkout `examples/persistence` for an example.
218
219// Let's keep the public API well documented!
220#![warn(missing_docs)]
221
222mod config;
223mod create_directory_dialog;
224mod data;
225mod file_dialog;
226mod file_system;
227/// Information panel showing the preview and metadata of the selected item
228pub mod information_panel;
229mod modals;
230
231pub use config::{
232 FileDialogConfig, FileDialogKeyBindings, FileDialogLabels, Filter, IconFilter, KeyBinding,
233 OpeningMode, PinnedFolder, QuickAccess, QuickAccessPath,
234};
235pub use data::{DirectoryEntry, Disk, Disks, Metadata, UserDirectories};
236pub use file_dialog::{DialogMode, DialogState, FileDialog, FileDialogStorage};
237pub use file_system::{FileSystem, NativeFileSystem};