mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Open file with
This commit is contained in:
@@ -140,4 +140,49 @@ impl FileTransferActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn action_find_open(&mut self) {
|
||||||
|
match self.get_found_selected_entries() {
|
||||||
|
SelectedEntry::One(entry) => {
|
||||||
|
// Open file
|
||||||
|
self.open_found_file(&entry, None);
|
||||||
|
}
|
||||||
|
SelectedEntry::Many(entries) => {
|
||||||
|
// Iter files
|
||||||
|
for entry in entries.iter() {
|
||||||
|
// Open file
|
||||||
|
self.open_found_file(entry, None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SelectedEntry::None => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn action_find_open_with(&mut self, with: &str) {
|
||||||
|
match self.get_found_selected_entries() {
|
||||||
|
SelectedEntry::One(entry) => {
|
||||||
|
// Open file
|
||||||
|
self.open_found_file(&entry, Some(with));
|
||||||
|
}
|
||||||
|
SelectedEntry::Many(entries) => {
|
||||||
|
// Iter files
|
||||||
|
for entry in entries.iter() {
|
||||||
|
// Open file
|
||||||
|
self.open_found_file(entry, Some(with));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SelectedEntry::None => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn open_found_file(&mut self, entry: &FsEntry, with: Option<&str>) {
|
||||||
|
match self.browser.tab() {
|
||||||
|
FileExplorerTab::FindLocal | FileExplorerTab::Local => {
|
||||||
|
self.action_open_local(entry, with);
|
||||||
|
}
|
||||||
|
FileExplorerTab::FindRemote | FileExplorerTab::Remote => {
|
||||||
|
self.action_open_remote(entry, with);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,13 +28,13 @@
|
|||||||
// deps
|
// deps
|
||||||
extern crate open;
|
extern crate open;
|
||||||
// locals
|
// locals
|
||||||
use super::{FileTransferActivity, FsEntry, LogLevel};
|
use super::{FileTransferActivity, FsEntry, LogLevel, SelectedEntry};
|
||||||
|
|
||||||
impl FileTransferActivity {
|
impl FileTransferActivity {
|
||||||
/// ### action_open_local
|
/// ### action_open_local
|
||||||
///
|
///
|
||||||
/// Open local file
|
/// Open local file
|
||||||
pub(crate) fn action_open_local(&mut self, entry: FsEntry, open_with: Option<String>) {
|
pub(crate) fn action_open_local(&mut self, entry: &FsEntry, open_with: Option<&str>) {
|
||||||
let real_entry: FsEntry = entry.get_realfile();
|
let real_entry: FsEntry = entry.get_realfile();
|
||||||
if let FsEntry::File(file) = real_entry {
|
if let FsEntry::File(file) = real_entry {
|
||||||
// Open file
|
// Open file
|
||||||
@@ -63,7 +63,7 @@ impl FileTransferActivity {
|
|||||||
/// ### action_open_local
|
/// ### action_open_local
|
||||||
///
|
///
|
||||||
/// Open remote file. The file is first downloaded to a temporary directory on localhost
|
/// Open remote file. The file is first downloaded to a temporary directory on localhost
|
||||||
pub(crate) fn action_open_remote(&mut self, entry: FsEntry, open_with: Option<String>) {
|
pub(crate) fn action_open_remote(&mut self, entry: &FsEntry, open_with: Option<&str>) {
|
||||||
let real_entry: FsEntry = entry.get_realfile();
|
let real_entry: FsEntry = entry.get_realfile();
|
||||||
if let FsEntry::File(file) = real_entry {
|
if let FsEntry::File(file) = real_entry {
|
||||||
// Download file
|
// Download file
|
||||||
@@ -99,4 +99,34 @@ impl FileTransferActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ### action_local_open_with
|
||||||
|
///
|
||||||
|
/// Open selected file with provided application
|
||||||
|
pub(crate) fn action_local_open_with(&mut self, with: &str) {
|
||||||
|
let entries: Vec<FsEntry> = match self.get_local_selected_entries() {
|
||||||
|
SelectedEntry::One(entry) => vec![entry],
|
||||||
|
SelectedEntry::Many(entries) => entries,
|
||||||
|
SelectedEntry::None => vec![],
|
||||||
|
};
|
||||||
|
// Open all entries
|
||||||
|
for entry in entries.iter() {
|
||||||
|
self.action_open_local(entry, Some(with));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ### action_remote_open_with
|
||||||
|
///
|
||||||
|
/// Open selected file with provided application
|
||||||
|
pub(crate) fn action_remote_open_with(&mut self, with: &str) {
|
||||||
|
let entries: Vec<FsEntry> = match self.get_remote_selected_entries() {
|
||||||
|
SelectedEntry::One(entry) => vec![entry],
|
||||||
|
SelectedEntry::Many(entries) => entries,
|
||||||
|
SelectedEntry::None => vec![],
|
||||||
|
};
|
||||||
|
// Open all entries
|
||||||
|
for entry in entries.iter() {
|
||||||
|
self.action_open_remote(entry, Some(with));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ impl FileTransferActivity {
|
|||||||
match action {
|
match action {
|
||||||
SubmitAction::ChangeDir => self.action_enter_local_dir(entry, false),
|
SubmitAction::ChangeDir => self.action_enter_local_dir(entry, false),
|
||||||
SubmitAction::OpenFile => {
|
SubmitAction::OpenFile => {
|
||||||
self.action_open_local(entry, None);
|
self.action_open_local(&entry, None);
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,7 +86,7 @@ impl FileTransferActivity {
|
|||||||
match action {
|
match action {
|
||||||
SubmitAction::ChangeDir => self.action_enter_remote_dir(entry, false),
|
SubmitAction::ChangeDir => self.action_enter_remote_dir(entry, false),
|
||||||
SubmitAction::OpenFile => {
|
SubmitAction::OpenFile => {
|
||||||
self.action_open_remote(entry, None);
|
self.action_open_remote(&entry, None);
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ const COMPONENT_INPUT_FIND: &str = "INPUT_FIND";
|
|||||||
const COMPONENT_INPUT_GOTO: &str = "INPUT_GOTO";
|
const COMPONENT_INPUT_GOTO: &str = "INPUT_GOTO";
|
||||||
const COMPONENT_INPUT_MKDIR: &str = "INPUT_MKDIR";
|
const COMPONENT_INPUT_MKDIR: &str = "INPUT_MKDIR";
|
||||||
const COMPONENT_INPUT_NEWFILE: &str = "INPUT_NEWFILE";
|
const COMPONENT_INPUT_NEWFILE: &str = "INPUT_NEWFILE";
|
||||||
|
const COMPONENT_INPUT_OPEN_WITH: &str = "INPUT_OPEN_WITH";
|
||||||
const COMPONENT_INPUT_RENAME: &str = "INPUT_RENAME";
|
const COMPONENT_INPUT_RENAME: &str = "INPUT_RENAME";
|
||||||
const COMPONENT_INPUT_SAVEAS: &str = "INPUT_SAVEAS";
|
const COMPONENT_INPUT_SAVEAS: &str = "INPUT_SAVEAS";
|
||||||
const COMPONENT_RADIO_DELETE: &str = "RADIO_DELETE";
|
const COMPONENT_RADIO_DELETE: &str = "RADIO_DELETE";
|
||||||
|
|||||||
@@ -32,11 +32,11 @@ use super::{
|
|||||||
actions::SelectedEntry, browser::FileExplorerTab, FileTransferActivity, LogLevel,
|
actions::SelectedEntry, browser::FileExplorerTab, FileTransferActivity, LogLevel,
|
||||||
COMPONENT_EXPLORER_FIND, COMPONENT_EXPLORER_LOCAL, COMPONENT_EXPLORER_REMOTE,
|
COMPONENT_EXPLORER_FIND, COMPONENT_EXPLORER_LOCAL, COMPONENT_EXPLORER_REMOTE,
|
||||||
COMPONENT_INPUT_COPY, COMPONENT_INPUT_EXEC, COMPONENT_INPUT_FIND, COMPONENT_INPUT_GOTO,
|
COMPONENT_INPUT_COPY, COMPONENT_INPUT_EXEC, COMPONENT_INPUT_FIND, COMPONENT_INPUT_GOTO,
|
||||||
COMPONENT_INPUT_MKDIR, COMPONENT_INPUT_NEWFILE, COMPONENT_INPUT_RENAME, COMPONENT_INPUT_SAVEAS,
|
COMPONENT_INPUT_MKDIR, COMPONENT_INPUT_NEWFILE, COMPONENT_INPUT_OPEN_WITH,
|
||||||
COMPONENT_LIST_FILEINFO, COMPONENT_LOG_BOX, COMPONENT_PROGRESS_BAR_FULL,
|
COMPONENT_INPUT_RENAME, COMPONENT_INPUT_SAVEAS, COMPONENT_LIST_FILEINFO, COMPONENT_LOG_BOX,
|
||||||
COMPONENT_PROGRESS_BAR_PARTIAL, COMPONENT_RADIO_DELETE, COMPONENT_RADIO_DISCONNECT,
|
COMPONENT_PROGRESS_BAR_FULL, COMPONENT_PROGRESS_BAR_PARTIAL, COMPONENT_RADIO_DELETE,
|
||||||
COMPONENT_RADIO_QUIT, COMPONENT_RADIO_SORTING, COMPONENT_TEXT_ERROR, COMPONENT_TEXT_FATAL,
|
COMPONENT_RADIO_DISCONNECT, COMPONENT_RADIO_QUIT, COMPONENT_RADIO_SORTING,
|
||||||
COMPONENT_TEXT_HELP,
|
COMPONENT_TEXT_ERROR, COMPONENT_TEXT_FATAL, COMPONENT_TEXT_HELP,
|
||||||
};
|
};
|
||||||
use crate::fs::explorer::FileSorting;
|
use crate::fs::explorer::FileSorting;
|
||||||
use crate::fs::FsEntry;
|
use crate::fs::FsEntry;
|
||||||
@@ -266,6 +266,12 @@ impl Update for FileTransferActivity {
|
|||||||
self.mount_saveas();
|
self.mount_saveas();
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
(COMPONENT_EXPLORER_LOCAL, &MSG_KEY_CHAR_W)
|
||||||
|
| (COMPONENT_EXPLORER_REMOTE, &MSG_KEY_CHAR_W)
|
||||||
|
| (COMPONENT_EXPLORER_FIND, &MSG_KEY_CHAR_W) => {
|
||||||
|
self.mount_openwith();
|
||||||
|
None
|
||||||
|
}
|
||||||
(COMPONENT_EXPLORER_LOCAL, &MSG_KEY_CHAR_X)
|
(COMPONENT_EXPLORER_LOCAL, &MSG_KEY_CHAR_X)
|
||||||
| (COMPONENT_EXPLORER_REMOTE, &MSG_KEY_CHAR_X) => {
|
| (COMPONENT_EXPLORER_REMOTE, &MSG_KEY_CHAR_X) => {
|
||||||
// Mount exec
|
// Mount exec
|
||||||
@@ -484,6 +490,22 @@ impl Update for FileTransferActivity {
|
|||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// -- open with
|
||||||
|
(COMPONENT_INPUT_OPEN_WITH, &MSG_KEY_ESC) => {
|
||||||
|
self.umount_openwith();
|
||||||
|
None
|
||||||
|
}
|
||||||
|
(COMPONENT_INPUT_OPEN_WITH, Msg::OnSubmit(Payload::One(Value::Str(input)))) => {
|
||||||
|
match self.browser.tab() {
|
||||||
|
FileExplorerTab::Local => self.action_local_open_with(input),
|
||||||
|
FileExplorerTab::Remote => self.action_remote_open_with(input),
|
||||||
|
FileExplorerTab::FindLocal | FileExplorerTab::FindRemote => {
|
||||||
|
self.action_find_open_with(input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.umount_openwith();
|
||||||
|
None
|
||||||
|
}
|
||||||
// -- rename
|
// -- rename
|
||||||
(COMPONENT_INPUT_RENAME, &MSG_KEY_ESC) => {
|
(COMPONENT_INPUT_RENAME, &MSG_KEY_ESC) => {
|
||||||
self.umount_rename();
|
self.umount_rename();
|
||||||
|
|||||||
@@ -215,6 +215,14 @@ impl FileTransferActivity {
|
|||||||
self.view.render(super::COMPONENT_INPUT_NEWFILE, f, popup);
|
self.view.render(super::COMPONENT_INPUT_NEWFILE, f, popup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let Some(props) = self.view.get_props(super::COMPONENT_INPUT_OPEN_WITH) {
|
||||||
|
if props.visible {
|
||||||
|
let popup = draw_area_in(f.size(), 40, 10);
|
||||||
|
f.render_widget(Clear, popup);
|
||||||
|
// make popup
|
||||||
|
self.view.render(super::COMPONENT_INPUT_OPEN_WITH, f, popup);
|
||||||
|
}
|
||||||
|
}
|
||||||
if let Some(props) = self.view.get_props(super::COMPONENT_INPUT_RENAME) {
|
if let Some(props) = self.view.get_props(super::COMPONENT_INPUT_RENAME) {
|
||||||
if props.visible {
|
if props.visible {
|
||||||
let popup = draw_area_in(f.size(), 40, 10);
|
let popup = draw_area_in(f.size(), 40, 10);
|
||||||
@@ -593,6 +601,23 @@ impl FileTransferActivity {
|
|||||||
self.view.umount(super::COMPONENT_INPUT_NEWFILE);
|
self.view.umount(super::COMPONENT_INPUT_NEWFILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) fn mount_openwith(&mut self) {
|
||||||
|
self.view.mount(
|
||||||
|
super::COMPONENT_INPUT_OPEN_WITH,
|
||||||
|
Box::new(Input::new(
|
||||||
|
InputPropsBuilder::default()
|
||||||
|
.with_borders(Borders::ALL, BorderType::Rounded, Color::White)
|
||||||
|
.with_label(String::from("Open file with..."))
|
||||||
|
.build(),
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
self.view.active(super::COMPONENT_INPUT_OPEN_WITH);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn umount_openwith(&mut self) {
|
||||||
|
self.view.umount(super::COMPONENT_INPUT_OPEN_WITH);
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn mount_rename(&mut self) {
|
pub(super) fn mount_rename(&mut self) {
|
||||||
self.view.mount(
|
self.view.mount(
|
||||||
super::COMPONENT_INPUT_RENAME,
|
super::COMPONENT_INPUT_RENAME,
|
||||||
|
|||||||
@@ -170,11 +170,11 @@ 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,
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
pub const MSG_KEY_CHAR_X: Msg = Msg::OnKey(KeyEvent {
|
pub const MSG_KEY_CHAR_X: Msg = Msg::OnKey(KeyEvent {
|
||||||
code: KeyCode::Char('x'),
|
code: KeyCode::Char('x'),
|
||||||
modifiers: KeyModifiers::NONE,
|
modifiers: KeyModifiers::NONE,
|
||||||
|
|||||||
Reference in New Issue
Block a user