Skip to content

Commit

Permalink
Group filter events together
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Dec 19, 2024
1 parent 8f4be97 commit 0289f88
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 157 deletions.
218 changes: 113 additions & 105 deletions src/gui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use crate::{
ResourceFile, SaveableResourceFile,
},
scan::{
layout::BackupLayout, prepare_backup_target, registry::RegistryItem, scan_game_for_backup, BackupId, Launchers,
ScanKind, SteamShortcuts, TitleFinder,
game_filter, layout::BackupLayout, prepare_backup_target, registry::RegistryItem, scan_game_for_backup,
BackupId, Launchers, ScanKind, SteamShortcuts, TitleFinder,
},
};

Expand Down Expand Up @@ -1951,21 +1951,6 @@ impl App {
self.save_config();
Task::none()
}
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())
}
Screen::Restore => {
self.restore_screen.log.search.show = !self.restore_screen.log.search.show;
iced::widget::text_input::focus(id::restore_search())
}
Screen::CustomGames => {
self.custom_games_screen.filter.enabled = !self.custom_games_screen.filter.enabled;
iced::widget::text_input::focus(id::custom_games_search())
}
_ => Task::none(),
},
Message::ToggleSpecificGamePathIgnored { name, path, scan_kind } => {
match scan_kind {
ScanKind::Backup => {
Expand Down Expand Up @@ -2019,95 +2004,118 @@ impl App {
self.save_config();
Task::none()
}
Message::EditedSearchGameName { screen, value } => {
match screen {
Screen::Backup => {
self.text_histories.backup_search_game_name.push(&value);
self.backup_screen.log.search.game_name = value;
}
Screen::Restore => {
self.text_histories.restore_search_game_name.push(&value);
self.restore_screen.log.search.game_name = value;
}
Screen::CustomGames => {
self.text_histories.custom_games_search_game_name.push(&value);
self.custom_games_screen.filter.name = value;
}
_ => {}
}
Task::none()
}
Message::ToggledSearchFilter { filter, enabled } => {
let search = if self.screen == Screen::Backup {
&mut self.backup_screen.log.search
} else {
&mut self.restore_screen.log.search
};
search.toggle_filter(filter, enabled);
Task::none()
}
Message::ResetSearchFilter => {
match self.screen {
Screen::Backup => {
self.backup_screen.log.search.reset();
self.text_histories.backup_search_game_name.push("");
}
Screen::Restore => {
self.restore_screen.log.search.reset();
self.text_histories.restore_search_game_name.push("");
}
Screen::CustomGames => {
self.custom_games_screen.filter.reset();
self.text_histories.custom_games_search_game_name.push("");
}
Screen::Other => {}
Message::Filter { event } => {
let mut task = None;

match event {
game_filter::Event::Toggled => match self.screen {
Screen::Backup => {
self.backup_screen.log.search.show = !self.backup_screen.log.search.show;
task = Some(iced::widget::text_input::focus(id::backup_search()));
}
Screen::Restore => {
self.restore_screen.log.search.show = !self.restore_screen.log.search.show;
task = Some(iced::widget::text_input::focus(id::restore_search()));
}
Screen::CustomGames => {
self.custom_games_screen.filter.enabled = !self.custom_games_screen.filter.enabled;
task = Some(iced::widget::text_input::focus(id::custom_games_search()));
}
Screen::Other => {}
},
game_filter::Event::ToggledFilter { filter, enabled } => match self.screen {
Screen::Backup => {
self.backup_screen.log.search.toggle_filter(filter, enabled);
}
Screen::Restore => {
self.restore_screen.log.search.toggle_filter(filter, enabled);
}
Screen::CustomGames => {}
Screen::Other => {}
},
game_filter::Event::EditedGameName(value) => match self.screen {
Screen::Backup => {
self.text_histories.backup_search_game_name.push(&value);
self.backup_screen.log.search.game_name = value;
}
Screen::Restore => {
self.text_histories.restore_search_game_name.push(&value);
self.restore_screen.log.search.game_name = value;
}
Screen::CustomGames => {
self.text_histories.custom_games_search_game_name.push(&value);
self.custom_games_screen.filter.name = value;
}
Screen::Other => {}
},
game_filter::Event::Reset => match self.screen {
Screen::Backup => {
self.backup_screen.log.search.reset();
self.text_histories.backup_search_game_name.push("");
}
Screen::Restore => {
self.restore_screen.log.search.reset();
self.text_histories.restore_search_game_name.push("");
}
Screen::CustomGames => {
self.custom_games_screen.filter.reset();
self.text_histories.custom_games_search_game_name.push("");
}
Screen::Other => {}
},
game_filter::Event::EditedFilterUniqueness(value) => match self.screen {
Screen::Backup => {
self.backup_screen.log.search.uniqueness.choice = value;
}
Screen::Restore => {
self.restore_screen.log.search.uniqueness.choice = value;
}
Screen::CustomGames => {}
Screen::Other => {}
},
game_filter::Event::EditedFilterCompleteness(value) => match self.screen {
Screen::Backup => {
self.backup_screen.log.search.completeness.choice = value;
}
Screen::Restore => {
self.restore_screen.log.search.completeness.choice = value;
}
Screen::CustomGames => {}
Screen::Other => {}
},
game_filter::Event::EditedFilterEnablement(value) => match self.screen {
Screen::Backup => {
self.backup_screen.log.search.enablement.choice = value;
}
Screen::Restore => {
self.restore_screen.log.search.enablement.choice = value;
}
Screen::CustomGames => {}
Screen::Other => {}
},
game_filter::Event::EditedFilterChange(value) => match self.screen {
Screen::Backup => {
self.backup_screen.log.search.change.choice = value;
}
Screen::Restore => {
self.restore_screen.log.search.change.choice = value;
}
Screen::CustomGames => {}
Screen::Other => {}
},
game_filter::Event::EditedFilterManifest(value) => match self.screen {
Screen::Backup => {
self.backup_screen.log.search.manifest.choice = value;
}
Screen::Restore => {
self.restore_screen.log.search.manifest.choice = value;
}
Screen::CustomGames => {}
Screen::Other => {}
},
}
Task::none()
}
Message::EditedSearchFilterUniqueness(filter) => {
let search = if self.screen == Screen::Backup {
&mut self.backup_screen.log.search
} else {
&mut self.restore_screen.log.search
};
search.uniqueness.choice = filter;
Task::none()
}
Message::EditedSearchFilterCompleteness(filter) => {
let search = if self.screen == Screen::Backup {
&mut self.backup_screen.log.search
} else {
&mut self.restore_screen.log.search
};
search.completeness.choice = filter;
Task::none()
}
Message::EditedSearchFilterEnablement(filter) => {
let search = if self.screen == Screen::Backup {
&mut self.backup_screen.log.search
} else {
&mut self.restore_screen.log.search
};
search.enablement.choice = filter;
Task::none()
}
Message::EditedSearchFilterChange(filter) => {
let search = if self.screen == Screen::Backup {
&mut self.backup_screen.log.search
} else {
&mut self.restore_screen.log.search
};
search.change.choice = filter;
Task::none()
}
Message::EditedSearchFilterManifest(filter) => {
let search = if self.screen == Screen::Backup {
&mut self.backup_screen.log.search
} else {
&mut self.restore_screen.log.search
};
search.manifest.choice = filter;
Task::none()

task.unwrap_or_else(Task::none)
}
Message::EditedSortKey { screen, value } => {
match screen {
Expand Down
11 changes: 8 additions & 3 deletions src/gui/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
lang::TRANSLATOR,
prelude::{Finality, SyncDirection},
resource::manifest,
scan::game_filter,
};

const WIDTH: u16 = 125;
Expand Down Expand Up @@ -145,18 +146,22 @@ pub fn choose_file<'a>(subject: BrowseFileSubject, modifiers: &keyboard::Modifie
}
}

pub fn filter<'a>(screen: Screen, open: bool) -> Element<'a> {
pub fn filter<'a>(open: bool) -> Element<'a> {
template(
Icon::Filter.text(),
Some(Message::ToggleSearch { screen }),
Some(Message::Filter {
event: game_filter::Event::Toggled,
}),
open.then_some(style::Button::Negative),
)
}

pub fn reset_filter<'a>(dirty: bool) -> Element<'a> {
template(
Icon::RemoveCircle.text(),
dirty.then_some(Message::ResetSearchFilter),
dirty.then_some(Message::Filter {
event: game_filter::Event::Reset,
}),
Some(style::Button::Negative),
)
}
Expand Down
18 changes: 2 additions & 16 deletions src/gui/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ pub enum Message {
enabled: bool,
scan_kind: ScanKind,
},
ToggleSearch {
screen: Screen,
},
ToggleSpecificGamePathIgnored {
name: String,
path: StrictPath,
Expand All @@ -192,20 +189,9 @@ pub enum Message {
index: usize,
enabled: bool,
},
EditedSearchGameName {
screen: Screen,
value: String,
},
ToggledSearchFilter {
filter: game_filter::FilterKind,
enabled: bool,
Filter {
event: game_filter::Event,
},
ResetSearchFilter,
EditedSearchFilterUniqueness(game_filter::Uniqueness),
EditedSearchFilterCompleteness(game_filter::Completeness),
EditedSearchFilterEnablement(game_filter::Enablement),
EditedSearchFilterChange(game_filter::Change),
EditedSearchFilterManifest(game_filter::Manifest),
EditedSortKey {
screen: Screen,
value: SortKey,
Expand Down
6 changes: 3 additions & 3 deletions src/gui/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Backup {
.push(button::toggle_all_scanned_games(
self.log.all_entries_selected(config, Self::SCAN_KIND),
))
.push(button::filter(Screen::Backup, self.log.search.show)),
.push(button::filter(self.log.search.show)),
)
.push(make_status_row(
&self.log.compute_operation_status(config, Self::SCAN_KIND),
Expand Down Expand Up @@ -175,7 +175,7 @@ impl Restore {
self.log.all_entries_selected(config, Self::SCAN_KIND),
))
.push(button::validate_backups(operation))
.push(button::filter(Screen::Restore, self.log.search.show)),
.push(button::filter(self.log.search.show)),
)
.push(make_status_row(
&self.log.compute_operation_status(config, Self::SCAN_KIND),
Expand Down Expand Up @@ -237,7 +237,7 @@ impl CustomGames {
.push(button::add_game())
.push(button::toggle_all_custom_games(config.are_all_custom_games_enabled()))
.push(button::sort(Message::SortCustomGames))
.push(button::filter(Screen::CustomGames, self.filter.enabled)),
.push(button::filter(self.filter.enabled)),
)
.push_maybe(self.filter.view(histories))
.push(editor::custom_games(
Expand Down
Loading

0 comments on commit 0289f88

Please sign in to comment.