Re-enable EditAttachments component

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/312/head
Manos Pitsidianakis 6 months ago
parent b5cc2a095f
commit ed8a5de2cb
No known key found for this signature in database
GPG Key ID: 7729C7707F7E09D0

@ -42,8 +42,8 @@ use crate::{accounts::JobRequest, jobs::JoinHandle, terminal::embedded::Terminal
#[cfg(feature = "gpgme")] #[cfg(feature = "gpgme")]
pub mod gpg; pub mod gpg;
//pub mod edit_attachments; pub mod edit_attachments;
//use edit_attachments::*; use edit_attachments::*;
pub mod hooks; pub mod hooks;
@ -119,9 +119,9 @@ pub struct Composer {
#[derive(Debug)] #[derive(Debug)]
enum ViewMode { enum ViewMode {
Discard(ComponentId, UIDialog<char>), Discard(ComponentId, UIDialog<char>),
//EditAttachments { EditAttachments {
// widget: EditAttachments, widget: EditAttachments,
//}, },
Edit, Edit,
EmbeddedPty, EmbeddedPty,
SelectRecipients(UIDialog<Address>), SelectRecipients(UIDialog<Address>),
@ -132,13 +132,15 @@ enum ViewMode {
} }
impl ViewMode { impl ViewMode {
#[inline]
fn is_edit(&self) -> bool { fn is_edit(&self) -> bool {
matches!(self, ViewMode::Edit) matches!(self, ViewMode::Edit)
} }
//fn is_edit_attachments(&self) -> bool { #[inline]
// matches!(self, ViewMode::EditAttachments { .. }) fn is_edit_attachments(&self) -> bool {
//} matches!(self, ViewMode::EditAttachments { .. })
}
} }
impl std::fmt::Display for Composer { impl std::fmt::Display for Composer {
@ -1036,19 +1038,22 @@ impl Component for Composer {
} }
self.pager.draw(grid, body_area, context); self.pager.draw(grid, body_area, context);
//if !self.mode.is_edit_attachments() { if !self.mode.is_edit_attachments() {
self.draw_attachments(grid, attachment_area, context); self.draw_attachments(grid, attachment_area, context);
//} }
match self.mode { match self.mode {
ViewMode::Edit | ViewMode::EmbeddedPty => {} ViewMode::Edit | ViewMode::EmbeddedPty => {}
//ViewMode::EditAttachments { ref mut widget } => { ViewMode::EditAttachments { ref mut widget } => {
// let inner_area = create_box(grid, area); let inner_area = area.center_inside((
// (EditAttachmentsRefMut { area.width().saturating_sub(2),
// inner: widget, area.height().saturating_sub(2),
// draft: &mut self.draft, ));
// }) (EditAttachmentsRefMut {
// .draw(grid, inner_area, context); inner: widget,
//} draft: &mut self.draft,
})
.draw(grid, inner_area, context);
}
ViewMode::Send(ref mut s) => { ViewMode::Send(ref mut s) => {
s.draw(grid, body_area, context); s.draw(grid, body_area, context);
} }
@ -1147,22 +1152,23 @@ impl Component for Composer {
return true; return true;
} }
} }
//(ViewMode::EditAttachments { ref mut widget }, _) => { (ViewMode::EditAttachments { ref mut widget }, _) => {
// if (EditAttachmentsRefMut { if (EditAttachmentsRefMut {
// inner: widget, inner: widget,
// draft: &mut self.draft, draft: &mut self.draft,
// }) })
// .process_event(event, context) .process_event(event, context)
// { {
// if matches!( if matches!(
// widget.buttons.result(), widget.buttons.result(),
// Some(FormButtonActions::Cancel | FormButtonActions::Accept) Some(FormButtonActions::Cancel | FormButtonActions::Accept)
// ) { self.mode = ViewMode::Edit; ) {
// } self.mode = ViewMode::Edit;
// self.set_dirty(true); }
// return true; self.set_dirty(true);
// } return true;
//} }
}
(ViewMode::Send(ref selector), UIEvent::FinishedUIDialog(id, result)) (ViewMode::Send(ref selector), UIEvent::FinishedUIDialog(id, result))
if selector.id() == *id => if selector.id() == *id =>
{ {
@ -1741,9 +1747,9 @@ impl Component for Composer {
&& self.cursor == Cursor::Attachments && self.cursor == Cursor::Attachments
&& shortcut!(key == shortcuts[Shortcuts::COMPOSING]["edit"]) => && shortcut!(key == shortcuts[Shortcuts::COMPOSING]["edit"]) =>
{ {
//self.mode = ViewMode::EditAttachments { self.mode = ViewMode::EditAttachments {
// widget: EditAttachments::new(Some(self.account_hash)), widget: EditAttachments::new(Some(self.account_hash)),
//}; };
self.set_dirty(true); self.set_dirty(true);
return true; return true;
@ -2189,13 +2195,13 @@ impl Component for Composer {
.map(EmbeddedPty::is_dirty) .map(EmbeddedPty::is_dirty)
.unwrap_or(false) .unwrap_or(false)
} }
//ViewMode::EditAttachments { ref widget } => { ViewMode::EditAttachments { ref widget } => {
// widget.dirty widget.dirty
// || widget.buttons.is_dirty() || widget.buttons.is_dirty()
// || self.dirty || self.dirty
// || self.pager.is_dirty() || self.pager.is_dirty()
// || self.form.is_dirty() || self.form.is_dirty()
//} }
ViewMode::Edit => 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) => { ViewMode::Discard(_, ref widget) => {
widget.is_dirty() || self.pager.is_dirty() || self.form.is_dirty() 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) { fn kill(&mut self, uuid: ComponentId, context: &mut Context) {

@ -152,44 +152,34 @@ impl Component for EditAttachmentsRefMut<'_, '_> {
} else { } else {
theme_default.bg theme_default.bg
}; };
if let Some(name) = a.content_type().name() { grid.write_string(
grid.write_string( &if let Some(name) = a.content_type().name() {
&format!( format!(
"[{}] \"{}\", {} {}", "[{}] \"{}\", {} {}",
i, i,
name, name,
a.content_type(), a.content_type(),
melib::BytesDisplay(a.raw.len()) melib::BytesDisplay(a.raw.len())
), )
theme_default.fg, } else {
bg, format!(
theme_default.attrs,
(pos_inc(area.upper_left(), (0, 1 + i)), area.bottom_right()),
None,
);
} else {
grid.write_string(
&format!(
"[{}] {} {}", "[{}] {} {}",
i, i,
a.content_type(), a.content_type(),
melib::BytesDisplay(a.raw.len()) melib::BytesDisplay(a.raw.len())
), )
theme_default.fg, },
bg, theme_default.fg,
theme_default.attrs, bg,
(pos_inc(area.upper_left(), (0, 1 + i)), area.bottom_right()), theme_default.attrs,
None, area.skip(2, 2 + i),
); None,
} );
} }
} }
self.inner.buttons.draw( self.inner.buttons.draw(
grid, grid,
( area.skip_rows(3 + self.draft.attachments().len()),
pos_inc(area.upper_left(), (0, 1 + self.draft.attachments().len())),
area.bottom_right(),
),
context, context,
); );
self.set_dirty(false); self.set_dirty(false);

Loading…
Cancel
Save