summaryrefslogtreecommitdiffstats
path: root/ui/src/components/mail/view
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-04-10 23:37:20 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-10 19:40:44 +0300
commit9bc76e3bcb837352b9c31d8875514d9974b84119 (patch)
tree2d7db5426d690f5868f304fa7b614c615e0585a8 /ui/src/components/mail/view
parent106744c7ca4e5444d993a04c23bc04d93e2bfa6a (diff)
ui: unwrap UIEventType
Diffstat (limited to 'ui/src/components/mail/view')
-rw-r--r--ui/src/components/mail/view/envelope.rs100
-rw-r--r--ui/src/components/mail/view/html.rs43
-rw-r--r--ui/src/components/mail/view/thread.rs42
3 files changed, 78 insertions, 107 deletions
diff --git a/ui/src/components/mail/view/envelope.rs b/ui/src/components/mail/view/envelope.rs
index 13217a5f..4d391d74 100644
--- a/ui/src/components/mail/view/envelope.rs
+++ b/ui/src/components/mail/view/envelope.rs
@@ -107,16 +107,13 @@ impl EnvelopeView {
.stdout(Stdio::piped())
.spawn();
if command_obj.is_err() {
- context.replies.push_back(UIEvent {
- id: 0,
- event_type: UIEventType::Notification(
- Some(format!(
- "Failed to start html filter process: {}",
- filter_invocation,
- )),
- String::new(),
- ),
- });
+ context.replies.push_back(UIEvent::Notification(
+ Some(format!(
+ "Failed to start html filter process: {}",
+ filter_invocation,
+ )),
+ String::new(),
+ ));
return;
}
@@ -372,20 +369,19 @@ impl Component for EnvelopeView {
return true;
}
}
- match event.event_type {
- UIEventType::Input(Key::Esc) | UIEventType::Input(Key::Alt('')) => {
+ match *event {
+ UIEvent::Input(Key::Esc) | UIEvent::Input(Key::Alt('')) => {
self.cmd_buf.clear();
- context.replies.push_back(UIEvent {
- id: 0,
- event_type: UIEventType::StatusEvent(StatusEvent::BufClear),
- });
+ context
+ .replies
+ .push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
return true;
}
- UIEventType::Input(Key::Char(c)) if c >= '0' && c <= '9' => {
+ UIEvent::Input(Key::Char(c)) if c >= '0' && c <= '9' => {
self.cmd_buf.push(c);
return true;
}
- UIEventType::Input(Key::Char('r'))
+ UIEvent::Input(Key::Char('r'))
if self.mode == ViewMode::Normal || self.mode == ViewMode::Raw =>
{
self.mode = if self.mode == ViewMode::Raw {
@@ -396,7 +392,7 @@ impl Component for EnvelopeView {
self.dirty = true;
return true;
}
- UIEventType::Input(Key::Char('r'))
+ UIEvent::Input(Key::Char('r'))
if self.mode.is_attachment() || self.mode == ViewMode::Subview =>
{
self.mode = ViewMode::Normal;
@@ -404,15 +400,14 @@ impl Component for EnvelopeView {
self.dirty = true;
return true;
}
- UIEventType::Input(Key::Char('a'))
+ UIEvent::Input(Key::Char('a'))
if !self.cmd_buf.is_empty() && self.mode == ViewMode::Normal =>
{
let lidx = self.cmd_buf.parse::<usize>().unwrap();
self.cmd_buf.clear();
- context.replies.push_back(UIEvent {
- id: 0,
- event_type: UIEventType::StatusEvent(StatusEvent::BufClear),
- });
+ context
+ .replies
+ .push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
{
let envelope: &Envelope = self.wrapper.envelope();
@@ -437,15 +432,11 @@ impl Component for EnvelopeView {
self.dirty = true;
}
ContentType::Multipart { .. } => {
- context.replies.push_back(UIEvent {
- id: 0,
- event_type: UIEventType::StatusEvent(
- StatusEvent::DisplayMessage(
- "Multipart attachments are not supported yet."
- .to_string(),
- ),
+ context.replies.push_back(UIEvent::StatusEvent(
+ StatusEvent::DisplayMessage(
+ "Multipart attachments are not supported yet.".to_string(),
),
- });
+ ));
return true;
}
ContentType::Unsupported { .. } => {
@@ -463,40 +454,36 @@ impl Component for EnvelopeView {
});
context.temp_files.push(p);
} else {
- context.replies.push_back(UIEvent {
- id: 0,
- event_type: UIEventType::StatusEvent(
- StatusEvent::DisplayMessage(format!(
- "Couldn't find a default application for type {}",
- attachment_type
- )),
- ),
- });
+ context.replies.push_back(UIEvent::StatusEvent(
+ StatusEvent::DisplayMessage(format!(
+ "Couldn't find a default application for type {}",
+ attachment_type
+ )),
+ ));
return true;
}
}
}
} else {
- context.replies.push_back(UIEvent {
- id: 0,
- event_type: UIEventType::StatusEvent(StatusEvent::DisplayMessage(
- format!("Attachment `{}` not found.", lidx),
+ context.replies.push_back(UIEvent::StatusEvent(
+ StatusEvent::DisplayMessage(format!(
+ "Attachment `{}` not found.",
+ lidx
)),
- });
+ ));
return true;
}
};
return true;
}
- UIEventType::Input(Key::Char('g'))
+ UIEvent::Input(Key::Char('g'))
if !self.cmd_buf.is_empty() && self.mode == ViewMode::Url =>
{
let lidx = self.cmd_buf.parse::<usize>().unwrap();
self.cmd_buf.clear();
- context.replies.push_back(UIEvent {
- id: 0,
- event_type: UIEventType::StatusEvent(StatusEvent::BufClear),
- });
+ context
+ .replies
+ .push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
let url = {
let envelope: &Envelope = self.wrapper.envelope();
let finder = LinkFinder::new();
@@ -508,12 +495,9 @@ impl Component for EnvelopeView {
if let Some(u) = links.get(lidx) {
u.as_str().to_string()
} else {
- context.replies.push_back(UIEvent {
- id: 0,
- event_type: UIEventType::StatusEvent(StatusEvent::DisplayMessage(
- format!("Link `{}` not found.", lidx),
- )),
- });
+ context.replies.push_back(UIEvent::StatusEvent(
+ StatusEvent::DisplayMessage(format!("Link `{}` not found.", lidx)),
+ ));
return true;
}
};
@@ -526,7 +510,7 @@ impl Component for EnvelopeView {
.expect("Failed to start xdg_open");
return true;
}
- UIEventType::Input(Key::Char('u')) => {
+ UIEvent::Input(Key::Char('u')) => {
match self.mode {
ViewMode::Normal => self.mode = ViewMode::Url,
ViewMode::Url => self.mode = ViewMode::Normal,
diff --git a/ui/src/components/mail/view/html.rs b/ui/src/components/mail/view/html.rs
index c5e5cfab..c711df5b 100644
--- a/ui/src/components/mail/view/html.rs
+++ b/ui/src/components/mail/view/html.rs
@@ -43,16 +43,13 @@ impl HtmlView {
.stdout(Stdio::piped())
.spawn();
if command_obj.is_err() {
- context.replies.push_back(UIEvent {
- id: 0,
- event_type: UIEventType::Notification(
- Some(format!(
- "Failed to start html filter process: {}",
- filter_invocation
- )),
- String::new(),
- ),
- });
+ context.replies.push_back(UIEvent::Notification(
+ Some(format!(
+ "Failed to start html filter process: {}",
+ filter_invocation
+ )),
+ String::new(),
+ ));
let pager = Pager::from_string(
String::from_utf8_lossy(&bytes).to_string(),
None,
@@ -102,15 +99,12 @@ impl HtmlView {
let pager = Pager::from_string(display_text, None, None, None);
HtmlView { pager, bytes, id }
} else {
- context.replies.push_back(UIEvent {
- id: 0,
- event_type: UIEventType::Notification(
- Some(format!(
- "Failed to find any application to use as html filter"
- )),
- String::new(),
- ),
- });
+ context.replies.push_back(UIEvent::Notification(
+ Some(format!(
+ "Failed to find any application to use as html filter"
+ )),
+ String::new(),
+ ));
let pager = Pager::from_string(
String::from_utf8_lossy(&bytes).to_string(),
None,
@@ -139,7 +133,7 @@ impl Component for HtmlView {
return true;
}
- if let UIEventType::Input(Key::Char('v')) = event.event_type {
+ if let UIEvent::Input(Key::Char('v')) = event {
// TODO: Optional filter that removes outgoing resource requests (images and
// scripts)
let binary = query_default_app("text/html");
@@ -153,12 +147,11 @@ impl Component for HtmlView {
.unwrap_or_else(|_| panic!("Failed to start {}", binary.display()));
context.temp_files.push(p);
} else {
- context.replies.push_back(UIEvent {
- id: 0,
- event_type: UIEventType::StatusEvent(StatusEvent::DisplayMessage(
+ context
+ .replies
+ .push_back(UIEvent::StatusEvent(StatusEvent::DisplayMessage(
"Couldn't find a default application for html files.".to_string(),
- )),
- });
+ )));
}
return true;
}
diff --git a/ui/src/components/mail/view/thread.rs b/ui/src/components/mail/view/thread.rs
index d5d2986f..21376337 100644
--- a/ui/src/components/mail/view/thread.rs
+++ b/ui/src/components/mail/view/thread.rs
@@ -847,18 +847,15 @@ impl Component for ThreadView {
if self.mailview.process_event(event, context) {
return true;
}
- match event.event_type {
- UIEventType::Input(Key::Char('R')) => {
- context.replies.push_back(UIEvent {
- id: 0,
- event_type: UIEventType::Action(Tab(Reply(
- self.coordinates,
- self.entries[self.expanded_pos].index.1,
- ))),
- });
+ match *event {
+ UIEvent::Input(Key::Char('R')) => {
+ context.replies.push_back(UIEvent::Action(Tab(Reply(
+ self.coordinates,
+ self.entries[self.expanded_pos].index.1,
+ ))));
return true;
}
- UIEventType::Input(Key::Char('e')) => {
+ UIEvent::Input(Key::Char('e')) => {
{
let mailbox = &context.accounts[self.coordinates.0][self.coordinates.1]
.as_ref()
@@ -884,29 +881,26 @@ impl Component for ThreadView {
);
}
}
- context.replies.push_back(UIEvent {
- id: 0,
- event_type: UIEventType::Action(Tab(Edit(
- self.coordinates,
- self.entries[self.expanded_pos].index.1,
- ))),
- });
+ context.replies.push_back(UIEvent::Action(Tab(Edit(
+ self.coordinates,
+ self.entries[self.expanded_pos].index.1,
+ ))));
return true;
}
- UIEventType::Input(Key::Up) => {
+ UIEvent::Input(Key::Up) => {
if self.cursor_pos > 0 {
self.new_cursor_pos = self.new_cursor_pos.saturating_sub(1);
}
return true;
}
- UIEventType::Input(Key::Down) => {
+ UIEvent::Input(Key::Down) => {
let height = self.visible_entries.iter().flat_map(|v| v.iter()).count();
if height > 0 && self.new_cursor_pos + 1 < height {
self.new_cursor_pos += 1;
}
return true;
}
- UIEventType::Input(Key::Char('\n')) => {
+ UIEvent::Input(Key::Char('\n')) => {
if self.entries.len() < 2 {
return true;
}
@@ -916,13 +910,13 @@ impl Component for ThreadView {
self.set_dirty();
return true;
}
- UIEventType::Input(Key::Char('p')) => {
+ UIEvent::Input(Key::Char('p')) => {
self.show_mailview = !self.show_mailview;
self.initiated = false;
self.mailview.set_dirty();
return true;
}
- UIEventType::Input(Key::Ctrl('r')) => {
+ UIEvent::Input(Key::Ctrl('r')) => {
self.reversed = !self.reversed;
let expanded_pos = self.expanded_pos;
self.initiate(Some(expanded_pos), context);
@@ -930,7 +924,7 @@ impl Component for ThreadView {
self.dirty = true;
return true;
}
- UIEventType::Input(Key::Char('h')) => {
+ UIEvent::Input(Key::Char('h')) => {
let current_pos = self.current_pos();
self.entries[current_pos].hidden = !self.entries[current_pos].hidden;
self.entries[current_pos].dirty = true;
@@ -960,7 +954,7 @@ impl Component for ThreadView {
self.dirty = true;
return true;
}
- UIEventType::Resize => {
+ UIEvent::Resize => {
self.set_dirty();
}
_ => {}