mirror of
https://github.com/veeso/termscp.git
synced 2026-09-27 06:21:22 -07:00
wip
This commit is contained in:
@@ -28,39 +28,49 @@
|
|||||||
// locals
|
// locals
|
||||||
use super::{FileTransferActivity, FsEntry, LogLevel};
|
use super::{FileTransferActivity, FsEntry, LogLevel};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use tuirealm::{Payload, Value};
|
||||||
|
|
||||||
impl FileTransferActivity {
|
impl FileTransferActivity {
|
||||||
/// ### action_local_copy
|
/// ### action_local_copy
|
||||||
///
|
///
|
||||||
/// Copy file on local
|
/// Copy file on local
|
||||||
pub(crate) fn action_local_copy(&mut self, input: String) {
|
pub(crate) fn action_local_copy(&mut self, input: String) {
|
||||||
if let Some(idx) = self.get_local_file_idx() {
|
match self.get_local_file_state() {
|
||||||
let dest_path: PathBuf = PathBuf::from(input);
|
Some(Payload::One(Value::Usize(idx))) => {
|
||||||
let entry: FsEntry = self.local().get(idx).unwrap().clone();
|
let dest_path: PathBuf = PathBuf::from(input);
|
||||||
match self.host.copy(&entry, dest_path.as_path()) {
|
let entry: FsEntry = self.local().get(idx).unwrap().clone();
|
||||||
Ok(_) => {
|
match self.host.copy(&entry, dest_path.as_path()) {
|
||||||
self.log(
|
Ok(_) => {
|
||||||
LogLevel::Info,
|
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!(
|
format!(
|
||||||
"Copied \"{}\" to \"{}\"",
|
"Could not copy \"{}\" to \"{}\": {}",
|
||||||
entry.get_abs_path().display(),
|
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
|
/// Copy file on remote
|
||||||
pub(crate) fn action_remote_copy(&mut self, input: String) {
|
pub(crate) fn action_remote_copy(&mut self, input: String) {
|
||||||
if let Some(idx) = self.get_remote_file_idx() {
|
match self.get_local_file_state() {
|
||||||
let dest_path: PathBuf = PathBuf::from(input);
|
Some(Payload::One(Value::Usize(idx))) => {
|
||||||
let entry: FsEntry = self.remote().get(idx).unwrap().clone();
|
let dest_path: PathBuf = PathBuf::from(input);
|
||||||
match self.client.as_mut().copy(&entry, dest_path.as_path()) {
|
let entry: FsEntry = self.remote().get(idx).unwrap().clone();
|
||||||
Ok(_) => {
|
match self.client.as_mut().copy(&entry, dest_path.as_path()) {
|
||||||
self.log(
|
Ok(_) => {
|
||||||
LogLevel::Info,
|
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!(
|
format!(
|
||||||
"Copied \"{}\" to \"{}\"",
|
"Could not copy \"{}\" to \"{}\": {}",
|
||||||
entry.get_abs_path().display(),
|
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
|
// locals
|
||||||
use super::{FileTransferActivity, FsEntry, LogLevel};
|
use super::{FileTransferActivity, FsEntry, LogLevel};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use tuirealm::{Payload, Value};
|
||||||
|
|
||||||
impl FileTransferActivity {
|
impl FileTransferActivity {
|
||||||
pub(crate) fn action_local_delete(&mut self) {
|
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();
|
let entry: Option<FsEntry> = self.get_local_file_entry().cloned();
|
||||||
if let Some(entry) = entry {
|
if let Some(entry) = entry {
|
||||||
let full_path: PathBuf = entry.get_abs_path();
|
let full_path: PathBuf = entry.get_abs_path();
|
||||||
@@ -57,7 +69,7 @@ impl FileTransferActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn action_remote_delete(&mut self) {
|
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
|
// Check if file entry exists
|
||||||
let entry = self.remote().get(idx).cloned();
|
let entry = self.remote().get(idx).cloned();
|
||||||
if let Some(entry) = entry {
|
if let Some(entry) = entry {
|
||||||
|
|||||||
@@ -45,9 +45,9 @@ impl FileTransferActivity {
|
|||||||
///
|
///
|
||||||
/// Get local file entry
|
/// Get local file entry
|
||||||
pub(crate) fn get_local_file_entry(&self) -> Option<&FsEntry> {
|
pub(crate) fn get_local_file_entry(&self) -> Option<&FsEntry> {
|
||||||
match self.get_local_file_idx() {
|
match self.get_local_file_state() {
|
||||||
None => None,
|
Some(Payload::One(Value::Usize(idx))) => self.local().get(idx),
|
||||||
Some(idx) => self.local().get(idx),
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,31 +55,25 @@ impl FileTransferActivity {
|
|||||||
///
|
///
|
||||||
/// Get remote file entry
|
/// Get remote file entry
|
||||||
pub(crate) fn get_remote_file_entry(&self) -> Option<&FsEntry> {
|
pub(crate) fn get_remote_file_entry(&self) -> Option<&FsEntry> {
|
||||||
match self.get_remote_file_idx() {
|
match self.get_remote_file_state() {
|
||||||
None => None,
|
Some(Payload::One(Value::Usize(idx))) => self.remote().get(idx),
|
||||||
Some(idx) => self.remote().get(idx),
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- private
|
// -- private
|
||||||
|
|
||||||
/// ### get_local_file_idx
|
/// ### get_local_file_state
|
||||||
///
|
///
|
||||||
/// Get index of selected file in the local tab
|
/// Get index of selected file in the local tab
|
||||||
fn get_local_file_idx(&self) -> Option<usize> {
|
fn get_local_file_state(&self) -> Option<Payload> {
|
||||||
match self.view.get_state(super::COMPONENT_EXPLORER_LOCAL) {
|
self.view.get_state(super::COMPONENT_EXPLORER_LOCAL)
|
||||||
Some(Payload::One(Value::Usize(idx))) => Some(idx),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ### get_remote_file_idx
|
/// ### get_remote_file_state
|
||||||
///
|
///
|
||||||
/// Get index of selected file in the remote file
|
/// Get index of selected file in the remote file
|
||||||
fn get_remote_file_idx(&self) -> Option<usize> {
|
fn get_remote_file_state(&self) -> Option<Payload> {
|
||||||
match self.view.get_state(super::COMPONENT_EXPLORER_REMOTE) {
|
self.view.get_state(super::COMPONENT_EXPLORER_REMOTE)
|
||||||
Some(Payload::One(Value::Usize(idx))) => Some(idx),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ impl FileTransferActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn action_remote_rename(&mut self, input: String) {
|
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();
|
let entry = self.remote().get(idx).cloned();
|
||||||
if let Some(entry) = entry {
|
if let Some(entry) = entry {
|
||||||
let dst_path: PathBuf = PathBuf::from(input);
|
let dst_path: PathBuf = PathBuf::from(input);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
impl FileTransferActivity {
|
impl FileTransferActivity {
|
||||||
pub(crate) fn action_local_saveas(&mut self, input: String) {
|
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
|
// Get pwd
|
||||||
let wrkdir: PathBuf = self.remote().wrkdir.clone();
|
let wrkdir: PathBuf = self.remote().wrkdir.clone();
|
||||||
if self.local().get(idx).is_some() {
|
if self.local().get(idx).is_some() {
|
||||||
@@ -43,7 +43,7 @@ impl FileTransferActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn action_remote_saveas(&mut self, input: String) {
|
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
|
// Get pwd
|
||||||
let wrkdir: PathBuf = self.local().wrkdir.clone();
|
let wrkdir: PathBuf = self.local().wrkdir.clone();
|
||||||
if self.remote().get(idx).is_some() {
|
if self.remote().get(idx).is_some() {
|
||||||
|
|||||||
@@ -380,7 +380,7 @@ impl Component for FileList {
|
|||||||
Msg::None
|
Msg::None
|
||||||
}
|
}
|
||||||
KeyCode::Char('a') => match key.modifiers.intersects(KeyModifiers::CONTROL) {
|
KeyCode::Char('a') => match key.modifiers.intersects(KeyModifiers::CONTROL) {
|
||||||
// CTRL+C
|
// CTRL+A
|
||||||
true => {
|
true => {
|
||||||
// Select all
|
// Select all
|
||||||
self.states.select_all();
|
self.states.select_all();
|
||||||
|
|||||||
Reference in New Issue
Block a user