diff --git a/src/ui/activities/filetransfer/actions/copy.rs b/src/ui/activities/filetransfer/actions/copy.rs index 3b3d7c4..c614b14 100644 --- a/src/ui/activities/filetransfer/actions/copy.rs +++ b/src/ui/activities/filetransfer/actions/copy.rs @@ -28,39 +28,49 @@ // locals use super::{FileTransferActivity, FsEntry, LogLevel}; use std::path::PathBuf; +use tuirealm::{Payload, Value}; impl FileTransferActivity { /// ### action_local_copy /// /// Copy file on local pub(crate) fn action_local_copy(&mut self, input: String) { - if let Some(idx) = self.get_local_file_idx() { - let dest_path: PathBuf = PathBuf::from(input); - let entry: FsEntry = self.local().get(idx).unwrap().clone(); - match self.host.copy(&entry, dest_path.as_path()) { - Ok(_) => { - self.log( - LogLevel::Info, + match self.get_local_file_state() { + Some(Payload::One(Value::Usize(idx))) => { + let dest_path: PathBuf = PathBuf::from(input); + let entry: FsEntry = self.local().get(idx).unwrap().clone(); + match self.host.copy(&entry, dest_path.as_path()) { + Ok(_) => { + self.log( + LogLevel::Info, + format!( + "Copied \"{}\" to \"{}\"", + entry.get_abs_path().display(), + dest_path.display() + ), + ); + // Reload entries + let wrkdir: PathBuf = self.local().wrkdir.clone(); + self.local_scan(wrkdir.as_path()); + } + Err(err) => self.log_and_alert( + LogLevel::Error, format!( - "Copied \"{}\" to \"{}\"", + "Could not copy \"{}\" to \"{}\": {}", entry.get_abs_path().display(), - dest_path.display() + dest_path.display(), + err ), - ); - // Reload entries - let wrkdir: PathBuf = self.local().wrkdir.clone(); - self.local_scan(wrkdir.as_path()); - } - Err(err) => self.log_and_alert( - LogLevel::Error, - format!( - "Could not copy \"{}\" to \"{}\": {}", - entry.get_abs_path().display(), - dest_path.display(), - err ), - ), + } } + Some(Payload::Vec(_)) => { + self.log_and_alert( + LogLevel::Warn, + format!("Copy is not supported when using seleection"), + ); + } + _ => {} } } @@ -68,31 +78,40 @@ impl FileTransferActivity { /// /// Copy file on remote pub(crate) fn action_remote_copy(&mut self, input: String) { - if let Some(idx) = self.get_remote_file_idx() { - let dest_path: PathBuf = PathBuf::from(input); - let entry: FsEntry = self.remote().get(idx).unwrap().clone(); - match self.client.as_mut().copy(&entry, dest_path.as_path()) { - Ok(_) => { - self.log( - LogLevel::Info, + match self.get_local_file_state() { + Some(Payload::One(Value::Usize(idx))) => { + let dest_path: PathBuf = PathBuf::from(input); + let entry: FsEntry = self.remote().get(idx).unwrap().clone(); + match self.client.as_mut().copy(&entry, dest_path.as_path()) { + Ok(_) => { + self.log( + LogLevel::Info, + format!( + "Copied \"{}\" to \"{}\"", + entry.get_abs_path().display(), + dest_path.display() + ), + ); + self.reload_remote_dir(); + } + Err(err) => self.log_and_alert( + LogLevel::Error, format!( - "Copied \"{}\" to \"{}\"", + "Could not copy \"{}\" to \"{}\": {}", entry.get_abs_path().display(), - dest_path.display() + dest_path.display(), + err ), - ); - self.reload_remote_dir(); - } - Err(err) => self.log_and_alert( - LogLevel::Error, - format!( - "Could not copy \"{}\" to \"{}\": {}", - entry.get_abs_path().display(), - dest_path.display(), - err ), - ), + } } + Some(Payload::Vec(_)) => { + self.log_and_alert( + LogLevel::Warn, + format!("Copy is not supported when using seleection"), + ); + } + _ => {} } } } diff --git a/src/ui/activities/filetransfer/actions/delete.rs b/src/ui/activities/filetransfer/actions/delete.rs index 4628c19..d231d18 100644 --- a/src/ui/activities/filetransfer/actions/delete.rs +++ b/src/ui/activities/filetransfer/actions/delete.rs @@ -28,9 +28,21 @@ // locals use super::{FileTransferActivity, FsEntry, LogLevel}; use std::path::PathBuf; +use tuirealm::{Payload, Value}; impl FileTransferActivity { pub(crate) fn action_local_delete(&mut self) { + // Get selection + let selection: Vec = match self.get_local_file_state() { + Some(Payload::One(Value::Usize(idx))) => vec![idx], + Some(Payload::Vec(list)) => list.into_iter().map(|x| { + match x { + Value::Usize(x) => x, + _ => panic!("File selection contains non-usize value"), + } + }), + + } let entry: Option = self.get_local_file_entry().cloned(); if let Some(entry) = entry { let full_path: PathBuf = entry.get_abs_path(); @@ -57,7 +69,7 @@ impl FileTransferActivity { } pub(crate) fn action_remote_delete(&mut self) { - if let Some(idx) = self.get_remote_file_idx() { + if let Some(idx) = self.get_remote_file_state() { // Check if file entry exists let entry = self.remote().get(idx).cloned(); if let Some(entry) = entry { diff --git a/src/ui/activities/filetransfer/actions/mod.rs b/src/ui/activities/filetransfer/actions/mod.rs index 1dda2ce..23397ab 100644 --- a/src/ui/activities/filetransfer/actions/mod.rs +++ b/src/ui/activities/filetransfer/actions/mod.rs @@ -45,9 +45,9 @@ impl FileTransferActivity { /// /// Get local file entry pub(crate) fn get_local_file_entry(&self) -> Option<&FsEntry> { - match self.get_local_file_idx() { - None => None, - Some(idx) => self.local().get(idx), + match self.get_local_file_state() { + Some(Payload::One(Value::Usize(idx))) => self.local().get(idx), + _ => None, } } @@ -55,31 +55,25 @@ impl FileTransferActivity { /// /// Get remote file entry pub(crate) fn get_remote_file_entry(&self) -> Option<&FsEntry> { - match self.get_remote_file_idx() { - None => None, - Some(idx) => self.remote().get(idx), + match self.get_remote_file_state() { + Some(Payload::One(Value::Usize(idx))) => self.remote().get(idx), + _ => None, } } // -- private - /// ### get_local_file_idx + /// ### get_local_file_state /// /// Get index of selected file in the local tab - fn get_local_file_idx(&self) -> Option { - match self.view.get_state(super::COMPONENT_EXPLORER_LOCAL) { - Some(Payload::One(Value::Usize(idx))) => Some(idx), - _ => None, - } + fn get_local_file_state(&self) -> Option { + self.view.get_state(super::COMPONENT_EXPLORER_LOCAL) } - /// ### get_remote_file_idx + /// ### get_remote_file_state /// /// Get index of selected file in the remote file - fn get_remote_file_idx(&self) -> Option { - match self.view.get_state(super::COMPONENT_EXPLORER_REMOTE) { - Some(Payload::One(Value::Usize(idx))) => Some(idx), - _ => None, - } + fn get_remote_file_state(&self) -> Option { + self.view.get_state(super::COMPONENT_EXPLORER_REMOTE) } } diff --git a/src/ui/activities/filetransfer/actions/rename.rs b/src/ui/activities/filetransfer/actions/rename.rs index 47a483a..5cae46d 100644 --- a/src/ui/activities/filetransfer/actions/rename.rs +++ b/src/ui/activities/filetransfer/actions/rename.rs @@ -68,7 +68,7 @@ impl FileTransferActivity { } pub(crate) fn action_remote_rename(&mut self, input: String) { - if let Some(idx) = self.get_remote_file_idx() { + if let Some(idx) = self.get_remote_file_state() { let entry = self.remote().get(idx).cloned(); if let Some(entry) = entry { let dst_path: PathBuf = PathBuf::from(input); diff --git a/src/ui/activities/filetransfer/actions/save.rs b/src/ui/activities/filetransfer/actions/save.rs index 22912a9..4a34079 100644 --- a/src/ui/activities/filetransfer/actions/save.rs +++ b/src/ui/activities/filetransfer/actions/save.rs @@ -31,7 +31,7 @@ use std::path::PathBuf; impl FileTransferActivity { pub(crate) fn action_local_saveas(&mut self, input: String) { - if let Some(idx) = self.get_local_file_idx() { + if let Some(idx) = self.get_local_file_state() { // Get pwd let wrkdir: PathBuf = self.remote().wrkdir.clone(); if self.local().get(idx).is_some() { @@ -43,7 +43,7 @@ impl FileTransferActivity { } pub(crate) fn action_remote_saveas(&mut self, input: String) { - if let Some(idx) = self.get_remote_file_idx() { + if let Some(idx) = self.get_remote_file_state() { // Get pwd let wrkdir: PathBuf = self.local().wrkdir.clone(); if self.remote().get(idx).is_some() { diff --git a/src/ui/components/file_list.rs b/src/ui/components/file_list.rs index 7c98774..6849ddd 100644 --- a/src/ui/components/file_list.rs +++ b/src/ui/components/file_list.rs @@ -380,7 +380,7 @@ impl Component for FileList { Msg::None } KeyCode::Char('a') => match key.modifiers.intersects(KeyModifiers::CONTROL) { - // CTRL+C + // CTRL+A true => { // Select all self.states.select_all();