mail/listing*: clear selection after perform_action()

memfd
Manos Pitsidianakis 2020-07-25 20:41:26 +03:00
parent b5530860d2
commit 26b327d86a
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
6 changed files with 111 additions and 73 deletions

View File

@ -341,6 +341,7 @@ pub trait MailListingTrait: ListingTrait {
} }
fn row_updates(&mut self) -> &mut SmallVec<[ThreadHash; 8]>; fn row_updates(&mut self) -> &mut SmallVec<[ThreadHash; 8]>;
fn selection(&mut self) -> &mut HashMap<ThreadHash, bool>;
fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]>; fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]>;
fn redraw_threads_list( fn redraw_threads_list(
&mut self, &mut self,
@ -743,6 +744,14 @@ impl Component for Listing {
| Action::Listing(a @ ListingAction::Tag(_)) => { | Action::Listing(a @ ListingAction::Tag(_)) => {
let focused = self.component.get_focused_items(context); let focused = self.component.get_focused_items(context);
self.component.perform_action(context, focused, a); 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); self.component.set_dirty(true);
return true; return true;
} }

View File

@ -44,71 +44,78 @@ macro_rules! address_list {
} }
macro_rules! row_attr { macro_rules! row_attr {
($color_cache:expr, $even: expr, $unseen:expr, $highlighted:expr, $selected:expr) => {{ ($color_cache:expr, $even: expr, $unseen:expr, $highlighted:expr, $selected:expr $(,)*) => {{
let fg = if $unseen { ThemeAttribute {
if $even { fg: if $highlighted {
$color_cache.even_unseen.fg 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 { } else {
$color_cache.odd_unseen.fg $color_cache.odd.fg
} },
} else if $highlighted { bg: if $highlighted {
if $even { if $even {
$color_cache.even_highlighted.fg $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 { } else {
$color_cache.odd_highlighted.fg $color_cache.odd.bg
} },
} else if $even { attrs: if $highlighted {
$color_cache.even.fg if $even {
} else { $color_cache.even_highlighted.attrs
$color_cache.odd.fg } else {
}; $color_cache.odd_highlighted.attrs
let bg = if $highlighted { }
if $even { } else if $selected {
$color_cache.even_highlighted.bg 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 { } else {
$color_cache.odd_highlighted.bg $color_cache.odd.attrs
} },
} 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 }
}}; }};
} }
@ -161,6 +168,10 @@ impl MailListingTrait for CompactListing {
&mut self.row_updates &mut self.row_updates
} }
fn selection(&mut self) -> &mut HashMap<ThreadHash, bool> {
&mut self.selection
}
fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]> { fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]> {
let is_selection_empty = self.selection.values().cloned().any(std::convert::identity); let is_selection_empty = self.selection.values().cloned().any(std::convert::identity);
let i = [self.get_thread_under_cursor(self.cursor_pos.2)]; let i = [self.get_thread_under_cursor(self.cursor_pos.2)];
@ -981,17 +992,13 @@ impl CompactListing {
return; return;
} }
let idx = self.order[&thread_hash]; let idx = self.order[&thread_hash];
let row_attr = if thread.unseen() > 0 { let row_attr = row_attr!(
if idx % 2 == 0 { self.color_cache,
self.color_cache.even_unseen idx % 2 == 0,
} else { thread.unseen() > 0,
self.color_cache.odd_unseen false,
} false,
} else if idx % 2 == 0 { );
self.color_cache.even
} else {
self.color_cache.odd
};
let envelope: EnvelopeRef = account.collection.get_env(env_hash); let envelope: EnvelopeRef = account.collection.get_env(env_hash);
let strings = self.make_entry_string(&envelope, context, &threads, thread_hash); let strings = self.make_entry_string(&envelope, context, &threads, thread_hash);
drop(envelope); drop(envelope);

View File

@ -131,6 +131,10 @@ impl MailListingTrait for ConversationsListing {
&mut self.row_updates &mut self.row_updates
} }
fn selection(&mut self) -> &mut HashMap<ThreadHash, bool> {
&mut self.selection
}
fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]> { fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]> {
let is_selection_empty = self.selection.values().cloned().any(std::convert::identity); let is_selection_empty = self.selection.values().cloned().any(std::convert::identity);
let i = [self.get_thread_under_cursor(self.cursor_pos.2)]; let i = [self.get_thread_under_cursor(self.cursor_pos.2)];

View File

@ -26,6 +26,7 @@ use crate::components::utilities::PageMovement;
pub struct OfflineListing { pub struct OfflineListing {
cursor_pos: (usize, MailboxHash), cursor_pos: (usize, MailboxHash),
_row_updates: SmallVec<[ThreadHash; 8]>, _row_updates: SmallVec<[ThreadHash; 8]>,
_selection: HashMap<ThreadHash, bool>,
dirty: bool, dirty: bool,
id: ComponentId, id: ComponentId,
} }
@ -35,6 +36,10 @@ impl MailListingTrait for OfflineListing {
&mut self._row_updates &mut self._row_updates
} }
fn selection(&mut self) -> &mut HashMap<ThreadHash, bool> {
&mut self._selection
}
fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]> { fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]> {
return SmallVec::new(); return SmallVec::new();
} }
@ -88,6 +93,7 @@ impl OfflineListing {
OfflineListing { OfflineListing {
cursor_pos, cursor_pos,
_row_updates: SmallVec::new(), _row_updates: SmallVec::new(),
_selection: HashMap::default(),
dirty: true, dirty: true,
id: ComponentId::new_v4(), id: ComponentId::new_v4(),
} }

View File

@ -66,6 +66,7 @@ pub struct PlainListing {
filtered_selection: Vec<EnvelopeHash>, filtered_selection: Vec<EnvelopeHash>,
filtered_order: HashMap<EnvelopeHash, usize>, filtered_order: HashMap<EnvelopeHash, usize>,
selection: HashMap<EnvelopeHash, bool>, selection: HashMap<EnvelopeHash, bool>,
_selection: HashMap<ThreadHash, bool>,
thread_node_hashes: HashMap<EnvelopeHash, ThreadNodeHash>, thread_node_hashes: HashMap<EnvelopeHash, ThreadNodeHash>,
local_collection: Vec<EnvelopeHash>, local_collection: Vec<EnvelopeHash>,
/// If we must redraw on next redraw event /// If we must redraw on next redraw event
@ -88,6 +89,10 @@ impl MailListingTrait for PlainListing {
&mut self._row_updates &mut self._row_updates
} }
fn selection(&mut self) -> &mut HashMap<ThreadHash, bool> {
&mut self._selection
}
fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]> { fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]> {
SmallVec::new() SmallVec::new()
/* /*
@ -707,6 +712,7 @@ impl PlainListing {
filtered_selection: Vec::new(), filtered_selection: Vec::new(),
filtered_order: HashMap::default(), filtered_order: HashMap::default(),
selection: HashMap::default(), selection: HashMap::default(),
_selection: HashMap::default(),
row_updates: SmallVec::new(), row_updates: SmallVec::new(),
_row_updates: SmallVec::new(), _row_updates: SmallVec::new(),
data_columns: DataColumns::default(), data_columns: DataColumns::default(),

View File

@ -41,6 +41,7 @@ pub struct ThreadListing {
rows_drawn: SegmentTree, rows_drawn: SegmentTree,
rows: Vec<((usize, bool, bool, EnvelopeHash), EntryStrings)>, rows: Vec<((usize, bool, bool, EnvelopeHash), EntryStrings)>,
row_updates: SmallVec<[ThreadHash; 8]>, row_updates: SmallVec<[ThreadHash; 8]>,
selection: HashMap<ThreadHash, bool>,
order: HashMap<EnvelopeHash, usize>, order: HashMap<EnvelopeHash, usize>,
/// If we must redraw on next redraw event /// If we must redraw on next redraw event
dirty: bool, dirty: bool,
@ -57,6 +58,10 @@ impl MailListingTrait for ThreadListing {
&mut self.row_updates &mut self.row_updates
} }
fn selection(&mut self) -> &mut HashMap<ThreadHash, bool> {
&mut self.selection
}
fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]> { fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]> {
SmallVec::new() SmallVec::new()
} }
@ -673,6 +678,7 @@ impl ThreadListing {
rows_drawn: SegmentTree::default(), rows_drawn: SegmentTree::default(),
rows: vec![], rows: vec![],
row_updates: SmallVec::new(), row_updates: SmallVec::new(),
selection: HashMap::default(),
order: HashMap::default(), order: HashMap::default(),
dirty: true, dirty: true,
unfocused: false, unfocused: false,