diff options
Diffstat (limited to 'schist_desktop_gui/src/gui/components/buckets_view.rs')
| -rw-r--r-- | schist_desktop_gui/src/gui/components/buckets_view.rs | 88 |
1 files changed, 47 insertions, 41 deletions
diff --git a/schist_desktop_gui/src/gui/components/buckets_view.rs b/schist_desktop_gui/src/gui/components/buckets_view.rs index 2b3258a..7f5b218 100644 --- a/schist_desktop_gui/src/gui/components/buckets_view.rs +++ b/schist_desktop_gui/src/gui/components/buckets_view.rs @@ -63,6 +63,43 @@ impl BucketsView { fn update_greeting(&mut self, active_entry: &str) { self.greeting = format!("Hello, {}!", active_entry); } + + fn expand_group(&mut self, group: String, buckets: Vec<Bucket>) -> Action { + match self.navigation.insert_after_first( + |bucket_navigation_entry| { + bucket_navigation_entry.is_group_and(|bucket_group_name| { + !bucket_group_name.is_open && bucket_group_name.group.eq(group.as_str()) + }) + }, + &buckets + .iter() + .map(BucketNavigationEntry::from_bucket) + .collect(), + ) { + InsertOptionResult::InsertedOptions => { + self.navigation.replace_first( + |bucket_navigation_entry| { + bucket_navigation_entry.is_group_and(|g| g.group.eq(group.as_str())) + }, + &vec![BucketNavigationEntry::from_group_open(&group)], + ); + Action::None + } + InsertOptionResult::NoSuchOption => Action::None, + } + } + + fn collapse_group(&mut self, group: String) -> Action { + self.navigation + .remove_options_where(|bucket_navigation_entry| { + bucket_navigation_entry.is_bucket_and(|bucket| bucket.group.eq(&group)) + }); + self.navigation.replace_first( + |bucket_navigation_entry| bucket_navigation_entry.is_group_and(|g| g.group.eq(&group)), + &vec![BucketNavigationEntry::from_group_closed(&group)], + ); + Action::None + } } impl<'a> Viewable<'a, Message> for BucketsView { @@ -97,7 +134,8 @@ impl<'a> Component<'a, Message, Action> for BucketsView { .navigation .update(navigation::Message::SetOptions(groups)) { - navigation::Action::SelectOption(bucket_navigation_entry) => { + navigation::Action::ActivateOption(bucket_navigation_entry) + | navigation::Action::SelectOption(bucket_navigation_entry) => { self.update_greeting(&bucket_navigation_entry.to_string()); Action::None } @@ -106,7 +144,8 @@ impl<'a> Component<'a, Message, Action> for BucketsView { } Message::NavigationMessage(message) => match self.navigation.update(message) { - navigation::Action::SelectOption(bucket_navigation_entry) => { + navigation::Action::ActivateOption(bucket_navigation_entry) + | navigation::Action::SelectOption(bucket_navigation_entry) => { self.update_greeting(&bucket_navigation_entry.to_string()); Action::None } @@ -114,7 +153,8 @@ impl<'a> Component<'a, Message, Action> for BucketsView { }, Message::SelectNext => match self.navigation.update(navigation::Message::SelectNext) { - navigation::Action::SelectOption(bucket_navigation_entry) => { + navigation::Action::ActivateOption(bucket_navigation_entry) + | navigation::Action::SelectOption(bucket_navigation_entry) => { self.update_greeting(&bucket_navigation_entry.to_string()); Action::None } @@ -122,51 +162,17 @@ impl<'a> Component<'a, Message, Action> for BucketsView { }, Message::SelectPrev => match self.navigation.update(navigation::Message::SelectPrev) { - navigation::Action::SelectOption(bucket_navigation_entry) => { + navigation::Action::ActivateOption(bucket_navigation_entry) + | navigation::Action::SelectOption(bucket_navigation_entry) => { self.update_greeting(&bucket_navigation_entry.to_string()); Action::None } navigation::Action::None => Action::None, }, - Message::ExpandGroup(group, buckets) => { - match self.navigation.insert_after_first( - |bucket_navigation_entry| { - bucket_navigation_entry.is_group_and(|bucket_group_name| { - !bucket_group_name.is_open && bucket_group_name.group.eq(group.as_str()) - }) - }, - &buckets - .iter() - .map(BucketNavigationEntry::from_bucket) - .collect(), - ) { - InsertOptionResult::InsertedOptions => { - self.navigation.replace_first( - |bucket_navigation_entry| { - bucket_navigation_entry.is_group_and(|g| g.group.eq(group.as_str())) - }, - &vec![BucketNavigationEntry::from_group_open(&group)], - ); - Action::None - } - InsertOptionResult::NoSuchOption => Action::None, - } - } + Message::ExpandGroup(group, buckets) => self.expand_group(group, buckets), - Message::CollapseGroup(group) => { - self.navigation - .remove_options_where(|bucket_navigation_entry| { - bucket_navigation_entry.is_bucket_and(|bucket| bucket.group.eq(&group)) - }); - self.navigation.replace_first( - |bucket_navigation_entry| { - bucket_navigation_entry.is_group_and(|g| g.group.eq(&group)) - }, - &vec![BucketNavigationEntry::from_group_closed(&group)], - ); - Action::None - } + Message::CollapseGroup(group) => self.collapse_group(group), } } } |
