Open files with <V>; fixed cache file names
This commit is contained in:
parent
d981b77ed7
commit
90afe204b1
|
@ -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),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -393,10 +393,7 @@ impl Component for FileList {
|
|||
self.states.toggle_file(self.states.list_index());
|
||||
Msg::None
|
||||
}
|
||||
KeyCode::Enter => match key.modifiers.intersects(KeyModifiers::SHIFT) {
|
||||
false => Msg::OnSubmit(self.get_state()),
|
||||
true => Msg::OnKey(key),
|
||||
},
|
||||
KeyCode::Enter => Msg::OnSubmit(self.get_state()),
|
||||
_ => {
|
||||
// Return key event to activity
|
||||
Msg::OnKey(key)
|
||||
|
@ -616,14 +613,6 @@ mod tests {
|
|||
component.on(Event::Key(KeyEvent::from(KeyCode::Enter))),
|
||||
Msg::OnSubmit(Payload::One(Value::Usize(0)))
|
||||
);
|
||||
// Enter shift
|
||||
assert_eq!(
|
||||
component.on(Event::Key(KeyEvent::new(
|
||||
KeyCode::Enter,
|
||||
KeyModifiers::SHIFT
|
||||
))),
|
||||
Msg::OnKey(KeyEvent::new(KeyCode::Enter, KeyModifiers::SHIFT))
|
||||
);
|
||||
// On key
|
||||
assert_eq!(
|
||||
component.on(Event::Key(KeyEvent::from(KeyCode::Backspace))),
|
||||
|
|
|
@ -34,10 +34,6 @@ pub const MSG_KEY_ENTER: Msg = Msg::OnKey(KeyEvent {
|
|||
code: KeyCode::Enter,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
});
|
||||
pub const MSG_KEY_SHIFT_ENTER: Msg = Msg::OnKey(KeyEvent {
|
||||
code: KeyCode::Enter,
|
||||
modifiers: KeyModifiers::SHIFT,
|
||||
});
|
||||
pub const MSG_KEY_ESC: Msg = Msg::OnKey(KeyEvent {
|
||||
code: KeyCode::Esc,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
|
@ -128,7 +124,7 @@ pub const MSG_KEY_CHAR_L: Msg = Msg::OnKey(KeyEvent {
|
|||
modifiers: KeyModifiers::NONE,
|
||||
});
|
||||
/*
|
||||
pub const MSG_KEY_CHAR_M: Msg = Msg::OnKey(KeyEvent {
|
||||
pub const MSG_KEY_CHAR_M: Msg = Msg::OnKey(KeyEvent { NOTE: used for mark
|
||||
code: KeyCode::Char('m'),
|
||||
modifiers: KeyModifiers::NONE,
|
||||
});
|
||||
|
@ -169,12 +165,10 @@ pub const MSG_KEY_CHAR_U: Msg = Msg::OnKey(KeyEvent {
|
|||
code: KeyCode::Char('u'),
|
||||
modifiers: KeyModifiers::NONE,
|
||||
});
|
||||
/*
|
||||
pub const MSG_KEY_CHAR_V: Msg = Msg::OnKey(KeyEvent {
|
||||
code: KeyCode::Char('v'),
|
||||
modifiers: KeyModifiers::NONE,
|
||||
});
|
||||
*/
|
||||
pub const MSG_KEY_CHAR_W: Msg = Msg::OnKey(KeyEvent {
|
||||
code: KeyCode::Char('w'),
|
||||
modifiers: KeyModifiers::NONE,
|
||||
|
|
Loading…
Reference in a new issue