Skip to content

Commit

Permalink
refactor: fix file system creation method (#241)
Browse files Browse the repository at this point in the history
* Fix file system creation method

* Fix doctest
  • Loading branch information
fluxxcode authored Feb 4, 2025
1 parent ad29dfc commit 57c9276
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/custom_filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl MyApp {
];

Self {
file_dialog: FileDialog::new().with_file_system(Arc::new(MyFileSystem(root))),
file_dialog: FileDialog::with_file_system(Arc::new(MyFileSystem(root))),
picked_file: None,
}
}
Expand Down
17 changes: 9 additions & 8 deletions src/file_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,22 @@ impl FileDialog {
}
}

/// Uses the given file system instead of the native file system.
#[must_use]
pub fn with_file_system(mut self, file_system: Arc<dyn FileSystem + Send + Sync>) -> Self {
self.config.initial_directory = file_system.current_dir().unwrap_or_default();
self.config.file_system = file_system;
self
}

/// Creates a new file dialog object and initializes it with the specified configuration.
pub fn with_config(config: FileDialogConfig) -> Self {
let mut obj = Self::new();
*obj.config_mut() = config;
obj
}

/// Uses the given file system instead of the native file system.
#[must_use]
pub fn with_file_system(file_system: Arc<dyn FileSystem + Send + Sync>) -> Self {
let mut obj = Self::new();
obj.config.initial_directory = file_system.current_dir().unwrap_or_default();
obj.config.file_system = file_system;
obj
}

// -------------------------------------------------
// Open, Update:

Expand Down
2 changes: 1 addition & 1 deletion src/file_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::data::{Disks, Metadata, UserDirectories};
/// fn current_dir(&self) -> io::Result<PathBuf> { Ok("/".into()) }
/// }
///
/// let dialog = FileDialog::new().with_file_system(std::sync::Arc::new(MyFileSystem));
/// let dialog = FileDialog::with_file_system(std::sync::Arc::new(MyFileSystem));
///
/// /* Use the file dialog as usual */
/// ```
Expand Down

0 comments on commit 57c9276

Please sign in to comment.