Open files with <V>; fixed cache file names

This commit is contained in:
veeso
2021-06-11 09:52:50 +02:00
parent d981b77ed7
commit 90afe204b1
6 changed files with 55 additions and 52 deletions

View File

@@ -94,13 +94,14 @@ impl FileTransferActivity {
pub(crate) fn action_open_remote_file(&mut self, entry: &FsEntry, open_with: Option<&str>) {
let entry: FsEntry = entry.get_realfile();
// Download file
let tmpfile: String = match self.get_cache_tmp_name(entry.get_name()) {
None => {
self.log(LogLevel::Error, String::from("Could not create tempdir"));
return;
}
Some(p) => p,
};
let tmpfile: String =
match self.get_cache_tmp_name(entry.get_name(), entry.get_ftype().as_deref()) {
None => {
self.log(LogLevel::Error, String::from("Could not create tempdir"));
return;
}
Some(p) => p,
};
let cache: PathBuf = match self.cache.as_ref() {
None => {
self.log(LogLevel::Error, String::from("Could not create tempdir"));
@@ -108,7 +109,7 @@ impl FileTransferActivity {
}
Some(p) => p.path().to_path_buf(),
};
self.filetransfer_recv(entry, cache.as_path(), Some(tmpfile.clone()));
self.filetransfer_recv(&entry, cache.as_path(), Some(tmpfile.clone()));
// Make file and open if file exists
let mut tmp: PathBuf = cache;
tmp.push(tmpfile.as_str());
@@ -120,17 +121,10 @@ impl FileTransferActivity {
};
// Log result
match result {
Ok(_) => self.log(
LogLevel::Info,
format!("Opened file `{}`", entry.get_abs_path().display()),
),
Ok(_) => self.log(LogLevel::Info, format!("Opened file `{}`", tmp.display())),
Err(err) => self.log(
LogLevel::Error,
format!(
"Failed to open filoe `{}`: {}",
entry.get_abs_path().display(),
err
),
format!("Failed to open filoe `{}`: {}", tmp.display(), err),
),
}
}

View File

@@ -197,16 +197,20 @@ impl FileTransferActivity {
/// ### get_cache_tmp_name
///
/// Get file name for a file in cache
pub(crate) fn get_cache_tmp_name(&self, name: &str) -> Option<String> {
pub(crate) fn get_cache_tmp_name(&self, name: &str, file_type: Option<&str>) -> Option<String> {
self.cache.as_ref().map(|_| {
format!(
let base: String = format!(
"{}-{}",
name,
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_millis()
)
);
match file_type {
None => base,
Some(file_type) => format!("{}.{}", base, file_type),
}
})
}
}

View File

@@ -211,18 +211,6 @@ impl Update for FileTransferActivity {
self.update_remote_filelist()
}
// -- common explorer keys
(COMPONENT_EXPLORER_LOCAL, &MSG_KEY_SHIFT_ENTER)
| (COMPONENT_EXPLORER_REMOTE, &MSG_KEY_SHIFT_ENTER)
| (COMPONENT_EXPLORER_FIND, &MSG_KEY_SHIFT_ENTER) => {
match self.browser.tab() {
FileExplorerTab::Local => self.action_open_local(),
FileExplorerTab::Remote => self.action_open_remote(),
FileExplorerTab::FindLocal | FileExplorerTab::FindRemote => {
self.action_find_open()
}
}
None
}
(COMPONENT_EXPLORER_LOCAL, &MSG_KEY_CHAR_B)
| (COMPONENT_EXPLORER_REMOTE, &MSG_KEY_CHAR_B) => {
// Show sorting file
@@ -278,9 +266,23 @@ impl Update for FileTransferActivity {
self.mount_saveas();
None
}
(COMPONENT_EXPLORER_LOCAL, &MSG_KEY_CHAR_V)
| (COMPONENT_EXPLORER_REMOTE, &MSG_KEY_CHAR_V)
| (COMPONENT_EXPLORER_FIND, &MSG_KEY_CHAR_V) => {
// View
match self.browser.tab() {
FileExplorerTab::Local => self.action_open_local(),
FileExplorerTab::Remote => self.action_open_remote(),
FileExplorerTab::FindLocal | FileExplorerTab::FindRemote => {
self.action_find_open()
}
}
None
}
(COMPONENT_EXPLORER_LOCAL, &MSG_KEY_CHAR_W)
| (COMPONENT_EXPLORER_REMOTE, &MSG_KEY_CHAR_W)
| (COMPONENT_EXPLORER_FIND, &MSG_KEY_CHAR_W) => {
// Open with
self.mount_openwith();
None
}

View File

@@ -959,7 +959,7 @@ impl FileTransferActivity {
.with_foreground(Color::Cyan)
.build(),
)
.add_col(TextSpan::from(" Enter directory / Open file"))
.add_col(TextSpan::from(" Enter directory"))
.add_row()
.add_col(
TextSpanBuilder::new("<SPACE>")
@@ -1091,6 +1091,26 @@ impl FileTransferActivity {
)
.add_col(TextSpan::from(" Go to parent directory"))
.add_row()
.add_col(
TextSpanBuilder::new("<V>")
.bold()
.with_foreground(Color::Cyan)
.build(),
)
.add_col(TextSpan::from(
" Open file with default application for file type",
))
.add_row()
.add_col(
TextSpanBuilder::new("<W>")
.bold()
.with_foreground(Color::Cyan)
.build(),
)
.add_col(TextSpan::from(
" Open file with specified application",
))
.add_row()
.add_col(
TextSpanBuilder::new("<X>")
.bold()