open-rs fixes

This commit is contained in:
veeso
2021-06-19 15:03:28 +02:00
parent b73c3228e4
commit 00bee04c2c
4 changed files with 55 additions and 58 deletions

View File

@@ -42,12 +42,14 @@ pub(crate) mod rename;
pub(crate) mod save; pub(crate) mod save;
pub(crate) mod submit; pub(crate) mod submit;
#[derive(Debug)]
pub(crate) enum SelectedEntry { pub(crate) enum SelectedEntry {
One(FsEntry), One(FsEntry),
Many(Vec<FsEntry>), Many(Vec<FsEntry>),
None, None,
} }
#[derive(Debug)]
enum SelectedEntryIndex { enum SelectedEntryIndex {
One(usize), One(usize),
Many(Vec<usize>), Many(Vec<usize>),

View File

@@ -57,7 +57,6 @@ use lib::transfer::TransferStates;
use chrono::{DateTime, Local}; use chrono::{DateTime, Local};
use crossterm::terminal::{disable_raw_mode, enable_raw_mode}; use crossterm::terminal::{disable_raw_mode, enable_raw_mode};
use std::collections::VecDeque; use std::collections::VecDeque;
use std::path::PathBuf;
use tempfile::TempDir; use tempfile::TempDir;
use tuirealm::View; use tuirealm::View;
@@ -236,11 +235,8 @@ impl Activity for FileTransferActivity {
if let Err(err) = enable_raw_mode() { if let Err(err) = enable_raw_mode() {
error!("Failed to enter raw mode: {}", err); error!("Failed to enter raw mode: {}", err);
} }
// Set working directory // Get files at current pwd
let pwd: PathBuf = self.host.pwd(); self.reload_local_dir();
// Get files at current wd
self.local_scan(pwd.as_path());
self.local_mut().wrkdir = pwd;
debug!("Read working directory"); debug!("Read working directory");
// Configure text editor // Configure text editor
self.setup_text_editor(); self.setup_text_editor();

View File

@@ -135,19 +135,59 @@ impl FileTransferActivity {
/// ### reload_remote_dir /// ### reload_remote_dir
/// ///
/// Reload remote directory entries /// Reload remote directory entries and update browser
pub(super) fn reload_remote_dir(&mut self) { pub(super) fn reload_remote_dir(&mut self) {
// Get current entries // Get current entries
if let Ok(pwd) = self.client.pwd() { if let Ok(wrkdir) = self.client.pwd() {
self.remote_scan(pwd.as_path()); self.remote_scan(wrkdir.as_path());
// Set wrkdir // Set wrkdir
self.remote_mut().wrkdir = pwd; self.remote_mut().wrkdir = wrkdir;
} }
} }
/// ### reload_local_dir
///
/// Reload local directory entries and update browser
pub(super) fn reload_local_dir(&mut self) { pub(super) fn reload_local_dir(&mut self) {
let wrkdir: PathBuf = self.local().wrkdir.clone(); let wrkdir: PathBuf = self.host.pwd();
self.local_scan(wrkdir.as_path()); self.local_scan(wrkdir.as_path());
self.local_mut().wrkdir = wrkdir;
}
/// ### local_scan
///
/// Scan current local directory
fn local_scan(&mut self, path: &Path) {
match self.host.scan_dir(path) {
Ok(files) => {
// Set files and sort (sorting is implicit)
self.local_mut().set_files(files);
}
Err(err) => {
self.log_and_alert(
LogLevel::Error,
format!("Could not scan current directory: {}", err),
);
}
}
}
/// ### remote_scan
///
/// Scan current remote directory
fn remote_scan(&mut self, path: &Path) {
match self.client.list_dir(path) {
Ok(files) => {
// Set files and sort (sorting is implicit)
self.remote_mut().set_files(files);
}
Err(err) => {
self.log_and_alert(
LogLevel::Error,
format!("Could not scan current directory: {}", err),
);
}
}
} }
/// ### filetransfer_send /// ### filetransfer_send
@@ -559,7 +599,7 @@ impl FileTransferActivity {
} }
} }
// Reload directory on local // Reload directory on local
self.local_scan(local_path); self.reload_local_dir();
// if aborted; show alert // if aborted; show alert
if self.transfer.aborted() { if self.transfer.aborted() {
// Log abort // Log abort
@@ -688,42 +728,6 @@ impl FileTransferActivity {
Ok(()) Ok(())
} }
/// ### local_scan
///
/// Scan current local directory
pub(super) fn local_scan(&mut self, path: &Path) {
match self.host.scan_dir(path) {
Ok(files) => {
// Set files and sort (sorting is implicit)
self.local_mut().set_files(files);
}
Err(err) => {
self.log_and_alert(
LogLevel::Error,
format!("Could not scan current directory: {}", err),
);
}
}
}
/// ### remote_scan
///
/// Scan current remote directory
pub(super) fn remote_scan(&mut self, path: &Path) {
match self.client.list_dir(path) {
Ok(files) => {
// Set files and sort (sorting is implicit)
self.remote_mut().set_files(files);
}
Err(err) => {
self.log_and_alert(
LogLevel::Error,
format!("Could not scan current directory: {}", err),
);
}
}
}
/// ### local_changedir /// ### local_changedir
/// ///
/// Change directory for local /// Change directory for local
@@ -738,9 +742,7 @@ impl FileTransferActivity {
format!("Changed directory on local: {}", path.display()), format!("Changed directory on local: {}", path.display()),
); );
// Reload files // Reload files
self.local_scan(path); self.reload_local_dir();
// Set wrkdir
self.local_mut().wrkdir = PathBuf::from(path);
// Push prev_dir to stack // Push prev_dir to stack
if push { if push {
self.local_mut().pushd(prev_dir.as_path()) self.local_mut().pushd(prev_dir.as_path())
@@ -767,9 +769,7 @@ impl FileTransferActivity {
format!("Changed directory on remote: {}", path.display()), format!("Changed directory on remote: {}", path.display()),
); );
// Update files // Update files
self.remote_scan(path); self.reload_remote_dir();
// Set wrkdir
self.remote_mut().wrkdir = PathBuf::from(path);
// Push prev_dir to stack // Push prev_dir to stack
if push { if push {
self.remote_mut().pushd(prev_dir.as_path()) self.remote_mut().pushd(prev_dir.as_path())
@@ -809,6 +809,7 @@ impl FileTransferActivity {
return Err(format!("Could not read file: {}", err)); return Err(format!("Could not read file: {}", err));
} }
} }
debug!("Ok, file {} is textual; opening file...", path.display());
// Put input mode back to normal // Put input mode back to normal
if let Err(err) = disable_raw_mode() { if let Err(err) = disable_raw_mode() {
error!("Failed to disable raw mode: {}", err); error!("Failed to disable raw mode: {}", err);

View File

@@ -118,8 +118,7 @@ impl Update for FileTransferActivity {
} }
(COMPONENT_EXPLORER_LOCAL, &MSG_KEY_CHAR_L) => { (COMPONENT_EXPLORER_LOCAL, &MSG_KEY_CHAR_L) => {
// Reload directory // Reload directory
let pwd: PathBuf = self.local().wrkdir.clone(); self.reload_local_dir();
self.local_scan(pwd.as_path());
// Reload file list component // Reload file list component
self.update_local_filelist() self.update_local_filelist()
} }
@@ -191,8 +190,7 @@ impl Update for FileTransferActivity {
} }
(COMPONENT_EXPLORER_REMOTE, &MSG_KEY_CHAR_L) => { (COMPONENT_EXPLORER_REMOTE, &MSG_KEY_CHAR_L) => {
// Reload directory // Reload directory
let pwd: PathBuf = self.remote().wrkdir.clone(); self.reload_remote_dir();
self.remote_scan(pwd.as_path());
// Reload file list component // Reload file list component
self.update_remote_filelist() self.update_remote_filelist()
} }