[gtk+/wip/gtkmenutrackeritem] GtkMenuTrackerItem: clean up "role" a bit
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/gtkmenutrackeritem] GtkMenuTrackerItem: clean up "role" a bit
- Date: Thu, 9 May 2013 15:51:59 +0000 (UTC)
commit db2a596f8322ab446201ef33d6c054ff78567b16
Author: Ryan Lortie <desrt desrt ca>
Date: Thu May 9 11:42:07 2013 -0400
GtkMenuTrackerItem: clean up "role" a bit
This property was combining something static (item is separator?) with
something dynamic (which state indicator shall we draw?). Split that
out by making is_separator a separate property and clarify things a bit
by renaming the "toggle" role to "check".
gtk/gtkmenushell.c | 2 +-
gtk/gtkmenutrackeritem.c | 24 +++++++++++++++++-------
gtk/gtkmenutrackeritem.h | 6 ++++--
gtk/gtkmodelmenuitem.c | 2 +-
4 files changed, 23 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkmenushell.c b/gtk/gtkmenushell.c
index efae721..b3d976a 100644
--- a/gtk/gtkmenushell.c
+++ b/gtk/gtkmenushell.c
@@ -2078,7 +2078,7 @@ gtk_menu_shell_tracker_insert_func (GtkMenuTrackerItem *item,
GtkMenuShell *menu_shell = user_data;
GtkWidget *widget;
- if (gtk_menu_tracker_item_get_role (item) == GTK_MENU_TRACKER_ITEM_ROLE_SEPARATOR)
+ if (gtk_menu_tracker_item_get_is_separator (item))
widget = gtk_separator_menu_item_new ();
else
widget = gtk_model_menu_item_new ();
diff --git a/gtk/gtkmenutrackeritem.c b/gtk/gtkmenutrackeritem.c
index 88b4739..c162de6 100644
--- a/gtk/gtkmenutrackeritem.c
+++ b/gtk/gtkmenutrackeritem.c
@@ -10,6 +10,7 @@ struct _GtkMenuTrackerItem
gchar *action_namespace;
GMenuItem *item;
GtkMenuTrackerItemRole role : 4;
+ guint is_separator : 1;
guint can_activate : 1;
guint sensitive : 1;
guint toggled : 1;
@@ -17,6 +18,7 @@ struct _GtkMenuTrackerItem
enum {
PROP_0,
+ PROP_IS_SEPARATOR,
PROP_LABEL,
PROP_ICON,
PROP_SENSITIVE,
@@ -44,9 +46,8 @@ gtk_menu_tracker_item_role_get_type (void)
{
static const GEnumValue values[] = {
{ GTK_MENU_TRACKER_ITEM_ROLE_NORMAL, "GTK_MENU_TRACKER_ITEM_ROLE_NORMAL", "normal" },
- { GTK_MENU_TRACKER_ITEM_ROLE_TOGGLE, "GTK_MENU_TRACKER_ITEM_ROLE_TOGGLE", "toggle" },
+ { GTK_MENU_TRACKER_ITEM_ROLE_CHECK, "GTK_MENU_TRACKER_ITEM_ROLE_CHECK", "check" },
{ GTK_MENU_TRACKER_ITEM_ROLE_RADIO, "GTK_MENU_TRACKER_ITEM_ROLE_RADIO", "radio" },
- { GTK_MENU_TRACKER_ITEM_ROLE_SEPARATOR, "GTK_MENU_TRACKER_ITEM_ROLE_SEPARATOR", "separator" },
{ 0, NULL, NULL }
};
GType type;
@@ -69,6 +70,9 @@ gtk_menu_tracker_item_get_property (GObject *object,
switch (prop_id)
{
+ case PROP_IS_SEPARATOR:
+ g_value_set_boolean (value, gtk_menu_tracker_item_get_is_separator (self));
+ break;
case PROP_LABEL:
g_value_set_string (value, gtk_menu_tracker_item_get_label (self));
break;
@@ -128,6 +132,8 @@ gtk_menu_tracker_item_class_init (GtkMenuTrackerItemClass *class)
class->get_property = gtk_menu_tracker_item_get_property;
class->finalize = gtk_menu_tracker_item_finalize;
+ gtk_menu_tracker_item_pspecs[PROP_IS_SEPARATOR] =
+ g_param_spec_boolean ("is-separator", "", "", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
gtk_menu_tracker_item_pspecs[PROP_LABEL] =
g_param_spec_string ("label", "", "", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
gtk_menu_tracker_item_pspecs[PROP_ICON] =
@@ -187,7 +193,7 @@ gtk_menu_tracker_item_action_added (GActionObserver *observer,
else if (state != NULL && g_variant_is_of_type (state, G_VARIANT_TYPE_BOOLEAN))
{
self->toggled = g_variant_get_boolean (state);
- self->role = GTK_MENU_TRACKER_ITEM_ROLE_TOGGLE;
+ self->role = GTK_MENU_TRACKER_ITEM_ROLE_CHECK;
}
g_object_freeze_notify (G_OBJECT (self));
@@ -317,6 +323,7 @@ gtk_menu_tracker_item_new (GActionObservable *observable,
self->item = g_menu_item_new_from_model (model, item_index);
self->action_namespace = g_strdup (action_namespace);
self->observable = g_object_ref (observable);
+ self->is_separator = is_separator;
if (!is_separator && g_menu_item_get_attribute (self->item, "action", "&s", &action_name))
{
@@ -352,10 +359,7 @@ gtk_menu_tracker_item_new (GActionObservable *observable,
g_variant_unref (state);
}
else
- {
- self->role = is_separator ? GTK_MENU_TRACKER_ITEM_ROLE_SEPARATOR : GTK_MENU_TRACKER_ITEM_ROLE_NORMAL;
- self->sensitive = TRUE;
- }
+ self->sensitive = TRUE;
return self;
}
@@ -366,6 +370,12 @@ gtk_menu_tracker_item_get_observable (GtkMenuTrackerItem *self)
return self->observable;
}
+gboolean
+gtk_menu_tracker_item_get_is_separator (GtkMenuTrackerItem *self)
+{
+ return self->is_separator;
+}
+
const gchar *
gtk_menu_tracker_item_get_label (GtkMenuTrackerItem *self)
{
diff --git a/gtk/gtkmenutrackeritem.h b/gtk/gtkmenutrackeritem.h
index 6e24bcb..6a13023 100644
--- a/gtk/gtkmenutrackeritem.h
+++ b/gtk/gtkmenutrackeritem.h
@@ -34,9 +34,8 @@ typedef struct _GtkMenuTrackerItem GtkMenuTrackerItem;
typedef enum {
GTK_MENU_TRACKER_ITEM_ROLE_NORMAL,
- GTK_MENU_TRACKER_ITEM_ROLE_TOGGLE,
+ GTK_MENU_TRACKER_ITEM_ROLE_CHECK,
GTK_MENU_TRACKER_ITEM_ROLE_RADIO,
- GTK_MENU_TRACKER_ITEM_ROLE_SEPARATOR
} GtkMenuTrackerItemRole;
G_GNUC_INTERNAL
@@ -56,6 +55,9 @@ G_GNUC_INTERNAL
GActionObservable * gtk_menu_tracker_item_get_observable (GtkMenuTrackerItem *self);
G_GNUC_INTERNAL
+gboolean gtk_menu_tracker_item_get_is_separator (GtkMenuTrackerItem *self);
+
+G_GNUC_INTERNAL
const gchar * gtk_menu_tracker_item_get_label (GtkMenuTrackerItem *self);
G_GNUC_INTERNAL
diff --git a/gtk/gtkmodelmenuitem.c b/gtk/gtkmodelmenuitem.c
index f7cc502..c698a52 100644
--- a/gtk/gtkmodelmenuitem.c
+++ b/gtk/gtkmodelmenuitem.c
@@ -109,7 +109,7 @@ gtk_model_menu_item_set_action_role (GtkModelMenuItem *item,
a11y_role = ATK_ROLE_MENU_ITEM;
break;
- case GTK_MENU_TRACKER_ITEM_ROLE_TOGGLE:
+ case GTK_MENU_TRACKER_ITEM_ROLE_CHECK:
a11y_role = ATK_ROLE_CHECK_MENU_ITEM;
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]