[gtk+/wip/gtkmenutrackeritem] GtkMenuTrackerItem: Unbreak accels
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/gtkmenutrackeritem] GtkMenuTrackerItem: Unbreak accels
- Date: Wed, 8 May 2013 17:53:58 +0000 (UTC)
commit 984aed809cf6ab030cfcfe408b6aae0a4bde8dcb
Author: Ryan Lortie <desrt desrt ca>
Date: Wed May 8 13:52:05 2013 -0400
GtkMenuTrackerItem: Unbreak accels
Forgot to port this one small part over. Add it back.
gtk/gtkmenushell.c | 1 +
gtk/gtkmenutrackeritem.c | 16 ++++++++++++
gtk/gtkmenutrackeritem.h | 3 ++
gtk/gtkmodelmenuitem.c | 61 ++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 79 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkmenushell.c b/gtk/gtkmenushell.c
index cd683ba..cf040a9 100644
--- a/gtk/gtkmenushell.c
+++ b/gtk/gtkmenushell.c
@@ -2101,6 +2101,7 @@ gtk_menu_shell_tracker_insert_func (GtkMenuTrackerItem *item,
g_object_bind_property (item, "visible", widget, "visible", G_BINDING_SYNC_CREATE);
g_object_bind_property (item, "role", widget, "action-role", G_BINDING_SYNC_CREATE);
g_object_bind_property (item, "toggled", widget, "toggled", G_BINDING_SYNC_CREATE);
+ g_object_bind_property (item, "accel", widget, "accel", G_BINDING_SYNC_CREATE);
g_signal_connect (widget, "activate", G_CALLBACK (gtk_menu_shell_item_activate), item);
diff --git a/gtk/gtkmenutrackeritem.c b/gtk/gtkmenutrackeritem.c
index 7712201..0f7210b 100644
--- a/gtk/gtkmenutrackeritem.c
+++ b/gtk/gtkmenutrackeritem.c
@@ -23,6 +23,7 @@ enum {
PROP_VISIBLE,
PROP_ROLE,
PROP_TOGGLED,
+ PROP_ACCEL,
PROP_SUBMENU,
PROP_SUBMENU_NAMESPACE,
N_PROPS
@@ -86,6 +87,9 @@ gtk_menu_tracker_item_get_property (GObject *object,
case PROP_TOGGLED:
g_value_set_boolean (value, gtk_menu_tracker_item_get_toggled (self));
break;
+ case PROP_ACCEL:
+ g_value_set_string (value, gtk_menu_tracker_item_get_accel (self));
+ break;
case PROP_SUBMENU:
g_value_set_object (value, gtk_menu_tracker_item_get_submenu (self));
break;
@@ -136,6 +140,8 @@ gtk_menu_tracker_item_class_init (GtkMenuTrackerItemClass *class)
G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
gtk_menu_tracker_item_pspecs[PROP_TOGGLED] =
g_param_spec_boolean ("toggled", "", "", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
+ gtk_menu_tracker_item_pspecs[PROP_ACCEL] =
+ g_param_spec_string ("accel", "", "", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
gtk_menu_tracker_item_pspecs[PROP_SUBMENU] =
g_param_spec_object ("submenu", "", "", G_TYPE_MENU_MODEL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
gtk_menu_tracker_item_pspecs[PROP_SUBMENU_NAMESPACE] =
@@ -409,6 +415,16 @@ gtk_menu_tracker_item_get_toggled (GtkMenuTrackerItem *self)
return self->toggled;
}
+const gchar *
+gtk_menu_tracker_item_get_accel (GtkMenuTrackerItem *self)
+{
+ const gchar *accel = NULL;
+
+ g_menu_item_get_attribute (self->item, "accel", "&s", &accel);
+
+ return accel;
+}
+
GMenuModel *
gtk_menu_tracker_item_get_submenu (GtkMenuTrackerItem *self)
{
diff --git a/gtk/gtkmenutrackeritem.h b/gtk/gtkmenutrackeritem.h
index 928389f..6e24bcb 100644
--- a/gtk/gtkmenutrackeritem.h
+++ b/gtk/gtkmenutrackeritem.h
@@ -74,6 +74,9 @@ G_GNUC_INTERNAL
gboolean gtk_menu_tracker_item_get_toggled (GtkMenuTrackerItem *self);
G_GNUC_INTERNAL
+const gchar * gtk_menu_tracker_item_get_accel (GtkMenuTrackerItem *self);
+
+G_GNUC_INTERNAL
GMenuModel * gtk_menu_tracker_item_get_submenu (GtkMenuTrackerItem *self);
G_GNUC_INTERNAL
diff --git a/gtk/gtkmodelmenuitem.c b/gtk/gtkmodelmenuitem.c
index e8a547e..f7cc502 100644
--- a/gtk/gtkmodelmenuitem.c
+++ b/gtk/gtkmodelmenuitem.c
@@ -21,7 +21,7 @@
#include "gtkmodelmenuitem.h"
-#include "gtklabel.h"
+#include "gtkaccellabel.h"
#include "gtkimage.h"
#include "gtkbox.h"
@@ -42,7 +42,8 @@ enum
PROP_ACTION_ROLE,
PROP_ICON,
PROP_TEXT,
- PROP_TOGGLED
+ PROP_TOGGLED,
+ PROP_ACCEL
};
static void
@@ -237,6 +238,55 @@ gtk_model_menu_item_set_text (GtkModelMenuItem *item,
}
static void
+gtk_model_menu_item_set_accel (GtkModelMenuItem *item,
+ const gchar *accel)
+{
+ GtkWidget *child;
+ GList *children;
+ GdkModifierType modifiers;
+ guint key;
+
+ if (accel)
+ {
+ gtk_accelerator_parse (accel, &key, &modifiers);
+ if (!key)
+ modifiers = 0;
+ }
+ else
+ {
+ key = 0;
+ modifiers = 0;
+ }
+
+ child = gtk_bin_get_child (GTK_BIN (item));
+ if (child == NULL)
+ {
+ gtk_menu_item_get_label (GTK_MENU_ITEM (item));
+ child = gtk_bin_get_child (GTK_BIN (item));
+ g_assert (GTK_IS_LABEL (child));
+ }
+
+ if (GTK_IS_LABEL (child))
+ {
+ gtk_accel_label_set_accel (GTK_ACCEL_LABEL (child), key, modifiers);
+ return;
+ }
+
+ if (!GTK_IS_CONTAINER (child))
+ return;
+
+ children = gtk_container_get_children (GTK_CONTAINER (child));
+
+ while (children)
+ {
+ if (GTK_IS_ACCEL_LABEL (children->data))
+ gtk_accel_label_set_accel (children->data, key, modifiers);
+
+ children = g_list_delete_link (children, children);
+ }
+}
+
+void
gtk_model_menu_item_set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
@@ -260,6 +310,10 @@ gtk_model_menu_item_set_property (GObject *object, guint prop_id,
_gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), g_value_get_boolean (value));
break;
+ case PROP_ACCEL:
+ gtk_model_menu_item_set_accel (item, g_value_get_string (value));
+ break;
+
default:
g_assert_not_reached ();
}
@@ -298,6 +352,9 @@ gtk_model_menu_item_class_init (GtkModelMenuItemClass *class)
g_object_class_install_property (object_class, PROP_TOGGLED,
g_param_spec_boolean ("toggled", "toggled", "toggled", FALSE,
G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_ACCEL,
+ g_param_spec_string ("accel", "accel", "accel", NULL,
+ G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
}
GtkWidget *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]