Skip to content

Commit 2f1786f

Browse files
lenemterzeebokdanirabbit
authored
Add 'Open in Photo Viewer' to screenshot notification (#2299)
Co-authored-by: Ryan Kornheisl <[email protected]> Co-authored-by: Danielle Foré <[email protected]>
1 parent 81ebb79 commit 2f1786f

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/ScreenshotManager.vala

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public class Gala.ScreenshotManager : Object {
6464
var show_in_files_action = new GLib.SimpleAction ("show-in-files", GLib.VariantType.STRING);
6565
show_in_files_action.activate.connect (show_in_files);
6666
notifications_manager.add_action (show_in_files_action);
67+
68+
var open_in_photos_action = new GLib.SimpleAction ("open-in-photos", GLib.VariantType.STRING);
69+
open_in_photos_action.activate.connect (open_in_photos);
70+
notifications_manager.add_action (open_in_photos_action);
6771
}
6872

6973
[CCode (instance_pos = -1)]
@@ -155,8 +159,23 @@ public class Gala.ScreenshotManager : Object {
155159

156160
string[] actions = {};
157161
if (!clipboard) {
158-
/// TRANSLATORS: 'Files' is the name of file manager used by elementary OS
159-
actions = { GLib.Action.print_detailed_name ("show-in-files", new Variant ("s", filename_used)), _("Show in Files") };
162+
var files_appinfo = AppInfo.get_default_for_type ("inode/directory", true);
163+
var photos_appinfo = AppInfo.get_default_for_type ("image/png", true);
164+
165+
actions = {
166+
GLib.Action.print_detailed_name (
167+
"show-in-files",
168+
new Variant ("s", filename_used)),
169+
/// TRANSLATORS: %s represents a name of file manager
170+
_("Show in %s").printf (files_appinfo.get_display_name ()
171+
),
172+
GLib.Action.print_detailed_name (
173+
"open-in-photos",
174+
new Variant ("s", filename_used)),
175+
/// TRANSLATORS: %s represents a name of image viewer
176+
_("Open in %s").printf (photos_appinfo.get_display_name ()
177+
)
178+
};
160179
}
161180

162181
notifications_manager.send.begin (
@@ -182,6 +201,19 @@ public class Gala.ScreenshotManager : Object {
182201
}
183202
}
184203

204+
private void open_in_photos (GLib.Variant? variant) requires (variant != null && variant.is_of_type (GLib.VariantType.STRING)) {
205+
var files_list = new GLib.List<GLib.File> ();
206+
files_list.append (GLib.File.new_for_path (variant.get_string ()));
207+
208+
var photos_appinfo = AppInfo.get_default_for_type ("image/png", true);
209+
210+
try {
211+
photos_appinfo.launch (files_list, null);
212+
} catch (Error e) {
213+
warning (e.message);
214+
}
215+
}
216+
185217
public void flash_area (int x, int y, int width, int height) throws DBusError, IOError {
186218
debug ("Flashing area");
187219

0 commit comments

Comments
 (0)