mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Open files with <V>; fixed cache file names
This commit is contained in:
@@ -94,7 +94,8 @@ impl FileTransferActivity {
|
|||||||
pub(crate) fn action_open_remote_file(&mut self, entry: &FsEntry, open_with: Option<&str>) {
|
pub(crate) fn action_open_remote_file(&mut self, entry: &FsEntry, open_with: Option<&str>) {
|
||||||
let entry: FsEntry = entry.get_realfile();
|
let entry: FsEntry = entry.get_realfile();
|
||||||
// Download file
|
// Download file
|
||||||
let tmpfile: String = match self.get_cache_tmp_name(entry.get_name()) {
|
let tmpfile: String =
|
||||||
|
match self.get_cache_tmp_name(entry.get_name(), entry.get_ftype().as_deref()) {
|
||||||
None => {
|
None => {
|
||||||
self.log(LogLevel::Error, String::from("Could not create tempdir"));
|
self.log(LogLevel::Error, String::from("Could not create tempdir"));
|
||||||
return;
|
return;
|
||||||
@@ -108,7 +109,7 @@ impl FileTransferActivity {
|
|||||||
}
|
}
|
||||||
Some(p) => p.path().to_path_buf(),
|
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
|
// Make file and open if file exists
|
||||||
let mut tmp: PathBuf = cache;
|
let mut tmp: PathBuf = cache;
|
||||||
tmp.push(tmpfile.as_str());
|
tmp.push(tmpfile.as_str());
|
||||||
@@ -120,17 +121,10 @@ impl FileTransferActivity {
|
|||||||
};
|
};
|
||||||
// Log result
|
// Log result
|
||||||
match result {
|
match result {
|
||||||
Ok(_) => self.log(
|
Ok(_) => self.log(LogLevel::Info, format!("Opened file `{}`", tmp.display())),
|
||||||
LogLevel::Info,
|
|
||||||
format!("Opened file `{}`", entry.get_abs_path().display()),
|
|
||||||
),
|
|
||||||
Err(err) => self.log(
|
Err(err) => self.log(
|
||||||
LogLevel::Error,
|
LogLevel::Error,
|
||||||
format!(
|
format!("Failed to open filoe `{}`: {}", tmp.display(), err),
|
||||||
"Failed to open filoe `{}`: {}",
|
|
||||||
entry.get_abs_path().display(),
|
|
||||||
err
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,16 +197,20 @@ impl FileTransferActivity {
|
|||||||
/// ### get_cache_tmp_name
|
/// ### get_cache_tmp_name
|
||||||
///
|
///
|
||||||
/// Get file name for a file in cache
|
/// 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(|_| {
|
self.cache.as_ref().map(|_| {
|
||||||
format!(
|
let base: String = format!(
|
||||||
"{}-{}",
|
"{}-{}",
|
||||||
name,
|
name,
|
||||||
std::time::SystemTime::now()
|
std::time::SystemTime::now()
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_millis()
|
.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()
|
self.update_remote_filelist()
|
||||||
}
|
}
|
||||||
// -- common explorer keys
|
// -- 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_LOCAL, &MSG_KEY_CHAR_B)
|
||||||
| (COMPONENT_EXPLORER_REMOTE, &MSG_KEY_CHAR_B) => {
|
| (COMPONENT_EXPLORER_REMOTE, &MSG_KEY_CHAR_B) => {
|
||||||
// Show sorting file
|
// Show sorting file
|
||||||
@@ -278,9 +266,23 @@ impl Update for FileTransferActivity {
|
|||||||
self.mount_saveas();
|
self.mount_saveas();
|
||||||
None
|
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_LOCAL, &MSG_KEY_CHAR_W)
|
||||||
| (COMPONENT_EXPLORER_REMOTE, &MSG_KEY_CHAR_W)
|
| (COMPONENT_EXPLORER_REMOTE, &MSG_KEY_CHAR_W)
|
||||||
| (COMPONENT_EXPLORER_FIND, &MSG_KEY_CHAR_W) => {
|
| (COMPONENT_EXPLORER_FIND, &MSG_KEY_CHAR_W) => {
|
||||||
|
// Open with
|
||||||
self.mount_openwith();
|
self.mount_openwith();
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -959,7 +959,7 @@ impl FileTransferActivity {
|
|||||||
.with_foreground(Color::Cyan)
|
.with_foreground(Color::Cyan)
|
||||||
.build(),
|
.build(),
|
||||||
)
|
)
|
||||||
.add_col(TextSpan::from(" Enter directory / Open file"))
|
.add_col(TextSpan::from(" Enter directory"))
|
||||||
.add_row()
|
.add_row()
|
||||||
.add_col(
|
.add_col(
|
||||||
TextSpanBuilder::new("<SPACE>")
|
TextSpanBuilder::new("<SPACE>")
|
||||||
@@ -1091,6 +1091,26 @@ impl FileTransferActivity {
|
|||||||
)
|
)
|
||||||
.add_col(TextSpan::from(" Go to parent directory"))
|
.add_col(TextSpan::from(" Go to parent directory"))
|
||||||
.add_row()
|
.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(
|
.add_col(
|
||||||
TextSpanBuilder::new("<X>")
|
TextSpanBuilder::new("<X>")
|
||||||
.bold()
|
.bold()
|
||||||
|
|||||||
@@ -393,10 +393,7 @@ impl Component for FileList {
|
|||||||
self.states.toggle_file(self.states.list_index());
|
self.states.toggle_file(self.states.list_index());
|
||||||
Msg::None
|
Msg::None
|
||||||
}
|
}
|
||||||
KeyCode::Enter => match key.modifiers.intersects(KeyModifiers::SHIFT) {
|
KeyCode::Enter => Msg::OnSubmit(self.get_state()),
|
||||||
false => Msg::OnSubmit(self.get_state()),
|
|
||||||
true => Msg::OnKey(key),
|
|
||||||
},
|
|
||||||
_ => {
|
_ => {
|
||||||
// Return key event to activity
|
// Return key event to activity
|
||||||
Msg::OnKey(key)
|
Msg::OnKey(key)
|
||||||
@@ -616,14 +613,6 @@ mod tests {
|
|||||||
component.on(Event::Key(KeyEvent::from(KeyCode::Enter))),
|
component.on(Event::Key(KeyEvent::from(KeyCode::Enter))),
|
||||||
Msg::OnSubmit(Payload::One(Value::Usize(0)))
|
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
|
// On key
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
component.on(Event::Key(KeyEvent::from(KeyCode::Backspace))),
|
component.on(Event::Key(KeyEvent::from(KeyCode::Backspace))),
|
||||||
|
|||||||
@@ -34,10 +34,6 @@ pub const MSG_KEY_ENTER: Msg = Msg::OnKey(KeyEvent {
|
|||||||
code: KeyCode::Enter,
|
code: KeyCode::Enter,
|
||||||
modifiers: KeyModifiers::NONE,
|
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 {
|
pub const MSG_KEY_ESC: Msg = Msg::OnKey(KeyEvent {
|
||||||
code: KeyCode::Esc,
|
code: KeyCode::Esc,
|
||||||
modifiers: KeyModifiers::NONE,
|
modifiers: KeyModifiers::NONE,
|
||||||
@@ -128,7 +124,7 @@ pub const MSG_KEY_CHAR_L: Msg = Msg::OnKey(KeyEvent {
|
|||||||
modifiers: KeyModifiers::NONE,
|
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'),
|
code: KeyCode::Char('m'),
|
||||||
modifiers: KeyModifiers::NONE,
|
modifiers: KeyModifiers::NONE,
|
||||||
});
|
});
|
||||||
@@ -169,12 +165,10 @@ pub const MSG_KEY_CHAR_U: Msg = Msg::OnKey(KeyEvent {
|
|||||||
code: KeyCode::Char('u'),
|
code: KeyCode::Char('u'),
|
||||||
modifiers: KeyModifiers::NONE,
|
modifiers: KeyModifiers::NONE,
|
||||||
});
|
});
|
||||||
/*
|
|
||||||
pub const MSG_KEY_CHAR_V: Msg = Msg::OnKey(KeyEvent {
|
pub const MSG_KEY_CHAR_V: Msg = Msg::OnKey(KeyEvent {
|
||||||
code: KeyCode::Char('v'),
|
code: KeyCode::Char('v'),
|
||||||
modifiers: KeyModifiers::NONE,
|
modifiers: KeyModifiers::NONE,
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
pub const MSG_KEY_CHAR_W: Msg = Msg::OnKey(KeyEvent {
|
pub const MSG_KEY_CHAR_W: Msg = Msg::OnKey(KeyEvent {
|
||||||
code: KeyCode::Char('w'),
|
code: KeyCode::Char('w'),
|
||||||
modifiers: KeyModifiers::NONE,
|
modifiers: KeyModifiers::NONE,
|
||||||
|
|||||||
Reference in New Issue
Block a user