ui: add statusbar change with tab switch and updates
parent
059d86de93
commit
5ddd68ad9f
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue