browse: shortcut to view mail fullscreen

This commit is contained in:
FliegendeWurst 2021-04-20 21:32:13 +02:00 committed by Arne Keller
parent 7e7d6b616e
commit 9a9b852bc5

View File

@ -1,8 +1,8 @@
#![feature(internal_output_capture)] #![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::align::HAlign;
use cursive::event::{Event, Key}; use cursive::event::{Event, Key};
use cursive::traits::Identifiable; 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 tree_resized = ResizedView::new(SizeConstraint::AtMost(120), SizeConstraint::Free, tree);
let mail_info = MailInfoView::new().with_name("mail_info"); 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::<ResizedView<OnEventView<NamedView<TextView>>>>() {
dummy__.borrow_mut().replace(textview.into_inner().unwrap_or_else(|_| panic!("?")));
s.call_on_name("mail_event_host", move |this: &mut OnEventView<NamedView<TextView>>| {
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<NamedView<TextView>>| {
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::<MailPart>::new(); let mut mail_part_select = TreeView::<MailPart>::new();
mail_part_select.set_on_select(|siv, row| { mail_part_select.set_on_select(|siv, row| {
let mail = siv.call_on_name("part_select", |tree: &mut TreeView<MailPart>| { let mail = siv.call_on_name("part_select", |tree: &mut TreeView<MailPart>| {