diff options
-rw-r--r-- | src/event_exec.rs | 16 | ||||
-rw-r--r-- | src/flagged.rs | 4 | ||||
-rw-r--r-- | src/shortcut.rs | 4 | ||||
-rw-r--r-- | src/status.rs | 13 | ||||
-rw-r--r-- | src/tab.rs | 6 | ||||
-rw-r--r-- | src/term_manager.rs | 19 | ||||
-rw-r--r-- | src/trash.rs | 8 | ||||
-rw-r--r-- | src/visited.rs | 6 |
8 files changed, 35 insertions, 41 deletions
diff --git a/src/event_exec.rs b/src/event_exec.rs index 356a485..e034348 100644 --- a/src/event_exec.rs +++ b/src/event_exec.rs @@ -245,7 +245,7 @@ impl EventExec { }; let tab = status.selected(); tab.input.clear(); - tab.history.push(&target_dir.to_path_buf()); + tab.history.push(target_dir); tab.path_content.change_directory(target_dir)?; let index = tab.find_jump_index(&jump_target).unwrap_or_default(); tab.path_content.select_index(index); @@ -446,8 +446,9 @@ impl EventExec { /// Does /// Add the starting directory to history. pub fn event_move_to_parent(tab: &mut Tab) -> FmResult<()> { - if let Some(parent) = tab.path_content.path.parent() { - tab.set_pathcontent(parent.to_path_buf())?; + let path = tab.path_content.path.clone(); + if let Some(parent) = path.parent() { + tab.set_pathcontent(parent)?; } Ok(()) } @@ -806,8 +807,9 @@ impl EventExec { return Ok(()); } tab.history.content.pop(); - let last = tab.history.content[tab.history.len() - 1].clone(); - tab.set_pathcontent(last)?; + let index = tab.history.len() - 1; + let last = tab.history.content[index].clone(); + tab.set_pathcontent(&last)?; Ok(()) } @@ -817,7 +819,7 @@ impl EventExec { let home_cow = shellexpand::tilde("~"); let home: &str = home_cow.borrow(); let path = std::fs::canonicalize(home)?; - tab.set_pathcontent(path)?; + tab.set_pathcontent(&path)?; Ok(()) } @@ -1285,7 +1287,7 @@ impl EventExec { if trash_mount_point != origin_mount_point { continue; } - status.trash.trash(flagged.to_owned())?; + status.trash.trash(flagged)?; } status.flagged.clear(); status.selected().refresh_view()?; diff --git a/src/flagged.rs b/src/flagged.rs index 20154a9..e8b487b 100644 --- a/src/flagged.rs +++ b/src/flagged.rs @@ -48,8 +48,8 @@ impl Flagged { /// True if the `path` is flagged. /// Since we maintain the content sorted, we can use a binary search and /// compensate a little bit with using a vector instead of a set. - pub fn contains(&self, path: &PathBuf) -> bool { - self.content.binary_search(path).is_ok() + pub fn contains(&self, path: &Path) -> bool { + self.content.binary_search(&path.to_path_buf()).is_ok() } /// Returns a vector of path which are present in the current directory. diff --git a/src/shortcut.rs b/src/shortcut.rs index 98f0b8e..0005fdc 100644 --- a/src/shortcut.rs +++ b/src/shortcut.rs @@ -42,8 +42,8 @@ impl Shortcut { /// Insert a shortcut to home directory of the current user. pub fn with_home_path(mut shortcuts: Vec<PathBuf>) -> Vec<PathBuf> { - if let Ok(pb) = PathBuf::from_str(shellexpand::tilde("~").borrow()) { - shortcuts.push(pb); + if let Ok(home_path) = PathBuf::from_str(shellexpand::tilde("~").borrow()) { + shortcuts.push(home_path); } shortcuts } diff --git a/src/status.rs b/src/status.rs index d7a8cab..1cdabe6 100644 --- a/src/status.rs +++ b/src/status.rs @@ -1,6 +1,6 @@ use std::fs; use std::os::unix::fs::PermissionsExt; -use std::path::{self, Path, PathBuf}; +use std::path::Path; use std::sync::Arc; use regex::Regex; @@ -154,13 +154,13 @@ impl Status { fn create_tab_from_skim_output(&mut self, cow_path: &Arc<dyn SkimItem>) { let mut tab = self.selected().clone(); let s_path = cow_path.output().to_string(); - if let Ok(path) = fs::canonicalize(path::Path::new(&s_path)) { + if let Ok(path) = fs::canonicalize(Path::new(&s_path)) { if path.is_file() { if let Some(parent) = path.parent() { - let _ = tab.set_pathcontent(parent.to_path_buf()); + let _ = tab.set_pathcontent(parent); } } else if path.is_dir() { - let _ = tab.set_pathcontent(path); + let _ = tab.set_pathcontent(&path); self.tabs[self.index] = tab; } } @@ -201,7 +201,10 @@ impl Status { /// Set the permissions of the flagged files according to a given permission. /// If the permission are invalid or if the user can't edit them, it may fail. - pub fn set_permissions(path: PathBuf, permissions: u32) -> FmResult<()> { + pub fn set_permissions<P>(path: P, permissions: u32) -> FmResult<()> + where + P: AsRef<Path>, + { Ok(std::fs::set_permissions( path, std::fs::Permissions::from_mode(permissions), @@ -141,9 +141,9 @@ impl Tab { /// Set the pathcontent to a new path. /// Reset the window. /// Add the last path to the history of visited paths. - pub fn set_pathcontent(&mut self, path: path::PathBuf) -> FmResult<()> { - self.history.push(&path); - self.path_content.change_directory(&path)?; + pub fn set_pathcontent(&mut self, path: &path::Path) -> FmResult<()> { + self.history.push(path); + self.path_content.change_directory(path)?; self.window.reset(self.path_content.content.len()); Ok(()) } diff --git a/src/term_manager.rs b/src/term_manager.rs index ad1bb05..6a20e79 100644 --- a/src/term_manager.rs +++ b/src/term_manager.rs @@ -428,18 +428,6 @@ impl<'a> WinTab<'a> { line.print(canvas, row, line_number_width_hex + 1); } } - Preview::Archive(text) => { - for (i, line) in (*text).window(tab.window.top, tab.window.bottom, length) { - let row = Self::calc_line_row(i, tab); - canvas.print_with_attr( - row, - 0, - &(i + 1 + tab.window.top).to_string(), - Self::ATTR_LINE_NR, - )?; - canvas.print(row, line_number_width + 3, line)?; - } - } Preview::Thumbnail(image) => { let (width, height) = canvas.size()?; @@ -459,11 +447,12 @@ impl<'a> WinTab<'a> { )?; } } - Preview::Text(text) => impl_preview!(text, tab, length, canvas, line_number_width), - Preview::Pdf(text) => impl_preview!(text, tab, length, canvas, line_number_width), + Preview::Archive(text) => impl_preview!(text, tab, length, canvas, line_number_width), + Preview::Directory(text) => impl_preview!(text, tab, length, canvas, line_number_width), Preview::Exif(text) => impl_preview!(text, tab, length, canvas, line_number_width), Preview::Media(text) => impl_preview!(text, tab, length, canvas, line_number_width), - Preview::Directory(text) => impl_preview!(text, tab, length, canvas, line_number_width), + Preview::Pdf(text) => impl_preview!(text, tab, length, canvas, line_number_width), + Preview::Text(text) => impl_preview!(text, tab, length, canvas, line_number_width), Preview::Empty => (), } diff --git a/src/trash.rs b/src/trash.rs index 0822d63..d20ff12 100644 --- a/src/trash.rs +++ b/src/trash.rs @@ -246,13 +246,13 @@ impl Trash { /// Move a file to the trash folder and create a new trash info file. /// Add a new TrashInfo to the content. - pub fn trash(&mut self, origin: PathBuf) -> FmResult<()> { + pub fn trash(&mut self, origin: &Path) -> FmResult<()> { if origin.is_relative() { return Err(FmError::custom("trash", "origin path should be absolute")); } - let dest_file_name = self.pick_dest_name(&origin)?; - let trash_info = TrashInfo::new(&origin, &dest_file_name); + let dest_file_name = self.pick_dest_name(origin)?; + let trash_info = TrashInfo::new(origin, &dest_file_name); let mut trashfile_filename = PathBuf::from(&self.trash_folder_files); trashfile_filename.push(&dest_file_name); @@ -264,7 +264,7 @@ impl Trash { self.content.push(trash_info); - std::fs::rename(&origin, &trashfile_filename)?; + std::fs::rename(origin, &trashfile_filename)?; info!("moved to trash {:?} -> {:?}", origin, dest_file_name); Ok(()) diff --git a/src/visited.rs b/src/visited.rs index e51cb4c..0832f77 100644 --- a/src/visited.rs +++ b/src/visited.rs @@ -18,9 +18,9 @@ pub struct History { impl History { /// Add a new path in the stack, without duplicates, and select the last /// one. - pub fn push(&mut self, path: &PathBuf) { - if !self.content.contains(path) { - self.content.push(path.to_owned()); + pub fn push(&mut self, path: &std::path::Path) { + if !self.content.contains(&path.to_path_buf()) { + self.content.push(path.to_path_buf()); self.index = self.len() - 1 } } |