From 9a9b852bc51e09312c985e66fe13ed36826e086b Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Tue, 20 Apr 2021 21:32:13 +0200 Subject: [PATCH] browse: shortcut to view mail fullscreen --- src/bin/browse.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/bin/browse.rs b/src/bin/browse.rs index 2f9cdb8..e67d9d8 100644 --- a/src/bin/browse.rs +++ b/src/bin/browse.rs @@ -1,8 +1,8 @@ #![feature(internal_output_capture)] -use std::{cell::RefCell, cmp, collections::{HashMap, HashSet}, env, fmt::Display, io, sync::Arc}; +use std::{cell::RefCell, cmp, collections::{HashMap, HashSet}, env, fmt::Display, io, sync::{Arc, atomic::{AtomicBool, Ordering}}}; -use cursive::{Cursive, Vec2}; +use cursive::{Cursive, Vec2, view::ViewWrapper}; use cursive::align::HAlign; use cursive::event::{Event, Key}; use cursive::traits::Identifiable; @@ -286,7 +286,31 @@ fn show_listing(mailbox: &str) -> Result<()> { }); let tree_resized = ResizedView::new(SizeConstraint::AtMost(120), SizeConstraint::Free, tree); let mail_info = MailInfoView::new().with_name("mail_info"); - let mail_content = TextView::new("").with_name("mail").scrollable().with_name("mail_scroller"); + let mail_content = TextView::new("").with_name("mail"); + static MAIL_FULLSCREEN: AtomicBool = AtomicBool::new(false); + let dummy = std::rc::Rc::new(RefCell::new(Some(OnEventView::new(TextView::new("dummy").with_name("dummy"))))); // TODO dummy content + let dummy_ = dummy.clone(); + let mail_content = OnEventView::new(mail_content) + .on_event('f', move |s| { + let dummy__ = dummy_.clone(); + if MAIL_FULLSCREEN.load(Ordering::SeqCst) { + let layer = s.pop_layer().unwrap(); + if let Ok(textview) = layer.downcast::>>>() { + dummy__.borrow_mut().replace(textview.into_inner().unwrap_or_else(|_| panic!("?"))); + s.call_on_name("mail_event_host", move |this: &mut OnEventView>| { + std::mem::swap(dummy__.borrow_mut().as_mut().unwrap(), this); + }); + } + MAIL_FULLSCREEN.store(false, Ordering::SeqCst); + } else { + s.call_on_name("mail_event_host", move |this: &mut OnEventView>| { + std::mem::swap(dummy__.borrow_mut().as_mut().unwrap(), this); + }); + s.add_fullscreen_layer(ResizedView::with_full_screen(dummy_.borrow_mut().take().unwrap())); + MAIL_FULLSCREEN.store(true, Ordering::SeqCst); + } + }).with_name("mail_event_host"); + let mail_content = mail_content.scrollable().with_name("mail_scroller"); let mut mail_part_select = TreeView::::new(); mail_part_select.set_on_select(|siv, row| { let mail = siv.call_on_name("part_select", |tree: &mut TreeView| {