diff options
author | rabite <rabite@posteo.de> | 2019-05-28 00:50:15 +0200 |
---|---|---|
committer | rabite <rabite@posteo.de> | 2019-05-28 00:51:47 +0200 |
commit | ad4e3d573fffe2412c7840319c39ca4a64c02b56 (patch) | |
tree | 06a8e64a71859fbb448cc37e523b8bcc8ab606d2 /src | |
parent | fdc4eb52d0403e041fe77f403b0dbc5686789087 (diff) |
add quick actions
Diffstat (limited to 'src')
-rw-r--r-- | src/file_browser.rs | 19 | ||||
-rw-r--r-- | src/foldview.rs | 43 | ||||
-rw-r--r-- | src/hbox.rs | 2 | ||||
-rw-r--r-- | src/listview.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 2 | ||||
-rw-r--r-- | src/paths.rs | 6 | ||||
-rw-r--r-- | src/preview.rs | 2 | ||||
-rw-r--r-- | src/proclist.rs | 4 | ||||
-rw-r--r-- | src/textview.rs | 2 |
9 files changed, 61 insertions, 21 deletions
diff --git a/src/file_browser.rs b/src/file_browser.rs index ad15d01..b8d15dd 100644 --- a/src/file_browser.rs +++ b/src/file_browser.rs @@ -468,6 +468,7 @@ impl FileBrowser { cmd: OsString::from(file.strip_prefix(&cwd)), short_cmd: None, args: None, + vars: None, cwd: cwd.clone(), cwd_files: None, tab_files: None, @@ -1084,6 +1085,7 @@ impl FileBrowser { cmd: OsString::from(cmd), short_cmd: None, args: None, + vars: None, cwd: cwd, cwd_files: cwd_files, tab_files: Some(tab_files), @@ -1135,6 +1137,22 @@ impl FileBrowser { Ok(()) } + pub fn quick_action(&self) -> HResult<()> { + let files = self.selected_files()?; + let files = if files.len() > 0 { files } + else { vec![self.selected_file()?.clone()] }; + + let sender = self.core.get_sender(); + let core = self.preview_widget()?.get_core()?.clone(); + let proc_view = self.proc_view.clone(); + + crate::quick_actions::open(files, + sender, + core, + proc_view)?; + Ok(()) + } + pub fn get_footer(&self) -> HResult<String> { let xsize = self.get_coordinates()?.xsize(); let ypos = self.get_coordinates()?.position().y(); @@ -1263,6 +1281,7 @@ impl Widget for FileBrowser { fn on_key(&mut self, key: Key) -> HResult<()> { match key { + Key::Char('a') => self.quick_action()?, Key::Char(']') => self.move_down_left_widget()?, Key::Char('[') => self.move_up_left_widget()?, Key::Alt(' ') => self.external_select()?, diff --git a/src/foldview.rs b/src/foldview.rs index b060bb5..84dad2b 100644 --- a/src/foldview.rs +++ b/src/foldview.rs @@ -21,7 +21,7 @@ pub struct LogEntry { impl Foldable for LogEntry { - fn description(&self) -> &String { + fn description(&self) -> &str { &self.description } fn content(&self) -> Option<&String> { @@ -87,6 +87,8 @@ pub trait FoldableWidgetExt { fn on_refresh(&mut self) -> HResult<()> { Ok(()) } fn render_header(&self) -> HResult<String> { Ok("".to_string()) } fn render_footer(&self) -> HResult<String> { Ok("".to_string()) } + fn on_key(&mut self, _key: Key) -> HResult<()> { Ok(()) } + fn render(&self) -> Vec<String> { vec![] } } impl FoldableWidgetExt for ListView<Vec<LogEntry>> { @@ -162,16 +164,18 @@ impl LogList for Vec<LogEntry> { pub trait Foldable { - fn description(&self) -> &String; + fn description(&self) -> &str; fn content(&self) -> Option<&String>; fn lines(&self) -> usize; fn toggle_fold(&mut self); fn is_folded(&self) -> bool; - fn text(&self) -> &String { + fn text(&self) -> &str { if !self.is_folded() && self.content().is_some() { self.content().unwrap() - } else { self.description() } + } else { + &self.description() + } } fn render_description(&self) -> String { @@ -200,7 +204,7 @@ impl<F: Foldable> ListView<Vec<F>> where ListView<Vec<F>>: FoldableWidgetExt { - fn toggle_fold(&mut self) -> HResult<()> { + pub fn toggle_fold(&mut self) -> HResult<()> { let fold = self.current_fold()?; let fold_pos = self.fold_start_pos(fold); @@ -214,7 +218,7 @@ where Ok(()) } - fn fold_start_pos(&self, fold: usize) -> usize { + pub fn fold_start_pos(&self, fold: usize) -> usize { self.content .iter() .take(fold) @@ -223,7 +227,7 @@ where }) } - fn current_fold(&self) -> Option<usize> { + pub fn current_fold(&self) -> Option<usize> { let pos = self.get_selection(); let fold_lines = self @@ -258,6 +262,10 @@ where } fn render(&self) -> Vec<String> { + let rendering = FoldableWidgetExt::render(self); + // HACK to check if no custom renderer + if rendering.len() > 0 { return rendering; } + let (xsize, _) = self.core.coordinates.size_u(); self.content .iter() @@ -284,15 +292,18 @@ where } fn on_key(&mut self, key: Key) -> HResult<()> { - match key { - Key::Up | Key::Char('k') => self.move_up(), - Key::Char('K') => for _ in 0..10 { self.move_up() }, - Key::Char('J') => for _ in 0..10 { self.move_down() }, - Key::Down | Key::Char('j') => self.move_down(), - Key::Char('t') => self.toggle_fold()?, - Key::Char('g') => self.popup_finnished()?, - _ => {} + let result = FoldableWidgetExt::on_key(self, key); + if let Err(HError::WidgetUndefinedKeyError{key}) = result { + match key { + Key::Up | Key::Char('k') => self.move_up(), + Key::Char('K') => for _ in 0..10 { self.move_up() }, + Key::Char('J') => for _ in 0..10 { self.move_down() }, + Key::Down | Key::Char('j') => self.move_down(), + Key::Char('t') => self.toggle_fold()?, + Key::Char('g') => self.popup_finnished()?, + _ => { HError::undefined_key(key)?; }, + } } - Ok(()) + result } } diff --git a/src/hbox.rs b/src/hbox.rs index d85bc51..edc8e4e 100644 --- a/src/hbox.rs +++ b/src/hbox.rs @@ -4,7 +4,7 @@ use crate::widget::{Widget, WidgetCore}; use crate::coordinates::{Coordinates, Size, Position}; use crate::fail::{HResult, HError, ErrorLog}; -#[derive(PartialEq)] +#[derive(Debug, PartialEq)] pub struct HBox<T: Widget> { pub core: WidgetCore, pub widgets: Vec<T>, diff --git a/src/listview.rs b/src/listview.rs index 62e6ace..1a9ea76 100644 --- a/src/listview.rs +++ b/src/listview.rs @@ -96,7 +96,7 @@ impl Listable for ListView<Files> { } } -#[derive(PartialEq)] +#[derive(Debug, PartialEq)] pub struct ListView<T> where ListView<T>: Listable { pub content: T, diff --git a/src/main.rs b/src/main.rs index 0c81349..7982f93 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,7 @@ extern crate signal_notify; extern crate tree_magic; extern crate systemstat; extern crate mime_guess; +extern crate mime; extern crate clap; extern crate osstrtools; @@ -55,6 +56,7 @@ mod fscache; mod config; mod stats; mod icon; +mod quick_actions; #[cfg(feature = "img")] mod imgview; diff --git a/src/paths.rs b/src/paths.rs index 68c6376..bfc7b53 100644 --- a/src/paths.rs +++ b/src/paths.rs @@ -55,3 +55,9 @@ pub fn history_path() -> HResult<PathBuf> { history_path.push("history"); Ok(history_path) } + +pub fn actions_path() -> HResult<PathBuf> { + let mut actions_path = hunter_path()?; + actions_path.push("actions"); + Ok(actions_path) +} diff --git a/src/preview.rs b/src/preview.rs index 1dbe511..3cb5da2 100644 --- a/src/preview.rs +++ b/src/preview.rs @@ -48,7 +48,7 @@ impl<W: Widget + Send + 'static> PartialEq for AsyncWidget<W> { } } - +#[derive(Debug)] pub struct AsyncWidget<W: Widget + Send + 'static> { pub widget: Async<W>, core: WidgetCore diff --git a/src/proclist.rs b/src/proclist.rs index fca5029..7af7670 100644 --- a/src/proclist.rs +++ b/src/proclist.rs @@ -36,6 +36,7 @@ struct Process { pub struct Cmd { pub cmd: OsString, pub args: Option<Vec<OsString>>, + pub vars: Option<Vec<(OsString, OsString)>>, pub short_cmd: Option<String>, pub cwd: File, pub cwd_files: Option<Vec<File>>, @@ -304,7 +305,7 @@ impl ListView<Vec<Process>> { } } -#[derive(PartialEq)] +#[derive(Debug, PartialEq)] enum ProcViewWidgets { List(ListView<Vec<Process>>), TextView(AsyncWidget<TextView>), @@ -337,6 +338,7 @@ impl Widget for ProcViewWidgets { } } +#[derive(Debug)] pub struct ProcView { core: WidgetCore, hbox: HBox<ProcViewWidgets>, diff --git a/src/textview.rs b/src/textview.rs index 0a67160..7dbf35f 100644 --- a/src/textview.rs +++ b/src/textview.rs @@ -6,7 +6,7 @@ use crate::widget::{Widget, WidgetCore}; use crate::fail::HResult; use crate::dirty::Dirtyable; -#[derive(PartialEq)] +#[derive(Debug, PartialEq)] pub struct TextView { pub lines: Vec<String>, pub core: WidgetCore, |