Alex
Alex

Reputation: 1641

gtk3 - persisting shortcuts while using GSimpleAction

In gtk3 there is the possibility to persist accelerator keys and pathes to file by using gtk_accel_map. The user is able to customize shortcuts by editing the related file.

Now I am about to replace the deprected GtkAction interface by making use of GSimpleAction.

So how can I get the required parametrs for gtk_accel_map_add_entry out of a GSimpleAction (or out of a GActionMap?), so that I can persist it ?

I defined the GSimpleAction like that:

void callback ( GSimpleAction *action, GVariant *parameter, gpointer user_data )
{
    g_print ( "<Ctrl>k pressed\n" );
}

static GActionEntry actions[] = {
  { "test", callback, NULL, NULL, NULL },
};

... // Inside application_startup (GApplication *gapp):
  g_action_map_add_action_entries(G_ACTION_MAP(application), actions, G_N_ELEMENTS(actions), NULL);

  const char *accels[] = {"<Ctrl>k", NULL};
  gtk_application_set_accels_for_action (application, "app.test", accels);
...

Possibly related: Recently I learned that gtk_accel_map will be gone in gtk4

Upvotes: 2

Views: 124

Answers (1)

ebassi
ebassi

Reputation: 8815

You cannot use GtkAccelMap with the GAction API. GAction, by itself, has no "presentational" information.

The accelerators are held by the GtkApplication instance, and you can query the with gtk_application_get_accels_for_action(); you will need to hold on to the list of actions you're interested on, because there is no API to iterate over the actions associated with a GtkApplication.

Upvotes: 2

Related Questions