ui: open MessageRfc822 attachments in new tab

embed
Manos Pitsidianakis 2019-09-07 22:07:13 +03:00
parent f72fb069fa
commit a866e060a1
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
8 changed files with 25 additions and 21 deletions

View File

@ -93,7 +93,7 @@ pub trait Component: Display + Debug + Send {
true
}
fn set_dirty(&mut self);
fn kill(&mut self, _id: ComponentId) {}
fn kill(&mut self, _id: ComponentId, _context: &mut Context) {}
fn set_id(&mut self, _id: ComponentId) {}
fn id(&self) -> ComponentId;

View File

@ -8,7 +8,6 @@ const MAX_COLS: usize = 500;
enum ViewMode {
List,
View(CardId),
Close(Uuid),
}
#[derive(Debug)]
@ -158,11 +157,6 @@ impl ContactList {
impl Component for ContactList {
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
if let ViewMode::Close(u) = self.mode {
context.replies.push_back(UIEvent::Action(Tab(Kill(u))));
return;
}
if let Some(mgr) = self.view.as_mut() {
mgr.draw(grid, area, context);
return;
@ -289,8 +283,9 @@ impl Component for ContactList {
self.dirty = true;
}
fn kill(&mut self, uuid: Uuid) {
self.mode = ViewMode::Close(uuid);
fn kill(&mut self, uuid: Uuid, context: &mut Context) {
debug_assert!(uuid == self.id);
context.replies.push_back(UIEvent::Action(Tab(Kill(uuid))));
}
fn get_shortcuts(&self, context: &Context) -> ShortcutMaps {
let mut map = self

View File

@ -65,7 +65,7 @@ impl Component for AccountsPanel {
UIEvent::Input(Key::Char('\n')) => {
context
.replies
.push_back(UIEvent::Action(Tab(TabOpen(Some(Box::new(
.push_back(UIEvent::Action(Tab(New(Some(Box::new(
ContactList::for_account(self.cursor),
))))));
return true;

View File

@ -713,7 +713,7 @@ impl Component for Composer {
}
}
fn kill(&mut self, uuid: Uuid) {
fn kill(&mut self, uuid: Uuid, _context: &mut Context) {
self.mode = ViewMode::Discard(uuid);
}

View File

@ -731,15 +731,16 @@ impl Component for MailView {
if let Some(u) = envelope.body(op).attachments().get(lidx) {
match u.content_type() {
ContentType::MessageRfc822 => {
self.mode = ViewMode::Subview;
match EnvelopeWrapper::new(u.raw().to_vec()) {
Ok(wrapper) => {
self.subview = Some(Box::new(EnvelopeView::new(
context.replies.push_back(UIEvent::Action(Tab(New(Some(
Box::new(EnvelopeView::new(
wrapper,
None,
None,
self.coordinates.0,
)));
)),
)))));
}
Err(e) => {
context.replies.push_back(UIEvent::StatusEvent(

View File

@ -555,6 +555,14 @@ impl Component for EnvelopeView {
fn id(&self) -> ComponentId {
self.id
}
fn kill(&mut self, id: ComponentId, context: &mut Context) {
debug_assert!(self.id == id);
context
.replies
.push_back(UIEvent::Action(Tab(Kill(self.id))));
}
fn set_id(&mut self, id: ComponentId) {
self.id = id;
}

View File

@ -1345,7 +1345,7 @@ impl Component for Tabbed {
self.children[self.cursor_pos].set_dirty();
return true;
}
UIEvent::Action(Tab(TabOpen(ref mut e))) if e.is_some() => {
UIEvent::Action(Tab(New(ref mut e))) if e.is_some() => {
self.add_component(e.take().unwrap());
self.cursor_pos = self.children.len() - 1;
self.children[self.cursor_pos].set_dirty();
@ -1356,7 +1356,7 @@ impl Component for Tabbed {
return true;
}
let id = self.children[self.cursor_pos].id();
self.children[self.cursor_pos].kill(id);
self.children[self.cursor_pos].kill(id, context);
self.set_dirty();
return true;
}

View File

@ -44,7 +44,7 @@ pub enum ListingAction {
#[derive(Debug)]
pub enum TabAction {
TabOpen(Option<Box<Component>>),
New(Option<Box<Component>>),
NewDraft(usize, Option<Draft>),
Reply((usize, usize, usize), ThreadHash), // thread coordinates (account, mailbox, root_set idx) and thread hash
Close,