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:
Christian Visintin
2026-04-19 01:54:46 +05:30
parent 3fb61a76fe
commit f6d35f1eea
75 changed files with 6595 additions and 6704 deletions
@@ -1,33 +1,33 @@
//! ## 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
use std::fs::File as StdFile;
use std::path::PathBuf;
use remotefs::fs::Metadata;
use super::{File, FileTransferActivity, LogLevel};
use super::{FileTransferActivity, LogLevel};
impl FileTransferActivity {
pub(crate) fn action_local_newfile(&mut self, input: String) {
// Check if file exists
let mut file_exists: bool = false;
for file in self.host_bridge().iter_files_all() {
if input == file.name() {
file_exists = true;
}
}
if file_exists {
self.log_and_alert(LogLevel::Warn, format!("File \"{input}\" already exists",));
/// Create a new empty file via the active tab's pane.
pub(crate) fn action_newfile(&mut self, input: String) {
// Check if file exists in current explorer listing
if self
.browser
.explorer()
.iter_files_all()
.any(|file| input == file.name())
{
self.log_and_alert(LogLevel::Warn, format!("File \"{input}\" already exists"));
return;
}
// Create file
let file_path: PathBuf = PathBuf::from(input.as_str());
let file_path = PathBuf::from(input.as_str());
let writer = match self
.host_bridge
.browser
.fs_pane_mut()
.fs
.create_file(file_path.as_path(), &Metadata::default())
{
Ok(f) => f,
@@ -40,7 +40,7 @@ impl FileTransferActivity {
}
};
// finalize write
if let Err(err) = self.host_bridge.finalize_write(writer) {
if let Err(err) = self.browser.fs_pane_mut().fs.finalize_write(writer) {
self.log_and_alert(
LogLevel::Error,
format!("Could not write file \"{}\": {}", file_path.display(), err),
@@ -53,67 +53,4 @@ impl FileTransferActivity {
format!("Created file \"{}\"", file_path.display()),
);
}
pub(crate) fn action_remote_newfile(&mut self, input: String) {
// Check if file exists
let mut file_exists: bool = false;
for file in self.remote().iter_files_all() {
if input == file.name() {
file_exists = true;
}
}
if file_exists {
self.log_and_alert(LogLevel::Warn, format!("File \"{input}\" already exists",));
return;
}
// Get path on remote
let file_path: PathBuf = PathBuf::from(input.as_str());
// Create file (on local)
match tempfile::NamedTempFile::new() {
Err(err) => {
self.log_and_alert(LogLevel::Error, format!("Could not create tempfile: {err}"))
}
Ok(tfile) => {
// Stat tempfile
let local_file: File = match self.host_bridge.stat(tfile.path()) {
Err(err) => {
self.log_and_alert(
LogLevel::Error,
format!("Could not stat tempfile: {err}"),
);
return;
}
Ok(f) => f,
};
if local_file.is_file() {
// Create file
let reader = Box::new(match StdFile::open(tfile.path()) {
Ok(f) => f,
Err(err) => {
self.log_and_alert(
LogLevel::Error,
format!("Could not open tempfile: {err}"),
);
return;
}
});
match self
.client
.create_file(file_path.as_path(), &local_file.metadata, reader)
{
Err(err) => self.log_and_alert(
LogLevel::Error,
format!("Could not create file \"{}\": {}", file_path.display(), err),
),
Ok(_) => {
self.log(
LogLevel::Info,
format!("Created file \"{}\"", file_path.display()),
);
}
}
}
}
}
}
}