Browse Source

Make Entity `Send`

tags/pre-alpha-0.0
Manos Pitsidianakis 3 years ago
parent
commit
00abea5bff
Signed by untrusted user: epilys GPG Key ID: 73627C2F690DF710
  1. 4
      melib/src/addressbook.rs
  2. 2
      ui/src/components.rs
  3. 4
      ui/src/components/contacts/contact_list.rs
  4. 11
      ui/src/components/mail/view.rs
  5. 4
      ui/src/components/utilities.rs
  6. 15
      ui/src/components/utilities/widgets.rs
  7. 8
      ui/src/execute/actions.rs

4
melib/src/addressbook.rs

@ -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,
}
}

2
ui/src/components.rs

@ -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 {

4
ui/src/components/contacts/contact_list.rs

@ -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();

11
ui/src/components/mail/view.rs

@ -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;

4
ui/src/components/utilities.rs

@ -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;
},
_ => {}

15
ui/src/components/utilities/widgets.rs

@ -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);

8
ui/src/execute/actions.rs

@ -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),

Loading…
Cancel
Save