summaryrefslogtreecommitdiff
path: root/gtk/gtkaccellabel.c
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2012-09-10 14:36:23 -0400
committerRyan Lortie <desrt@desrt.ca>2012-09-17 12:31:22 -0400
commit778aa7ade0107fa645ab1427132551d138c7334a (patch)
treeecb61096cd6d72d7dc4f4362f8158d2f3c9bcdf8 /gtk/gtkaccellabel.c
parent338b5f6c2dc6cdb73ec3dfb6973b2269d4664b80 (diff)
downloadgtk+-778aa7ade0107fa645ab1427132551d138c7334a.tar.gz
GtkAccelLabel: add manual accel API
Add an API to GtkAccelLabel for hardcoding the accel key to be displayed (ie: allowing us to bypass the GtkAccelGroup lookup). Use that from the GMenuModel-based GtkMenu construction code instead of passing around the accel group. This makes accel labels work in bloatpad again. This patch effectively removes any hope of automatic runtime accel changes in GMenuModel-based menus without additional application support but it leaves the door open for this to be supported again in the future (if we decide that it's important). https://bugzilla.gnome.org/show_bug.cgi?id=683738
Diffstat (limited to 'gtk/gtkaccellabel.c')
-rw-r--r--gtk/gtkaccellabel.c54
1 files changed, 48 insertions, 6 deletions
diff --git a/gtk/gtkaccellabel.c b/gtk/gtkaccellabel.c
index 452f43cd32..d374faa871 100644
--- a/gtk/gtkaccellabel.c
+++ b/gtk/gtkaccellabel.c
@@ -104,6 +104,9 @@ struct _GtkAccelLabelPrivate
gchar *accel_string; /* has set function */
guint accel_padding; /* should be style property? */
guint16 accel_string_width; /* seems to be private */
+
+ guint accel_key; /* manual accel key specification if != 0 */
+ GdkModifierType accel_mods;
};
static void gtk_accel_label_set_property (GObject *object,
@@ -903,19 +906,31 @@ gtk_accel_label_refetch (GtkAccelLabel *accel_label)
"gtk-enable-accels", &enable_accels,
NULL);
- if (enable_accels && accel_label->priv->accel_closure)
+ if (enable_accels && (accel_label->priv->accel_closure || accel_label->priv->accel_key))
{
- GtkAccelKey *key = gtk_accel_group_find (accel_label->priv->accel_group, find_accel, accel_label->priv->accel_closure);
+ guint accel_key = accel_label->priv->accel_key;
+ GdkModifierType accel_mods = accel_label->priv->accel_mods;
+
+ /* If we don't have a hardcoded value, check the accel group */
+ if (!accel_key)
+ {
+ GtkAccelKey *key = gtk_accel_group_find (accel_label->priv->accel_group, find_accel, accel_label->priv->accel_closure);
+
+ if (key && key->accel_flags & GTK_ACCEL_VISIBLE)
+ {
+ accel_key = key->accel_key;
+ accel_mods = key->accel_mods;
+ }
+ }
- if (key && key->accel_flags & GTK_ACCEL_VISIBLE)
+ /* If we found a key using either method, set it */
+ if (accel_key)
{
GtkAccelLabelClass *klass;
gchar *tmp;
klass = GTK_ACCEL_LABEL_GET_CLASS (accel_label);
- tmp = _gtk_accel_label_class_get_accelerator_label (klass,
- key->accel_key,
- key->accel_mods);
+ tmp = _gtk_accel_label_class_get_accelerator_label (klass, accel_key, accel_mods);
accel_label->priv->accel_string = g_strconcat (" ", tmp, NULL);
g_free (tmp);
}
@@ -930,3 +945,30 @@ gtk_accel_label_refetch (GtkAccelLabel *accel_label)
return FALSE;
}
+
+/**
+ * gtk_accel_label_set_accel:
+ * @accel_label: a #GtkAccelLabel
+ * @accelerator_key: a keyval, or 0
+ * @accelerator_mods: the modifier mask for the accel
+ *
+ * Manually sets a keyval and modifier mask as the accelerator rendered
+ * by @accel_label.
+ *
+ * If a keyval and modifier are explicitly set then these values are
+ * used regardless of any associated accel closure or widget.
+ *
+ * Providing an @accelerator_key of 0 removes the manual setting.
+ *
+ * Since: 3.6
+ */
+void
+gtk_accel_label_set_accel (GtkAccelLabel *accel_label,
+ guint accelerator_key,
+ GdkModifierType accelerator_mods)
+{
+ accel_label->priv->accel_key = accelerator_key;
+ accel_label->priv->accel_mods = accelerator_mods;
+
+ gtk_accel_label_reset (accel_label);
+}