summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-09-15 09:41:52 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-09-15 23:38:31 +0300
commit5ddd68ad9f32ae4be4a6ec5f15f6724d7aa8a2a5 (patch)
tree7b8cb5328eec77ff3e3730a5207ca463cd232537
parent059d86de9338817c73ec75c47c3eebbc9e84004b (diff)
ui: add statusbar change with tab switch and updates
-rw-r--r--ui/src/components.rs4
-rw-r--r--ui/src/components/mail/listing.rs57
-rw-r--r--ui/src/components/utilities.rs35
-rw-r--r--ui/src/types.rs1
4 files changed, 74 insertions, 23 deletions
diff --git a/ui/src/components.rs b/ui/src/components.rs
index fd8faaf8..bc56f14a 100644
--- a/ui/src/components.rs
+++ b/ui/src/components.rs
@@ -100,6 +100,10 @@ pub trait Component: Display + Debug + Send {
fn get_shortcuts(&self, _context: &Context) -> ShortcutMaps {
Default::default()
}
+
+ fn get_status(&self, _context: &Context) -> Option<String> {
+ None
+ }
}
/*
diff --git a/ui/src/components/mail/listing.rs b/ui/src/components/mail/listing.rs
index 9533b94b..2feb7259 100644
--- a/ui/src/components/mail/listing.rs
+++ b/ui/src/components/mail/listing.rs
@@ -295,6 +295,11 @@ impl Component for Listing {
context
.replies
.push_back(UIEvent::RefreshMailbox((self.cursor_pos.0, folder_hash)));
+ context
+ .replies
+ .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus(
+ self.get_status(context).unwrap(),
+ )));
return true;
}
UIEvent::Input(ref k)
@@ -335,6 +340,11 @@ impl Component for Listing {
context
.replies
.push_back(UIEvent::RefreshMailbox((self.cursor_pos.0, folder_hash)));
+ context
+ .replies
+ .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus(
+ self.get_status(context).unwrap(),
+ )));
return true;
}
UIEvent::Action(ref action) => match action {
@@ -365,6 +375,11 @@ impl Component for Listing {
.position(|&h| h == folder_hash)
.unwrap_or(0),
);
+ context
+ .replies
+ .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus(
+ self.get_status(context).unwrap(),
+ )));
self.dirty = true;
}
UIEvent::ChangeMode(UIMode::Normal) => {
@@ -385,9 +400,19 @@ impl Component for Listing {
}
UIEvent::StartupCheck(_) => {
self.dirty = true;
+ context
+ .replies
+ .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus(
+ self.get_status(context).unwrap(),
+ )));
}
UIEvent::MailboxUpdate(_) => {
self.dirty = true;
+ context
+ .replies
+ .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus(
+ self.get_status(context).unwrap(),
+ )));
}
_ => {}
}
@@ -489,6 +514,38 @@ impl Component for Listing {
Conversations(ref mut l) => l.set_id(id),
}
}
+
+ fn get_status(&self, context: &Context) -> Option<String> {
+ Some({
+ let folder_hash = if let Some(h) = context.accounts[self.cursor_pos.0]
+ .folders_order
+ .get(self.cursor_pos.1)
+ {
+ *h
+ } else {
+ return Some(String::new());
+ };
+ if !context.accounts[self.cursor_pos.0].folders[&folder_hash].is_available() {
+ return Some(String::new());
+ }
+ let account = &context.accounts[self.cursor_pos.0];
+ let m = if account[self.cursor_pos.1].is_available() {
+ account[self.cursor_pos.1].unwrap()
+ } else {
+ return Some(String::new());
+ };
+ format!(
+ "Mailbox: {}, Messages: {}, New: {}",
+ m.folder.name(),
+ m.envelopes.len(),
+ m.envelopes
+ .iter()
+ .map(|h| &account.collection[&h])
+ .filter(|e| !e.is_seen())
+ .count()
+ )
+ })
+ }
}
impl From<IndexStyle> for ListingComponent {
diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs
index 5c66c895..4b676385 100644
--- a/ui/src/components/utilities.rs
+++ b/ui/src/components/utilities.rs
@@ -929,29 +929,7 @@ impl Component for StatusBar {
return true;
}
- match &event {
- UIEvent::RefreshMailbox((ref idx_a, ref idx_f)) => {
- match context.accounts[*idx_a].status(*idx_f) {
- Ok(_) => {}
- Err(_) => {
- return false;
- }
- }
- let account = &context.accounts[*idx_a];
- let m = &account[*idx_f].unwrap();
- self.status = format!(
- "{} | Mailbox: {}, Messages: {}, New: {}",
- self.mode,
- m.folder.name(),
- m.envelopes.len(),
- m.envelopes
- .iter()
- .map(|h| &account.collection[&h])
- .filter(|e| !e.is_seen())
- .count()
- );
- self.dirty = true;
- }
+ match event {
UIEvent::ChangeMode(m) => {
let offset = self.status.find('|').unwrap_or_else(|| self.status.len());
self.status.replace_range(..offset, &format!("{} ", m));
@@ -1038,6 +1016,10 @@ impl Component for StatusBar {
self.display_buffer = s.clone();
self.dirty = true;
}
+ UIEvent::StatusEvent(StatusEvent::UpdateStatus(ref mut s)) => {
+ self.status = format!("{} | {}", self.mode, std::mem::replace(s, String::new()));
+ self.dirty = true;
+ }
_ => {}
}
false
@@ -1321,6 +1303,13 @@ impl Component for Tabbed {
match *event {
UIEvent::Input(Key::Char('T')) => {
self.cursor_pos = (self.cursor_pos + 1) % self.children.len();
+ context
+ .replies
+ .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus(
+ self.children[self.cursor_pos]
+ .get_status(context)
+ .unwrap_or_default(),
+ )));
self.set_dirty();
return true;
}
diff --git a/ui/src/types.rs b/ui/src/types.rs
index 174fa9ad..24e5ba25 100644
--- a/ui/src/types.rs
+++ b/ui/src/types.rs
@@ -38,6 +38,7 @@ pub enum StatusEvent {
DisplayMessage(String),
BufClear,
BufSet(String),
+ UpdateStatus(String),
}
/// `ThreadEvent` encapsulates all of the possible values we need to transfer between our threads