diff options
Diffstat (limited to 'src/commands/file_ops/copy.rs')
-rw-r--r-- | src/commands/file_ops/copy.rs | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/commands/file_ops/copy.rs b/src/commands/file_ops/copy.rs index 7e05752..6632e2a 100644 --- a/src/commands/file_ops/copy.rs +++ b/src/commands/file_ops/copy.rs @@ -1,11 +1,11 @@ +use std::path; + use crate::commands::{JoshutoCommand, JoshutoRunnable}; -use crate::context::JoshutoContext; +use crate::context::{JoshutoContext, LocalStateContext}; use crate::error::JoshutoResult; use crate::io::FileOp; use crate::ui::TuiBackend; -use super::local_state::LocalState; - #[derive(Clone, Debug)] pub struct CopyFiles; @@ -28,10 +28,24 @@ impl std::fmt::Display for CopyFiles { impl JoshutoRunnable for CopyFiles { fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { - let curr_tab = context.curr_tab_ref(); - if let Some(list) = curr_tab.curr_list_ref() { - LocalState::repopulate(list)?; - LocalState::set_file_op(FileOp::Copy); + if let Some(list) = context.tab_context_ref().curr_tab_ref().curr_list_ref() { + let mut selected: Vec<&path::Path> = list + .iter() + .filter(|e| e.is_selected()) + .map(|e| e.file_path()) + .collect(); + if selected.is_empty() { + selected = match list.get_curr_ref() { + Some(s) => vec![s.file_path()], + None => vec![], + } + } + + let mut local_state = LocalStateContext::new(); + local_state.set_paths(selected.into_iter()); + local_state.set_file_op(FileOp::Copy); + + context.set_local_state(local_state); } Ok(()) } |