1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
//! # egui-file-dialog
//!
//! An easy-to-use and customizable file dialog (a.k.a. file explorer, file picker) for
//! [egui](https://github.com/emilk/egui).
//!
//! The project is currently in a very early version. Some planned features are still missing
//! and some improvements still need to be made.
//!
//! **Currently only tested on Linux and Windows!**
//!
//! Read more about the project: <https://github.com/fluxxcode/egui-file-dialog>
//!
//! ### Features
//! - Select a file or a directory
//! - Save a file (Prompt user for a destination path)
//! - Create a new folder
//! - Navigation buttons to open the parent or previous directories
//! - Search for items in a directory
//! - Shortcut for user directories (Home, Documents, ...) and system disks
//! - Customization highlights:
//! - Customize which areas and functions of the dialog are visible
//! - Multilingual support: Customize the text labels that the dialog uses
//! - Customize file and folder icons
//!
//! ### A simple example
//!
//! The following example shows of how you can use the file dialog to let the user select a file. \
//! See the full example at
//! <https://github.com/fluxxcode/egui-file-dialog/tree/master/examples/select_file>
//!
//! ```
//! use egui_file_dialog::FileDialog;
//!
//! struct MyApp {
//! file_dialog: FileDialog,
//! }
//!
//! impl MyApp {
//! pub fn new() -> Self {
//! Self {
//! // Create a new FileDialog instance
//! file_dialog: FileDialog::new(),
//! }
//! }
//! }
//!
//! impl MyApp {
//! fn update(&mut self, ctx: &egui::Context, ui: &mut egui::Ui) {
//! if ui.button("Select file").clicked() {
//! // Open the file dialog to select a file
//! self.file_dialog.select_file();
//! }
//!
//! // Update the dialog and check if the user selected a file
//! if let Some(path) = self.file_dialog.update(ctx).selected() {
//! println!("Selected file: {:?}", path);
//! }
//! }
//! }
//! ```
//!
//! ### Customization
//!
//! Many things can be customized so that the dialog can be used in different situations. \
//! A few highlights of the customization are listed below.
//! (More customization will be implemented in the future!)
//!
//! - Set which areas and functions of the dialog are visible using `FileDialog::show_*` methods
//! - Update the text labels that the dialog uses. See [Multilingual support](#multilingual-support)
//! - Customize file and folder icons using `FileDialog::set_file_icon`
//! (Currently only unicode is supported)
//!
//! Since the dialog uses the egui style to look like the rest of the application,
//! the appearance can be customized with `egui::Style`.
//!
//! The following example shows how a file dialog can be customized. If you need to
//! configure multiple file dialog objects with the same or almost the same options,
//! it is a good idea to use `FileDialogConfig` and `FileDialog::with_config`
//!
//! ```
//! use std::path::PathBuf;
//! use std::sync::Arc;
//!
//! use egui_file_dialog::FileDialog;
//!
//! FileDialog::new()
//! .initial_directory(PathBuf::from("/path/to/app"))
//! .default_file_name("app.cfg")
//! .default_size([600.0, 400.0])
//! .resizable(false)
//! .show_new_folder_button(false)
//! .show_search(false)
//! // Markdown and text files should use the "document with text (U+1F5B9)" icon
//! .set_file_icon(
//! "🖹",
//! Arc::new(|path| {
//! match path
//! .extension()
//! .unwrap_or_default()
//! .to_str()
//! .unwrap_or_default()
//! {
//! "md" => true,
//! "txt" => true,
//! _ => false,
//! }
//! }),
//! )
//! // .gitignore files should use the "web-github (U+E624)" icon
//! .set_file_icon(
//! "",
//! Arc::new(|path| path.file_name().unwrap_or_default() == ".gitignore"),
//! );
//! ```
//!
//! ### Multilingual support
//! For desktop applications it is often necessary to offer different languages.
//! While the dialog currently only offers English labels by default, the labels are
//! fully customizable. This makes it possible to adapt the labels to different languages.
//!
//! The following example shows how the labels can be changed to display the file dialog in
//! English or German. Checkout `examples/multilingual` for the full example.
//!
//! ```
//! use egui_file_dialog::{FileDialog, FileDialogLabels};
//!
//! enum Language {
//! English,
//! German,
//! }
//!
//! fn get_labels_german() -> FileDialogLabels {
//! FileDialogLabels {
//! title_select_directory: "📁 Ordner Öffnen".to_string(),
//! title_select_file: "📂 Datei Öffnen".to_string(),
//! title_save_file: "📥 Datei Speichern".to_string(),
//!
//! // ... See examples/multilingual for the other labels
//!
//! ..Default::default()
//! }
//! }
//!
//! /// Updates the labels of the file dialog.
//! /// Should be called every time the user selects a different language.
//! fn update_labels(language: &Language, file_dialog: &mut FileDialog) {
//! *file_dialog.labels_mut() = match language {
//! // English labels are used by default
//! Language::English => FileDialogLabels::default(),
//! // Use custom labels for German
//! Language::German => get_labels_german(),
//! };
//! }
//! ```
#![warn(missing_docs)] // Let's keep the public API well documented!
mod config;
mod create_directory_dialog;
mod data;
mod file_dialog;
pub use config::{FileDialogConfig, FileDialogLabels};
pub use file_dialog::{DialogMode, DialogState, FileDialog};