aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/misc
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2012-02-17 00:22:28 +0800
committerMilan Crha <mcrha@redhat.com>2012-02-17 00:23:07 +0800
commit83d001baa23d3cce1d983dbc7946a7c5375c05f2 (patch)
tree5c19dd40d965b35d2ca26a926e964946dcd91178 /widgets/misc
parentaeb3238ad0fc239a26a9b3708679bb677030063b (diff)
downloadgsoc2013-evolution-83d001baa23d3cce1d983dbc7946a7c5375c05f2.tar.gz
gsoc2013-evolution-83d001baa23d3cce1d983dbc7946a7c5375c05f2.tar.zst
gsoc2013-evolution-83d001baa23d3cce1d983dbc7946a7c5375c05f2.zip
Bug #320976 - Remember last New button choice in Calendar view
Diffstat (limited to 'widgets/misc')
-rw-r--r--widgets/misc/e-menu-tool-button.c139
-rw-r--r--widgets/misc/e-menu-tool-button.h9
2 files changed, 141 insertions, 7 deletions
diff --git a/widgets/misc/e-menu-tool-button.c b/widgets/misc/e-menu-tool-button.c
index 0c5ef95f33..5a052a1844 100644
--- a/widgets/misc/e-menu-tool-button.c
+++ b/widgets/misc/e-menu-tool-button.c
@@ -25,6 +25,16 @@
#include "e-menu-tool-button.h"
+enum {
+ PROP_0,
+ PROP_PREFER_ITEM
+};
+
+struct _EMenuToolButtonPrivate
+{
+ gchar *prefer_item;
+};
+
G_DEFINE_TYPE (
EMenuToolButton,
e_menu_tool_button,
@@ -48,11 +58,12 @@ menu_tool_button_clone_image (GtkWidget *source)
}
static GtkMenuItem *
-menu_tool_button_get_first_menu_item (GtkMenuToolButton *menu_tool_button)
+menu_tool_button_get_prefer_menu_item (GtkMenuToolButton *menu_tool_button)
{
GtkWidget *menu;
- GtkMenuItem *item;
+ GtkMenuItem *item = NULL;
GList *children;
+ const gchar *prefer_item;
menu = gtk_menu_tool_button_get_menu (menu_tool_button);
if (!GTK_IS_MENU (menu))
@@ -62,7 +73,29 @@ menu_tool_button_get_first_menu_item (GtkMenuToolButton *menu_tool_button)
if (children == NULL)
return NULL;
- item = GTK_MENU_ITEM (children->data);
+ prefer_item = e_menu_tool_button_get_prefer_item (E_MENU_TOOL_BUTTON (menu_tool_button));
+ if (prefer_item && *prefer_item) {
+ GtkAction *action;
+ GList *iter;
+
+ for (iter = children; iter != NULL; iter = iter->next) {
+ item = GTK_MENU_ITEM (iter->data);
+
+ if (!item)
+ continue;
+
+ action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (item));
+ if (action && g_strcmp0 (gtk_action_get_name (action), prefer_item) == 0)
+ break;
+ else if (!action && g_strcmp0 (gtk_widget_get_name (GTK_WIDGET (item)), prefer_item) == 0)
+ break;
+
+ item = NULL;
+ }
+ }
+
+ if (!item)
+ item = GTK_MENU_ITEM (children->data);
g_list_free (children);
@@ -80,7 +113,7 @@ menu_tool_button_update_button (GtkToolButton *tool_button)
gchar *tooltip = NULL;
menu_tool_button = GTK_MENU_TOOL_BUTTON (tool_button);
- menu_item = menu_tool_button_get_first_menu_item (menu_tool_button);
+ menu_item = menu_tool_button_get_prefer_menu_item (menu_tool_button);
if (!GTK_IS_IMAGE_MENU_ITEM (menu_item))
return;
@@ -110,24 +143,95 @@ menu_tool_button_clicked (GtkToolButton *tool_button)
GtkMenuToolButton *menu_tool_button;
menu_tool_button = GTK_MENU_TOOL_BUTTON (tool_button);
- menu_item = menu_tool_button_get_first_menu_item (menu_tool_button);
+ menu_item = menu_tool_button_get_prefer_menu_item (menu_tool_button);
if (GTK_IS_MENU_ITEM (menu_item))
gtk_menu_item_activate (menu_item);
}
static void
+menu_tool_button_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_PREFER_ITEM:
+ e_menu_tool_button_set_prefer_item (
+ E_MENU_TOOL_BUTTON (object),
+ g_value_get_string (value));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+menu_tool_button_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_PREFER_ITEM:
+ g_value_set_string (
+ value, e_menu_tool_button_get_prefer_item (
+ E_MENU_TOOL_BUTTON (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+menu_tool_button_dispose (GObject *object)
+{
+ EMenuToolButtonPrivate *priv = E_MENU_TOOL_BUTTON (object)->priv;
+
+ if (priv->prefer_item) {
+ g_free (priv->prefer_item);
+ priv->prefer_item = NULL;
+ }
+
+ /* Chain up to parent's dispose() method. */
+ G_OBJECT_CLASS (e_menu_tool_button_parent_class)->dispose (object);
+}
+
+static void
e_menu_tool_button_class_init (EMenuToolButtonClass *class)
{
+ GObjectClass *object_class;
GtkToolButtonClass *tool_button_class;
+ g_type_class_add_private (class, sizeof (EMenuToolButtonPrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = menu_tool_button_set_property;
+ object_class->get_property = menu_tool_button_get_property;
+ object_class->dispose = menu_tool_button_dispose;
+
tool_button_class = GTK_TOOL_BUTTON_CLASS (class);
tool_button_class->clicked = menu_tool_button_clicked;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_PREFER_ITEM,
+ g_param_spec_string (
+ "prefer-item",
+ "Prefer Item",
+ "Name of an item to show instead of the first",
+ NULL,
+ G_PARAM_READWRITE));
}
static void
e_menu_tool_button_init (EMenuToolButton *button)
{
+ button->priv = G_TYPE_INSTANCE_GET_PRIVATE (
+ button, E_TYPE_MENU_TOOL_BUTTON, EMenuToolButtonPrivate);
+
+ button->priv->prefer_item = NULL;
+
g_signal_connect (
button, "notify::menu",
G_CALLBACK (menu_tool_button_update_button), NULL);
@@ -138,3 +242,28 @@ e_menu_tool_button_new (const gchar *label)
{
return g_object_new (E_TYPE_MENU_TOOL_BUTTON, "label", label, NULL);
}
+
+void
+e_menu_tool_button_set_prefer_item (EMenuToolButton *button,
+ const gchar *prefer_item)
+{
+ g_return_if_fail (button != NULL);
+ g_return_if_fail (E_IS_MENU_TOOL_BUTTON (button));
+
+ if (g_strcmp0 (button->priv->prefer_item, prefer_item) == 0)
+ return;
+
+ g_free (button->priv->prefer_item);
+ button->priv->prefer_item = g_strdup (prefer_item);
+
+ g_object_notify (G_OBJECT (button), "prefer-item");
+}
+
+const gchar *
+e_menu_tool_button_get_prefer_item (EMenuToolButton *button)
+{
+ g_return_val_if_fail (button != NULL, NULL);
+ g_return_val_if_fail (E_IS_MENU_TOOL_BUTTON (button), NULL);
+
+ return button->priv->prefer_item;
+}
diff --git a/widgets/misc/e-menu-tool-button.h b/widgets/misc/e-menu-tool-button.h
index 214f5ab217..803ec8ff58 100644
--- a/widgets/misc/e-menu-tool-button.h
+++ b/widgets/misc/e-menu-tool-button.h
@@ -50,18 +50,23 @@
G_BEGIN_DECLS
typedef struct _EMenuToolButton EMenuToolButton;
+typedef struct _EMenuToolButtonPrivate EMenuToolButtonPrivate;
typedef struct _EMenuToolButtonClass EMenuToolButtonClass;
struct _EMenuToolButton {
GtkMenuToolButton parent;
+ EMenuToolButtonPrivate *priv;
};
struct _EMenuToolButtonClass {
GtkMenuToolButtonClass parent_class;
};
-GType e_menu_tool_button_get_type (void);
-GtkToolItem * e_menu_tool_button_new (const gchar *label);
+GType e_menu_tool_button_get_type (void);
+GtkToolItem * e_menu_tool_button_new (const gchar *label);
+void e_menu_tool_button_set_prefer_item (EMenuToolButton *button,
+ const gchar *prefer_item);
+const gchar * e_menu_tool_button_get_prefer_item (EMenuToolButton *button);
G_END_DECLS