diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d9cf70..4c0c128 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,12 +29,12 @@ Released on FIXME: > ❄️ Winter update 2022 ⛄ - **Enhancements**: - - Find feature: + - **Find** feature: - A "wait popup" will now be displayed while searching files - If find command doesn't return any result show an info dialog and not an empty explorer - It is now possible to keep navigating on the other explorer while "found tab" is open - ❗ It is not possible though to have the "found tab" on both explorers (otherwise you wouldn't be able to tell whether you're transferring files) - - Files found from search are now displayed with their absolute path + - Files found from search are now displayed with their relative path from working directory ## 0.7.0 diff --git a/src/fs/explorer/formatter.rs b/src/fs/explorer/formatter.rs index d377456..4acaf6c 100644 --- a/src/fs/explorer/formatter.rs +++ b/src/fs/explorer/formatter.rs @@ -28,9 +28,11 @@ // Locals use super::FsEntry; use crate::utils::fmt::{fmt_path_elide, fmt_pex, fmt_time}; +use crate::utils::path::diff_paths; // Ext use bytesize::ByteSize; use regex::Regex; +use std::path::PathBuf; #[cfg(target_family = "unix")] use users::{get_group_by_gid, get_user_by_uid}; // Types @@ -346,15 +348,23 @@ impl Formatter { cur_str: &str, prefix: &str, fmt_len: Option<&usize>, - _fmt_extra: Option<&String>, + fmt_extra: Option<&String>, ) -> String { + let p = match fmt_extra { + None => fsentry.get_abs_path(), + Some(rel) => diff_paths( + fsentry.get_abs_path().as_path(), + PathBuf::from(rel.as_str()).as_path(), + ) + .unwrap_or_else(|| fsentry.get_abs_path()), + }; format!( "{}{}{}", cur_str, prefix, match fmt_len { - None => fsentry.get_abs_path().display().to_string(), - Some(len) => fmt_path_elide(fsentry.get_abs_path().as_path(), *len), + None => p.display().to_string(), + Some(len) => fmt_path_elide(p.as_path(), *len), } ) } @@ -935,6 +945,8 @@ mod tests { formatter.fmt(&entry).as_str(), "File path: /tmp/…/c/bar.txt" ); + let formatter: Formatter = Formatter::new("File path: {PATH:128:/tmp/a/b}"); + assert_eq!(formatter.fmt(&entry).as_str(), "File path: c/bar.txt"); } /// ### dummy_fmt diff --git a/src/ui/activities/filetransfer/lib/browser.rs b/src/ui/activities/filetransfer/lib/browser.rs index 932f3c9..396f371 100644 --- a/src/ui/activities/filetransfer/lib/browser.rs +++ b/src/ui/activities/filetransfer/lib/browser.rs @@ -29,6 +29,8 @@ use crate::fs::explorer::{builder::FileExplorerBuilder, FileExplorer, FileSortin use crate::fs::FsEntry; use crate::system::config_client::ConfigClient; +use std::path::Path; + /// ## FileExplorerTab /// /// File explorer tab @@ -98,8 +100,8 @@ impl Browser { self.found.as_mut().map(|x| &mut x.1) } - pub fn set_found(&mut self, tab: FoundExplorerTab, files: Vec) { - let mut explorer = Self::build_found_explorer(); + pub fn set_found(&mut self, tab: FoundExplorerTab, files: Vec, wrkdir: &Path) { + let mut explorer = Self::build_found_explorer(wrkdir); explorer.set_files(files); self.found = Some((tab, explorer)); } @@ -168,13 +170,15 @@ impl Browser { /// ### build_found_explorer /// /// Build explorer reading from `ConfigClient`, for found result (has some differences) - fn build_found_explorer() -> FileExplorer { + fn build_found_explorer(wrkdir: &Path) -> FileExplorer { FileExplorerBuilder::new() .with_file_sorting(FileSorting::Name) .with_group_dirs(Some(GroupDirs::First)) .with_hidden_files(true) .with_stack_size(0) - .with_formatter(Some("{PATH:36} {SYMLINK}")) + .with_formatter(Some( + format!("{{PATH:36:{}}} {{SYMLINK}}", wrkdir.display()).as_str(), + )) .build() } } diff --git a/src/ui/activities/filetransfer/update.rs b/src/ui/activities/filetransfer/update.rs index 2a035b5..da003bf 100644 --- a/src/ui/activities/filetransfer/update.rs +++ b/src/ui/activities/filetransfer/update.rs @@ -494,6 +494,11 @@ impl Update for FileTransferActivity { ); } Ok(files) => { + // Get wrkdir + let wrkdir = match self.browser.tab() { + FileExplorerTab::Local => self.local().wrkdir.clone(), + _ => self.remote().wrkdir.clone(), + }; // Create explorer and load files self.browser.set_found( match self.browser.tab() { @@ -501,6 +506,7 @@ impl Update for FileTransferActivity { _ => FoundExplorerTab::Remote, }, files, + wrkdir.as_path(), ); // Mount result widget self.mount_find(input);