Add support for component specific actions for shortcuts
parent
f119789cb0
commit
d763699324
|
@ -32,6 +32,7 @@ pub struct Account {
|
||||||
sent_folder: Option<usize>,
|
sent_folder: Option<usize>,
|
||||||
|
|
||||||
pub settings: AccountSettings,
|
pub settings: AccountSettings,
|
||||||
|
pub runtime_settings: AccountSettings,
|
||||||
pub backend: Box<MailBackend>,
|
pub backend: Box<MailBackend>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +54,8 @@ impl Account {
|
||||||
|
|
||||||
sent_folder: sent_folder,
|
sent_folder: sent_folder,
|
||||||
|
|
||||||
settings: settings,
|
settings: settings.clone(),
|
||||||
|
runtime_settings: settings,
|
||||||
backend: backend,
|
backend: backend,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
const MAX_COLS: usize = 500;
|
const MAX_COLS: usize = 500;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum MailListingAction {
|
||||||
|
ToggleThreaded,
|
||||||
|
}
|
||||||
|
|
||||||
/// A list of all mail (`Envelope`s) in a `Mailbox`. On `\n` it opens the `Envelope` content in a
|
/// A list of all mail (`Envelope`s) in a `Mailbox`. On `\n` it opens the `Envelope` content in a
|
||||||
/// `Pager`.
|
/// `Pager`.
|
||||||
pub struct MailListing {
|
pub struct MailListing {
|
||||||
|
@ -46,7 +51,7 @@ impl MailListing {
|
||||||
self.cursor_pos.1 = self.new_cursor_pos.1;
|
self.cursor_pos.1 = self.new_cursor_pos.1;
|
||||||
self.cursor_pos.0 = self.new_cursor_pos.0;
|
self.cursor_pos.0 = self.new_cursor_pos.0;
|
||||||
|
|
||||||
let threaded = context.accounts[self.cursor_pos.0].settings.threaded;
|
let threaded = context.accounts[self.cursor_pos.0].runtime_settings.threaded;
|
||||||
// Get mailbox as a reference.
|
// Get mailbox as a reference.
|
||||||
let mailbox = &mut context.accounts[self.cursor_pos.0][self.cursor_pos.1].as_ref().unwrap().as_ref().unwrap();
|
let mailbox = &mut context.accounts[self.cursor_pos.0][self.cursor_pos.1].as_ref().unwrap().as_ref().unwrap();
|
||||||
// Inform State that we changed the current folder view.
|
// Inform State that we changed the current folder view.
|
||||||
|
@ -195,7 +200,7 @@ impl MailListing {
|
||||||
self.content = content;
|
self.content = content;
|
||||||
}
|
}
|
||||||
fn highlight_line(&self, grid: &mut CellBuffer, area: Area, idx: usize, context: &Context) {
|
fn highlight_line(&self, grid: &mut CellBuffer, area: Area, idx: usize, context: &Context) {
|
||||||
let threaded = context.accounts[self.cursor_pos.0].settings.threaded;
|
let threaded = context.accounts[self.cursor_pos.0].runtime_settings.threaded;
|
||||||
let mailbox = &context.accounts[self.cursor_pos.0][self.cursor_pos.1].as_ref().unwrap().as_ref().unwrap();
|
let mailbox = &context.accounts[self.cursor_pos.0][self.cursor_pos.1].as_ref().unwrap().as_ref().unwrap();
|
||||||
let envelope: &Envelope = if threaded {
|
let envelope: &Envelope = if threaded {
|
||||||
let i = mailbox.threaded_mail(idx);
|
let i = mailbox.threaded_mail(idx);
|
||||||
|
@ -270,17 +275,17 @@ impl MailListing {
|
||||||
/// Create a pager for the `Envelope` currently under the cursor.
|
/// Create a pager for the `Envelope` currently under the cursor.
|
||||||
fn draw_mail_view(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
fn draw_mail_view(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
||||||
{
|
{
|
||||||
let threaded = context.accounts[self.cursor_pos.0].settings.threaded;
|
let envelope_idx: usize = {
|
||||||
let mailbox = &mut context.accounts[self.cursor_pos.0][self.cursor_pos.1].as_ref().unwrap().as_ref().unwrap();
|
let threaded = context.accounts[self.cursor_pos.0].runtime_settings.threaded;
|
||||||
let envelope: &Envelope = if threaded {
|
let mailbox = &mut context.accounts[self.cursor_pos.0][self.cursor_pos.1].as_ref().unwrap().as_ref().unwrap();
|
||||||
let i = mailbox.threaded_mail(self.cursor_pos.2);
|
if threaded {
|
||||||
&mailbox.collection[i]
|
mailbox.threaded_mail(self.cursor_pos.2)
|
||||||
} else {
|
} else {
|
||||||
&mailbox.collection[self.cursor_pos.2]
|
self.cursor_pos.2
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let pager_filter = context.settings.pager.filter.clone();
|
self.pager = Some(Pager::from_envelope((self.cursor_pos.0, self.cursor_pos.1), envelope_idx, context));
|
||||||
self.pager = Some(Pager::new(&envelope, pager_filter));
|
|
||||||
}
|
}
|
||||||
self.pager.as_mut().map(|p| p.draw(grid, area, context));
|
self.pager.as_mut().map(|p| p.draw(grid, area, context));
|
||||||
}
|
}
|
||||||
|
@ -399,7 +404,7 @@ impl Component for MailListing {
|
||||||
/* Draw header */
|
/* Draw header */
|
||||||
let y =
|
let y =
|
||||||
{
|
{
|
||||||
let threaded = context.accounts[self.cursor_pos.0].settings.threaded;
|
let threaded = context.accounts[self.cursor_pos.0].runtime_settings.threaded;
|
||||||
let mailbox = &mut context.accounts[self.cursor_pos.0][self.cursor_pos.1].as_ref().unwrap().as_ref().unwrap();
|
let mailbox = &mut context.accounts[self.cursor_pos.0][self.cursor_pos.1].as_ref().unwrap().as_ref().unwrap();
|
||||||
let envelope: &Envelope = if threaded {
|
let envelope: &Envelope = if threaded {
|
||||||
let i = mailbox.threaded_mail(self.cursor_pos.2);
|
let i = mailbox.threaded_mail(self.cursor_pos.2);
|
||||||
|
@ -605,6 +610,23 @@ impl Component for MailListing {
|
||||||
UIEventType::Resize => {
|
UIEventType::Resize => {
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
},
|
},
|
||||||
|
UIEventType::Action(ref action) => {
|
||||||
|
eprintln!("got action");
|
||||||
|
match action {
|
||||||
|
Action::MailListing(MailListingAction::ToggleThreaded) => {
|
||||||
|
eprintln!("toggled");
|
||||||
|
context.accounts[self.cursor_pos.0].runtime_settings.threaded = !context.accounts[self.cursor_pos.0].runtime_settings.threaded;
|
||||||
|
self.refresh_mailbox(context);
|
||||||
|
self.dirty = true;
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
|
_ => { unreachable!() },
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
_ => {
|
_ => {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,11 @@ use termion::screen::AlternateScreen;
|
||||||
extern crate nom;
|
extern crate nom;
|
||||||
use chan::Sender;
|
use chan::Sender;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Action {
|
||||||
|
MailListing(MailListingAction),
|
||||||
|
}
|
||||||
|
|
||||||
/// `ThreadEvent` encapsulates all of the possible values we need to transfer between our threads
|
/// `ThreadEvent` encapsulates all of the possible values we need to transfer between our threads
|
||||||
/// to the main process.
|
/// to the main process.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -100,6 +105,7 @@ pub enum UIEventType {
|
||||||
Command(String),
|
Command(String),
|
||||||
Notification(String),
|
Notification(String),
|
||||||
EditDraft(std::path::PathBuf),
|
EditDraft(std::path::PathBuf),
|
||||||
|
Action(Action),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -139,6 +145,8 @@ pub struct Notification {
|
||||||
pub struct Context {
|
pub struct Context {
|
||||||
pub accounts: Vec<Account>,
|
pub accounts: Vec<Account>,
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
|
|
||||||
|
runtime_settings: Settings,
|
||||||
/// Areas of the screen that must be redrawn in the next render
|
/// Areas of the screen that must be redrawn in the next render
|
||||||
dirty_areas: VecDeque<Area>,
|
dirty_areas: VecDeque<Area>,
|
||||||
|
|
||||||
|
@ -210,7 +218,8 @@ impl<W: Write> State<W> {
|
||||||
context: Context {
|
context: Context {
|
||||||
accounts: accounts,
|
accounts: accounts,
|
||||||
backends: backends,
|
backends: backends,
|
||||||
settings: settings,
|
settings: settings.clone(),
|
||||||
|
runtime_settings: settings,
|
||||||
dirty_areas: VecDeque::with_capacity(5),
|
dirty_areas: VecDeque::with_capacity(5),
|
||||||
replies: VecDeque::with_capacity(5),
|
replies: VecDeque::with_capacity(5),
|
||||||
|
|
||||||
|
@ -352,7 +361,12 @@ impl<W: Write> State<W> {
|
||||||
eprintln!("{}",String::from_utf8_lossy(&output.stdout));
|
eprintln!("{}",String::from_utf8_lossy(&output.stdout));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
},
|
||||||
|
UIEventType::Input(Key::Char('t')) =>
|
||||||
|
for i in 0..self.entities.len() {
|
||||||
|
self.entities[i].rcv_event(&UIEvent{ id: 0, event_type: UIEventType::Action(Action::MailListing(MailListingAction::ToggleThreaded)) }, &mut self.context);
|
||||||
|
}
|
||||||
|
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
/* inform each entity */
|
/* inform each entity */
|
||||||
|
|
Loading…
Reference in New Issue