ui/MailView: unwrap Pager out of option
There's no need anymore for pager to be inside an Option.jmap
parent
874a252394
commit
3e33335914
|
@ -72,7 +72,7 @@ impl ViewMode {
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct MailView {
|
pub struct MailView {
|
||||||
coordinates: (usize, usize, EnvelopeHash),
|
coordinates: (usize, usize, EnvelopeHash),
|
||||||
pager: Option<Pager>,
|
pager: Pager,
|
||||||
subview: Option<Box<dyn Component>>,
|
subview: Option<Box<dyn Component>>,
|
||||||
dirty: bool,
|
dirty: bool,
|
||||||
mode: ViewMode,
|
mode: ViewMode,
|
||||||
|
@ -110,7 +110,7 @@ impl MailView {
|
||||||
) -> Self {
|
) -> Self {
|
||||||
MailView {
|
MailView {
|
||||||
coordinates,
|
coordinates,
|
||||||
pager,
|
pager: pager.unwrap_or_default(),
|
||||||
subview,
|
subview,
|
||||||
dirty: true,
|
dirty: true,
|
||||||
mode: ViewMode::Normal,
|
mode: ViewMode::Normal,
|
||||||
|
@ -591,14 +591,12 @@ impl Component for MailView {
|
||||||
};
|
};
|
||||||
match self.mode {
|
match self.mode {
|
||||||
ViewMode::Attachment(aidx) if body.attachments()[aidx].is_html() => {
|
ViewMode::Attachment(aidx) if body.attachments()[aidx].is_html() => {
|
||||||
self.pager = None;
|
|
||||||
let attachment = &body.attachments()[aidx];
|
let attachment = &body.attachments()[aidx];
|
||||||
self.subview = Some(Box::new(HtmlView::new(&attachment, context)));
|
self.subview = Some(Box::new(HtmlView::new(&attachment, context)));
|
||||||
self.mode = ViewMode::Subview;
|
self.mode = ViewMode::Subview;
|
||||||
}
|
}
|
||||||
ViewMode::Normal if body.is_html() => {
|
ViewMode::Normal if body.is_html() => {
|
||||||
self.subview = Some(Box::new(HtmlView::new(&body, context)));
|
self.subview = Some(Box::new(HtmlView::new(&body, context)));
|
||||||
self.pager = None;
|
|
||||||
self.mode = ViewMode::Subview;
|
self.mode = ViewMode::Subview;
|
||||||
}
|
}
|
||||||
ViewMode::Subview | ViewMode::ContactSelector(_) => {}
|
ViewMode::Subview | ViewMode::ContactSelector(_) => {}
|
||||||
|
@ -611,8 +609,7 @@ impl Component for MailView {
|
||||||
.map(|v| String::from_utf8_lossy(v).into_owned())
|
.map(|v| String::from_utf8_lossy(v).into_owned())
|
||||||
.unwrap_or_else(|e| e.to_string())
|
.unwrap_or_else(|e| e.to_string())
|
||||||
};
|
};
|
||||||
self.pager = Some(Pager::from_string(text, Some(context), None, None));
|
self.pager = Pager::from_string(text, Some(context), None, None);
|
||||||
self.subview = None;
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let text = {
|
let text = {
|
||||||
|
@ -623,11 +620,11 @@ impl Component for MailView {
|
||||||
*/
|
*/
|
||||||
};
|
};
|
||||||
let cursor_pos = if self.mode.is_attachment() {
|
let cursor_pos = if self.mode.is_attachment() {
|
||||||
Some(0)
|
0
|
||||||
} else {
|
} else {
|
||||||
self.pager.as_mut().map(|p| p.cursor_pos())
|
self.pager.cursor_pos()
|
||||||
};
|
};
|
||||||
self.pager = Some(Pager::from_string(text, Some(context), cursor_pos, None));
|
self.pager = Pager::from_string(text, Some(context), Some(cursor_pos), None);
|
||||||
self.subview = None;
|
self.subview = None;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -639,9 +636,8 @@ impl Component for MailView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if let Some(p) = self.pager.as_mut() {
|
self.pager
|
||||||
p.draw(grid, (set_y(upper_left, y + 1), bottom_right), context);
|
.draw(grid, (set_y(upper_left, y + 1), bottom_right), context);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let ViewMode::ContactSelector(ref mut s) = self.mode {
|
if let ViewMode::ContactSelector(ref mut s) = self.mode {
|
||||||
|
@ -676,20 +672,16 @@ impl Component for MailView {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if let Some(p) = self.pager.as_mut() {
|
if self.pager.process_event(event, context) {
|
||||||
if p.process_event(event, context) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
_ => {
|
_ => {
|
||||||
if let Some(p) = self.pager.as_mut() {
|
if self.pager.process_event(event, context) {
|
||||||
if p.process_event(event, context) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let shortcuts = &self.get_shortcuts(context)[MailView::DESCRIPTION];
|
let shortcuts = &self.get_shortcuts(context)[MailView::DESCRIPTION];
|
||||||
match *event {
|
match *event {
|
||||||
|
@ -1284,7 +1276,7 @@ impl Component for MailView {
|
||||||
}
|
}
|
||||||
fn is_dirty(&self) -> bool {
|
fn is_dirty(&self) -> bool {
|
||||||
self.dirty
|
self.dirty
|
||||||
|| self.pager.as_ref().map(|p| p.is_dirty()).unwrap_or(false)
|
|| self.pager.is_dirty()
|
||||||
|| self.subview.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 {
|
|| if let ViewMode::ContactSelector(ref s) = self.mode {
|
||||||
s.is_dirty()
|
s.is_dirty()
|
||||||
|
@ -1296,9 +1288,7 @@ impl Component for MailView {
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
match self.mode {
|
match self.mode {
|
||||||
ViewMode::Normal => {
|
ViewMode::Normal => {
|
||||||
if let Some(p) = self.pager.as_mut() {
|
self.pager.set_dirty();
|
||||||
p.set_dirty();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ViewMode::Subview => {
|
ViewMode::Subview => {
|
||||||
if let Some(s) = self.subview.as_mut() {
|
if let Some(s) = self.subview.as_mut() {
|
||||||
|
@ -1311,10 +1301,8 @@ impl Component for MailView {
|
||||||
fn get_shortcuts(&self, context: &Context) -> ShortcutMaps {
|
fn get_shortcuts(&self, context: &Context) -> ShortcutMaps {
|
||||||
let mut map = if let Some(ref sbv) = self.subview {
|
let mut map = if let Some(ref sbv) = self.subview {
|
||||||
sbv.get_shortcuts(context)
|
sbv.get_shortcuts(context)
|
||||||
} else if let Some(ref pgr) = self.pager {
|
|
||||||
pgr.get_shortcuts(context)
|
|
||||||
} else {
|
} else {
|
||||||
Default::default()
|
self.pager.get_shortcuts(context)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut our_map = FnvHashMap::with_capacity_and_hasher(4, Default::default());
|
let mut our_map = FnvHashMap::with_capacity_and_hasher(4, Default::default());
|
||||||
|
|
Loading…
Reference in New Issue