Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: remove result from open method #242

Merged
merged 5 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Renamed `DialogState`'s: `Selected` -> `Picked`, `SelectedMultiple` -> `PickedMultiple` [#229](https://github.com/fluxxcode/egui-file-dialog/pull/229)
- Renamed `active_entry` -> `selected_entry` [#229](https://github.com/fluxxcode/egui-file-dialog/pull/229)
- Renamed `active_selected_entries` -> `selected_entries` [#229](https://github.com/fluxxcode/egui-file-dialog/pull/229)
- Removed result from `FileDialog::open` [#242](https://github.com/fluxxcode/egui-file-dialog/pull/242)

#### Breaking changes due to new features and updated configuration
- Added `file_system` to `FileDialogConfig` [#227](https://github.com/fluxxcode/egui-file-dialog/pull/227)
Expand Down
6 changes: 2 additions & 4 deletions examples/multiple_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
if ui.button("Pick file a").clicked() {
let _ = self
.file_dialog
self.file_dialog
.open(DialogMode::PickFile, true, Some("pick_a"));
}

if ui.button("Pick file b").clicked() {
let _ = self
.file_dialog
self.file_dialog
.open(DialogMode::PickFile, true, Some("pick_b"));
}

Expand Down
19 changes: 5 additions & 14 deletions src/file_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::modals::{FileDialogModal, ModalAction, ModalState, OverwriteFileModal
use crate::{FileSystem, NativeFileSystem};
use egui::text::{CCursor, CCursorRange};
use std::fmt::Debug;
use std::io;
use std::path::{Path, PathBuf};
use std::sync::Arc;

Expand Down Expand Up @@ -310,12 +309,7 @@ impl FileDialog {
/// }
/// }
/// ```
pub fn open(
&mut self,
mode: DialogMode,
mut show_files: bool,
operation_id: Option<&str>,
) -> io::Result<()> {
pub fn open(&mut self, mode: DialogMode, mut show_files: bool, operation_id: Option<&str>) {
self.reset();
self.refresh();

Expand Down Expand Up @@ -348,9 +342,6 @@ impl FileDialog {
.map_or_else(|| egui::Id::new(self.get_window_title()), |id| id);

self.load_directory(&self.get_initial_directory());

// TODO: Dont return a result from this method
Ok(())
}

/// Shortcut function to open the file dialog to prompt the user to pick a directory.
Expand All @@ -361,7 +352,7 @@ impl FileDialog {
///
/// The function ignores the result of the initial directory loading operation.
pub fn pick_directory(&mut self) {
let _ = self.open(DialogMode::PickDirectory, false, None);
self.open(DialogMode::PickDirectory, false, None);
}

/// Shortcut function to open the file dialog to prompt the user to pick a file.
Expand All @@ -370,7 +361,7 @@ impl FileDialog {
///
/// The function ignores the result of the initial directory loading operation.
pub fn pick_file(&mut self) {
let _ = self.open(DialogMode::PickFile, true, None);
self.open(DialogMode::PickFile, true, None);
}

/// Shortcut function to open the file dialog to prompt the user to pick multiple
Expand All @@ -380,7 +371,7 @@ impl FileDialog {
///
/// The function ignores the result of the initial directory loading operation.
pub fn pick_multiple(&mut self) {
let _ = self.open(DialogMode::PickMultiple, true, None);
self.open(DialogMode::PickMultiple, true, None);
}

/// Shortcut function to open the file dialog to prompt the user to save a file.
Expand All @@ -389,7 +380,7 @@ impl FileDialog {
///
/// The function ignores the result of the initial directory loading operation.
pub fn save_file(&mut self) {
let _ = self.open(DialogMode::SaveFile, true, None);
self.open(DialogMode::SaveFile, true, None);
}

/// The main update method that should be called every frame if the dialog is to be visible.
Expand Down