From 16a8fc3ad881a92974268fb419f2fbfa92bdc768 Mon Sep 17 00:00:00 2001 From: veeso Date: Sun, 21 Mar 2021 12:03:08 +0100 Subject: [PATCH] Handle enter/space for explorers --- .../filetransfer_activity/update.rs | 91 +++++++++++++++++++ src/ui/activities/keymap.rs | 4 + 2 files changed, 95 insertions(+) diff --git a/src/ui/activities/filetransfer_activity/update.rs b/src/ui/activities/filetransfer_activity/update.rs index 01878f1..76f4d3c 100644 --- a/src/ui/activities/filetransfer_activity/update.rs +++ b/src/ui/activities/filetransfer_activity/update.rs @@ -75,6 +75,51 @@ impl FileTransferActivity { // Reload file list component self.update_local_filelist() } + (COMPONENT_EXPLORER_LOCAL, Msg::OnSubmit(Payload::Unsigned(idx))) => { + // Match selected file + let mut entry: Option = None; + if let Some(e) = self.local.get(*idx) { + entry = Some(e.clone()); + } + if let Some(entry) = entry { + // If directory, enter directory, otherwise check if symlink + match entry { + FsEntry::Directory(dir) => { + self.local_changedir(dir.abs_path.as_path(), true); + self.update_local_filelist() + } + FsEntry::File(file) => { + // Check if symlink + match &file.symlink { + Some(pointer) => match &**pointer { + FsEntry::Directory(dir) => { + self.local_changedir(dir.abs_path.as_path(), true); + self.update_local_filelist() + } + _ => None, + }, + None => None, + } + } + } + } else { + None + } + } + (COMPONENT_EXPLORER_LOCAL, &MSG_KEY_SPACE) => { + // Get pwd + let wrkdir: PathBuf = self.remote.wrkdir.clone(); + // Get file and clone (due to mutable / immutable stuff...) + if self.get_local_file_entry().is_some() { + let file: FsEntry = self.get_local_file_entry().unwrap().clone(); + let name: String = file.get_name().to_string(); + // Call upload; pass realfile, keep link name + self.filetransfer_send(&file.get_realfile(), wrkdir.as_path(), Some(name)); + self.update_local_filelist() + } else { + None + } + } (COMPONENT_EXPLORER_LOCAL, &MSG_KEY_CHAR_A) => { // Toggle hidden files self.local.toggle_hidden_files(); @@ -140,6 +185,52 @@ impl FileTransferActivity { self.tab = FileExplorerTab::Local; None } + (COMPONENT_EXPLORER_REMOTE, Msg::OnSubmit(Payload::Unsigned(idx))) => { + // Match selected file + let mut entry: Option = None; + if let Some(e) = self.remote.get(*idx) { + entry = Some(e.clone()); + } + if let Some(entry) = entry { + // If directory, enter directory; if file, check if is symlink + match entry { + FsEntry::Directory(dir) => { + self.remote_changedir(dir.abs_path.as_path(), true); + self.update_remote_filelist() + } + FsEntry::File(file) => { + match &file.symlink { + Some(symlink_entry) => { + // If symlink and is directory, point to symlink + match &**symlink_entry { + FsEntry::Directory(dir) => { + self.remote_changedir(dir.abs_path.as_path(), true); + self.update_remote_filelist() + } + _ => None, + } + } + None => None, + } + } + } + } else { + None + } + } + (COMPONENT_EXPLORER_REMOTE, &MSG_KEY_SPACE) => { + // Get file and clone (due to mutable / immutable stuff...) + if self.get_remote_file_entry().is_some() { + let file: FsEntry = self.get_remote_file_entry().unwrap().clone(); + let name: String = file.get_name().to_string(); + // Call upload; pass realfile, keep link name + let wrkdir: PathBuf = self.local.wrkdir.clone(); + self.filetransfer_recv(&file.get_realfile(), wrkdir.as_path(), Some(name)); + self.update_remote_filelist() + } else { + None + } + } (COMPONENT_EXPLORER_REMOTE, &MSG_KEY_BACKSPACE) => { // Go to previous directory if let Some(d) = self.remote.popd() { diff --git a/src/ui/activities/keymap.rs b/src/ui/activities/keymap.rs index 5993092..c86d502 100644 --- a/src/ui/activities/keymap.rs +++ b/src/ui/activities/keymap.rs @@ -64,6 +64,10 @@ pub const MSG_KEY_UP: Msg = Msg::OnKey(KeyEvent { code: KeyCode::Up, modifiers: KeyModifiers::NONE, }); +pub const MSG_KEY_SPACE: Msg = Msg::OnKey(KeyEvent { + code: KeyCode::Char(' '), + modifiers: KeyModifiers::NONE, +}); // -- char keys