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
This commit is contained in:
Giovanni Campagna 2014-01-19 18:46:36 +01:00
parent 9ba4790b4d
commit 7e27afb645
3 changed files with 71 additions and 20 deletions

View File

@ -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());

View File

@ -1185,31 +1185,15 @@ app_child_setup (gpointer user_data)
}
#endif
/**
* shell_app_launch:
* @timestamp: Event timestamp, or 0 for current event timestamp
* @workspace: Start on this workspace, or -1 for default
* @error: A #GError
*/
gboolean
shell_app_launch (ShellApp *app,
guint timestamp,
int workspace,
GError **error)
static GAppLaunchContext *
make_launch_context (guint timestamp,
int workspace)
{
GdkAppLaunchContext *context;
gboolean ret;
ShellGlobal *global;
MetaScreen *screen;
GdkDisplay *gdisplay;
if (app->info == NULL)
{
MetaWindow *window = window_backed_app_get_window (app);
meta_window_activate (window, timestamp);
return TRUE;
}
global = shell_global_get ();
screen = shell_global_get_screen (global);
gdisplay = gdk_screen_get_display (shell_global_get_gdk_screen (global));
@ -1224,8 +1208,35 @@ shell_app_launch (ShellApp *app,
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
* @workspace: Start on this workspace, or -1 for default
* @error: A #GError
*/
gboolean
shell_app_launch (ShellApp *app,
guint timestamp,
int workspace,
GError **error)
{
GAppLaunchContext *context;
gboolean ret;
if (app->info == NULL)
{
MetaWindow *window = window_backed_app_get_window (app);
meta_window_activate (window, timestamp);
return TRUE;
}
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),
@ -1239,6 +1250,30 @@ shell_app_launch (ShellApp *app,
return ret;
}
/**
* 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

View File

@ -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);