ui: make EnvelopeRename event not folder specific

And pass EnvelopeRename events to subviews
embed
Manos Pitsidianakis 2019-06-06 00:27:40 +03:00
parent 85d1aaaa69
commit b6c0236d24
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
5 changed files with 36 additions and 30 deletions

View File

@ -646,10 +646,7 @@ impl Component for MailboxView {
self.refresh_mailbox(context); self.refresh_mailbox(context);
self.set_dirty(); self.set_dirty();
} }
UIEvent::EnvelopeRename(ref folder_hash, ref old_hash, ref new_hash) UIEvent::EnvelopeRename(ref old_hash, ref new_hash) => {
if *folder_hash
== context.accounts[self.cursor_pos.0].folders_order[self.new_cursor_pos.1] =>
{
if let Some(row) = self.order.remove(old_hash) { if let Some(row) = self.order.remove(old_hash) {
self.order.insert(*new_hash, row); self.order.insert(*new_hash, row);
self.highlight_line(None, ((0, row), (MAX_COLS - 1, row)), row, context); self.highlight_line(None, ((0, row), (MAX_COLS - 1, row)), row, context);
@ -658,6 +655,8 @@ impl Component for MailboxView {
} else { } else {
/* Listing has was updated in time before the event */ /* Listing has was updated in time before the event */
} }
self.view
.process_event(&mut UIEvent::EnvelopeRename(*old_hash, *new_hash), context);
} }
UIEvent::ChangeMode(UIMode::Normal) => { UIEvent::ChangeMode(UIMode::Normal) => {
self.dirty = true; self.dirty = true;
@ -872,7 +871,7 @@ impl Component for CompactListing {
| UIEvent::ComponentKill(_) | UIEvent::ComponentKill(_)
| UIEvent::StartupCheck(_) | UIEvent::StartupCheck(_)
| UIEvent::EnvelopeUpdate(_) | UIEvent::EnvelopeUpdate(_)
| UIEvent::EnvelopeRename(_, _, _) | UIEvent::EnvelopeRename(_, _)
| UIEvent::EnvelopeRemove(_) => { | UIEvent::EnvelopeRemove(_) => {
return self.views[self.cursor].process_event(event, context) return self.views[self.cursor].process_event(event, context)
} }

View File

@ -88,23 +88,6 @@ impl MailView {
subview: Option<Box<Component>>, subview: Option<Box<Component>>,
context: &mut Context, context: &mut Context,
) -> Self { ) -> Self {
let account = &mut context.accounts[coordinates.0];
let (hash, is_seen) = {
let envelope: &Envelope = &account.get_env(&coordinates.2);
(envelope.hash(), envelope.is_seen())
};
if !is_seen {
let folder_hash = {
let mailbox = &mut account[coordinates.1].as_mut().unwrap();
mailbox.folder.hash()
};
let op = {
let backend = &account.backend;
backend.operation(hash, folder_hash)
};
let envelope: &mut Envelope = &mut account.get_env_mut(&coordinates.2);
envelope.set_seen(op).unwrap();
}
MailView { MailView {
coordinates, coordinates,
pager, pager,
@ -304,6 +287,19 @@ impl Component for MailView {
* arrive */ * arrive */
return; return;
} }
let (hash, is_seen) = {
let envelope: &Envelope = &account.get_env(&self.coordinates.2);
(envelope.hash(), envelope.is_seen())
};
if !is_seen {
let folder_hash = {
let mailbox = &mut account[self.coordinates.1].as_mut().unwrap();
mailbox.folder.hash()
};
let op = account.operation(&hash);
let envelope: &mut Envelope = &mut account.get_env_mut(&self.coordinates.2);
envelope.set_seen(op).unwrap();
}
let envelope: &Envelope = &account.get_env(&self.coordinates.2); let envelope: &Envelope = &account.get_env(&self.coordinates.2);
if self.mode == ViewMode::Raw { if self.mode == ViewMode::Raw {
@ -746,7 +742,7 @@ impl Component for MailView {
} }
self.dirty = true; self.dirty = true;
} }
UIEvent::EnvelopeRename(_, old_hash, new_hash) if old_hash == self.coordinates.2 => { UIEvent::EnvelopeRename(old_hash, new_hash) => {
self.coordinates.2 = new_hash; self.coordinates.2 = new_hash;
} }
_ => { _ => {

View File

@ -291,8 +291,7 @@ impl ThreadView {
/* Box character drawing stuff */ /* Box character drawing stuff */
let mut x = 0; let mut x = 0;
for i in 0..e.index.0 { for i in 0..e.index.0 {
let color = let color = INDENTATION_COLORS[(i).wrapping_rem(INDENTATION_COLORS.len())];
INDENTATION_COLORS[(i).wrapping_rem(INDENTATION_COLORS.len())];
change_colors( change_colors(
&mut content, &mut content,
((x, 2 * y), (x + 3, 2 * y + 1)), ((x, 2 * y), (x + 3, 2 * y + 1)),
@ -408,6 +407,7 @@ impl ThreadView {
/// draw the list /// draw the list
fn draw_list(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { fn draw_list(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
/* Make space on the left for the scrollbar */
let mut upper_left = pos_inc(upper_left!(area), (1, 0)); let mut upper_left = pos_inc(upper_left!(area), (1, 0));
let bottom_right = bottom_right!(area); let bottom_right = bottom_right!(area);
let (width, height) = self.content.size(); let (width, height) = self.content.size();
@ -613,9 +613,11 @@ impl ThreadView {
let i = if let Some(i) = thread_node.message() { let i = if let Some(i) = thread_node.message() {
i i
} else { } else {
threads.thread_nodes()[&thread_node.children()[0]] let mut iter_ptr = thread_node.children()[0];
.message() while threads.thread_nodes()[&iter_ptr].message().is_none() {
.unwrap() iter_ptr = threads.thread_nodes()[&iter_ptr].children()[0];
}
threads.thread_nodes()[&iter_ptr].message().unwrap()
}; };
let envelope: &Envelope = account.get_env(&i); let envelope: &Envelope = account.get_env(&i);
@ -1013,6 +1015,15 @@ impl Component for ThreadView {
UIEvent::Resize => { UIEvent::Resize => {
self.set_dirty(); self.set_dirty();
} }
UIEvent::EnvelopeRename(ref old_hash, ref new_hash) => {
for e in self.entries.iter_mut() {
if e.msg_hash == *old_hash {
e.msg_hash = *new_hash;
}
}
self.mailview
.process_event(&mut UIEvent::EnvelopeRename(*old_hash, *new_hash), context);
}
_ => { _ => {
if self.mailview.process_event(event, context) { if self.mailview.process_event(event, context) {
return true; return true;

View File

@ -314,7 +314,7 @@ impl Account {
let mailbox = mailbox!(&folder_hash, self.folders); let mailbox = mailbox!(&folder_hash, self.folders);
mailbox.rename(old_hash, new_hash); mailbox.rename(old_hash, new_hash);
self.collection.rename(old_hash, new_hash, folder_hash); self.collection.rename(old_hash, new_hash, folder_hash);
return Some(EnvelopeRename(mailbox.folder.hash(), old_hash, new_hash)); return Some(EnvelopeRename(old_hash, new_hash));
} }
RefreshEventKind::Create(envelope) => { RefreshEventKind::Create(envelope) => {
let env_hash = envelope.hash(); let env_hash = envelope.hash();

View File

@ -87,7 +87,7 @@ pub enum UIEvent {
StartupCheck(FolderHash), StartupCheck(FolderHash),
RefreshEvent(Box<RefreshEvent>), RefreshEvent(Box<RefreshEvent>),
EnvelopeUpdate(EnvelopeHash), EnvelopeUpdate(EnvelopeHash),
EnvelopeRename(FolderHash, EnvelopeHash, EnvelopeHash), // folder_hash, old_hash, new_hash EnvelopeRename(EnvelopeHash, EnvelopeHash), // old_hash, new_hash
EnvelopeRemove(EnvelopeHash), EnvelopeRemove(EnvelopeHash),
} }