diff --git a/meli/src/mail/compose.rs b/meli/src/mail/compose.rs index 2b8eff01..58819ee8 100644 --- a/meli/src/mail/compose.rs +++ b/meli/src/mail/compose.rs @@ -42,8 +42,8 @@ use crate::{accounts::JobRequest, jobs::JoinHandle, terminal::embedded::Terminal #[cfg(feature = "gpgme")] pub mod gpg; -//pub mod edit_attachments; -//use edit_attachments::*; +pub mod edit_attachments; +use edit_attachments::*; pub mod hooks; @@ -119,9 +119,9 @@ pub struct Composer { #[derive(Debug)] enum ViewMode { Discard(ComponentId, UIDialog), - //EditAttachments { - // widget: EditAttachments, - //}, + EditAttachments { + widget: EditAttachments, + }, Edit, EmbeddedPty, SelectRecipients(UIDialog
), @@ -132,13 +132,15 @@ enum ViewMode { } impl ViewMode { + #[inline] fn is_edit(&self) -> bool { matches!(self, ViewMode::Edit) } - //fn is_edit_attachments(&self) -> bool { - // matches!(self, ViewMode::EditAttachments { .. }) - //} + #[inline] + fn is_edit_attachments(&self) -> bool { + matches!(self, ViewMode::EditAttachments { .. }) + } } impl std::fmt::Display for Composer { @@ -1036,19 +1038,22 @@ impl Component for Composer { } self.pager.draw(grid, body_area, context); - //if !self.mode.is_edit_attachments() { - self.draw_attachments(grid, attachment_area, context); - //} + if !self.mode.is_edit_attachments() { + self.draw_attachments(grid, attachment_area, context); + } match self.mode { ViewMode::Edit | ViewMode::EmbeddedPty => {} - //ViewMode::EditAttachments { ref mut widget } => { - // let inner_area = create_box(grid, area); - // (EditAttachmentsRefMut { - // inner: widget, - // draft: &mut self.draft, - // }) - // .draw(grid, inner_area, context); - //} + ViewMode::EditAttachments { ref mut widget } => { + let inner_area = area.center_inside(( + area.width().saturating_sub(2), + area.height().saturating_sub(2), + )); + (EditAttachmentsRefMut { + inner: widget, + draft: &mut self.draft, + }) + .draw(grid, inner_area, context); + } ViewMode::Send(ref mut s) => { s.draw(grid, body_area, context); } @@ -1147,22 +1152,23 @@ impl Component for Composer { return true; } } - //(ViewMode::EditAttachments { ref mut widget }, _) => { - // if (EditAttachmentsRefMut { - // inner: widget, - // draft: &mut self.draft, - // }) - // .process_event(event, context) - // { - // if matches!( - // widget.buttons.result(), - // Some(FormButtonActions::Cancel | FormButtonActions::Accept) - // ) { self.mode = ViewMode::Edit; - // } - // self.set_dirty(true); - // return true; - // } - //} + (ViewMode::EditAttachments { ref mut widget }, _) => { + if (EditAttachmentsRefMut { + inner: widget, + draft: &mut self.draft, + }) + .process_event(event, context) + { + if matches!( + widget.buttons.result(), + Some(FormButtonActions::Cancel | FormButtonActions::Accept) + ) { + self.mode = ViewMode::Edit; + } + self.set_dirty(true); + return true; + } + } (ViewMode::Send(ref selector), UIEvent::FinishedUIDialog(id, result)) if selector.id() == *id => { @@ -1741,9 +1747,9 @@ impl Component for Composer { && self.cursor == Cursor::Attachments && shortcut!(key == shortcuts[Shortcuts::COMPOSING]["edit"]) => { - //self.mode = ViewMode::EditAttachments { - // widget: EditAttachments::new(Some(self.account_hash)), - //}; + self.mode = ViewMode::EditAttachments { + widget: EditAttachments::new(Some(self.account_hash)), + }; self.set_dirty(true); return true; @@ -2189,13 +2195,13 @@ impl Component for Composer { .map(EmbeddedPty::is_dirty) .unwrap_or(false) } - //ViewMode::EditAttachments { ref widget } => { - // widget.dirty - // || widget.buttons.is_dirty() - // || self.dirty - // || self.pager.is_dirty() - // || self.form.is_dirty() - //} + ViewMode::EditAttachments { ref widget } => { + widget.dirty + || widget.buttons.is_dirty() + || self.dirty + || self.pager.is_dirty() + || self.form.is_dirty() + } ViewMode::Edit => self.dirty || self.pager.is_dirty() || self.form.is_dirty(), ViewMode::Discard(_, ref widget) => { widget.is_dirty() || self.pager.is_dirty() || self.form.is_dirty() @@ -2245,14 +2251,14 @@ impl Component for Composer { } } } + ViewMode::EditAttachments { ref mut widget } => { + (EditAttachmentsRefMut { + inner: widget, + draft: &mut self.draft, + }) + .set_dirty(value); + } } - //if let ViewMode::EditAttachments { ref mut widget } = self.mode { - // (EditAttachmentsRefMut { - // inner: widget, - // draft: &mut self.draft, - // }) - // .set_dirty(value); - //} } fn kill(&mut self, uuid: ComponentId, context: &mut Context) { diff --git a/meli/src/mail/compose/edit_attachments.rs b/meli/src/mail/compose/edit_attachments.rs index 378695cb..ed0e1d0a 100644 --- a/meli/src/mail/compose/edit_attachments.rs +++ b/meli/src/mail/compose/edit_attachments.rs @@ -152,44 +152,34 @@ impl Component for EditAttachmentsRefMut<'_, '_> { } else { theme_default.bg }; - if let Some(name) = a.content_type().name() { - grid.write_string( - &format!( + grid.write_string( + &if let Some(name) = a.content_type().name() { + format!( "[{}] \"{}\", {} {}", i, name, a.content_type(), melib::BytesDisplay(a.raw.len()) - ), - theme_default.fg, - bg, - theme_default.attrs, - (pos_inc(area.upper_left(), (0, 1 + i)), area.bottom_right()), - None, - ); - } else { - grid.write_string( - &format!( + ) + } else { + format!( "[{}] {} {}", i, a.content_type(), melib::BytesDisplay(a.raw.len()) - ), - theme_default.fg, - bg, - theme_default.attrs, - (pos_inc(area.upper_left(), (0, 1 + i)), area.bottom_right()), - None, - ); - } + ) + }, + theme_default.fg, + bg, + theme_default.attrs, + area.skip(2, 2 + i), + None, + ); } } self.inner.buttons.draw( grid, - ( - pos_inc(area.upper_left(), (0, 1 + self.draft.attachments().len())), - area.bottom_right(), - ), + area.skip_rows(3 + self.draft.attachments().len()), context, ); self.set_dirty(false);