Remove Option<EnvelopeHash> from ListingTrait

It was never used.
async
Manos Pitsidianakis 2019-12-01 15:28:15 +02:00
parent 46a807eee1
commit 6cf73b4238
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
5 changed files with 55 additions and 137 deletions

View File

@ -46,9 +46,9 @@ struct AccountMenuEntry {
index: usize, index: usize,
} }
pub trait ListingTrait { pub trait ListingTrait: Component {
fn coordinates(&self) -> (usize, usize, Option<EnvelopeHash>); fn coordinates(&self) -> (usize, usize);
fn set_coordinates(&mut self, _: (usize, usize, Option<EnvelopeHash>)); fn set_coordinates(&mut self, _: (usize, usize));
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);
fn highlight_line(&mut self, grid: &mut CellBuffer, area: Area, idx: usize, context: &Context); fn highlight_line(&mut self, grid: &mut CellBuffer, area: Area, idx: usize, context: &Context);
fn filter(&mut self, _filter_term: &str, _context: &Context) {} fn filter(&mut self, _filter_term: &str, _context: &Context) {}
@ -64,45 +64,26 @@ pub enum ListingComponent {
} }
use crate::ListingComponent::*; use crate::ListingComponent::*;
impl ListingTrait for ListingComponent { impl core::ops::Deref for ListingComponent {
fn coordinates(&self) -> (usize, usize, Option<EnvelopeHash>) { type Target = dyn ListingTrait;
fn deref(&self) -> &Self::Target {
match &self { match &self {
Compact(ref l) => l.coordinates(), Compact(ref l) => l,
Plain(ref l) => l.coordinates(), Plain(ref l) => l,
Threaded(ref l) => l.coordinates(), Threaded(ref l) => l,
Conversations(ref l) => l.coordinates(), Conversations(ref l) => l,
} }
} }
fn set_coordinates(&mut self, c: (usize, usize, Option<EnvelopeHash>)) { }
impl core::ops::DerefMut for ListingComponent {
fn deref_mut(&mut self) -> &mut (dyn ListingTrait + 'static) {
match self { match self {
Compact(ref mut l) => l.set_coordinates(c), Compact(l) => l,
Plain(ref mut l) => l.set_coordinates(c), Plain(l) => l,
Threaded(ref mut l) => l.set_coordinates(c), Threaded(l) => l,
Conversations(ref mut l) => l.set_coordinates(c), Conversations(l) => l,
}
}
fn draw_list(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
match self {
Compact(ref mut l) => l.draw_list(grid, area, context),
Plain(ref mut l) => l.draw_list(grid, area, context),
Threaded(ref mut l) => l.draw_list(grid, area, context),
Conversations(ref mut l) => l.draw_list(grid, area, context),
}
}
fn highlight_line(&mut self, grid: &mut CellBuffer, area: Area, idx: usize, context: &Context) {
match self {
Compact(ref mut l) => l.highlight_line(grid, area, idx, context),
Plain(ref mut l) => l.highlight_line(grid, area, idx, context),
Threaded(ref mut l) => l.highlight_line(grid, area, idx, context),
Conversations(ref mut l) => l.highlight_line(grid, area, idx, context),
}
}
fn set_movement(&mut self, mvm: PageMovement) {
match self {
Compact(ref mut l) => l.set_movement(mvm),
Plain(ref mut l) => l.set_movement(mvm),
Threaded(ref mut l) => l.set_movement(mvm),
Conversations(ref mut l) => l.set_movement(mvm),
} }
} }
} }
@ -116,7 +97,7 @@ impl ListingComponent {
} }
let mut new_l = PlainListing::default(); let mut new_l = PlainListing::default();
let coors = self.coordinates(); let coors = self.coordinates();
new_l.set_coordinates((coors.0, coors.1, None)); new_l.set_coordinates((coors.0, coors.1));
*self = Plain(new_l); *self = Plain(new_l);
} }
IndexStyle::Threaded => { IndexStyle::Threaded => {
@ -125,7 +106,7 @@ impl ListingComponent {
} }
let mut new_l = ThreadListing::default(); let mut new_l = ThreadListing::default();
let coors = self.coordinates(); let coors = self.coordinates();
new_l.set_coordinates((coors.0, coors.1, None)); new_l.set_coordinates((coors.0, coors.1));
*self = Threaded(new_l); *self = Threaded(new_l);
} }
IndexStyle::Compact => { IndexStyle::Compact => {
@ -134,7 +115,7 @@ impl ListingComponent {
} }
let mut new_l = CompactListing::default(); let mut new_l = CompactListing::default();
let coors = self.coordinates(); let coors = self.coordinates();
new_l.set_coordinates((coors.0, coors.1, None)); new_l.set_coordinates((coors.0, coors.1));
*self = Compact(new_l); *self = Compact(new_l);
} }
IndexStyle::Conversations => { IndexStyle::Conversations => {
@ -143,7 +124,7 @@ impl ListingComponent {
} }
let mut new_l = ConversationsListing::default(); let mut new_l = ConversationsListing::default();
let coors = self.coordinates(); let coors = self.coordinates();
new_l.set_coordinates((coors.0, coors.1, None)); new_l.set_coordinates((coors.0, coors.1));
*self = Conversations(new_l); *self = Conversations(new_l);
} }
} }
@ -232,12 +213,7 @@ impl Component for Listing {
context.dirty_areas.push_back(area); context.dirty_areas.push_back(area);
return; return;
} }
match self.component { self.component.draw(grid, area, context);
Compact(ref mut l) => l.draw(grid, area, context),
Plain(ref mut l) => l.draw(grid, area, context),
Threaded(ref mut l) => l.draw(grid, area, context),
Conversations(ref mut l) => l.draw(grid, area, context),
}
} else if right_component_width == 0 { } else if right_component_width == 0 {
self.draw_menu(grid, area, context); self.draw_menu(grid, area, context);
} else { } else {
@ -256,30 +232,13 @@ impl Component for Listing {
context.dirty_areas.push_back(area); context.dirty_areas.push_back(area);
return; return;
} }
match self.component { self.component
Compact(ref mut l) => { .draw(grid, (set_x(upper_left, mid + 1), bottom_right), context);
l.draw(grid, (set_x(upper_left, mid + 1), bottom_right), context)
}
Plain(ref mut l) => {
l.draw(grid, (set_x(upper_left, mid + 1), bottom_right), context)
}
Threaded(ref mut l) => {
l.draw(grid, (set_x(upper_left, mid + 1), bottom_right), context)
}
Conversations(ref mut l) => {
l.draw(grid, (set_x(upper_left, mid + 1), bottom_right), context)
}
}
} }
self.dirty = false; self.dirty = false;
} }
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool { fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
if match self.component { if self.component.process_event(event, context) {
Plain(ref mut l) => l.process_event(event, context),
Compact(ref mut l) => l.process_event(event, context),
Threaded(ref mut l) => l.process_event(event, context),
Conversations(ref mut l) => l.process_event(event, context),
} {
return true; return true;
} }
@ -311,11 +270,8 @@ impl Component for Listing {
{ {
if self.cursor_pos.1 + amount < folder_length { if self.cursor_pos.1 + amount < folder_length {
self.cursor_pos.1 += amount; self.cursor_pos.1 += amount;
self.component.set_coordinates(( self.component
self.cursor_pos.0, .set_coordinates((self.cursor_pos.0, self.cursor_pos.1));
self.cursor_pos.1,
None,
));
self.set_dirty(); self.set_dirty();
} else { } else {
return true; return true;
@ -324,11 +280,8 @@ impl Component for Listing {
k if shortcut!(k == shortcuts[Listing::DESCRIPTION]["prev_folder"]) => { k if shortcut!(k == shortcuts[Listing::DESCRIPTION]["prev_folder"]) => {
if self.cursor_pos.1 >= amount { if self.cursor_pos.1 >= amount {
self.cursor_pos.1 -= amount; self.cursor_pos.1 -= amount;
self.component.set_coordinates(( self.component
self.cursor_pos.0, .set_coordinates((self.cursor_pos.0, self.cursor_pos.1));
self.cursor_pos.1,
None,
));
self.set_dirty(); self.set_dirty();
} else { } else {
return true; return true;
@ -382,7 +335,7 @@ impl Component for Listing {
k if shortcut!(k == shortcuts[Listing::DESCRIPTION]["next_account"]) => { k if shortcut!(k == shortcuts[Listing::DESCRIPTION]["next_account"]) => {
if self.cursor_pos.0 + amount < self.accounts.len() { if self.cursor_pos.0 + amount < self.accounts.len() {
self.cursor_pos = (self.cursor_pos.0 + amount, 0); self.cursor_pos = (self.cursor_pos.0 + amount, 0);
self.component.set_coordinates((self.cursor_pos.0, 0, None)); self.component.set_coordinates((self.cursor_pos.0, 0));
self.set_dirty(); self.set_dirty();
} else { } else {
return true; return true;
@ -391,7 +344,7 @@ impl Component for Listing {
k if shortcut!(k == shortcuts[Listing::DESCRIPTION]["prev_account"]) => { k if shortcut!(k == shortcuts[Listing::DESCRIPTION]["prev_account"]) => {
if self.cursor_pos.0 >= amount { if self.cursor_pos.0 >= amount {
self.cursor_pos = (self.cursor_pos.0 - amount, 0); self.cursor_pos = (self.cursor_pos.0 - amount, 0);
self.component.set_coordinates((self.cursor_pos.0, 0, None)); self.component.set_coordinates((self.cursor_pos.0, 0));
self.set_dirty(); self.set_dirty();
} else { } else {
return true; return true;
@ -585,12 +538,7 @@ impl Component for Listing {
if shortcut!(key == shortcuts[Listing::DESCRIPTION]["set_seen"]) => if shortcut!(key == shortcuts[Listing::DESCRIPTION]["set_seen"]) =>
{ {
let mut event = UIEvent::Action(Action::Listing(ListingAction::SetSeen)); let mut event = UIEvent::Action(Action::Listing(ListingAction::SetSeen));
if match self.component { if self.component.process_event(&mut event, context) {
Plain(ref mut l) => l.process_event(&mut event, context),
Compact(ref mut l) => l.process_event(&mut event, context),
Threaded(ref mut l) => l.process_event(&mut event, context),
Conversations(ref mut l) => l.process_event(&mut event, context),
} {
return true; return true;
} }
} }
@ -631,31 +579,15 @@ impl Component for Listing {
false false
} }
fn is_dirty(&self) -> bool { fn is_dirty(&self) -> bool {
self.dirty self.dirty || self.component.is_dirty()
|| match self.component {
Compact(ref l) => l.is_dirty(),
Plain(ref l) => l.is_dirty(),
Threaded(ref l) => l.is_dirty(),
Conversations(ref l) => l.is_dirty(),
}
} }
fn set_dirty(&mut self) { fn set_dirty(&mut self) {
self.dirty = true; self.dirty = true;
match self.component { self.component.set_dirty();
Compact(ref mut l) => l.set_dirty(),
Plain(ref mut l) => l.set_dirty(),
Threaded(ref mut l) => l.set_dirty(),
Conversations(ref mut l) => l.set_dirty(),
}
} }
fn get_shortcuts(&self, context: &Context) -> ShortcutMaps { fn get_shortcuts(&self, context: &Context) -> ShortcutMaps {
let mut map = match self.component { let mut map = self.component.get_shortcuts(context);
Compact(ref l) => l.get_shortcuts(context),
Plain(ref l) => l.get_shortcuts(context),
Threaded(ref l) => l.get_shortcuts(context),
Conversations(ref l) => l.get_shortcuts(context),
};
let config_map = context.settings.shortcuts.listing.key_values(); let config_map = context.settings.shortcuts.listing.key_values();
map.insert(Listing::DESCRIPTION, config_map); map.insert(Listing::DESCRIPTION, config_map);
@ -663,20 +595,10 @@ impl Component for Listing {
} }
fn id(&self) -> ComponentId { fn id(&self) -> ComponentId {
match self.component { self.component.id()
Compact(ref l) => l.id(),
Plain(ref l) => l.id(),
Threaded(ref l) => l.id(),
Conversations(ref l) => l.id(),
}
} }
fn set_id(&mut self, id: ComponentId) { fn set_id(&mut self, id: ComponentId) {
match self.component { self.component.set_id(id);
Compact(ref mut l) => l.set_id(id),
Plain(ref mut l) => l.set_id(id),
Threaded(ref mut l) => l.set_id(id),
Conversations(ref mut l) => l.set_id(id),
}
} }
fn get_status(&self, context: &Context) -> Option<String> { fn get_status(&self, context: &Context) -> Option<String> {

View File

@ -75,11 +75,11 @@ pub struct CompactListing {
} }
impl ListingTrait for CompactListing { impl ListingTrait for CompactListing {
fn coordinates(&self) -> (usize, usize, Option<EnvelopeHash>) { fn coordinates(&self) -> (usize, usize) {
(self.new_cursor_pos.0, self.new_cursor_pos.1, None) (self.new_cursor_pos.0, self.new_cursor_pos.1)
} }
fn set_coordinates(&mut self, coordinates: (usize, usize, Option<EnvelopeHash>)) { 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.unfocused = false;
self.filtered_selection.clear(); self.filtered_selection.clear();
@ -1336,7 +1336,7 @@ impl Component for CompactListing {
self.dirty = true; self.dirty = true;
} }
UIEvent::Input(Key::Esc) if !self.unfocused && !self.filter_term.is_empty() => { 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.set_coordinates((self.new_cursor_pos.0, self.new_cursor_pos.1));
self.refresh_mailbox(context); self.refresh_mailbox(context);
self.set_dirty(); self.set_dirty();
return true; return true;

View File

@ -107,11 +107,11 @@ pub struct ConversationsListing {
} }
impl ListingTrait for ConversationsListing { impl ListingTrait for ConversationsListing {
fn coordinates(&self) -> (usize, usize, Option<EnvelopeHash>) { fn coordinates(&self) -> (usize, usize) {
(self.new_cursor_pos.0, self.new_cursor_pos.1, None) (self.new_cursor_pos.0, self.new_cursor_pos.1)
} }
fn set_coordinates(&mut self, coordinates: (usize, usize, Option<EnvelopeHash>)) { 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.unfocused = false;
self.filtered_selection.clear(); self.filtered_selection.clear();
@ -1316,7 +1316,7 @@ impl Component for ConversationsListing {
{ {
return true; return true;
} }
self.set_coordinates((self.new_cursor_pos.0, *idx, None)); self.set_coordinates((self.new_cursor_pos.0, *idx));
self.refresh_mailbox(context); self.refresh_mailbox(context);
return true; return true;
} }
@ -1331,7 +1331,7 @@ impl Component for ConversationsListing {
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));
self.refresh_mailbox(context); self.refresh_mailbox(context);
self.force_draw = false; self.force_draw = false;
self.set_dirty(); self.set_dirty();

View File

@ -76,11 +76,11 @@ pub struct PlainListing {
} }
impl ListingTrait for PlainListing { impl ListingTrait for PlainListing {
fn coordinates(&self) -> (usize, usize, Option<EnvelopeHash>) { fn coordinates(&self) -> (usize, usize) {
(self.new_cursor_pos.0, self.new_cursor_pos.1, None) (self.new_cursor_pos.0, self.new_cursor_pos.1)
} }
fn set_coordinates(&mut self, coordinates: (usize, usize, Option<EnvelopeHash>)) { 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.unfocused = false;
self.filtered_selection.clear(); self.filtered_selection.clear();
@ -1116,7 +1116,7 @@ impl Component for PlainListing {
self.dirty = true; self.dirty = true;
} }
UIEvent::Input(Key::Esc) if !self.unfocused && !self.filter_term.is_empty() => { 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.set_coordinates((self.new_cursor_pos.0, self.new_cursor_pos.1));
self.set_dirty(); self.set_dirty();
self.refresh_mailbox(context); self.refresh_mailbox(context);
return true; return true;

View File

@ -49,14 +49,10 @@ pub struct ThreadListing {
} }
impl ListingTrait for ThreadListing { impl ListingTrait for ThreadListing {
fn coordinates(&self) -> (usize, usize, Option<EnvelopeHash>) { fn coordinates(&self) -> (usize, usize) {
( (self.new_cursor_pos.0, self.new_cursor_pos.1)
self.new_cursor_pos.0,
self.new_cursor_pos.1,
self.locations.get(self.new_cursor_pos.2).map(|&k| k),
)
} }
fn set_coordinates(&mut self, coordinates: (usize, usize, Option<EnvelopeHash>)) { 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.unfocused = false;
self.locations.clear(); self.locations.clear();