Make Entity `Send`

embed
Manos Pitsidianakis 2019-02-26 10:55:22 +02:00
parent bac75b96dd
commit 00abea5bff
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
7 changed files with 35 additions and 13 deletions

View File

@ -50,8 +50,9 @@ pub struct Card {
url: String,
key: String,
color: u8,
last_edited: DateTime<Local>,
extra_properties: FnvHashMap<String, String>
extra_properties: FnvHashMap<String, String>,
}
impl AddressBook {
@ -102,6 +103,7 @@ impl Card {
last_edited: Local::now(),
extra_properties: FnvHashMap::default(),
color: 0,
}
}

View File

@ -144,7 +144,7 @@ impl Entity {
/// Types implementing this Trait can draw on the terminal and receive events.
/// If a type wants to skip drawing if it has not changed anything, it can hold some flag in its
/// fields (eg self.dirty = false) and act upon that in their `draw` implementation.
pub trait Component: Display + Debug {
pub trait Component: Display + Debug + Send {
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context);
fn process_event(&mut self, event: &UIEvent, context: &mut Context) -> bool;
fn is_dirty(&self) -> bool {

View File

@ -87,7 +87,7 @@ impl Component for ContactList {
if self.dirty {
self.initialize(context);
clear_area(grid, area);
copy_area(grid, &self.content, area, ((0, 0), (MAX_COLS - 1, self.content.size().1 - 1)));
copy_area(grid, &self.content, area, ((0, 0), (MAX_COLS - 1, self.content.size().1.saturating_sub(1))));
context.dirty_areas.push_back(area);
self.dirty = false;
}
@ -113,7 +113,7 @@ impl Component for ContactList {
}
}
match event.event_type {
UIEventType::Input(Key::Char('e')) => {
UIEventType::Input(Key::Char('e')) if self.length > 0 => {
let account = &mut context.accounts[self.account_pos];
let book = &mut account.address_book;
let card = book[&self.id_positions[self.cursor_pos]].clone();

View File

@ -323,7 +323,7 @@ impl Component for MailView {
self.pager = None;
self.mode = ViewMode::Subview;
}
ViewMode::Subview => {}
ViewMode::Subview | ViewMode::ContactSelector(_) => {}
_ => {
let buf = {
let text = self.attachment_to_text(&body);
@ -349,7 +349,8 @@ impl Component for MailView {
}
},
ViewMode::ContactSelector(ref mut s) => {
s.draw(grid, (set_y(upper_left, y + 1), bottom_right), context);
clear_area(grid, (set_y(upper_left, y + 1), bottom_right));
s.draw(grid, (set_y(upper_left, y + 1), bottom_right), context);
}
_ => {
if let Some(p) = self.pager.as_mut() {
@ -415,6 +416,7 @@ impl Component for MailView {
entries.push((envelope.from()[0].get_email().into_bytes(), format!("{}", envelope.from()[0])));
entries.push((String::from("foo@bar.de").into_bytes(), String::from("Johann de Vir <foo@bar.de>")));
self.mode = ViewMode::ContactSelector(Selector::new(entries, true));
self.dirty = true;
//context.accounts.context(self.coordinates.0).address_book.add_card(new_card);
},
UIEventType::Input(Key::Esc) | UIEventType::Input(Key::Alt('')) => {
@ -604,6 +606,11 @@ impl Component for MailView {
self.dirty
|| self.pager.as_ref().map(|p| p.is_dirty()).unwrap_or(false)
|| self.subview.as_ref().map(|p| p.is_dirty()).unwrap_or(false)
|| if let ViewMode::ContactSelector(ref s) = self.mode {
s.is_dirty()
} else {
false
}
}
fn set_dirty(&mut self) {
self.dirty = true;

View File

@ -864,6 +864,7 @@ impl fmt::Display for Selector {
impl Component for Selector {
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
eprintln!("drawing");
let (width, height) = self.content.size();
copy_area_with_break(
grid,
@ -897,14 +898,17 @@ impl Component for Selector {
false,
);
}
self.dirty = true;
return true;
},
UIEventType::Input(Key::Up) if self.cursor > 0 => {
self.cursor -= 1;
self.dirty = true;
return true;
},
UIEventType::Input(Key::Down) if self.cursor < height.saturating_sub(1) => {
self.cursor += 1;
self.dirty = true;
return true;
},
_ => {}

View File

@ -8,6 +8,13 @@ enum FormFocus {
TextInput,
}
/*
enum Field {
Text(String),
Choice(Vec<String>),
}
*/
impl Default for FormFocus {
fn default() -> FormFocus {
FormFocus::Fields
@ -195,7 +202,7 @@ impl Component for FormWidget {
#[derive(Debug, Default)]
pub struct ButtonWidget<T> where T: std::fmt::Debug + Default{
pub struct ButtonWidget<T> where T: std::fmt::Debug + Default + Send{
buttons: FnvHashMap<String, T>,
layout: Vec<String>,
@ -203,13 +210,13 @@ pub struct ButtonWidget<T> where T: std::fmt::Debug + Default{
cursor: usize,
}
impl<T> fmt::Display for ButtonWidget<T> where T: std::fmt::Debug + Default {
impl<T> fmt::Display for ButtonWidget<T> where T: std::fmt::Debug + Default + Send {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Display::fmt("", f)
}
}
impl<T> ButtonWidget<T> where T: std::fmt::Debug + Default {
impl<T> ButtonWidget<T> where T: std::fmt::Debug + Default + Send {
pub fn new(init_val: (String, T)) -> ButtonWidget<T> {
ButtonWidget {
layout: vec![init_val.0.clone()],
@ -230,7 +237,7 @@ impl<T> ButtonWidget<T> where T: std::fmt::Debug + Default {
}
impl<T> Component for ButtonWidget<T> where T: std::fmt::Debug + Default {
impl<T> Component for ButtonWidget<T> where T: std::fmt::Debug + Default + Send {
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
let upper_left = upper_left!(area);
let bottom_right = bottom_right!(area);

View File

@ -24,26 +24,28 @@
*/
pub use melib::mailbox::{SortField, SortOrder};
use components::Entity;
extern crate uuid;
use uuid::Uuid;
#[derive(Debug, Clone)]
#[derive(Debug, )]
pub enum ListingAction {
SetPlain,
SetThreaded,
SetCompact,
}
#[derive(Debug, Clone)]
#[derive(Debug, )]
pub enum TabAction {
EntityOpen(Entity),
NewDraft,
Reply((usize, usize, usize), usize), // thread coordinates (account, mailbox, root_set idx) and message idx
Close,
Kill(Uuid),
}
#[derive(Debug, Clone)]
#[derive(Debug, )]
pub enum Action {
Listing(ListingAction),
ViewMailbox(usize),