diff --git a/src/app.rs b/src/app.rs index ea8373a..f2fc705 100644 --- a/src/app.rs +++ b/src/app.rs @@ -145,6 +145,7 @@ pub enum Message { NotifyEvent(notify::Event), NotifyWatcher(WatcherWrapper), OpenTerminal(Option), + OpenWith(PathBuf, mime_app::MimeApp), Paste(Option), PendingComplete(u64), PendingError(u64, String), @@ -896,9 +897,9 @@ impl Application for App { Ok(()) => {} Err(err) => { log::warn!( - "failed to launch terminal {:?} in {:?}: {}", - terminal.id, + "failed to open {:?} with terminal {:?}: {}", path, + terminal.id, err ) } @@ -909,6 +910,21 @@ impl Application for App { } } } + Message::OpenWith(path, app) => { + if let Some(mut command) = app.command(Some(path.clone())) { + match spawn_detached(&mut command) { + Ok(()) => {} + Err(err) => { + log::warn!("failed to open {:?} with {:?}: {}", path, app.id, err) + } + } + } else { + log::warn!("failed to get command for {:?}", app.id); + } + + // Close Open With context view + self.core.window.show_context = false; + } Message::Paste(_entity_opt) => { log::warn!("TODO: PASTE"); } diff --git a/src/tab.rs b/src/tab.rs index 1f6e30a..e74e89b 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -32,7 +32,7 @@ use std::{ }; use crate::{ - app::Action, + app::{self, Action}, config::{IconSizes, TabConfig}, dialog::DialogKind, fl, @@ -485,7 +485,7 @@ pub struct Item { } impl Item { - pub fn open_with_view(&self, sizes: IconSizes) -> Element { + pub fn open_with_view(&self, sizes: IconSizes) -> Element { let cosmic_theme::Spacing { space_xs, space_xxxs, @@ -505,6 +505,8 @@ impl Item { ]) .spacing(space_xs), ) + //TODO: do not clone so much? + .on_press(app::Message::OpenWith(self.path.clone(), app.clone())) .padding(space_xs) .width(Length::Fill), ); @@ -513,7 +515,7 @@ impl Item { column.into() } - pub fn property_view(&self, sizes: IconSizes) -> Element { + pub fn property_view(&self, sizes: IconSizes) -> Element { let cosmic_theme::Spacing { space_xxxs, .. } = theme::active().cosmic().spacing; let mut column = widget::column().spacing(space_xxxs);