@@ -38,6 +38,7 @@ public class Gala.ScreenshotManager : Object {
3838 }
3939
4040 private Settings desktop_settings;
41+ private GLib . HashTable<uint32, string?> notifications_id_to_path;
4142
4243 private string prev_font_regular;
4344 private string prev_font_document;
@@ -50,6 +51,7 @@ public class Gala.ScreenshotManager : Object {
5051
5152 construct {
5253 desktop_settings = new Settings (" org.gnome.desktop.interface" );
54+ notifications_id_to_path = new GLib .HashTable<uint32, string> (GLib . direct_hash, GLib . direct_equal);
5355
5456 var keybinding_settings = new GLib .Settings (" io.elementary.desktop.wm.keybindings" );
5557 unowned var display = wm. get_display ();
@@ -61,13 +63,8 @@ public class Gala.ScreenshotManager : Object {
6163 display. add_keybinding (" window-screenshot-clip" , keybinding_settings, IGNORE_AUTOREPEAT , handle_screenshot);
6264 display. add_keybinding (" area-screenshot-clip" , keybinding_settings, IGNORE_AUTOREPEAT , handle_screenshot);
6365
64- var show_in_files_action = new GLib .SimpleAction (" show-in-files" , GLib . VariantType . STRING );
65- show_in_files_action. activate. connect (show_in_files);
66- 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);
66+ notifications_manager. action_invoked. connect (handle_action_invoked);
67+ notifications_manager. notification_closed. connect ((id) = > notifications_id_to_path. remove (id));
7168 }
7269
7370 [CCode (instance_pos = -1 )]
@@ -113,7 +110,7 @@ public class Gala.ScreenshotManager : Object {
113110 yield screenshot (false , true , filename, out success, out filename_used);
114111
115112 if (success) {
116- send_screenshot_notification (filename_used);
113+ send_screenshot_notification. begin (filename_used);
117114 }
118115 } catch (Error e) {
119116 warning (e. message);
@@ -131,7 +128,7 @@ public class Gala.ScreenshotManager : Object {
131128 yield screenshot_area (x, y, w, h, true , filename, out success, out filename_used);
132129
133130 if (success) {
134- send_screenshot_notification (filename_used);
131+ send_screenshot_notification. begin (filename_used);
135132 }
136133 } catch (Error e) {
137134 warning (e. message);
@@ -147,73 +144,81 @@ public class Gala.ScreenshotManager : Object {
147144 yield screenshot_window (true , false , true , filename, out success, out filename_used);
148145
149146 if (success) {
150- send_screenshot_notification (filename_used);
147+ send_screenshot_notification. begin (filename_used);
151148 }
152149 } catch (Error e) {
153150 warning (e. message);
154151 }
155152 }
156153
157- private void send_screenshot_notification (string filename_used ) {
154+ private async void send_screenshot_notification (string filename_used ) {
158155 var clipboard = filename_used == " " ;
159156
160157 string [] actions = {};
161158 if (! clipboard) {
162159 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- var open_in_photos_action = GLib . Action . print_detailed_name (
166- " open-in-photos" ,
167- new Variant (" s" , filename_used)
168- );
169-
170- // / TRANSLATORS: %s represents a name of image viewer
171- var open_in_photos_label = _(" Open in %s " ). printf (photos_appinfo. get_display_name ());
172160
173161 actions = {
174- GLib . Action . print_detailed_name (
175- " show-in-files" ,
176- new Variant (" s" , filename_used)),
177- // / TRANSLATORS: %s represents a name of file manager
178- _(" Show in %s " ). printf (files_appinfo. get_display_name ()
179- ),
180- // TODO: uncomment when https://github.com/elementary/notifications/issues/237 is fixed
181- // open_in_photo_action
182- // open_in_photos_label
162+ " default" ,
163+ " " ,
164+
165+ " show-in-files" ,
166+ // / TRANSLATORS: %s represents a name of file manager
167+ _(" Show in %s " ). printf (files_appinfo. get_display_name ())
183168 };
184169 }
185170
186- notifications_manager. send. begin (
171+ var notification_id = yield notifications_manager. send (
187172 " ScreenshotManager" ,
188173 " image-x-generic" ,
189174 _(" Screenshot taken" ),
190175 clipboard ? _(" Screenshot is saved to clipboard" ) : _(" Screenshot saved to screenshots folder" ),
191176 actions,
192177 new GLib .HashTable<string, Variant > (null , null )
193178 );
179+
180+ if (notification_id != null && ! clipboard) {
181+ notifications_id_to_path[notification_id] = filename_used;
182+ }
183+ }
184+
185+ private void handle_action_invoked (uint32 id , string name , GLib .Variant ? target_value ) {
186+ var path = notifications_id_to_path[id];
187+ if (path == null ) {
188+ return ;
189+ }
190+
191+ switch (name) {
192+ case " default" :
193+ open_in_photo_viewer (path);
194+ break ;
195+ case " show-in-files" :
196+ show_in_files (path);
197+ break ;
198+ }
194199 }
195200
196- private void show_in_files ( GLib . Variant ? variant ) requires ( variant != null && variant . is_of_type ( GLib . VariantType . STRING ) ) {
201+ private void open_in_photo_viewer ( string path ) {
197202 var files_list = new GLib .List<GLib . File > ();
198- files_list. append (GLib . File . new_for_path (variant . get_string () ));
203+ files_list. append (GLib . File . new_for_path (path ));
199204
200- var files_appinfo = AppInfo . get_default_for_type (" inode/directory " , true );
205+ var photos_appinfo = AppInfo . get_default_for_type (" image/png " , true );
201206
202207 try {
203- files_appinfo . launch (files_list, null );
208+ photos_appinfo . launch (files_list, null );
204209 } catch (Error e) {
205210 warning (e. message);
206211 }
207212 }
208213
209- private void open_in_photos ( GLib . Variant ? variant ) requires ( variant != null && variant . is_of_type ( GLib . VariantType . STRING ) ) {
214+ private void show_in_files ( string path ) {
210215 var files_list = new GLib .List<GLib . File > ();
211- files_list. append (GLib . File . new_for_path (variant . get_string () ));
216+ files_list. append (GLib . File . new_for_path (path ));
212217
213- var photos_appinfo = AppInfo . get_default_for_type (" image/png " , true );
218+ var files_appinfo = AppInfo . get_default_for_type (" inode/directory " , true );
214219
215220 try {
216- photos_appinfo . launch (files_list, null );
221+ files_appinfo . launch (files_list, null );
217222 } catch (Error e) {
218223 warning (e. message);
219224 }
0 commit comments