From ee550266c67b9f1c013991671f9c8f053f473d6d Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Fri, 17 Oct 2025 16:02:55 -0400 Subject: [PATCH] chore: focus empty trash and mount error buttons --- src/app.rs | 80 ++++++++++++++++++++++++++++++++------------------- src/dialog.rs | 5 +++- 2 files changed, 54 insertions(+), 31 deletions(-) diff --git a/src/app.rs b/src/app.rs index 324710a..104bf13 100644 --- a/src/app.rs +++ b/src/app.rs @@ -98,12 +98,18 @@ static PERMANENT_DELETE_BUTTON_ID: LazyLock = static CONFIRM_OPEN_WITH_BUTTON_ID: LazyLock = LazyLock::new(|| widget::Id::new("confirm-open-with-button")); +static EMPTY_TRASH_BUTTON_ID: LazyLock = + LazyLock::new(|| widget::Id::new("empty-trash-button")); + static SET_EXECUTABLE_AND_LAUNCH_CONFIRM_BUTTON_ID: LazyLock = LazyLock::new(|| widget::Id::new("set-executable-and-launch-confirm-button")); static FAVORITE_PATH_ERROR_REMOVE_BUTTON_ID: LazyLock = LazyLock::new(|| widget::Id::new("favorite-path-error-remove-button")); +static MOUNT_ERROR_TRY_AGAIN_BUTTON_ID: LazyLock = + LazyLock::new(|| widget::Id::new("mount-error-try-again-button")); + pub(crate) static REPLACE_BUTTON_ID: LazyLock = LazyLock::new(|| widget::Id::new("replace-button")); @@ -3103,23 +3109,26 @@ impl Application for App { } Err(error) => { log::warn!("failed to connect to {:?}: {}", item, error); - return self.dialog_pages.push_back(DialogPage::MountError { - mounter_key, - item, - error, - }); + return self.push_dialog( + DialogPage::MountError { + mounter_key, + item, + error, + }, + Some(MOUNT_ERROR_TRY_AGAIN_BUTTON_ID.clone()), + ); } }, Message::NetworkAuth(mounter_key, uri, auth, auth_tx) => { - return Task::batch([ - self.dialog_pages.push_back(DialogPage::NetworkAuth { + return self.push_dialog( + DialogPage::NetworkAuth { mounter_key, uri, auth, auth_tx, - }), - widget::text_input::focus(self.dialog_text_input.clone()), - ]); + }, + Some(self.dialog_text_input.clone()), + ); } Message::NetworkDriveInput(input) => { self.network_drive_input = input; @@ -3533,6 +3542,8 @@ impl Application for App { }, })); } + tasks.push(widget::text_input::focus(self.dialog_text_input.clone())); + // Remove from progress self.progress_operations.remove(&id); self.failed_operations @@ -3990,7 +4001,10 @@ impl Application for App { commands.push(self.update(Message::PasteContents(to, from))); } tab::Command::EmptyTrash => { - return self.dialog_pages.push_back(DialogPage::EmptyTrash); + return self.push_dialog( + DialogPage::EmptyTrash, + Some(EMPTY_TRASH_BUTTON_ID.clone()), + ); } #[cfg(feature = "desktop")] tab::Command::ExecEntryAction(entry, action) => { @@ -4566,7 +4580,8 @@ impl Application for App { } NavMenuAction::EmptyTrash => { - return self.dialog_pages.push_front(DialogPage::EmptyTrash); + return self + .push_dialog(DialogPage::EmptyTrash, Some(EMPTY_TRASH_BUTTON_ID.clone())); } }, Message::Recents => { @@ -4951,7 +4966,9 @@ impl Application for App { .title(fl!("empty-trash")) .body(fl!("empty-trash-warning")) .primary_action( - widget::button::suggested(fl!("empty-trash")).on_press(Message::DialogComplete), + widget::button::suggested(fl!("empty-trash")) + .on_press(Message::DialogComplete) + .id(EMPTY_TRASH_BUTTON_ID.clone()), ) .secondary_action( widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel), @@ -4970,23 +4987,24 @@ impl Application for App { widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel), ) } - DialogPage::ExtractPassword { id, password } => { - widget::dialog() - .title(fl!("extract-password-required")) - .icon(icon::from_name("dialog-error").size(64)) - .control(widget::text_input("", password).password().on_input( - move |password| { + DialogPage::ExtractPassword { id, password } => widget::dialog() + .title(fl!("extract-password-required")) + .icon(icon::from_name("dialog-error").size(64)) + .control( + widget::text_input("", password) + .password() + .on_input(move |password| { Message::DialogUpdate(DialogPage::ExtractPassword { id: *id, password }) - }, - )) - .primary_action( - widget::button::suggested(fl!("extract-here")) - .on_press(Message::DialogComplete), - ) - .secondary_action( - widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel), - ) - } + }) + .id(self.dialog_text_input.clone()), + ) + .primary_action( + widget::button::suggested(fl!("extract-here")) + .on_press(Message::DialogComplete), + ) + .secondary_action( + widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel), + ), DialogPage::MountError { mounter_key: _, item: _, @@ -4996,7 +5014,9 @@ impl Application for App { .body(error) .icon(icon::from_name("dialog-error").size(64)) .primary_action( - widget::button::standard(fl!("try-again")).on_press(Message::DialogComplete), + widget::button::standard(fl!("try-again")) + .on_press(Message::DialogComplete) + .id(MOUNT_ERROR_TRY_AGAIN_BUTTON_ID.clone()), ) .secondary_action( widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel), diff --git a/src/dialog.rs b/src/dialog.rs index 341c527..a2af77e 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -36,7 +36,9 @@ use std::{ }; use crate::{ - app::{Action, ContextPage, Message as AppMessage, PreviewItem, PreviewKind}, + app::{ + Action, ContextPage, Message as AppMessage, PreviewItem, PreviewKind, REPLACE_BUTTON_ID, + }, config::{Config, DialogConfig, Favorite, TIME_CONFIG_ID, ThumbCfg, TimeConfig, TypeToSearch}, fl, home_dir, key_bind::key_binds, @@ -1597,6 +1599,7 @@ impl Application for App { self.dialog_pages.push_back(DialogPage::Replace { filename: filename.clone(), }); + return widget::button::focus(REPLACE_BUTTON_ID.clone()); } else { self.result_opt = Some(DialogResult::Open(vec![path])); return window::close(self.flags.window_id);