Skip to content

Commit

Permalink
#287: Auto-focus title search field after clicking the filter button
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Dec 18, 2023
1 parent 8d74fbc commit 3ba18dc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* Changed:
* GUI: A different icon is now used for the button to hide the backup comment field.
The previous icon (a red X) could have been misinterpreted as "delete" rather than "close".
* GUI: When you click the filter icon on the backup/restore screen,
the title search field is automatically focused.
* CLI: Help text is now styled a bit differently.
* Fixed:
* GUI: On some systems using Wayland, Ludusavi would crash on startup.
Expand Down
23 changes: 11 additions & 12 deletions src/gui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
screen,
shortcuts::{Shortcut, TextHistories, TextHistory},
style,
widget::{Column, Container, Element, IcedParentExt, Progress, Row},
widget::{id, Column, Container, Element, IcedParentExt, Progress, Row},
},
lang::TRANSLATOR,
prelude::{app_dir, get_threads_from_env, initialize_rayon, Error, Finality, StrictPath, SyncDirection},
Expand Down Expand Up @@ -1590,18 +1590,17 @@ impl Application for App {
self.config.save();
Command::none()
}
Message::ToggleSearch { screen } => {
match screen {
Screen::Backup => {
self.backup_screen.log.search.show = !self.backup_screen.log.search.show;
}
Screen::Restore => {
self.restore_screen.log.search.show = !self.restore_screen.log.search.show;
}
_ => {}
Message::ToggleSearch { screen } => match screen {
Screen::Backup => {
self.backup_screen.log.search.show = !self.backup_screen.log.search.show;
iced::widget::text_input::focus(id::backup_search())
}
Command::none()
}
Screen::Restore => {
self.restore_screen.log.search.show = !self.restore_screen.log.search.show;
iced::widget::text_input::focus(id::restore_search())
}
_ => Command::none(),
},
Message::ToggleSpecificGamePathIgnored {
name,
path,
Expand Down
12 changes: 11 additions & 1 deletion src/gui/shortcuts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
common::{EditAction, Message, RedirectEditActionField, Screen, UndoSubject},
modal::{ModalField, ModalInputKind},
style,
widget::{Element, TextInput, Undoable},
widget::{id, Element, TextInput, Undoable},
},
lang::TRANSLATOR,
prelude::StrictPath,
Expand Down Expand Up @@ -406,6 +406,12 @@ impl TextHistories {
| UndoSubject::ModalField(_) => None,
};

let id = match subject {
UndoSubject::BackupSearchGameName => Some(id::backup_search()),
UndoSubject::RestoreSearchGameName => Some(id::restore_search()),
_ => None,
};

Undoable::new(
{
let mut input = TextInput::new(&placeholder, &current)
Expand All @@ -422,6 +428,10 @@ impl TextHistories {
input = input.password();
}

if let Some(id) = id {
input = input.id(id);
}

input
},
move |action| Message::UndoRedo(action, subject),
Expand Down
11 changes: 11 additions & 0 deletions src/gui/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ pub mod id {
pub static OTHER_SCROLL: Lazy<iced::widget::scrollable::Id> = Lazy::new(iced::widget::scrollable::Id::unique);
pub static MODAL_SCROLL: Lazy<iced::widget::scrollable::Id> = Lazy::new(iced::widget::scrollable::Id::unique);

pub static BACKUP_SEARCH: Lazy<iced::widget::text_input::Id> = Lazy::new(iced::widget::text_input::Id::unique);
pub static RESTORE_SEARCH: Lazy<iced::widget::text_input::Id> = Lazy::new(iced::widget::text_input::Id::unique);

pub fn backup_scroll() -> iced::widget::scrollable::Id {
(*BACKUP_SCROLL).clone()
}
Expand All @@ -79,6 +82,14 @@ pub mod id {
pub fn modal_scroll() -> iced::widget::scrollable::Id {
(*MODAL_SCROLL).clone()
}

pub fn backup_search() -> iced::widget::text_input::Id {
(*BACKUP_SEARCH).clone()
}

pub fn restore_search() -> iced::widget::text_input::Id {
(*RESTORE_SEARCH).clone()
}
}

pub fn number_input<'a>(
Expand Down

0 comments on commit 3ba18dc

Please sign in to comment.