Skip to content

Commit bccb474

Browse files
committed
Use show_uri_on_window for editing images
1 parent 54b3830 commit bccb474

2 files changed

Lines changed: 17 additions & 44 deletions

File tree

com.github.philip_scott.spice-up.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ finish-args:
1010
- '--share=ipc'
1111
- '--socket=fallback-x11'
1212
- '--socket=wayland'
13-
13+
1414
- '--device=all' # Required for Controllers
1515
- '--filesystem=xdg-documents' # Required for library
16+
- '--filesystem=/tmp' # Required to share images for editing with external apps
1617

1718
modules:
1819
- name: gudev

src/Widgets/Toolbars/ImageBar.vala

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121

2222
public class Spice.Widgets.ImageToolbar : Spice.Widgets.Toolbar {
23-
private Gtk.MenuButton open_with;
23+
private Gtk.Button open_with;
2424
private Gtk.Button replace_image;
2525

2626
private unowned SlideManager manager;
@@ -30,12 +30,24 @@ public class Spice.Widgets.ImageToolbar : Spice.Widgets.Toolbar {
3030
}
3131

3232
construct {
33-
open_with = new Gtk.MenuButton ();
33+
open_with = new Gtk.Button ();
3434
open_with.add (new Gtk.Image.from_icon_name ("applications-graphics-symbolic", Gtk.IconSize.MENU));
3535
open_with.set_tooltip_text (_("Edit image with…"));
3636
open_with.get_style_context ().add_class (Gtk.STYLE_CLASS_RAISED);
3737
open_with.get_style_context ().add_class ("image-button");
3838

39+
open_with.clicked.connect (() => {
40+
var image_item = (ImageItem) item;
41+
var file = File.new_for_path (image_item.url);
42+
43+
try {
44+
Gtk.show_uri_on_window(Application.get_active_spice_window (), file.get_uri (), Gdk.CURRENT_TIME);
45+
} catch (Error e) {
46+
warning ("Could not launch open with portal %s", e.message);
47+
return;
48+
}
49+
});
50+
3951
replace_image = new Gtk.Button ();
4052
replace_image.add (new Gtk.Image.from_icon_name ("document-new-symbolic", Gtk.IconSize.MENU));
4153
replace_image.set_tooltip_text (_("Replace Image…"));
@@ -55,47 +67,7 @@ public class Spice.Widgets.ImageToolbar : Spice.Widgets.Toolbar {
5567
add (replace_image);
5668
}
5769

58-
private void launch_editor (AppInfo app) {
59-
var list = new List<File>();
60-
list.append (File.new_for_path (((ImageItem) this.item).url));
61-
62-
try {
63-
app.launch (list, null);
64-
} catch (Error e) {
65-
warning ("Could launch application: %s", e.message);
66-
}
67-
}
68-
69-
protected override void item_selected (Spice.CanvasItem? _item, bool new_item = false) {
70-
var item = _item as Spice.ImageItem;
71-
72-
if (item != null) {
73-
var menu = new Gtk.Menu ();
74-
open_with.popup = menu;
75-
76-
var file = File.new_for_path (item.url);
77-
78-
try {
79-
var file_info = file.query_info ("standard::*", 0);
80-
81-
var apps = AppInfo.get_all_for_type (file_info.get_content_type ());
82-
83-
foreach (var app in apps) {
84-
var meun_item = new Gtk.MenuItem.with_label (app.get_name ());
85-
menu.add (meun_item);
86-
87-
meun_item.activate.connect (() => {
88-
launch_editor (app);
89-
});
90-
}
91-
92-
menu.show_all ();
93-
} catch (Error e) {
94-
warning ("Could not get file info %s", e.message);
95-
return;
96-
}
97-
}
98-
}
70+
protected override void item_selected (Spice.CanvasItem? _item, bool new_item = false) {}
9971

10072
public override void update_properties () {}
10173
}

0 commit comments

Comments
 (0)