Browse Source

ui: add envelope views in new tab action

tags/pre-alpha-0.3.0
Manos Pitsidianakis 2 years ago
parent
commit
af38b7e7cb
Signed by untrusted user: epilys GPG Key ID: 73627C2F690DF710
  1. 28
      ui/src/components/mail/view.rs
  2. 25
      ui/src/components/mail/view/thread.rs
  3. 6
      ui/src/components/utilities.rs
  4. 13
      ui/src/execute.rs
  5. 1
      ui/src/execute/actions.rs

28
ui/src/components/mail/view.rs

@ -37,7 +37,7 @@ pub use self::envelope::*;
use mime_apps::query_default_app;
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Debug, Clone)]
enum ViewMode {
Normal,
Url,
@ -77,6 +77,18 @@ pub struct MailView {
id: ComponentId,
}
impl Clone for MailView {
fn clone(&self) -> Self {
MailView {
subview: None,
cmd_buf: String::with_capacity(4),
pager: self.pager.clone(),
mode: self.mode.clone(),
..*self
}
}
}
impl fmt::Display for MailView {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// TODO display subject/info
@ -974,6 +986,12 @@ impl Component for MailView {
}
}
}
UIEvent::Action(Listing(OpenInNewTab)) => {
context
.replies
.push_back(UIEvent::Action(Tab(New(Some(Box::new(self.clone()))))));
return true;
}
_ => {}
}
false
@ -1035,7 +1053,15 @@ impl Component for MailView {
fn id(&self) -> ComponentId {
self.id
}
fn set_id(&mut self, id: ComponentId) {
self.id = id;
}
fn kill(&mut self, id: ComponentId, context: &mut Context) {
debug_assert!(self.id == id);
context
.replies
.push_back(UIEvent::Action(Tab(Kill(self.id))));
}
}

25
ui/src/components/mail/view/thread.rs

@ -44,7 +44,7 @@ struct ThreadEntry {
heading: String,
}
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct ThreadView {
new_cursor_pos: usize,
cursor_pos: usize,
@ -896,9 +896,24 @@ impl Component for ThreadView {
}
}
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
match event {
UIEvent::Action(Listing(OpenInNewTab)) => {
/* Handle this before self.mailview does */
context
.replies
.push_back(UIEvent::Action(Tab(New(Some(Box::new(Self {
initiated: false,
..self.clone()
}))))));
return true;
}
_ => {}
}
if self.show_mailview && self.mailview.process_event(event, context) {
return true;
}
let shortcuts = &self.get_shortcuts(context)[ThreadView::DESCRIPTION];
match *event {
UIEvent::Input(Key::Char('R')) => {
@ -1102,7 +1117,15 @@ impl Component for ThreadView {
fn id(&self) -> ComponentId {
self.id
}
fn set_id(&mut self, id: ComponentId) {
self.id = id;
}
fn kill(&mut self, id: ComponentId, context: &mut Context) {
debug_assert!(self.id == id);
context
.replies
.push_back(UIEvent::Action(Tab(Kill(self.id))));
}
}

6
ui/src/components/utilities.rs

@ -263,7 +263,7 @@ impl Component for VSplit {
}
}
#[derive(Debug)]
#[derive(Debug, Clone, Copy)]
pub enum PageMovement {
Home,
PageUp,
@ -274,7 +274,7 @@ pub enum PageMovement {
/// A pager for text.
/// `Pager` holds its own content in its own `CellBuffer` and when `draw` is called, it draws the
/// current view of the text. It is responsible for scrolling etc.
#[derive(Default, Debug)]
#[derive(Default, Debug, Clone)]
pub struct Pager {
text: String,
cursor_pos: usize,
@ -1393,7 +1393,7 @@ impl Component for Tabbed {
type EntryIdentifier = Vec<u8>;
/// Shows selection to user
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct Selector {
single_only: bool,
/// allow only one selection

13
ui/src/execute.rs

@ -285,6 +285,17 @@ define_commands!([
)
);
)
},
{ tags: ["open-in-tab"],
desc: "opens envelope view in new tab",
parser:(
named!( open_in_new_tab<Action>,
do_parse!(
ws!(tag!("open-in-tab"))
>> (Listing(OpenInNewTab))
)
);
)
}
]);
@ -334,7 +345,7 @@ named!(
named!(
listing_action<Action>,
alt_complete!(toggle | envelope_action | filter | toggle_thread_snooze)
alt_complete!(toggle | envelope_action | filter | toggle_thread_snooze | open_in_new_tab)
);
named!(

1
ui/src/execute/actions.rs

@ -42,6 +42,7 @@ pub enum ListingAction {
SetSeen,
SetUnseen,
Delete,
OpenInNewTab,
}
#[derive(Debug)]

Loading…
Cancel
Save