mirror of
https://github.com/veeso/termscp.git
synced 2026-09-28 06:51:20 -07:00
refactor: FileTransferActivity pane-agnostic dispatch (#386)
Comprehensive design for incremental refactoring of the 13k-line FileTransferActivity god-struct using a unified Pane abstraction. Detailed step-by-step plan covering 6 phases: split monoliths, error handling, Pane struct, action dedup, session split, view reorg. Extract 26 popup components from the monolithic 1,868-line popups.rs into 20 individual files under popups/. Each file contains one or two related components with their own imports. The popups.rs module file now contains only module declarations and re-exports. Replace 8 panic!() calls with error!() logging and early returns/fallthrough. These panics documented invariants (e.g. "this tab can't do X") but would crash the app if somehow triggered. Error logging is safer and more resilient. Replace raw FileExplorer fields in Browser with Pane structs that bundle the explorer and connected state. Move host_bridge_connected and remote_connected from FileTransferActivity into the panes. Add navigation API (fs_pane, opposite_pane, is_find_tab) for future unification tasks. Rename private get_selected_file to get_selected_file_by_id and add three new unified methods (get_selected_entries, get_selected_file, is_selected_one) that dispatch based on self.browser.tab(). Old per-tab methods are kept for now until their callers are migrated in subsequent tasks. Collapse _local_/_remote_ action method pairs (mkdir, delete, symlink, chmod, rename, copy) into unified methods that branch internally on is_local_tab(). This halves the number of action methods and simplifies the update.rs dispatch logic. Also unifies ShowFileInfoPopup and ShowChmodPopup dispatching to use get_selected_entries(). Move `host_bridge` and `client` filesystem fields from FileTransferActivity into the Pane struct, enabling tab-agnostic dispatch via `fs_pane()`/ `fs_pane_mut()`. This eliminates most `is_local_tab()` branching across 15+ action files. Key changes: - Add `fs: Box<dyn HostBridge>` to Pane, remove from FileTransferActivity - Replace per-side method pairs with unified pane-dispatched methods - Unify navigation (changedir, reload, scan, file_exists, has_file_changed) - Replace 147-line popup if/else chain with data-driven priority table - Replace assert!/panic!/unreachable! with proper error handling - Fix typo "filetransfer_activiy" across ~29 files - Add unit tests for Pane Net result: -473 lines, single code path for most file operations.
This commit is contained in:
@@ -1,57 +1,50 @@
|
||||
//! ## FileTransferActivity
|
||||
//!
|
||||
//! `filetransfer_activiy` is the module which implements the Filetransfer activity, which is the main activity afterall
|
||||
//! `filetransfer_activity` is the module which implements the Filetransfer activity, which is the main activity afterall
|
||||
|
||||
// locals
|
||||
// ext
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use super::{File, FileTransferActivity, LogLevel, SelectedFile, TransferPayload};
|
||||
use super::{File, FileTransferActivity, LogLevel, TransferPayload};
|
||||
|
||||
impl FileTransferActivity {
|
||||
/// Open local file
|
||||
pub(crate) fn action_open_local(&mut self) {
|
||||
let entries: Vec<File> = match self.get_local_selected_entries() {
|
||||
SelectedFile::One(entry) => vec![entry],
|
||||
SelectedFile::Many(entries) => entries.into_iter().map(|(f, _)| f).collect(),
|
||||
SelectedFile::None => vec![],
|
||||
};
|
||||
entries
|
||||
.iter()
|
||||
.for_each(|x| self.action_open_local_file(x, None));
|
||||
/// Open selected file(s) with default application
|
||||
pub(crate) fn action_open(&mut self) {
|
||||
let entries = self.get_selected_entries().get_files();
|
||||
entries.iter().for_each(|x| self.open_file(x, None));
|
||||
|
||||
// clear selection
|
||||
self.host_bridge_mut().clear_queue();
|
||||
self.reload_host_bridge_filelist();
|
||||
// clear queue
|
||||
self.browser.explorer_mut().clear_queue();
|
||||
self.reload_browser_file_list();
|
||||
}
|
||||
|
||||
/// Open local file
|
||||
pub(crate) fn action_open_remote(&mut self) {
|
||||
let entries: Vec<File> = match self.get_remote_selected_entries() {
|
||||
SelectedFile::One(entry) => vec![entry],
|
||||
SelectedFile::Many(entries) => entries.into_iter().map(|(f, _)| f).collect(),
|
||||
SelectedFile::None => vec![],
|
||||
};
|
||||
entries
|
||||
.iter()
|
||||
.for_each(|x| self.action_open_remote_file(x, None));
|
||||
/// Open selected file(s) with provided application
|
||||
pub(crate) fn action_open_with(&mut self, with: &str) {
|
||||
let entries = self.get_selected_entries().get_files();
|
||||
entries.iter().for_each(|x| self.open_file(x, Some(with)));
|
||||
|
||||
// clear selection
|
||||
self.remote_mut().clear_queue();
|
||||
self.reload_remote_filelist();
|
||||
// clear queue
|
||||
self.browser.explorer_mut().clear_queue();
|
||||
self.reload_browser_file_list();
|
||||
}
|
||||
|
||||
/// Perform open lopcal file
|
||||
pub(crate) fn action_open_local_file(&mut self, entry: &File, open_with: Option<&str>) {
|
||||
if self.host_bridge.is_localhost() {
|
||||
/// Open a file, dispatching based on whether the active pane is localhost.
|
||||
pub(crate) fn open_file(&mut self, entry: &File, open_with: Option<&str>) {
|
||||
if self.browser.fs_pane().fs.is_localhost() {
|
||||
// Direct open from local path
|
||||
self.open_path_with(entry.path(), open_with);
|
||||
} else {
|
||||
} else if self.is_local_tab() {
|
||||
// Non-localhost host bridge: download via HostBridge API
|
||||
self.open_bridged_file(entry, open_with);
|
||||
} else {
|
||||
// Remote: download via filetransfer_recv
|
||||
self.action_open_remote_file(entry, open_with);
|
||||
}
|
||||
}
|
||||
|
||||
/// Open remote file. The file is first downloaded to a temporary directory on localhost
|
||||
pub(crate) fn action_open_remote_file(&mut self, entry: &File, open_with: Option<&str>) {
|
||||
fn action_open_remote_file(&mut self, entry: &File, open_with: Option<&str>) {
|
||||
// Download file
|
||||
let tmpfile: String =
|
||||
match self.get_cache_tmp_name(&entry.name(), entry.extension().as_deref()) {
|
||||
@@ -90,39 +83,6 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// Open selected file with provided application
|
||||
pub(crate) fn action_local_open_with(&mut self, with: &str) {
|
||||
let entries: Vec<File> = match self.get_local_selected_entries() {
|
||||
SelectedFile::One(entry) => vec![entry],
|
||||
SelectedFile::Many(entries) => entries.into_iter().map(|(f, _)| f).collect(),
|
||||
SelectedFile::None => vec![],
|
||||
};
|
||||
// Open all entries
|
||||
entries
|
||||
.iter()
|
||||
.for_each(|x| self.action_open_local_file(x, Some(with)));
|
||||
|
||||
// clear selection
|
||||
self.host_bridge_mut().clear_queue();
|
||||
}
|
||||
|
||||
/// Open selected file with provided application
|
||||
pub(crate) fn action_remote_open_with(&mut self, with: &str) {
|
||||
let entries: Vec<File> = match self.get_remote_selected_entries() {
|
||||
SelectedFile::One(entry) => vec![entry],
|
||||
SelectedFile::Many(entries) => entries.into_iter().map(|(f, _)| f).collect(),
|
||||
SelectedFile::None => vec![],
|
||||
};
|
||||
// Open all entries
|
||||
entries
|
||||
.iter()
|
||||
.for_each(|x| self.action_open_remote_file(x, Some(with)));
|
||||
|
||||
// clear selection
|
||||
self.remote_mut().clear_queue();
|
||||
self.reload_remote_filelist();
|
||||
}
|
||||
|
||||
fn open_bridged_file(&mut self, entry: &File, open_with: Option<&str>) {
|
||||
// Download file
|
||||
let tmpfile: String =
|
||||
@@ -144,7 +104,7 @@ impl FileTransferActivity {
|
||||
let tmpfile = cache.join(tmpfile);
|
||||
|
||||
// open from host bridge
|
||||
let mut reader = match self.host_bridge.open_file(entry.path()) {
|
||||
let mut reader = match self.browser.local_pane_mut().fs.open_file(entry.path()) {
|
||||
Ok(reader) => reader,
|
||||
Err(err) => {
|
||||
self.log(
|
||||
|
||||
Reference in New Issue
Block a user