[gnome-shell] Introduce support for desktop actions in the dash



commit 7e27afb645560135a55763b06c94d74193a25762
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sun Jan 19 18:46:36 2014 +0100

    Introduce support for desktop actions in the dash
    
    Using the new list_actions() API in Gio, add entries for static
    actions specified in .desktop files in the right-click app menus,
    in the dash, app well and search.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=669603

 js/ui/appDisplay.js |   11 ++++++++
 src/shell-app.c     |   71 ++++++++++++++++++++++++++++++++++++++-------------
 src/shell-app.h     |    5 +++
 3 files changed, 69 insertions(+), 18 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 47ff948..3a2125a 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -1501,7 +1501,18 @@ const AppIconMenu = new Lang.Class({
                 this._source.app.open_new_window(-1);
                 this.emit('activate-window', null);
             }));
+            this._appendSeparator();
 
+            let appInfo = this._source.app.get_app_info();
+            let actions = appInfo.list_actions();
+            for (let i = 0; i < actions.length; i++) {
+                let action = actions[i];
+                let item = this._appendMenuItem(appInfo.get_action_name(action));
+                item.connect('activate', Lang.bind(this, function(emitter, event) {
+                    this._source.app.launch_action(action, event.get_time(), -1);
+                    this.emit('activate-window', null);
+                }));
+            }
             this._appendSeparator();
 
             let isFavorite = AppFavorites.getAppFavorites().isFavorite(this._source.app.get_id());
diff --git a/src/shell-app.c b/src/shell-app.c
index 07fe943..283bd53 100644
--- a/src/shell-app.c
+++ b/src/shell-app.c
@@ -1185,6 +1185,32 @@ app_child_setup (gpointer user_data)
 }
 #endif
 
+static GAppLaunchContext *
+make_launch_context (guint timestamp,
+                     int   workspace)
+{
+  GdkAppLaunchContext *context;
+  ShellGlobal *global;
+  MetaScreen *screen;
+  GdkDisplay *gdisplay;
+
+  global = shell_global_get ();
+  screen = shell_global_get_screen (global);
+  gdisplay = gdk_screen_get_display (shell_global_get_gdk_screen (global));
+
+  if (timestamp == 0)
+    timestamp = shell_global_get_current_time (global);
+
+  if (workspace < 0)
+    workspace = meta_screen_get_active_workspace_index (screen);
+
+  context = gdk_display_get_app_launch_context (gdisplay);
+  gdk_app_launch_context_set_timestamp (context, timestamp);
+  gdk_app_launch_context_set_desktop (context, workspace);
+
+  return G_APP_LAUNCH_CONTEXT (context);
+}
+
 /**
  * shell_app_launch:
  * @timestamp: Event timestamp, or 0 for current event timestamp
@@ -1197,11 +1223,8 @@ shell_app_launch (ShellApp     *app,
                   int           workspace,
                   GError      **error)
 {
-  GdkAppLaunchContext *context;
+  GAppLaunchContext *context;
   gboolean ret;
-  ShellGlobal *global;
-  MetaScreen *screen;
-  GdkDisplay *gdisplay;
 
   if (app->info == NULL)
     {
@@ -1210,22 +1233,10 @@ shell_app_launch (ShellApp     *app,
       return TRUE;
     }
 
-  global = shell_global_get ();
-  screen = shell_global_get_screen (global);
-  gdisplay = gdk_screen_get_display (shell_global_get_gdk_screen (global));
-
-  if (timestamp == 0)
-    timestamp = shell_global_get_current_time (global);
-
-  if (workspace < 0)
-    workspace = meta_screen_get_active_workspace_index (screen);
-
-  context = gdk_display_get_app_launch_context (gdisplay);
-  gdk_app_launch_context_set_timestamp (context, timestamp);
-  gdk_app_launch_context_set_desktop (context, workspace);
+  context = make_launch_context (timestamp, workspace),
 
   ret = g_desktop_app_info_launch_uris_as_manager (app->info, NULL,
-                                                   G_APP_LAUNCH_CONTEXT (context),
+                                                   context,
                                                    G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
 #ifdef HAVE_SYSTEMD
                                                    app_child_setup, (gpointer)shell_app_get_id (app),
@@ -1240,6 +1251,30 @@ shell_app_launch (ShellApp     *app,
 }
 
 /**
+ * shell_app_launch_action:
+ * @app: the #ShellApp
+ * @action_name: the name of the action to launch (as obtained by
+ *               g_desktop_app_info_list_actions())
+ * @timestamp: Event timestamp, or 0 for current event timestamp
+ * @workspace: Start on this workspace, or -1 for default
+ */
+void
+shell_app_launch_action (ShellApp        *app,
+                         const char      *action_name,
+                         guint            timestamp,
+                         int              workspace)
+{
+  GAppLaunchContext *context;
+
+  context = make_launch_context (timestamp, workspace);
+
+  g_desktop_app_info_launch_action (G_DESKTOP_APP_INFO (app->info),
+                                    action_name, context);
+
+  g_object_unref (context);
+}
+
+/**
  * shell_app_get_app_info:
  * @app: a #ShellApp
  *
diff --git a/src/shell-app.h b/src/shell-app.h
index dabf8bb..120385c 100644
--- a/src/shell-app.h
+++ b/src/shell-app.h
@@ -74,6 +74,11 @@ gboolean shell_app_launch (ShellApp     *app,
                            int           workspace,
                            GError      **error);
 
+void shell_app_launch_action (ShellApp        *app,
+                              const char      *action_name,
+                              guint            timestamp,
+                              int              workspace);
+
 int shell_app_compare_by_name (ShellApp *app, ShellApp *other);
 
 int shell_app_compare (ShellApp *app, ShellApp *other);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]