diff options
author | makeefu <makeefu@ya.ru> | 2021-05-16 09:07:59 +0300 |
---|---|---|
committer | makeefu <makeefu@ya.ru> | 2021-05-16 09:07:59 +0300 |
commit | 21c27b14f9108f4535a505958e240b31bdd22d21 (patch) | |
tree | 91c98622650b789c167f649bb10054162cc790f0 /src | |
parent | 716bfae31b7e8396cf53155c9f00c1bff37d3172 (diff) |
renamed CopyDir to CopyDirName
function copy_dirname optimized
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/file_ops.rs | 29 | ||||
-rw-r--r-- | src/commands/key_command.rs | 8 |
2 files changed, 11 insertions, 26 deletions
diff --git a/src/commands/file_ops.rs b/src/commands/file_ops.rs index def2e69..fb6728e 100644 --- a/src/commands/file_ops.rs +++ b/src/commands/file_ops.rs @@ -77,35 +77,22 @@ pub fn copy_filepath(context: &mut AppContext) -> JoshutoResult<()> { Ok(()) } -pub fn copy_dir(context: &mut AppContext) -> JoshutoResult<()> { +pub fn copy_dirname(context: &mut AppContext) -> JoshutoResult<()> { let opt_entry = context .tab_context_ref() .curr_tab_ref() .curr_list_ref() - .and_then(|c| c.curr_entry_ref()); - - let dir: Option<String> = opt_entry - .and_then(|entry| entry.file_path().to_str() ) - .and_then(|filepath| { - let mut pathbuf = std::path::PathBuf::from(filepath); - pathbuf.pop(); - Some(pathbuf) - }) - .and_then(|pathbuf| Some(pathbuf.into_os_string()) ) - .and_then(|oss| { match oss.into_string(){ - Ok(string) => Some(string), - Err(_) => None, - } - }); - - if let Some(dir) = dir { - copy_string_to_buffer(dir)? + .map(|dirlist| dirlist.file_path()); + + if let Some(pathbuf) = opt_entry { + if let Some(dir) = pathbuf.to_str().map(|s| String::from(s)) { + copy_string_to_buffer(dir)? + } }; Ok(()) } fn copy_string_to_buffer(string: String) -> JoshutoResult<()> { - let clipboards = [ ( "wl-copy", @@ -136,5 +123,3 @@ fn copy_string_to_buffer(string: String) -> JoshutoResult<()> { )); return err; } - - diff --git a/src/commands/key_command.rs b/src/commands/key_command.rs index 3e16da0..87c1b17 100644 --- a/src/commands/key_command.rs +++ b/src/commands/key_command.rs @@ -25,7 +25,7 @@ pub enum KeyCommand { PasteFiles(IoWorkerOptions), CopyFileName, CopyFilePath, - CopyDir, + CopyDirName, CursorMoveUp(usize), CursorMoveDown(usize), @@ -86,7 +86,7 @@ impl KeyCommand { Self::PasteFiles(_) => "paste_files", Self::CopyFileName => "copy_filename", Self::CopyFilePath => "copy_filepath", - Self::CopyDir => "copy_dir", + Self::CopyDirName => "copy_dirname", Self::CursorMoveUp(_) => "cursor_move_up", Self::CursorMoveDown(_) => "cursor_move_down", @@ -160,7 +160,7 @@ impl KeyCommand { "copy_files" => Ok(Self::CopyFiles), "copy_filename" => Ok(Self::CopyFileName), "copy_filepath" => Ok(Self::CopyFilePath), - "copy_dir" => Ok(Self::CopyDir), + "copy_dirname" => Ok(Self::CopyDirName), "cursor_move_home" => Ok(Self::CursorMoveHome), "cursor_move_end" => Ok(Self::CursorMoveEnd), "cursor_move_page_up" => Ok(Self::CursorMovePageUp), @@ -361,7 +361,7 @@ impl AppExecute for KeyCommand { Self::PasteFiles(options) => file_ops::paste(context, options.clone()), Self::CopyFileName => file_ops::copy_filename(context), Self::CopyFilePath => file_ops::copy_filepath(context), - Self::CopyDir => file_ops::copy_dir(context), + Self::CopyDirName => file_ops::copy_dirname(context), Self::CursorMoveUp(u) => cursor_move::up(context, *u), Self::CursorMoveDown(u) => cursor_move::down(context, *u), |