summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--development.md1
-rw-r--r--src/event_exec.rs18
-rw-r--r--src/tab.rs11
-rw-r--r--src/tree.rs14
4 files changed, 25 insertions, 19 deletions
diff --git a/development.md b/development.md
index 9115ea5..9ccb8d4 100644
--- a/development.md
+++ b/development.md
@@ -585,6 +585,7 @@ New view: Tree ! Toggle with 't', fold with 'z'. Navigate normally.
- [x] preview pdf with ueberzug. First page extracted with poppler -> cairo -> thumbnail -> ueberzug
- [x] FIX: when encrypted drive is already mounted don't let user mount it again
- [x] FIX: group & owner metadata alignement in tree mode
+- [ ] Tree mode Copy / Move / New should copy in selected directory not root of tree
- [ ] document filepicking (from my config etc.).
- [ ] avoid multiple refreshs if we edit files ourself
diff --git a/src/event_exec.rs b/src/event_exec.rs
index eff4b91..6fce1a5 100644
--- a/src/event_exec.rs
+++ b/src/event_exec.rs
@@ -696,8 +696,8 @@ impl EventAction {
let mut must_reset_mode = true;
match status.selected_non_mut().mode {
Mode::InputSimple(InputSimple::Rename) => LeaveMode::rename(status.selected())?,
- Mode::InputSimple(InputSimple::Newfile) => LeaveMode::newfile(status.selected())?,
- Mode::InputSimple(InputSimple::Newdir) => LeaveMode::newdir(status.selected())?,
+ Mode::InputSimple(InputSimple::Newfile) => LeaveMode::new_file(status.selected())?,
+ Mode::InputSimple(InputSimple::Newdir) => LeaveMode::new_dir(status.selected())?,
Mode::InputSimple(InputSimple::Chmod) => LeaveMode::chmod(status)?,
Mode::InputSimple(InputSimple::RegexMatch) => LeaveMode::regex(status)?,
Mode::InputSimple(InputSimple::SetNvimAddr) => LeaveMode::set_nvim_addr(status)?,
@@ -1139,10 +1139,12 @@ impl Display for NodeCreation {
impl NodeCreation {
fn create(&self, tab: &mut Tab) -> Result<()> {
- let path = tab
- .path_content
- .path
- .join(sanitize_filename::sanitize(tab.input.string()));
+ let root_path = match tab.previous_mode {
+ Mode::Tree => tab.directory.tree.directory_of_selected()?.to_owned(),
+ _ => tab.path_content.path.clone(),
+ };
+ log::info!("root_path: {root_path:?}");
+ let path = root_path.join(sanitize_filename::sanitize(tab.input.string()));
if path.exists() {
write_log_line(format!(
"{self} {path} already exists",
@@ -1365,7 +1367,7 @@ impl LeaveMode {
/// Creates a new file with input string as name.
/// Nothing is done if the file already exists.
/// Filename is sanitized before processing.
- pub fn newfile(tab: &mut Tab) -> Result<()> {
+ pub fn new_file(tab: &mut Tab) -> Result<()> {
NodeCreation::Newfile.create(tab)
}
@@ -1374,7 +1376,7 @@ impl LeaveMode {
/// We use `fs::create_dir` internally so it will fail if the input string
/// ie. the user can create `newdir` or `newdir/newfolder`.
/// Directory name is sanitized before processing.
- pub fn newdir(tab: &mut Tab) -> Result<()> {
+ pub fn new_dir(tab: &mut Tab) -> Result<()> {
NodeCreation::Newdir.create(tab)
}
diff --git a/src/tab.rs b/src/tab.rs
index 0fe3eb3..8d7c4d2 100644
--- a/src/tab.rs
+++ b/src/tab.rs
@@ -413,16 +413,7 @@ impl Tab {
/// In normal mode it's the current working directory.
pub fn directory_of_selected(&self) -> Result<&path::Path> {
match self.mode {
- Mode::Tree => {
- let fileinfo = &self.directory.tree.current_node.fileinfo;
- match fileinfo.file_kind {
- FileKind::Directory => Ok(&self.directory.tree.current_node.fileinfo.path),
- _ => Ok(fileinfo
- .path
- .parent()
- .context("selected file should have a parent")?),
- }
- }
+ Mode::Tree => self.directory.tree.directory_of_selected(),
_ => Ok(&self.path_content.path),
}
}
diff --git a/src/tree.rs b/src/tree.rs
index cc7605d..57609b6 100644
--- a/src/tree.rs
+++ b/src/tree.rs
@@ -1,6 +1,6 @@
use std::path::Path;
-use anyhow::Result;
+use anyhow::{Context, Result};
use tuikit::attr::Attr;
use users::UsersCache;
@@ -574,6 +574,18 @@ impl Tree {
visited.node.position.clone()
}
+
+ pub fn directory_of_selected(&self) -> Result<&std::path::Path> {
+ let fileinfo = &self.current_node.fileinfo;
+
+ match fileinfo.file_kind {
+ FileKind::Directory => Ok(&self.current_node.fileinfo.path),
+ _ => Ok(fileinfo
+ .path
+ .parent()
+ .context("selected file should have a parent")?),
+ }
+ }
}
fn first_prefix(mut prefix: String) -> String {