Files found from search are now displayed with their relative path from working directory

This commit is contained in:
veeso
2021-11-20 09:40:06 +01:00
committed by Christian Visintin
parent 3927fb2a39
commit bc6b7b582e
4 changed files with 31 additions and 9 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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<FsEntry>) {
let mut explorer = Self::build_found_explorer();
pub fn set_found(&mut self, tab: FoundExplorerTab, files: Vec<FsEntry>, 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()
}
}

View File

@@ -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);