egui_file_dialog

Trait FileSystem

Source
pub trait FileSystem {
    // Required methods
    fn metadata(&self, path: &Path) -> Result<Metadata>;
    fn is_dir(&self, path: &Path) -> bool;
    fn is_file(&self, path: &Path) -> bool;
    fn read_dir(&self, path: &Path) -> Result<Vec<PathBuf>>;
    fn get_disks(&self, canonicalize_paths: bool) -> Disks;
    fn is_path_hidden(&self, path: &Path) -> bool;
    fn create_dir(&self, path: &Path) -> Result<()>;
    fn user_dirs(&self, canonicalize_paths: bool) -> Option<UserDirectories>;
    fn current_dir(&self) -> Result<PathBuf>;

    // Provided method
    fn load_text_file_preview(
        &self,
        _path: &Path,
        _max_chars: usize,
    ) -> Result<String> { ... }
}
Expand description

An abstraction over the host system, allowing the file dialog to be used to browse e.g. in memory filesystems.

§Examples

use egui_file_dialog::{FileDialog, FileSystem, UserDirectories, Metadata, Disks};
use std::{io, path::{Path, PathBuf}};

struct MyFileSystem;

impl FileSystem for MyFileSystem {
    fn metadata(&self, path: &Path) -> io::Result<Metadata> { todo!() }
    fn is_dir(&self, path: &Path) -> bool { todo!() }
    fn is_file(&self, path: &Path) -> bool { todo!() }
    fn read_dir(&self, path: &Path) -> io::Result<Vec<PathBuf>> { todo!() }
    fn get_disks(&self, canonicalize_paths: bool) -> Disks { todo!() }
    fn is_path_hidden(&self, path: &Path) -> bool { todo!() }
    fn create_dir(&self, path: &Path) -> io::Result<()> { todo!() }
    fn user_dirs(&self, canonicalize_paths: bool) -> Option<UserDirectories> { todo!() }
    fn current_dir(&self) -> io::Result<PathBuf> { Ok("/".into()) }
}

let dialog = FileDialog::with_file_system(std::sync::Arc::new(MyFileSystem));

/* Use the file dialog as usual */

Required Methods§

Source

fn metadata(&self, path: &Path) -> Result<Metadata>

Queries metadata for the given path

Source

fn is_dir(&self, path: &Path) -> bool

Returns true if the path exists and is a directory

Source

fn is_file(&self, path: &Path) -> bool

Returns true if the path exists and is a file

Source

fn read_dir(&self, path: &Path) -> Result<Vec<PathBuf>>

Gets the children of a directory

Source

fn get_disks(&self, canonicalize_paths: bool) -> Disks

List out the disks in the system

Source

fn is_path_hidden(&self, path: &Path) -> bool

Determine if a path is hidden

Source

fn create_dir(&self, path: &Path) -> Result<()>

Creates a new directory

Source

fn user_dirs(&self, canonicalize_paths: bool) -> Option<UserDirectories>

Returns the user directories

Source

fn current_dir(&self) -> Result<PathBuf>

Get the current working directory

Provided Methods§

Source

fn load_text_file_preview( &self, _path: &Path, _max_chars: usize, ) -> Result<String>

Read a short preview of a text file

Trait Implementations§

Source§

impl Debug for dyn FileSystem + Send + Sync

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Implementors§