@@ -201,47 +201,83 @@ namespace Scratch.Utils {
201201 return false ;
202202 }
203203
204- public GLib .Menu create_executable_app_items_for_file (GLib .File file , string file_type ) {
205- var external_apps = GLib . AppInfo . get_all_for_type (file_type );
206- var this_id = GLib . Application . get_default () . application_id + " .desktop" ;
204+ public GLib .Menu ? create_executable_app_items_for_file (GLib .File file , string file_type ) {
205+ var scratch_app = ( Scratch . Application ) ( GLib . Application . get_default () );
206+ var this_id = scratch_app . application_id + " .desktop" ;
207207 var menu = new GLib .Menu ();
208208
209- external_apps. sort ((a, b) = > {
210- return a. get_name (). collate (b. get_name ());
211- });
212-
213- foreach (AppInfo app_info in external_apps) {
214- string app_id = app_info. get_id ();
215- if (app_id == this_id) {
216- continue ;
217- }
218-
209+ if (scratch_app. is_running_in_flatpak) {
219210 var menu_item = new MenuItem (
220- app_info. get_name (),
211+ // /TRANSLATORS '%s' represents the quoted basename of a uri to be opened with the default app
212+ _(" Show '%s ' with default app" ). printf (file. get_basename ()),
221213 GLib . Action . print_detailed_name (
222214 Scratch . FolderManager . FileView . ACTION_PREFIX
223215 + Scratch . FolderManager . FileView . ACTION_LAUNCH_APP_WITH_FILE_PATH ,
224216 new GLib .Variant .array (
225217 GLib . VariantType . STRING ,
226- { file. get_path (), app_id }
218+ { file. get_path (), " " }
227219 )
228220 )
229221 );
230- menu_item. set_icon (app_info. get_icon ());
231222 menu. append_item (menu_item);
223+ } else {
224+ List<AppInfo > external_apps = null ;
225+ if (file_type == " " ) {
226+ var files_appinfo = AppInfo . get_default_for_type (" inode/directory" , true );
227+ external_apps. prepend (files_appinfo);
228+ } else {
229+ external_apps = GLib . AppInfo . get_all_for_type (file_type);
230+ external_apps. sort ((a, b) = > {
231+ return a. get_name (). collate (b. get_name ());
232+ });
233+ }
234+
235+ foreach (AppInfo app_info in external_apps) {
236+ string app_id = app_info. get_id ();
237+ if (app_id == this_id) {
238+ continue ;
239+ }
240+
241+ var menu_item = new MenuItem (
242+ app_info. get_name (),
243+ GLib . Action . print_detailed_name (
244+ Scratch . FolderManager . FileView . ACTION_PREFIX
245+ + Scratch . FolderManager . FileView . ACTION_LAUNCH_APP_WITH_FILE_PATH ,
246+ new GLib .Variant .array (
247+ GLib . VariantType . STRING ,
248+ { file. get_path (), app_id }
249+ )
250+ )
251+ );
252+ menu_item. set_icon (app_info. get_icon ());
253+ menu. append_item (menu_item);
254+ }
232255 }
233256
234257 return menu;
235258 }
236259
237- public void launch_app_with_file (AppInfo app_info , GLib .File file ) {
238- var file_list = new List<GLib . File > ();
239- file_list. append (file);
260+ public void launch_app_with_file (string app_id , string path ) {
261+ var scratch_app = (Scratch . Application ) (GLib . Application . get_default ());
262+ if (scratch_app. is_running_in_flatpak || app_id == " " ) {
263+ var uri = Uri . join (UriFlags . NONE , " file" , null , null , - 1 , path, null , null );
240264
241- try {
242- app_info. launch (file_list, null );
243- } catch (Error e) {
244- warning (e. message);
265+ try {
266+ Gtk . show_uri_on_window (scratch_app. get_active_window (), uri, Gdk . CURRENT_TIME );
267+ } catch (Error e) {
268+ warning (" Error showing uri %s , %s " , uri, e. message);
269+ }
270+ } else {
271+ var app_info = new GLib .DesktopAppInfo (app_id);
272+ var file = GLib . File . new_for_path (path);
273+ var file_list = new List<GLib . File > ();
274+ file_list. append (file);
275+
276+ try {
277+ app_info. launch (file_list, null );
278+ } catch (Error e) {
279+ warning (e. message);
280+ }
245281 }
246282 }
247283
0 commit comments