GtkMenuItem: implement GtkActionable

...using the new GtkActionHelper
This commit is contained in:
Ryan Lortie 2012-08-17 23:01:53 -04:00
parent 694be447e3
commit ea5a56dacf
2 changed files with 77 additions and 4 deletions

View File

@ -44,7 +44,6 @@
#include "gtktypebuiltins.h" #include "gtktypebuiltins.h"
#include "a11y/gtkmenuitemaccessible.h" #include "a11y/gtkmenuitemaccessible.h"
/** /**
* SECTION:gtkmenuitem * SECTION:gtkmenuitem
* @Short_description: The widget used for item in menus * @Short_description: The widget used for item in menus
@ -97,7 +96,10 @@ enum {
/* activatable properties */ /* activatable properties */
PROP_ACTIVATABLE_RELATED_ACTION, PROP_ACTIVATABLE_RELATED_ACTION,
PROP_ACTIVATABLE_USE_ACTION_APPEARANCE PROP_ACTIVATABLE_USE_ACTION_APPEARANCE,
PROP_ACTION_NAME,
PROP_ACTION_TARGET
}; };
@ -179,6 +181,7 @@ static void gtk_menu_item_buildable_custom_finished(GtkBuildable *buildab
const gchar *tagname, const gchar *tagname,
gpointer user_data); gpointer user_data);
static void gtk_menu_item_actionable_interface_init (GtkActionableInterface *iface);
static void gtk_menu_item_activatable_interface_init (GtkActivatableIface *iface); static void gtk_menu_item_activatable_interface_init (GtkActivatableIface *iface);
static void gtk_menu_item_update (GtkActivatable *activatable, static void gtk_menu_item_update (GtkActivatable *activatable,
GtkAction *action, GtkAction *action,
@ -198,7 +201,58 @@ G_DEFINE_TYPE_WITH_CODE (GtkMenuItem, gtk_menu_item, GTK_TYPE_BIN,
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
gtk_menu_item_buildable_interface_init) gtk_menu_item_buildable_interface_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE, G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
gtk_menu_item_activatable_interface_init)) gtk_menu_item_activatable_interface_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIONABLE,
gtk_menu_item_actionable_interface_init))
static void
gtk_menu_item_set_action_name (GtkActionable *actionable,
const gchar *action_name)
{
GtkMenuItem *menu_item = GTK_MENU_ITEM (actionable);
if (!menu_item->priv->action_helper)
menu_item->priv->action_helper = gtk_action_helper_new (actionable);
gtk_action_helper_set_action_name (menu_item->priv->action_helper, action_name);
}
static void
gtk_menu_item_set_action_target_value (GtkActionable *actionable,
GVariant *action_target)
{
GtkMenuItem *menu_item = GTK_MENU_ITEM (actionable);
if (!menu_item->priv->action_helper)
menu_item->priv->action_helper = gtk_action_helper_new (actionable);
gtk_action_helper_set_action_target_value (menu_item->priv->action_helper, action_target);
}
static const gchar *
gtk_menu_item_get_action_name (GtkActionable *actionable)
{
GtkMenuItem *menu_item = GTK_MENU_ITEM (actionable);
return gtk_action_helper_get_action_name (menu_item->priv->action_helper);
}
static GVariant *
gtk_menu_item_get_action_target_value (GtkActionable *actionable)
{
GtkMenuItem *menu_item = GTK_MENU_ITEM (actionable);
return gtk_action_helper_get_action_target_value (menu_item->priv->action_helper);
}
static void
gtk_menu_item_actionable_interface_init (GtkActionableInterface *iface)
{
iface->set_action_name = gtk_menu_item_set_action_name;
iface->get_action_name = gtk_menu_item_get_action_name;
iface->set_action_target_value = gtk_menu_item_set_action_target_value;
iface->get_action_target_value = gtk_menu_item_get_action_target_value;
}
static void static void
gtk_menu_item_class_init (GtkMenuItemClass *klass) gtk_menu_item_class_init (GtkMenuItemClass *klass)
@ -397,6 +451,9 @@ gtk_menu_item_class_init (GtkMenuItemClass *klass)
g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action"); g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance"); g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");
g_object_class_override_property (gobject_class, PROP_ACTION_NAME, "action-name");
g_object_class_override_property (gobject_class, PROP_ACTION_TARGET, "action-target");
gtk_widget_class_install_style_property_parser (widget_class, gtk_widget_class_install_style_property_parser (widget_class,
g_param_spec_enum ("selected-shadow-type", g_param_spec_enum ("selected-shadow-type",
"Selected Shadow Type", "Selected Shadow Type",
@ -602,6 +659,12 @@ gtk_menu_item_set_property (GObject *object,
case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE: case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
gtk_menu_item_set_use_action_appearance (menu_item, g_value_get_boolean (value)); gtk_menu_item_set_use_action_appearance (menu_item, g_value_get_boolean (value));
break; break;
case PROP_ACTION_NAME:
gtk_menu_item_set_action_name (GTK_ACTIONABLE (menu_item), g_value_get_string (value));
break;
case PROP_ACTION_TARGET:
gtk_menu_item_set_action_target_value (GTK_ACTIONABLE (menu_item), g_value_get_variant (value));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -640,6 +703,12 @@ gtk_menu_item_get_property (GObject *object,
case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE: case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
g_value_set_boolean (value, priv->use_action_appearance); g_value_set_boolean (value, priv->use_action_appearance);
break; break;
case PROP_ACTION_NAME:
g_value_set_string (value, gtk_action_helper_get_action_name (priv->action_helper));
break;
case PROP_ACTION_TARGET:
g_value_set_variant (value, gtk_action_helper_get_action_target_value (priv->action_helper));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -1749,6 +1818,9 @@ gtk_real_menu_item_activate (GtkMenuItem *menu_item)
{ {
GtkMenuItemPrivate *priv = menu_item->priv; GtkMenuItemPrivate *priv = menu_item->priv;
if (priv->action_helper)
gtk_action_helper_activate (priv->action_helper);
if (priv->action) if (priv->action)
gtk_action_activate (priv->action); gtk_action_activate (priv->action);
} }

View File

@ -20,7 +20,7 @@
#include <gtk/gtkmenuitem.h> #include <gtk/gtkmenuitem.h>
#include <gtk/gtkaction.h> #include <gtk/gtkaction.h>
#include <gtk/gtkactionhelper.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -37,6 +37,7 @@ struct _GtkMenuItemPrivate
gchar *accel_path; gchar *accel_path;
GtkAction *action; GtkAction *action;
GtkActionHelper *action_helper;
guint show_submenu_indicator : 1; guint show_submenu_indicator : 1;
guint submenu_placement : 1; guint submenu_placement : 1;