diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2020-02-06 01:51:20 +0200 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2020-02-08 23:54:15 +0200 |
commit | 144eb62b766476f42e8f391b262eaa0732c69abd (patch) | |
tree | 288cf168de795cbd40820c9e5338bfeb82cefe6b /src/components/mail/listing/conversations.rs | |
parent | f5e694cf5a688036c814c2ebd60a21779ca988c1 (diff) |
ui: force refresh_mailbox etc on Mailbox{Delete,Create}
Diffstat (limited to 'src/components/mail/listing/conversations.rs')
-rw-r--r-- | src/components/mail/listing/conversations.rs | 205 |
1 files changed, 104 insertions, 101 deletions
diff --git a/src/components/mail/listing/conversations.rs b/src/components/mail/listing/conversations.rs index f6588c75..3a5283ec 100644 --- a/src/components/mail/listing/conversations.rs +++ b/src/components/mail/listing/conversations.rs @@ -79,6 +79,100 @@ impl MailListingTrait for ConversationsListing { .cloned(); SmallVec::from_iter(iter.into_iter()) } + + /// Fill the `self.data_columns` `CellBuffers` with the contents of the account folder the user has + /// chosen. + fn refresh_mailbox(&mut self, context: &mut Context, force: bool) { + self.dirty = true; + let old_folder_hash = self.folder_hash; + let old_cursor_pos = self.cursor_pos; + if !(self.cursor_pos.0 == self.new_cursor_pos.0 + && self.cursor_pos.1 == self.new_cursor_pos.1) + { + self.cursor_pos.2 = 0; + self.new_cursor_pos.2 = 0; + } + self.cursor_pos.1 = self.new_cursor_pos.1; + self.cursor_pos.0 = self.new_cursor_pos.0; + self.folder_hash = if let Some(h) = context.accounts[self.cursor_pos.0] + .folders_order + .get(self.cursor_pos.1) + { + *h + } else { + self.cursor_pos.1 = old_cursor_pos.1; + self.dirty = false; + return; + }; + + self.color_cache = ColorCache { + theme_default: crate::conf::value(context, "mail.listing.conversations"), + subject: crate::conf::value(context, "mail.listing.conversations.subject"), + from: crate::conf::value(context, "mail.listing.conversations.from"), + date: crate::conf::value(context, "mail.listing.conversations.date"), + padding: crate::conf::value(context, "mail.listing.conversations.padding"), + unseen: crate::conf::value(context, "mail.listing.conversations.unseen"), + unseen_padding: crate::conf::value( + context, + "mail.listing.conversations.unseen_padding", + ), + highlighted: crate::conf::value(context, "mail.listing.conversations.highlighted"), + attachment_flag: crate::conf::value(context, "mail.listing.attachment_flag"), + thread_snooze_flag: crate::conf::value(context, "mail.listing.thread_snooze_flag"), + ..self.color_cache + }; + + if std::env::var("NO_COLOR").is_ok() + && (context.settings.terminal.use_color.is_false() + || context.settings.terminal.use_color.is_internal()) + { + self.color_cache.highlighted.attrs |= Attr::Reverse; + } + // Get mailbox as a reference. + // + match context.accounts[self.cursor_pos.0].status(self.folder_hash) { + Ok(()) => {} + Err(_) => { + let message: String = + context.accounts[self.cursor_pos.0][self.folder_hash].to_string(); + self.content = + CellBuffer::new_with_context(message.len(), 1, Cell::with_char(' '), context); + self.length = 0; + write_string_to_grid( + message.as_str(), + &mut self.content, + Color::Default, + Color::Default, + Attr::Default, + ((0, 0), (message.len() - 1, 0)), + None, + ); + return; + } + } + + let threads = &context.accounts[self.cursor_pos.0].collection.threads[&self.folder_hash]; + self.all_threads.clear(); + let mut roots = threads.roots(); + threads.group_inner_sort_by( + &mut roots, + self.sort, + &context.accounts[self.cursor_pos.0].collection.envelopes, + ); + + self.redraw_list( + context, + Box::new(roots.into_iter()) as Box<dyn Iterator<Item = ThreadHash>>, + ); + + if !force && old_cursor_pos == self.new_cursor_pos && old_folder_hash == self.folder_hash { + self.view.update(context); + } else if self.unfocused { + let thread_group = self.get_thread_under_cursor(self.cursor_pos.2); + + self.view = ThreadView::new(self.new_cursor_pos, thread_group, None, context); + } + } } impl ListingTrait for ConversationsListing { @@ -88,7 +182,9 @@ impl ListingTrait for ConversationsListing { fn set_coordinates(&mut self, coordinates: (usize, usize)) { self.new_cursor_pos = (coordinates.0, coordinates.1, 0); + self.new_cursor_pos = (coordinates.0, coordinates.1, 0); self.unfocused = false; + self.view = ThreadView::default(); self.filtered_selection.clear(); self.filtered_order.clear(); self.filter_term.clear(); @@ -183,7 +279,7 @@ impl ListingTrait for ConversationsListing { fn draw_list(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { if self.cursor_pos.1 != self.new_cursor_pos.1 || self.cursor_pos.0 != self.new_cursor_pos.0 { - self.refresh_mailbox(context); + self.refresh_mailbox(context, false); } let upper_left = upper_left!(area); let bottom_right = bottom_right!(area); @@ -550,99 +646,6 @@ impl ConversationsListing { } } - /// Fill the `self.data_columns` `CellBuffers` with the contents of the account folder the user has - /// chosen. - fn refresh_mailbox(&mut self, context: &mut Context) { - self.dirty = true; - let old_cursor_pos = self.cursor_pos; - if !(self.cursor_pos.0 == self.new_cursor_pos.0 - && self.cursor_pos.1 == self.new_cursor_pos.1) - { - self.cursor_pos.2 = 0; - self.new_cursor_pos.2 = 0; - } - self.cursor_pos.1 = self.new_cursor_pos.1; - self.cursor_pos.0 = self.new_cursor_pos.0; - self.folder_hash = if let Some(h) = context.accounts[self.cursor_pos.0] - .folders_order - .get(self.cursor_pos.1) - { - *h - } else { - self.cursor_pos.1 = old_cursor_pos.1; - self.dirty = false; - return; - }; - - self.color_cache = ColorCache { - theme_default: crate::conf::value(context, "mail.listing.conversations"), - subject: crate::conf::value(context, "mail.listing.conversations.subject"), - from: crate::conf::value(context, "mail.listing.conversations.from"), - date: crate::conf::value(context, "mail.listing.conversations.date"), - padding: crate::conf::value(context, "mail.listing.conversations.padding"), - unseen: crate::conf::value(context, "mail.listing.conversations.unseen"), - unseen_padding: crate::conf::value( - context, - "mail.listing.conversations.unseen_padding", - ), - highlighted: crate::conf::value(context, "mail.listing.conversations.highlighted"), - attachment_flag: crate::conf::value(context, "mail.listing.attachment_flag"), - thread_snooze_flag: crate::conf::value(context, "mail.listing.thread_snooze_flag"), - ..self.color_cache - }; - - if std::env::var("NO_COLOR").is_ok() - && (context.settings.terminal.use_color.is_false() - || context.settings.terminal.use_color.is_internal()) - { - self.color_cache.highlighted.attrs |= Attr::Reverse; - } - // Get mailbox as a reference. - // - match context.accounts[self.cursor_pos.0].status(self.folder_hash) { - Ok(()) => {} - Err(_) => { - let message: String = - context.accounts[self.cursor_pos.0][self.folder_hash].to_string(); - self.content = - CellBuffer::new_with_context(message.len(), 1, Cell::with_char(' '), context); - self.length = 0; - write_string_to_grid( - message.as_str(), - &mut self.content, - Color::Default, - Color::Default, - Attr::Default, - ((0, 0), (message.len() - 1, 0)), - None, - ); - return; - } - } - - let threads = &context.accounts[self.cursor_pos.0].collection.threads[&self.folder_hash]; - self.all_threads.clear(); - let mut roots = threads.roots(); - threads.group_inner_sort_by( - &mut roots, - self.sort, - &context.accounts[self.cursor_pos.0].collection.envelopes, - ); - - self.redraw_list( - context, - Box::new(roots.into_iter()) as Box<dyn Iterator<Item = ThreadHash>>, - ); - - if old_cursor_pos == self.new_cursor_pos { - self.view.update(context); - } else if self.unfocused { - let thread_group = self.get_thread_under_cursor(self.cursor_pos.2); - - self.view = ThreadView::new(self.new_cursor_pos, thread_group, None, context); - } - } - fn redraw_list(&mut self, context: &Context, items: Box<dyn Iterator<Item = ThreadHash>>) { let account = &context.accounts[self.cursor_pos.0]; let mailbox = &account[self.cursor_pos.1].unwrap(); @@ -1206,7 +1209,7 @@ impl Component for ConversationsListing { // let threads = &account.collection.threads[&self.folder_hash]; // threads.vec_inner_sort_by(&mut self.filtered_selection, self.sort, &account.collection); //} else { - // self.refresh_mailbox(context); + // self.refresh_mailbox(context, false); //} return true; } @@ -1225,7 +1228,7 @@ impl Component for ConversationsListing { ); self.dirty = true; } else { - self.refresh_mailbox(context); + self.refresh_mailbox(context, false); } */ return true; @@ -1242,7 +1245,7 @@ impl Component for ConversationsListing { threads.thread_ref_mut(thread).set_snoozed(!is_snoozed); }); self.row_updates.push(thread); - self.refresh_mailbox(context); + self.refresh_mailbox(context, false); return true; } _ => {} @@ -1254,11 +1257,11 @@ impl Component for ConversationsListing { UIEvent::MailboxUpdate((ref idxa, ref idxf)) if (*idxa, *idxf) == (self.new_cursor_pos.0, self.folder_hash) => { - self.refresh_mailbox(context); + self.refresh_mailbox(context, false); self.set_dirty(true); } UIEvent::StartupCheck(ref f) if *f == self.folder_hash => { - self.refresh_mailbox(context); + self.refresh_mailbox(context, false); self.set_dirty(true); } UIEvent::ChangeMode(UIMode::Normal) => { @@ -1277,7 +1280,7 @@ impl Component for ConversationsListing { return true; } self.set_coordinates((self.new_cursor_pos.0, *idx)); - self.refresh_mailbox(context); + self.refresh_mailbox(context, false); return true; } @@ -1292,7 +1295,7 @@ impl Component for ConversationsListing { if !self.unfocused && !&self.filter_term.is_empty() => { self.set_coordinates((self.new_cursor_pos.0, self.new_cursor_pos.1)); - self.refresh_mailbox(context); + self.refresh_mailbox(context, false); self.force_draw = false; self.set_dirty(true); return true; |