mirror of
https://git.meli.delivery/meli/meli
synced 2024-11-17 03:26:20 +00:00
ui: do not recreate ThreadView on envelope update event
This commit is contained in:
parent
ba6c259820
commit
d7a4bd24c3
@ -42,7 +42,7 @@ pub struct CompactListing {
|
||||
dirty: bool,
|
||||
/// If `self.view` exists or not.
|
||||
unfocused: bool,
|
||||
view: Option<ThreadView>,
|
||||
view: ThreadView,
|
||||
|
||||
movement: Option<PageMovement>,
|
||||
}
|
||||
@ -101,7 +101,7 @@ impl CompactListing {
|
||||
content,
|
||||
dirty: true,
|
||||
unfocused: false,
|
||||
view: None,
|
||||
view: ThreadView::default(),
|
||||
|
||||
movement: None,
|
||||
}
|
||||
@ -110,6 +110,12 @@ impl CompactListing {
|
||||
/// chosen.
|
||||
fn refresh_mailbox(&mut self, context: &mut Context) {
|
||||
self.dirty = true;
|
||||
if self.cursor_pos == self.new_cursor_pos {
|
||||
self.view.update(context);
|
||||
} else {
|
||||
self.view = ThreadView::new(self.cursor_pos, None, context);
|
||||
}
|
||||
|
||||
if !(self.cursor_pos.0 == self.new_cursor_pos.0
|
||||
&& self.cursor_pos.1 == self.new_cursor_pos.1)
|
||||
{
|
||||
@ -384,23 +390,13 @@ impl Component for CompactListing {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Render the mail body in a pager */
|
||||
if !self.dirty {
|
||||
if let Some(v) = self.view.as_mut() {
|
||||
v.draw(grid, area, context);
|
||||
}
|
||||
return;
|
||||
}
|
||||
self.view = Some(ThreadView::new(self.cursor_pos, None, context));
|
||||
self.view.as_mut().unwrap().draw(grid, area, context);
|
||||
self.view.draw(grid, area, context);
|
||||
}
|
||||
self.dirty = false;
|
||||
}
|
||||
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
|
||||
if let Some(ref mut v) = self.view {
|
||||
if v.process_event(event, context) {
|
||||
return true;
|
||||
}
|
||||
if self.unfocused && self.view.process_event(event, context) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let shortcuts = self.get_shortcuts(context);
|
||||
@ -420,6 +416,7 @@ impl Component for CompactListing {
|
||||
return true;
|
||||
}
|
||||
UIEventType::Input(ref k) if !self.unfocused && *k == shortcuts["open_thread"] => {
|
||||
self.view = ThreadView::new(self.cursor_pos, None, context);
|
||||
self.unfocused = true;
|
||||
self.dirty = true;
|
||||
return true;
|
||||
@ -435,7 +432,6 @@ impl Component for CompactListing {
|
||||
UIEventType::Input(ref k) if self.unfocused && *k == shortcuts["exit_thread"] => {
|
||||
self.unfocused = false;
|
||||
self.dirty = true;
|
||||
self.view = None;
|
||||
return true;
|
||||
}
|
||||
UIEventType::Input(Key::Char(k @ 'J')) | UIEventType::Input(Key::Char(k @ 'K')) => {
|
||||
@ -485,7 +481,6 @@ impl Component for CompactListing {
|
||||
return true;
|
||||
}
|
||||
UIEventType::RefreshMailbox(_) => {
|
||||
self.view = None;
|
||||
self.dirty = true;
|
||||
}
|
||||
UIEventType::MailboxUpdate((ref idxa, ref idxf)) if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 => {
|
||||
@ -538,21 +533,21 @@ impl Component for CompactListing {
|
||||
false
|
||||
}
|
||||
fn is_dirty(&self) -> bool {
|
||||
self.dirty || self.view.as_ref().map(|p| p.is_dirty()).unwrap_or(false)
|
||||
self.dirty || if self.unfocused { self.view.is_dirty() } else { false }
|
||||
}
|
||||
fn set_dirty(&mut self) {
|
||||
if let Some(p) = self.view.as_mut() {
|
||||
p.set_dirty();
|
||||
if self.unfocused {
|
||||
self.view.set_dirty();
|
||||
}
|
||||
self.dirty = true;
|
||||
}
|
||||
|
||||
fn get_shortcuts(&self, context: &Context) -> ShortcutMap {
|
||||
let mut map = self
|
||||
.view
|
||||
.as_ref()
|
||||
.map(|p| p.get_shortcuts(context))
|
||||
.unwrap_or_default();
|
||||
let mut map = if self.unfocused {
|
||||
self.view.get_shortcuts(context)
|
||||
} else {
|
||||
ShortcutMap::default()
|
||||
};
|
||||
|
||||
let config_map = context.settings.shortcuts.compact_listing.key_values();
|
||||
map.insert(
|
||||
|
@ -75,6 +75,40 @@ impl ThreadView {
|
||||
view.new_cursor_pos = view.new_expanded_pos;
|
||||
view
|
||||
}
|
||||
pub fn update(&mut self, context: &Context) {
|
||||
if self.entries.is_empty() {
|
||||
return;
|
||||
}
|
||||
let old_focused_entry = if self.entries.len() > self.cursor_pos {
|
||||
Some(self.entries.remove(self.cursor_pos))
|
||||
} else { None };
|
||||
|
||||
let old_expanded_entry = if self.entries.len() > self.expanded_pos {
|
||||
Some(self.entries.remove(self.expanded_pos))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// FIXME 2018
|
||||
let expanded_pos = self.expanded_pos;
|
||||
self.initiate(Some(expanded_pos), context);
|
||||
if let Some(old_focused_entry) = old_focused_entry {
|
||||
if let Some(new_entry_idx) = self.entries.iter().position(
|
||||
|e| e.msg_idx == old_focused_entry.msg_idx ||
|
||||
(e.index.1 == old_focused_entry.index.1 && e.index.2 == old_focused_entry.index.2)) {
|
||||
self.cursor_pos = new_entry_idx;
|
||||
}
|
||||
}
|
||||
if let Some(old_expanded_entry) = old_expanded_entry {
|
||||
if let Some(new_entry_idx) = self.entries.iter().position(
|
||||
|e| e.msg_idx == old_expanded_entry.msg_idx ||
|
||||
(e.index.1 == old_expanded_entry.index.1 && e.index.2 == old_expanded_entry.index.2)) {
|
||||
self.expanded_pos = new_entry_idx;
|
||||
}
|
||||
}
|
||||
self.set_dirty();
|
||||
|
||||
}
|
||||
fn initiate(&mut self, expanded_idx: Option<usize>, context: &Context) {
|
||||
/* stack to push thread messages in order in order to pop and print them later */
|
||||
let mailbox = &context.accounts[self.coordinates.0][self.coordinates.1]
|
||||
|
Loading…
Reference in New Issue
Block a user