summaryrefslogtreecommitdiffstats
path: root/src/main_view.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main_view.rs')
-rw-r--r--src/main_view.rs78
1 files changed, 46 insertions, 32 deletions
diff --git a/src/main_view.rs b/src/main_view.rs
index 8425872..c0dcd08 100644
--- a/src/main_view.rs
+++ b/src/main_view.rs
@@ -16,24 +16,38 @@ use cursive::views::NamedView;
use cursive::views::ResizedView;
use cursive::traits::Resizable;
use cursive_multiplex::Mux;
+use cursive::view::SizeConstraint;
+use cursive::event::Key;
+use getset::{Getters, MutGetters};
use crate::configuration::Configuration;
use crate::maillist_view::MaillistView;
use crate::maillist_view::MailListingData;
+use crate::bindings::Bindings;
+use crate::bindings::BindingCaller;
pub const MAIN_VIEW_NAME: &'static str = "main_view";
pub const MAIN_MUX_NAME: &'static str = "main_mux";
pub const MAIN_MAIL_LIST_NAME: &'static str = "main_mail_list";
+#[derive(Getters, MutGetters)]
pub struct MainView {
config: Configuration,
muxroot: cursive_multiplex::Id,
+
+ #[getset(get = "pub", get_mut = "pub")]
tabs: cursive_tabs::TabPanel<String>,
+
+ bindings: Bindings,
+ bindings_caller: Option<ResizedView<NamedView<BindingCaller>>>,
}
impl View for MainView {
fn draw(&self, printer: &Printer) {
- self.tabs.draw(printer)
+ self.tabs.draw(printer);
+ if let Some(caller) = self.bindings_caller.as_ref() {
+ caller.draw(printer);
+ }
}
fn layout(&mut self, xy: XY<usize>) {
@@ -49,35 +63,34 @@ impl View for MainView {
}
fn on_event(&mut self, e: Event) -> EventResult {
- match e {
- Event::Char('q') => {
- if self.tabs.tab_order().len() == 1 {
- EventResult::Ignored
- } else {
- if let Some(key) = self.tabs.active_tab().cloned() {
- debug!("Removing tab: {}", key);
- if let Err(e) = self.tabs.remove_tab(&key) {
- error!("{:?}", e); // TODO do more than just logging
- }
- debug!("Remove tab");
- EventResult::Consumed(None)
- } else {
- debug!("No tab to remove found.");
- EventResult::Ignored
- }
- }
- },
-
- Event::Key(cursive::event::Key::Enter) => {
- let muxroot = self.muxroot.clone();
- EventResult::Consumed(Some(Callback::from_fn(move |siv| Self::add_mailview(siv, muxroot))))
- },
-
- Event::Char('o') => {
- EventResult::Consumed(Some(Callback::from_fn(MainView::add_notmuch_query_layer)))
+ debug!("Received event: {:?}", e);
+ match self.bindings_caller.as_mut() {
+ Some(caller) => match e {
+ Event::Key(Key::Esc) => {
+ self.bindings_caller = None;
+ debug!("Escape. Resetting bindings caller.");
+ EventResult::Consumed(None)
+ },
+ other => {
+ debug!("Forwarding event to bindings caller");
+ caller.on_event(other)
+ },
},
-
- other => self.tabs.on_event(other),
+ None => match e {
+ Event::Char(':') => {
+ debug!(": -> Constructing bindings caller.");
+ self.bindings_caller = Some({
+ self.bindings.caller()
+ .with_name(crate::bindings::BINDINGS_CALLER)
+ .resized(SizeConstraint::Full, SizeConstraint::AtLeast(5))
+ });
+ EventResult::Consumed(None)
+ },
+ other => {
+ debug!("Forwarding event to tabs");
+ self.tabs.on_event(other)
+ },
+ }
}
}
@@ -105,7 +118,6 @@ impl View for MainView {
impl MainView {
pub fn new(config: Configuration) -> Result<NamedView<Self>> {
- use cursive::view::SizeConstraint;
let mut tab = cursive_multiplex::Mux::new();
let muxroot = tab.root().build().unwrap();
@@ -123,7 +135,9 @@ impl MainView {
.with_bar_placement(cursive_tabs::Placement::HorizontalTop)
.with_tab(config.notmuch_default_query().clone(), tab.with_name(MAIN_MUX_NAME));
- Ok(MainView { config, muxroot, tabs }.with_name(MAIN_VIEW_NAME))
+ let bindings = crate::bindings::get_bindings();
+
+ Ok(MainView { config, muxroot, tabs, bindings, bindings_caller: None }.with_name(MAIN_VIEW_NAME))
}
pub fn add_tab<T: View>(&mut self, id: String, view: T) {
@@ -134,7 +148,7 @@ impl MainView {
&self.config
}
- fn add_notmuch_query_layer(siv: &mut Cursive) {
+ pub fn add_notmuch_query_layer(siv: &mut Cursive) {
use crate::util::dialog_for;
use crate::util::error_dialog_for;