ui/listings: split events according to length
Some events are invalid when there are no messages shown in the listing. Instead of checking for self.length > 0 in each of these events, put them together in an if block.sql
parent
498f8e8e21
commit
f718510eeb
|
@ -940,6 +940,7 @@ impl Component for CompactListing {
|
||||||
}
|
}
|
||||||
|
|
||||||
let shortcuts = &self.get_shortcuts(context)[CompactListing::DESCRIPTION];
|
let shortcuts = &self.get_shortcuts(context)[CompactListing::DESCRIPTION];
|
||||||
|
if self.length > 0 {
|
||||||
match *event {
|
match *event {
|
||||||
UIEvent::Input(Key::Up) => {
|
UIEvent::Input(Key::Up) => {
|
||||||
if self.cursor_pos.2 > 0 {
|
if self.cursor_pos.2 > 0 {
|
||||||
|
@ -949,7 +950,7 @@ impl Component for CompactListing {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
UIEvent::Input(Key::Down) => {
|
UIEvent::Input(Key::Down) => {
|
||||||
if self.length > 0 && self.new_cursor_pos.2 < self.length - 1 {
|
if self.new_cursor_pos.2 < self.length - 1 {
|
||||||
self.new_cursor_pos.2 += 1;
|
self.new_cursor_pos.2 += 1;
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
}
|
}
|
||||||
|
@ -989,6 +990,90 @@ impl Component for CompactListing {
|
||||||
let thread_hash = self.get_thread_under_cursor(self.cursor_pos.2, context);
|
let thread_hash = self.get_thread_under_cursor(self.cursor_pos.2, context);
|
||||||
self.selection.entry(thread_hash).and_modify(|e| *e = !*e);
|
self.selection.entry(thread_hash).and_modify(|e| *e = !*e);
|
||||||
}
|
}
|
||||||
|
UIEvent::Action(ref action) => match action {
|
||||||
|
Action::SubSort(field, order) if !self.unfocused => {
|
||||||
|
debug!("SubSort {:?} , {:?}", field, order);
|
||||||
|
self.subsort = (*field, *order);
|
||||||
|
//if !self.filtered_selection.is_empty() {
|
||||||
|
// let threads = &account.collection.threads[&folder_hash];
|
||||||
|
// threads.vec_inner_sort_by(&mut self.filtered_selection, self.sort, &account.collection);
|
||||||
|
//} else {
|
||||||
|
// self.refresh_mailbox(context);
|
||||||
|
//}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Action::Sort(field, order) if !self.unfocused => {
|
||||||
|
debug!("Sort {:?} , {:?}", field, order);
|
||||||
|
self.sort = (*field, *order);
|
||||||
|
if !self.filtered_selection.is_empty() {
|
||||||
|
let folder_hash = context.accounts[self.cursor_pos.0]
|
||||||
|
[self.cursor_pos.1]
|
||||||
|
.unwrap()
|
||||||
|
.folder
|
||||||
|
.hash();
|
||||||
|
let threads = &context.accounts[self.cursor_pos.0].collection.threads
|
||||||
|
[&folder_hash];
|
||||||
|
threads.vec_inner_sort_by(
|
||||||
|
&mut self.filtered_selection,
|
||||||
|
self.sort,
|
||||||
|
&context.accounts[self.cursor_pos.0].collection.envelopes,
|
||||||
|
);
|
||||||
|
self.dirty = true;
|
||||||
|
} else {
|
||||||
|
self.refresh_mailbox(context);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Action::ToggleThreadSnooze if !self.unfocused => {
|
||||||
|
let thread_hash = self.get_thread_under_cursor(self.cursor_pos.2, context);
|
||||||
|
let account = &mut context.accounts[self.cursor_pos.0];
|
||||||
|
let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
|
||||||
|
let threads = account.collection.threads.entry(folder_hash).or_default();
|
||||||
|
let root_node = threads.thread_nodes.entry(thread_hash).or_default();
|
||||||
|
let is_snoozed = root_node.snoozed();
|
||||||
|
root_node.set_snoozed(!is_snoozed);
|
||||||
|
self.row_updates.push(thread_hash);
|
||||||
|
self.refresh_mailbox(context);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Action::Listing(a @ ListingAction::SetSeen)
|
||||||
|
| Action::Listing(a @ ListingAction::SetUnseen)
|
||||||
|
| Action::Listing(a @ ListingAction::Delete)
|
||||||
|
if !self.unfocused =>
|
||||||
|
{
|
||||||
|
let is_selection_empty =
|
||||||
|
self.selection.values().cloned().any(std::convert::identity);
|
||||||
|
let i = [self.get_thread_under_cursor(self.cursor_pos.2, context)];
|
||||||
|
let cursor_iter;
|
||||||
|
let sel_iter = if is_selection_empty {
|
||||||
|
cursor_iter = None;
|
||||||
|
Some(self.selection.iter().filter(|(_, v)| **v).map(|(k, _)| k))
|
||||||
|
} else {
|
||||||
|
cursor_iter = Some(i.iter());
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let iter = sel_iter
|
||||||
|
.into_iter()
|
||||||
|
.flatten()
|
||||||
|
.chain(cursor_iter.into_iter().flatten())
|
||||||
|
.cloned();
|
||||||
|
let stack = StackVec::from_iter(iter.into_iter());
|
||||||
|
for i in stack {
|
||||||
|
self.perform_action(context, i, a);
|
||||||
|
}
|
||||||
|
self.dirty = true;
|
||||||
|
for v in self.selection.values_mut() {
|
||||||
|
*v = false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match *event {
|
||||||
UIEvent::MailboxUpdate((ref idxa, ref idxf))
|
UIEvent::MailboxUpdate((ref idxa, ref idxf))
|
||||||
if (*idxa, *idxf)
|
if (*idxa, *idxf)
|
||||||
== (
|
== (
|
||||||
|
@ -1058,6 +1143,11 @@ impl Component for CompactListing {
|
||||||
UIEvent::Resize => {
|
UIEvent::Resize => {
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
}
|
}
|
||||||
|
UIEvent::Input(Key::Esc) if !self.unfocused && !self.filter_term.is_empty() => {
|
||||||
|
self.set_coordinates((self.new_cursor_pos.0, self.new_cursor_pos.1, None));
|
||||||
|
self.refresh_mailbox(context);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
UIEvent::Action(ref action) => match action {
|
UIEvent::Action(ref action) => match action {
|
||||||
Action::ViewMailbox(idx) => {
|
Action::ViewMailbox(idx) => {
|
||||||
if context.accounts[self.cursor_pos.0]
|
if context.accounts[self.cursor_pos.0]
|
||||||
|
@ -1072,93 +1162,12 @@ impl Component for CompactListing {
|
||||||
self.refresh_mailbox(context);
|
self.refresh_mailbox(context);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Action::SubSort(field, order) if !self.unfocused => {
|
|
||||||
debug!("SubSort {:?} , {:?}", field, order);
|
|
||||||
self.subsort = (*field, *order);
|
|
||||||
//if !self.filtered_selection.is_empty() {
|
|
||||||
// let threads = &account.collection.threads[&folder_hash];
|
|
||||||
// threads.vec_inner_sort_by(&mut self.filtered_selection, self.sort, &account.collection);
|
|
||||||
//} else {
|
|
||||||
// self.refresh_mailbox(context);
|
|
||||||
//}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Action::Sort(field, order) if !self.unfocused => {
|
|
||||||
debug!("Sort {:?} , {:?}", field, order);
|
|
||||||
self.sort = (*field, *order);
|
|
||||||
if !self.filtered_selection.is_empty() {
|
|
||||||
let folder_hash = context.accounts[self.cursor_pos.0][self.cursor_pos.1]
|
|
||||||
.unwrap()
|
|
||||||
.folder
|
|
||||||
.hash();
|
|
||||||
let threads =
|
|
||||||
&context.accounts[self.cursor_pos.0].collection.threads[&folder_hash];
|
|
||||||
threads.vec_inner_sort_by(
|
|
||||||
&mut self.filtered_selection,
|
|
||||||
self.sort,
|
|
||||||
&context.accounts[self.cursor_pos.0].collection.envelopes,
|
|
||||||
);
|
|
||||||
self.dirty = true;
|
|
||||||
} else {
|
|
||||||
self.refresh_mailbox(context);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Action::ToggleThreadSnooze if !self.unfocused => {
|
|
||||||
let thread_hash = self.get_thread_under_cursor(self.cursor_pos.2, context);
|
|
||||||
let account = &mut context.accounts[self.cursor_pos.0];
|
|
||||||
let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
|
|
||||||
let threads = account.collection.threads.entry(folder_hash).or_default();
|
|
||||||
let root_node = threads.thread_nodes.entry(thread_hash).or_default();
|
|
||||||
let is_snoozed = root_node.snoozed();
|
|
||||||
root_node.set_snoozed(!is_snoozed);
|
|
||||||
self.row_updates.push(thread_hash);
|
|
||||||
self.refresh_mailbox(context);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Action::Listing(Filter(ref filter_term)) if !self.unfocused => {
|
Action::Listing(Filter(ref filter_term)) if !self.unfocused => {
|
||||||
self.filter(filter_term, context);
|
self.filter(filter_term, context);
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
}
|
}
|
||||||
Action::Listing(a @ ListingAction::SetSeen)
|
|
||||||
| Action::Listing(a @ ListingAction::SetUnseen)
|
|
||||||
| Action::Listing(a @ ListingAction::Delete)
|
|
||||||
if !self.unfocused =>
|
|
||||||
{
|
|
||||||
let is_selection_empty =
|
|
||||||
self.selection.values().cloned().any(std::convert::identity);
|
|
||||||
let i = [self.get_thread_under_cursor(self.cursor_pos.2, context)];
|
|
||||||
let cursor_iter;
|
|
||||||
let sel_iter = if is_selection_empty {
|
|
||||||
cursor_iter = None;
|
|
||||||
Some(self.selection.iter().filter(|(_, v)| **v).map(|(k, _)| k))
|
|
||||||
} else {
|
|
||||||
cursor_iter = Some(i.iter());
|
|
||||||
None
|
|
||||||
};
|
|
||||||
let iter = sel_iter
|
|
||||||
.into_iter()
|
|
||||||
.flatten()
|
|
||||||
.chain(cursor_iter.into_iter().flatten())
|
|
||||||
.cloned();
|
|
||||||
let stack = StackVec::from_iter(iter.into_iter());
|
|
||||||
for i in stack {
|
|
||||||
self.perform_action(context, i, a);
|
|
||||||
}
|
|
||||||
self.dirty = true;
|
|
||||||
for v in self.selection.values_mut() {
|
|
||||||
*v = false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
UIEvent::Input(Key::Esc) if !self.unfocused && !self.filter_term.is_empty() => {
|
|
||||||
self.set_coordinates((self.new_cursor_pos.0, self.new_cursor_pos.1, None));
|
|
||||||
self.refresh_mailbox(context);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
|
|
|
@ -974,6 +974,7 @@ impl Component for ConversationsListing {
|
||||||
}
|
}
|
||||||
|
|
||||||
let shortcuts = &self.get_shortcuts(context)[ConversationsListing::DESCRIPTION];
|
let shortcuts = &self.get_shortcuts(context)[ConversationsListing::DESCRIPTION];
|
||||||
|
if self.length > 0 {
|
||||||
match *event {
|
match *event {
|
||||||
UIEvent::Input(Key::Up) => {
|
UIEvent::Input(Key::Up) => {
|
||||||
if self.cursor_pos.2 > 0 {
|
if self.cursor_pos.2 > 0 {
|
||||||
|
@ -1029,24 +1030,6 @@ impl Component for ConversationsListing {
|
||||||
self.selection.entry(thread_hash).and_modify(|e| *e = !*e);
|
self.selection.entry(thread_hash).and_modify(|e| *e = !*e);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
UIEvent::MailboxUpdate((ref idxa, ref idxf))
|
|
||||||
if (*idxa, *idxf)
|
|
||||||
== (
|
|
||||||
self.new_cursor_pos.0,
|
|
||||||
context.accounts[self.new_cursor_pos.0].folders_order
|
|
||||||
[self.new_cursor_pos.1],
|
|
||||||
) =>
|
|
||||||
{
|
|
||||||
self.refresh_mailbox(context);
|
|
||||||
self.set_dirty();
|
|
||||||
}
|
|
||||||
UIEvent::StartupCheck(ref f)
|
|
||||||
if *f
|
|
||||||
== context.accounts[self.cursor_pos.0].folders_order[self.new_cursor_pos.1] =>
|
|
||||||
{
|
|
||||||
self.refresh_mailbox(context);
|
|
||||||
self.set_dirty();
|
|
||||||
}
|
|
||||||
UIEvent::EnvelopeRename(ref old_hash, ref new_hash) => {
|
UIEvent::EnvelopeRename(ref old_hash, ref new_hash) => {
|
||||||
let account = &context.accounts[self.cursor_pos.0];
|
let account = &context.accounts[self.cursor_pos.0];
|
||||||
let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
|
let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
|
||||||
|
@ -1092,25 +1075,7 @@ impl Component for ConversationsListing {
|
||||||
self.view
|
self.view
|
||||||
.process_event(&mut UIEvent::EnvelopeRename(*old_hash, *new_hash), context);
|
.process_event(&mut UIEvent::EnvelopeRename(*old_hash, *new_hash), context);
|
||||||
}
|
}
|
||||||
UIEvent::ChangeMode(UIMode::Normal) => {
|
|
||||||
self.dirty = true;
|
|
||||||
}
|
|
||||||
UIEvent::Resize => {
|
|
||||||
self.dirty = true;
|
|
||||||
}
|
|
||||||
UIEvent::Action(ref action) => match action {
|
UIEvent::Action(ref action) => match action {
|
||||||
Action::ViewMailbox(idx) => {
|
|
||||||
if context.accounts[self.cursor_pos.0]
|
|
||||||
.folders_order
|
|
||||||
.get(*idx)
|
|
||||||
.is_none()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
self.set_coordinates((self.new_cursor_pos.0, *idx, None));
|
|
||||||
self.refresh_mailbox(context);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Action::SubSort(field, order) if !self.unfocused => {
|
Action::SubSort(field, order) if !self.unfocused => {
|
||||||
debug!("SubSort {:?} , {:?}", field, order);
|
debug!("SubSort {:?} , {:?}", field, order);
|
||||||
self.subsort = (*field, *order);
|
self.subsort = (*field, *order);
|
||||||
|
@ -1126,12 +1091,13 @@ impl Component for ConversationsListing {
|
||||||
debug!("Sort {:?} , {:?}", field, order);
|
debug!("Sort {:?} , {:?}", field, order);
|
||||||
self.sort = (*field, *order);
|
self.sort = (*field, *order);
|
||||||
if !self.filtered_selection.is_empty() {
|
if !self.filtered_selection.is_empty() {
|
||||||
let folder_hash = context.accounts[self.cursor_pos.0][self.cursor_pos.1]
|
let folder_hash = context.accounts[self.cursor_pos.0]
|
||||||
|
[self.cursor_pos.1]
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.folder
|
.folder
|
||||||
.hash();
|
.hash();
|
||||||
let threads =
|
let threads = &context.accounts[self.cursor_pos.0].collection.threads
|
||||||
&context.accounts[self.cursor_pos.0].collection.threads[&folder_hash];
|
[&folder_hash];
|
||||||
threads.vec_inner_sort_by(
|
threads.vec_inner_sort_by(
|
||||||
&mut self.filtered_selection,
|
&mut self.filtered_selection,
|
||||||
self.sort,
|
self.sort,
|
||||||
|
@ -1155,11 +1121,6 @@ impl Component for ConversationsListing {
|
||||||
self.refresh_mailbox(context);
|
self.refresh_mailbox(context);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Action::Listing(Filter(ref filter_term)) if !self.unfocused => {
|
|
||||||
self.filter(filter_term, context);
|
|
||||||
self.dirty = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Action::Listing(a @ ListingAction::SetSeen)
|
Action::Listing(a @ ListingAction::SetSeen)
|
||||||
| Action::Listing(a @ ListingAction::SetUnseen)
|
| Action::Listing(a @ ListingAction::SetUnseen)
|
||||||
| Action::Listing(a @ ListingAction::Delete)
|
| Action::Listing(a @ ListingAction::Delete)
|
||||||
|
@ -1193,16 +1154,67 @@ impl Component for ConversationsListing {
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match *event {
|
||||||
|
UIEvent::MailboxUpdate((ref idxa, ref idxf))
|
||||||
|
if (*idxa, *idxf)
|
||||||
|
== (
|
||||||
|
self.new_cursor_pos.0,
|
||||||
|
context.accounts[self.new_cursor_pos.0].folders_order
|
||||||
|
[self.new_cursor_pos.1],
|
||||||
|
) =>
|
||||||
|
{
|
||||||
|
self.refresh_mailbox(context);
|
||||||
|
self.set_dirty();
|
||||||
|
}
|
||||||
|
UIEvent::StartupCheck(ref f)
|
||||||
|
if *f
|
||||||
|
== context.accounts[self.cursor_pos.0].folders_order[self.new_cursor_pos.1] =>
|
||||||
|
{
|
||||||
|
self.refresh_mailbox(context);
|
||||||
|
self.set_dirty();
|
||||||
|
}
|
||||||
|
UIEvent::ChangeMode(UIMode::Normal) => {
|
||||||
|
self.dirty = true;
|
||||||
|
}
|
||||||
|
UIEvent::Resize => {
|
||||||
|
self.dirty = true;
|
||||||
|
}
|
||||||
|
UIEvent::Action(ref action) => match action {
|
||||||
|
Action::ViewMailbox(idx) => {
|
||||||
|
if context.accounts[self.cursor_pos.0]
|
||||||
|
.folders_order
|
||||||
|
.get(*idx)
|
||||||
|
.is_none()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
self.set_coordinates((self.new_cursor_pos.0, *idx, None));
|
||||||
|
self.refresh_mailbox(context);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Action::Listing(Filter(ref filter_term)) if !self.unfocused => {
|
||||||
|
self.filter(filter_term, context);
|
||||||
|
self.dirty = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
UIEvent::Input(Key::Esc) | UIEvent::Input(Key::Char(''))
|
UIEvent::Input(Key::Esc) | UIEvent::Input(Key::Char(''))
|
||||||
if !self.unfocused && !&self.filter_term.is_empty() =>
|
if !self.unfocused && !&self.filter_term.is_empty() =>
|
||||||
{
|
{
|
||||||
self.set_coordinates((self.new_cursor_pos.0, self.new_cursor_pos.1, None));
|
self.set_coordinates((self.new_cursor_pos.0, self.new_cursor_pos.1, None));
|
||||||
self.refresh_mailbox(context);
|
self.refresh_mailbox(context);
|
||||||
self.force_draw = false;
|
self.force_draw = false;
|
||||||
|
self.set_dirty();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
fn is_dirty(&self) -> bool {
|
fn is_dirty(&self) -> bool {
|
||||||
|
|
Loading…
Reference in New Issue