From 26b327d86ac94d3affbf192250098dc47cc08b0a Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sat, 25 Jul 2020 20:41:26 +0300 Subject: [PATCH] mail/listing*: clear selection after perform_action() --- src/components/mail/listing.rs | 9 ++ src/components/mail/listing/compact.rs | 153 ++++++++++--------- src/components/mail/listing/conversations.rs | 4 + src/components/mail/listing/offline.rs | 6 + src/components/mail/listing/plain.rs | 6 + src/components/mail/listing/thread.rs | 6 + 6 files changed, 111 insertions(+), 73 deletions(-) diff --git a/src/components/mail/listing.rs b/src/components/mail/listing.rs index 799b11d4..eaf55fcc 100644 --- a/src/components/mail/listing.rs +++ b/src/components/mail/listing.rs @@ -341,6 +341,7 @@ pub trait MailListingTrait: ListingTrait { } fn row_updates(&mut self) -> &mut SmallVec<[ThreadHash; 8]>; + fn selection(&mut self) -> &mut HashMap; fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]>; fn redraw_threads_list( &mut self, @@ -743,6 +744,14 @@ impl Component for Listing { | Action::Listing(a @ ListingAction::Tag(_)) => { let focused = self.component.get_focused_items(context); self.component.perform_action(context, focused, a); + let mut row_updates: SmallVec<[ThreadHash; 8]> = SmallVec::new(); + for (k, v) in self.component.selection().iter_mut() { + if *v { + *v = false; + row_updates.push(*k); + } + } + self.component.row_updates().extend(row_updates.drain(..)); self.component.set_dirty(true); return true; } diff --git a/src/components/mail/listing/compact.rs b/src/components/mail/listing/compact.rs index 3635e76b..04d0d6d1 100644 --- a/src/components/mail/listing/compact.rs +++ b/src/components/mail/listing/compact.rs @@ -44,71 +44,78 @@ macro_rules! address_list { } macro_rules! row_attr { - ($color_cache:expr, $even: expr, $unseen:expr, $highlighted:expr, $selected:expr) => {{ - let fg = if $unseen { - if $even { - $color_cache.even_unseen.fg + ($color_cache:expr, $even: expr, $unseen:expr, $highlighted:expr, $selected:expr $(,)*) => {{ + ThemeAttribute { + fg: if $highlighted { + if $even { + $color_cache.even_highlighted.fg + } else { + $color_cache.odd_highlighted.fg + } + } else if $selected { + if $even { + $color_cache.even_selected.fg + } else { + $color_cache.odd_selected.fg + } + } else if $unseen { + if $even { + $color_cache.even_unseen.fg + } else { + $color_cache.odd_unseen.fg + } + } else if $even { + $color_cache.even.fg } else { - $color_cache.odd_unseen.fg - } - } else if $highlighted { - if $even { - $color_cache.even_highlighted.fg + $color_cache.odd.fg + }, + bg: if $highlighted { + if $even { + $color_cache.even_highlighted.bg + } else { + $color_cache.odd_highlighted.bg + } + } else if $selected { + if $even { + $color_cache.even_selected.bg + } else { + $color_cache.odd_selected.bg + } + } else if $unseen { + if $even { + $color_cache.even_unseen.bg + } else { + $color_cache.odd_unseen.bg + } + } else if $even { + $color_cache.even.bg } else { - $color_cache.odd_highlighted.fg - } - } else if $even { - $color_cache.even.fg - } else { - $color_cache.odd.fg - }; - let bg = if $highlighted { - if $even { - $color_cache.even_highlighted.bg + $color_cache.odd.bg + }, + attrs: if $highlighted { + if $even { + $color_cache.even_highlighted.attrs + } else { + $color_cache.odd_highlighted.attrs + } + } else if $selected { + if $even { + $color_cache.even_selected.attrs + } else { + $color_cache.odd_selected.attrs + } + } else if $unseen { + if $even { + $color_cache.even_unseen.attrs + } else { + $color_cache.odd_unseen.attrs + } + } else if $even { + $color_cache.even.attrs } else { - $color_cache.odd_highlighted.bg - } - } else if $selected { - if $even { - $color_cache.even_selected.bg - } else { - $color_cache.odd_selected.bg - } - } else if $unseen { - if $even { - $color_cache.even_unseen.bg - } else { - $color_cache.odd_unseen.bg - } - } else if $even { - $color_cache.even.bg - } else { - $color_cache.odd.bg - }; - let attrs = if $highlighted { - if $even { - $color_cache.even_highlighted.attrs - } else { - $color_cache.odd_highlighted.attrs - } - } else if $selected { - if $even { - $color_cache.even_selected.attrs - } else { - $color_cache.odd_selected.attrs - } - } else if $unseen { - if $even { - $color_cache.even_unseen.attrs - } else { - $color_cache.odd_unseen.attrs - } - } else if $even { - $color_cache.even.attrs - } else { - $color_cache.odd.attrs - }; - ThemeAttribute { fg, bg, attrs } + $color_cache.odd.attrs + }, + } }}; } @@ -161,6 +168,10 @@ impl MailListingTrait for CompactListing { &mut self.row_updates } + fn selection(&mut self) -> &mut HashMap { + &mut self.selection + } + fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]> { let is_selection_empty = self.selection.values().cloned().any(std::convert::identity); let i = [self.get_thread_under_cursor(self.cursor_pos.2)]; @@ -981,17 +992,13 @@ impl CompactListing { return; } let idx = self.order[&thread_hash]; - let row_attr = if thread.unseen() > 0 { - if idx % 2 == 0 { - self.color_cache.even_unseen - } else { - self.color_cache.odd_unseen - } - } else if idx % 2 == 0 { - self.color_cache.even - } else { - self.color_cache.odd - }; + let row_attr = row_attr!( + self.color_cache, + idx % 2 == 0, + thread.unseen() > 0, + false, + false, + ); let envelope: EnvelopeRef = account.collection.get_env(env_hash); let strings = self.make_entry_string(&envelope, context, &threads, thread_hash); drop(envelope); diff --git a/src/components/mail/listing/conversations.rs b/src/components/mail/listing/conversations.rs index b4988673..d83c0de0 100644 --- a/src/components/mail/listing/conversations.rs +++ b/src/components/mail/listing/conversations.rs @@ -131,6 +131,10 @@ impl MailListingTrait for ConversationsListing { &mut self.row_updates } + fn selection(&mut self) -> &mut HashMap { + &mut self.selection + } + fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]> { let is_selection_empty = self.selection.values().cloned().any(std::convert::identity); let i = [self.get_thread_under_cursor(self.cursor_pos.2)]; diff --git a/src/components/mail/listing/offline.rs b/src/components/mail/listing/offline.rs index ed3eb680..1f506eeb 100644 --- a/src/components/mail/listing/offline.rs +++ b/src/components/mail/listing/offline.rs @@ -26,6 +26,7 @@ use crate::components::utilities::PageMovement; pub struct OfflineListing { cursor_pos: (usize, MailboxHash), _row_updates: SmallVec<[ThreadHash; 8]>, + _selection: HashMap, dirty: bool, id: ComponentId, } @@ -35,6 +36,10 @@ impl MailListingTrait for OfflineListing { &mut self._row_updates } + fn selection(&mut self) -> &mut HashMap { + &mut self._selection + } + fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]> { return SmallVec::new(); } @@ -88,6 +93,7 @@ impl OfflineListing { OfflineListing { cursor_pos, _row_updates: SmallVec::new(), + _selection: HashMap::default(), dirty: true, id: ComponentId::new_v4(), } diff --git a/src/components/mail/listing/plain.rs b/src/components/mail/listing/plain.rs index 33a1c097..1eef4fda 100644 --- a/src/components/mail/listing/plain.rs +++ b/src/components/mail/listing/plain.rs @@ -66,6 +66,7 @@ pub struct PlainListing { filtered_selection: Vec, filtered_order: HashMap, selection: HashMap, + _selection: HashMap, thread_node_hashes: HashMap, local_collection: Vec, /// If we must redraw on next redraw event @@ -88,6 +89,10 @@ impl MailListingTrait for PlainListing { &mut self._row_updates } + fn selection(&mut self) -> &mut HashMap { + &mut self._selection + } + fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]> { SmallVec::new() /* @@ -707,6 +712,7 @@ impl PlainListing { filtered_selection: Vec::new(), filtered_order: HashMap::default(), selection: HashMap::default(), + _selection: HashMap::default(), row_updates: SmallVec::new(), _row_updates: SmallVec::new(), data_columns: DataColumns::default(), diff --git a/src/components/mail/listing/thread.rs b/src/components/mail/listing/thread.rs index 0be1ba7c..9475649c 100644 --- a/src/components/mail/listing/thread.rs +++ b/src/components/mail/listing/thread.rs @@ -41,6 +41,7 @@ pub struct ThreadListing { rows_drawn: SegmentTree, rows: Vec<((usize, bool, bool, EnvelopeHash), EntryStrings)>, row_updates: SmallVec<[ThreadHash; 8]>, + selection: HashMap, order: HashMap, /// If we must redraw on next redraw event dirty: bool, @@ -57,6 +58,10 @@ impl MailListingTrait for ThreadListing { &mut self.row_updates } + fn selection(&mut self) -> &mut HashMap { + &mut self.selection + } + fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]> { SmallVec::new() } @@ -673,6 +678,7 @@ impl ThreadListing { rows_drawn: SegmentTree::default(), rows: vec![], row_updates: SmallVec::new(), + selection: HashMap::default(), order: HashMap::default(), dirty: true, unfocused: false,