Implement open with buttons
This commit is contained in:
parent
a54957ddf2
commit
ac4626d9cf
2 changed files with 23 additions and 5 deletions
20
src/app.rs
20
src/app.rs
|
|
@ -145,6 +145,7 @@ pub enum Message {
|
|||
NotifyEvent(notify::Event),
|
||||
NotifyWatcher(WatcherWrapper),
|
||||
OpenTerminal(Option<Entity>),
|
||||
OpenWith(PathBuf, mime_app::MimeApp),
|
||||
Paste(Option<Entity>),
|
||||
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");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<crate::app::Message> {
|
||||
pub fn open_with_view(&self, sizes: IconSizes) -> Element<app::Message> {
|
||||
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<crate::app::Message> {
|
||||
pub fn property_view(&self, sizes: IconSizes) -> Element<app::Message> {
|
||||
let cosmic_theme::Spacing { space_xxxs, .. } = theme::active().cosmic().spacing;
|
||||
|
||||
let mut column = widget::column().spacing(space_xxxs);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue