Commit 3b988ce5 authored by Sébastien Wilmet's avatar Sébastien Wilmet

app: share function to normalise detailed action name

Put the function in gtkactionmuxer.c, where
gtk_print_action_and_target() is implemented.

https://bugzilla.gnome.org/show_bug.cgi?id=764879
parent 3d182160
......@@ -930,3 +930,23 @@ gtk_print_action_and_target (const gchar *action_namespace,
return g_string_free (result, FALSE);
}
gchar *
gtk_normalise_detailed_action_name (const gchar *detailed_action_name)
{
GError *error = NULL;
gchar *action_and_target;
gchar *action_name;
GVariant *target;
g_action_parse_detailed_name (detailed_action_name, &action_name, &target, &error);
g_assert_no_error (error);
action_and_target = gtk_print_action_and_target (NULL, action_name, target);
if (target)
g_variant_unref (target);
g_free (action_name);
return action_and_target;
}
......@@ -56,11 +56,13 @@ void gtk_action_muxer_set_primary_accel (GtkActi
const gchar * gtk_action_muxer_get_primary_accel (GtkActionMuxer *muxer,
const gchar *action_and_target);
/* No better place for this... */
/* No better place for these... */
gchar * gtk_print_action_and_target (const gchar *action_namespace,
const gchar *action_name,
GVariant *target);
gchar * gtk_normalise_detailed_action_name (const gchar *detailed_action_name);
G_END_DECLS
#endif /* __GTK_ACTION_MUXER_H__ */
......@@ -1308,27 +1308,6 @@ gtk_application_list_action_descriptions (GtkApplication *application)
return gtk_application_accels_list_action_descriptions (application->priv->accels);
}
static gchar *
normalise_detailed_name (const gchar *detailed_action_name)
{
GError *error = NULL;
gchar *action_and_target;
gchar *action_name;
GVariant *target;
g_action_parse_detailed_name (detailed_action_name, &action_name, &target, &error);
g_assert_no_error (error);
action_and_target = gtk_print_action_and_target (NULL, action_name, target);
if (target)
g_variant_unref (target);
g_free (action_name);
return action_and_target;
}
/**
* gtk_application_set_accels_for_action:
* @application: a #GtkApplication
......@@ -1364,7 +1343,7 @@ gtk_application_set_accels_for_action (GtkApplication *application,
detailed_action_name,
accels);
action_and_target = normalise_detailed_name (detailed_action_name);
action_and_target = gtk_normalise_detailed_action_name (detailed_action_name);
gtk_action_muxer_set_primary_accel (application->priv->muxer, action_and_target, accels[0]);
g_free (action_and_target);
......
......@@ -40,27 +40,6 @@ struct _GtkApplicationAccels
G_DEFINE_TYPE (GtkApplicationAccels, gtk_application_accels, G_TYPE_OBJECT)
static gchar *
normalise_detailed_name (const gchar *detailed_action_name)
{
GError *error = NULL;
gchar *action_and_target;
gchar *action_name;
GVariant *target;
g_action_parse_detailed_name (detailed_action_name, &action_name, &target, &error);
g_assert_no_error (error);
action_and_target = gtk_print_action_and_target (NULL, action_name, target);
if (target)
g_variant_unref (target);
g_free (action_name);
return action_and_target;
}
static AccelKey *
accel_key_copy (const AccelKey *source)
{
......@@ -205,7 +184,7 @@ gtk_application_accels_set_accels_for_action (GtkApplicationAccels *accels,
AccelKey *keys, *old_keys;
gint i, n;
action_and_target = normalise_detailed_name (detailed_action_name);
action_and_target = gtk_normalise_detailed_action_name (detailed_action_name);
n = accelerators ? g_strv_length ((gchar **) accelerators) : 0;
......@@ -261,7 +240,7 @@ gtk_application_accels_get_accels_for_action (GtkApplicationAccels *accels,
gchar **result;
gint n, i = 0;
action_and_target = normalise_detailed_name (detailed_action_name);
action_and_target = gtk_normalise_detailed_action_name (detailed_action_name);
keys = g_hash_table_lookup (accels->action_to_accels, action_and_target);
if (!keys)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment