mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
wip
This commit is contained in:
@@ -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"),
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<usize> = 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<FsEntry> = 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 {
|
||||
|
||||
@@ -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<usize> {
|
||||
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<Payload> {
|
||||
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<usize> {
|
||||
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<Payload> {
|
||||
self.view.get_state(super::COMPONENT_EXPLORER_REMOTE)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user