diff options
author | Canop <cano.petrole@gmail.com> | 2020-07-26 18:07:24 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2020-07-26 18:07:24 +0200 |
commit | b2f489e9c731a62dd1a63b4b82b43509ef58d602 (patch) | |
tree | 30cbcd5a2637a12af202c6a7a3ecb5e58fc37616 /src/browser/browser_state.rs | |
parent | 53cc8f0fa652c7e04d04490c0d6cfd84006c58ed (diff) |
{line} in a verb execution pattern refers to the line number
This makes it possible to open files directly on the line
which was selected in the preview
Diffstat (limited to 'src/browser/browser_state.rs')
-rw-r--r-- | src/browser/browser_state.rs | 96 |
1 files changed, 30 insertions, 66 deletions
diff --git a/src/browser/browser_state.rs b/src/browser/browser_state.rs index 3c676e1..b794d40 100644 --- a/src/browser/browser_state.rs +++ b/src/browser/browser_state.rs @@ -11,7 +11,6 @@ use { path, path_anchor::PathAnchor, print, - selection_type::SelectionType, skin::PanelSkin, task_sync::Dam, tree::*, @@ -84,6 +83,10 @@ impl BrowserState { self.tree.root() } + fn selection_type(&self) -> SelectionType { + self.displayed_tree().selected_line().selection_type() + } + pub fn page_height(screen: &Screen) -> i32 { i32::from(screen.height) - 2 } @@ -164,7 +167,7 @@ impl BrowserState { TreeLineType::File => make_opener(line.path.clone(), line.is_exe(), con), TreeLineType::Dir | TreeLineType::SymLinkToDir(_) => { Ok(if con.launch_args.cmd_export_path.is_some() { - CD.to_cmd_result(w, &line.target(), &None, &None, con)? + CD.to_cmd_result(w, line.as_selection(), &None, &None, con)? } else { AppStateCmdResult::DisplayError( "This feature needs broot to be launched with the `br` script".to_owned(), @@ -205,28 +208,6 @@ impl BrowserState { } } - fn no_verb_status(&self, has_pattern: bool, con: &AppContext) -> Status { - if self.displayed_tree().selection == 0 { - if has_pattern { - con.standard_status.root_pat.clone() - } else { - con.standard_status.root_no_pat.clone() - } - } else if self.selection_type() == SelectionType::Directory { - if has_pattern { - con.standard_status.dir_pat.clone() - } else { - con.standard_status.dir_no_pat.clone() - } - } else { - if has_pattern { - con.standard_status.file_pat.clone() - } else { - con.standard_status.file_no_pat.clone() - } - } - } - } /// build a AppStateCmdResult with a launchable which will be used to @@ -266,53 +247,14 @@ impl AppState for BrowserState { } } - fn get_status( - &self, - cmd: &Command, - other_path: &Option<PathBuf>, - con: &AppContext, - ) -> Status { - match cmd { - Command::PatternEdit{ .. } => self.no_verb_status(true, con), - Command::VerbEdit(invocation) => { - if invocation.name.is_empty() { - Status::new( - "Type a verb then *enter* to execute it (*?* for the list of verbs)", - false, - ) - } else { - match con.verb_store.search(&invocation.name) { - PrefixSearchResult::NoMatch => { - Status::new("No matching verb (*?* for the list of verbs)", true) - } - PrefixSearchResult::Match(_, verb) => { - let line = self.displayed_tree().selected_line(); - verb.get_status(&line.path, other_path, invocation) - } - PrefixSearchResult::Matches(completions) => Status::new( - format!( - "Possible verbs: {}", - completions - .iter() - .map(|c| format!("*{}*", c)) - .collect::<Vec<String>>() - .join(", "), - ), - false, - ), - } - } - } - _ => self.no_verb_status(false, con), - } - } fn selected_path(&self) -> &Path { &self.displayed_tree().selected_line().path } - fn selection_type(&self) -> SelectionType { - self.displayed_tree().selected_line().selection_type() + + fn selection(&self) -> Selection<'_> { + self.displayed_tree().selected_line().as_selection() } fn clear_pending(&mut self) { @@ -655,6 +597,28 @@ impl AppState for BrowserState { }) } + fn no_verb_status(&self, has_pattern: bool, con: &AppContext) -> Status { + if self.displayed_tree().selection == 0 { + if has_pattern { + con.standard_status.root_pat.clone() + } else { + con.standard_status.root_no_pat.clone() + } + } else if self.selection_type() == SelectionType::Directory { + if has_pattern { + con.standard_status.dir_pat.clone() + } else { + con.standard_status.dir_no_pat.clone() + } + } else { + if has_pattern { + con.standard_status.file_pat.clone() + } else { + con.standard_status.file_no_pat.clone() + } + } + } + /// do some work, totally or partially, if there's some to do. /// Stop as soon as the dam asks for interruption fn do_pending_task( |