Re: Gio.Menu item with data ?
- From: Christian Hergert <christian hergert me>
- To: gtk-devel-list gnome org
- Subject: Re: Gio.Menu item with data ?
- Date: Sat, 5 Dec 2015 12:13:33 -0800
Hi,
On 12/05/2015 06:06 AM, Stuart Axon wrote:
Hi,
I'm going a bit mad trying to find decent examples - I want to have a
bit of data attached to a menu item, how can I do it ?
(my action is something like win.open_example + I want to have a
filename attached to each item).
- I can't find anything with SimpleAction so far.
You want to make a single action that takes a parameter, in this case,
your filename (or rather, a string URI).
static void
on_open_file (GSimpleAction *action,
GVariant *param,
gpointer user_data)
{
const gchar *uri = g_variant_get_string (param);
GFile *file = g_file_new_for_uri (uri);
// ...
}
static const GActionEntry entries[] = {
{ "open-file", on_open_file, "s" },
};
and then where you call the action, use the detailed action name or
specify a target like:
g_menu_item_set_action_and_target (menu_item, "prefix.open-file",
"s", uri);
If you'd like a similar, rather complex example, check out how we open
files based on mime-types in Builder.
https://git.gnome.org/browse/gnome-builder/tree/plugins/project-tree/gb-project-tree-builder.c?h=wip/chergert/perspective#n223
https://git.gnome.org/browse/gnome-builder/tree/plugins/project-tree/gb-project-tree-actions.c?h=wip/chergert/perspective#n152
Hope that helps,
-- Christian
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]