window: Use GtkFileLauncher
GtkFileLauncher handles using the portal when appropriate.
This commit is contained in:
parent
9d7dae408b
commit
eae81ebc60
1 changed files with 8 additions and 23 deletions
|
|
@ -25,11 +25,6 @@ use glib::clone;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::CompositeTemplate;
|
use gtk::CompositeTemplate;
|
||||||
|
|
||||||
use ashpd::desktop::open_uri;
|
|
||||||
use ashpd::WindowIdentifier;
|
|
||||||
|
|
||||||
use gtk_macros::spawn;
|
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
||||||
use crate::config;
|
use crate::config;
|
||||||
|
|
@ -143,8 +138,8 @@ mod imp {
|
||||||
win.pick_file().await;
|
win.pick_file().await;
|
||||||
});
|
});
|
||||||
|
|
||||||
klass.install_action("win.open-with", None, move |win, _, _| {
|
klass.install_action_async("win.open-with", None, |win, _, _| async move {
|
||||||
win.open_with();
|
win.open_with().await;
|
||||||
});
|
});
|
||||||
|
|
||||||
klass.install_action("win.rotate", Some("d"), move |win, _, angle| {
|
klass.install_action("win.rotate", Some("d"), move |win, _, angle| {
|
||||||
|
|
@ -383,26 +378,16 @@ impl LpWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open_with(&self) {
|
async fn open_with(&self) {
|
||||||
let imp = self.imp();
|
let imp = self.imp();
|
||||||
|
|
||||||
if let Some(file) = imp
|
if let Some(ref file) = imp.image_view.active_file() {
|
||||||
.image_view
|
let launcher = gtk::FileLauncher::new(Some(file));
|
||||||
.active_file()
|
if let Err(e) = launcher.launch_future(Some(self)).await {
|
||||||
.and_then(|f| f.peek_path())
|
if !e.matches(gtk::DialogError::Dismissed) {
|
||||||
.and_then(|p| std::fs::File::open(p).ok())
|
|
||||||
{
|
|
||||||
spawn!(clone!(@weak self as win => async move {
|
|
||||||
if let Err(e) =
|
|
||||||
open_uri::OpenFileRequest::default()
|
|
||||||
.ask(true)
|
|
||||||
.writeable(true)
|
|
||||||
.identifier(WindowIdentifier::from_native(&win).await)
|
|
||||||
.build_file(&file).await
|
|
||||||
{
|
|
||||||
log::error!("Could not open image in external program: {}", e);
|
log::error!("Could not open image in external program: {}", e);
|
||||||
}
|
}
|
||||||
}));
|
}
|
||||||
} else {
|
} else {
|
||||||
log::error!("Could not load a path for the current image.")
|
log::error!("Could not load a path for the current image.")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue