Skip to content

Commit

Permalink
Cargo fix & fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Masterchef365 committed Jan 20, 2025
1 parent 0c03bdd commit 4714abd
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 24 deletions.
18 changes: 8 additions & 10 deletions examples/custom_filesystem.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use egui_file_dialog::{Disk, Disks, FileDialog, FileDialogConfig, FileSystem};
use egui_file_dialog::{Disk, Disks, FileDialog, FileSystem};
use std::{
path::{Component, Path, PathBuf},
sync::Arc,
Expand Down Expand Up @@ -39,9 +39,7 @@ impl MyApp {
];

Self {
file_dialog: FileDialog::new().with_file_system(
Arc::new(MyFileSystem(root)),
),
file_dialog: FileDialog::new().with_file_system(Arc::new(MyFileSystem(root))),
picked_file: None,
}
}
Expand Down Expand Up @@ -132,11 +130,11 @@ impl FileSystem for MyFileSystem {
})
}

fn metadata(&self, path: &Path) -> std::io::Result<egui_file_dialog::Metadata> {
fn metadata(&self, _path: &Path) -> std::io::Result<egui_file_dialog::Metadata> {
Ok(Default::default())
}

fn get_disks(&self, canonicalize_paths: bool) -> egui_file_dialog::Disks {
fn get_disks(&self, _canonicalize_paths: bool) -> egui_file_dialog::Disks {
Disks::new(vec![Disk::new(
Some("I'm a fake disk"),
&PathBuf::from("/disk"),
Expand All @@ -145,11 +143,11 @@ impl FileSystem for MyFileSystem {
)])
}

fn user_dirs(&self, canonicalize_paths: bool) -> Option<egui_file_dialog::UserDirectories> {
fn user_dirs(&self, _canonicalize_paths: bool) -> Option<egui_file_dialog::UserDirectories> {
None
}

fn create_dir(&self, path: &Path) -> std::io::Result<()> {
fn create_dir(&self, _path: &Path) -> std::io::Result<()> {
Err(std::io::Error::new(
std::io::ErrorKind::Unsupported,
"Unsupported".to_string(),
Expand All @@ -160,11 +158,11 @@ impl FileSystem for MyFileSystem {
Ok("folder_a".into())
}

fn is_path_hidden(&self, path: &Path) -> bool {
fn is_path_hidden(&self, _path: &Path) -> bool {
false
}

fn load_text_file_preview(&self, path: &Path, max_chars: usize) -> std::io::Result<String> {
fn load_text_file_preview(&self, _path: &Path, _max_chars: usize) -> std::io::Result<String> {
Err(std::io::Error::new(
std::io::ErrorKind::Unsupported,
"Unsupported".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion examples/pick_file.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::path::PathBuf;
use egui_file_dialog::FileDialog;
use std::path::PathBuf;

use eframe::egui;

Expand Down
8 changes: 7 additions & 1 deletion src/data/directory_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,13 @@ impl DirectoryContent {
let p = path.to_path_buf();
let f = file_filter.cloned();
thread::spawn(move || {
let _ = tx.send(load_directory(&c, &p, include_files, f.as_ref(), &*file_system));
let _ = tx.send(load_directory(
&c,
&p,
include_files,
f.as_ref(),
&*file_system,
));
});

Self {
Expand Down
8 changes: 4 additions & 4 deletions src/data/disks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ pub struct Disks {
impl Disks {
/// Create a new set of disks
pub fn new(disks: Vec<Disk>) -> Self {
Self {
disks,
}
Self { disks }
}

/// Queries the operating system for disks
pub fn new_native_disks(canonicalize_paths: bool) -> Disks {
Disks { disks: load_disks(canonicalize_paths) }
Disks {
disks: load_disks(canonicalize_paths),
}
}

/// Very simple wrapper method of the disks `.iter()` method.
Expand Down
22 changes: 17 additions & 5 deletions src/file_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,11 @@ impl FileDialog {
} else if let Some(parent) = path.parent() {
// Else, go to the parent directory
self.load_directory(parent);
self.select_item(&mut DirectoryEntry::from_path(&self.config, path, &*self.config.file_system));
self.select_item(&mut DirectoryEntry::from_path(
&self.config,
path,
&*self.config.file_system,
));
self.scroll_to_selection = true;
repaint = true;
}
Expand Down Expand Up @@ -2022,7 +2026,8 @@ impl FileDialog {
DirectoryContentState::Finished => {
if self.mode == DialogMode::PickDirectory {
if let Some(dir) = self.current_directory() {
let mut dir_entry = DirectoryEntry::from_path(&self.config, dir, &*self.config.file_system);
let mut dir_entry =
DirectoryEntry::from_path(&self.config, dir, &*self.config.file_system);
self.select_item(&mut dir_entry);
}
}
Expand Down Expand Up @@ -2665,7 +2670,8 @@ impl FileDialog {

/// Function that processes a newly created folder.
fn process_new_folder(&mut self, created_dir: &Path) -> DirectoryEntry {
let mut entry = DirectoryEntry::from_path(&self.config, created_dir, &*self.config.file_system);
let mut entry =
DirectoryEntry::from_path(&self.config, created_dir, &*self.config.file_system);

self.directory_content.push(entry.clone());

Expand Down Expand Up @@ -2733,8 +2739,14 @@ impl FileDialog {
/// Refreshes the dialog.
/// Including the user directories, system disks and currently open directory.
fn refresh(&mut self) {
self.user_directories = self.config.file_system.user_dirs(self.config.canonicalize_paths);
self.system_disks = self.config.file_system.get_disks(self.config.canonicalize_paths);
self.user_directories = self
.config
.file_system
.user_dirs(self.config.canonicalize_paths);
self.system_disks = self
.config
.file_system
.get_disks(self.config.canonicalize_paths);

self.reload_directory();
}
Expand Down
4 changes: 3 additions & 1 deletion src/information_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ impl InformationPanel {

fn load_content(&self, path: PathBuf) -> Option<String> {
if self.load_text_content {
self.file_system.load_text_file_preview(&path, self.text_content_max_chars).ok()
self.file_system
.load_text_file_preview(&path, self.text_content_max_chars)
.ok()
} else {
None
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,16 @@ mod config;
mod create_directory_dialog;
mod data;
mod file_dialog;
mod file_system;
/// Information panel showing the preview and metadata of the selected item
pub mod information_panel;
mod modals;
mod file_system;

pub use config::{
FileDialogConfig, FileDialogKeyBindings, FileDialogLabels, FileDialogStorage, IconFilter,
KeyBinding, QuickAccess, QuickAccessPath,
};
pub use data::{DirectoryEntry, Metadata, UserDirectories, Disks, Disk};
pub use data::{DirectoryEntry, Disk, Disks, Metadata, UserDirectories};
pub use file_dialog::{DialogMode, DialogState, FileDialog};

pub use file_system::{FileSystem, NativeFileSystem};

0 comments on commit 4714abd

Please sign in to comment.