Open file with

This commit is contained in:
veeso 2021-06-10 12:14:09 +02:00
parent a8354ee38f
commit 4e50038b41
7 changed files with 134 additions and 11 deletions

View file

@ -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);
}
}
}
}

View file

@ -28,13 +28,13 @@
// deps
extern crate open;
// locals
use super::{FileTransferActivity, FsEntry, LogLevel};
use super::{FileTransferActivity, FsEntry, LogLevel, SelectedEntry};
impl FileTransferActivity {
/// ### action_open_local
///
/// 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();
if let FsEntry::File(file) = real_entry {
// Open file
@ -63,7 +63,7 @@ impl FileTransferActivity {
/// ### action_open_local
///
/// 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();
if let FsEntry::File(file) = real_entry {
// 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));
}
}
}

View file

@ -57,7 +57,7 @@ impl FileTransferActivity {
match action {
SubmitAction::ChangeDir => self.action_enter_local_dir(entry, false),
SubmitAction::OpenFile => {
self.action_open_local(entry, None);
self.action_open_local(&entry, None);
false
}
}
@ -86,7 +86,7 @@ impl FileTransferActivity {
match action {
SubmitAction::ChangeDir => self.action_enter_remote_dir(entry, false),
SubmitAction::OpenFile => {
self.action_open_remote(entry, None);
self.action_open_remote(&entry, None);
false
}
}

View file

@ -83,6 +83,7 @@ const COMPONENT_INPUT_FIND: &str = "INPUT_FIND";
const COMPONENT_INPUT_GOTO: &str = "INPUT_GOTO";
const COMPONENT_INPUT_MKDIR: &str = "INPUT_MKDIR";
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_SAVEAS: &str = "INPUT_SAVEAS";
const COMPONENT_RADIO_DELETE: &str = "RADIO_DELETE";

View file

@ -32,11 +32,11 @@ use super::{
actions::SelectedEntry, browser::FileExplorerTab, FileTransferActivity, LogLevel,
COMPONENT_EXPLORER_FIND, COMPONENT_EXPLORER_LOCAL, COMPONENT_EXPLORER_REMOTE,
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_LIST_FILEINFO, COMPONENT_LOG_BOX, COMPONENT_PROGRESS_BAR_FULL,
COMPONENT_PROGRESS_BAR_PARTIAL, COMPONENT_RADIO_DELETE, COMPONENT_RADIO_DISCONNECT,
COMPONENT_RADIO_QUIT, COMPONENT_RADIO_SORTING, COMPONENT_TEXT_ERROR, COMPONENT_TEXT_FATAL,
COMPONENT_TEXT_HELP,
COMPONENT_INPUT_MKDIR, COMPONENT_INPUT_NEWFILE, COMPONENT_INPUT_OPEN_WITH,
COMPONENT_INPUT_RENAME, COMPONENT_INPUT_SAVEAS, COMPONENT_LIST_FILEINFO, COMPONENT_LOG_BOX,
COMPONENT_PROGRESS_BAR_FULL, COMPONENT_PROGRESS_BAR_PARTIAL, COMPONENT_RADIO_DELETE,
COMPONENT_RADIO_DISCONNECT, COMPONENT_RADIO_QUIT, COMPONENT_RADIO_SORTING,
COMPONENT_TEXT_ERROR, COMPONENT_TEXT_FATAL, COMPONENT_TEXT_HELP,
};
use crate::fs::explorer::FileSorting;
use crate::fs::FsEntry;
@ -266,6 +266,12 @@ impl Update for FileTransferActivity {
self.mount_saveas();
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_REMOTE, &MSG_KEY_CHAR_X) => {
// Mount exec
@ -484,6 +490,22 @@ impl Update for FileTransferActivity {
_ => 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
(COMPONENT_INPUT_RENAME, &MSG_KEY_ESC) => {
self.umount_rename();

View file

@ -215,6 +215,14 @@ impl FileTransferActivity {
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 props.visible {
let popup = draw_area_in(f.size(), 40, 10);
@ -593,6 +601,23 @@ impl FileTransferActivity {
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) {
self.view.mount(
super::COMPONENT_INPUT_RENAME,

View file

@ -170,11 +170,11 @@ 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,
});
*/
pub const MSG_KEY_CHAR_X: Msg = Msg::OnKey(KeyEvent {
code: KeyCode::Char('x'),
modifiers: KeyModifiers::NONE,