diff options
author | qkzk <qu3nt1n@gmail.com> | 2023-10-24 19:29:38 +0200 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2023-10-24 19:29:38 +0200 |
commit | ad86a843f89ca5d8fb37f802625261b740e1a145 (patch) | |
tree | 9ff896c53d66eea735f37a1575267ef4e47e180e /src/tree.rs | |
parent | cd4e066f23cfe8f514a7038c8cebd35ef5764873 (diff) |
Tree mode: file & directory are created in selected dir
Diffstat (limited to 'src/tree.rs')
-rw-r--r-- | src/tree.rs | 14 |
1 files changed, 13 insertions, 1 deletions
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 { |