diff options
Diffstat (limited to 'src/commands/file_ops.rs')
-rw-r--r-- | src/commands/file_ops.rs | 45 |
1 files changed, 19 insertions, 26 deletions
diff --git a/src/commands/file_ops.rs b/src/commands/file_ops.rs index c50129b..dd16264 100644 --- a/src/commands/file_ops.rs +++ b/src/commands/file_ops.rs @@ -5,42 +5,35 @@ use crate::context::{AppContext, LocalStateContext}; use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult}; use crate::io::{FileOperation, FileOperationOptions, IoWorkerThread}; -pub fn cut(context: &mut AppContext) -> JoshutoResult { - if let Some(list) = context.tab_context_ref().curr_tab_ref().curr_list_ref() { - let selected = list.get_selected_paths(); +fn new_local_state(context: &mut AppContext, file_op: FileOperation) -> Option<()> { + let list = context.tab_context_ref().curr_tab_ref().curr_list_ref()?; + let selected = list.get_selected_paths(); - let mut local_state = LocalStateContext::new(); - local_state.set_paths(selected.into_iter()); - local_state.set_file_op(FileOperation::Cut); + let mut local_state = LocalStateContext::new(); + local_state.set_paths(selected.into_iter()); + local_state.set_file_op(file_op); - context.set_local_state(local_state); - } + context.set_local_state(local_state); + Some(()) +} + +pub fn cut(context: &mut AppContext) -> JoshutoResult { + new_local_state(context, FileOperation::Cut); Ok(()) } pub fn copy(context: &mut AppContext) -> JoshutoResult { - if let Some(list) = context.tab_context_ref().curr_tab_ref().curr_list_ref() { - let selected = list.get_selected_paths(); - - let mut local_state = LocalStateContext::new(); - local_state.set_paths(selected.into_iter()); - local_state.set_file_op(FileOperation::Copy); - - context.set_local_state(local_state); - } + new_local_state(context, FileOperation::Copy); Ok(()) } -pub fn link(context: &mut AppContext) -> JoshutoResult { - if let Some(list) = context.tab_context_ref().curr_tab_ref().curr_list_ref() { - let selected = list.get_selected_paths(); - - let mut local_state = LocalStateContext::new(); - local_state.set_paths(selected.into_iter()); - local_state.set_file_op(FileOperation::Symlink); +pub fn symlink_absolute(context: &mut AppContext) -> JoshutoResult { + new_local_state(context, FileOperation::Symlink { relative: false }); + Ok(()) +} - context.set_local_state(local_state); - } +pub fn symlink_relative(context: &mut AppContext) -> JoshutoResult { + new_local_state(context, FileOperation::Symlink { relative: true }); Ok(()) } |