aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mail/Makefile.am2
-rw-r--r--mail/e-mail-label-action.c155
-rw-r--r--mail/e-mail-label-action.h73
-rw-r--r--modules/mail/e-mail-shell-view-actions.c15
-rw-r--r--modules/mail/e-mail-shell-view-private.h1
5 files changed, 239 insertions, 7 deletions
diff --git a/mail/Makefile.am b/mail/Makefile.am
index 01d41aaaa6..286d27dc12 100644
--- a/mail/Makefile.am
+++ b/mail/Makefile.am
@@ -40,6 +40,7 @@ mailinclude_HEADERS = \
e-mail-attachment-bar.h \
e-mail-browser.h \
e-mail-display.h \
+ e-mail-label-action.h \
e-mail-label-dialog.h \
e-mail-label-list-store.h \
e-mail-label-manager.h \
@@ -96,6 +97,7 @@ libevolution_mail_la_SOURCES = \
e-mail-attachment-bar.c \
e-mail-browser.c \
e-mail-display.c \
+ e-mail-label-action.c \
e-mail-label-dialog.c \
e-mail-label-list-store.c \
e-mail-label-manager.c \
diff --git a/mail/e-mail-label-action.c b/mail/e-mail-label-action.c
new file mode 100644
index 0000000000..2647564223
--- /dev/null
+++ b/mail/e-mail-label-action.c
@@ -0,0 +1,155 @@
+/*
+ * e-mail-label-action.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ */
+
+#include "e-mail-label-action.h"
+
+#include "e-util/e-binding.h"
+
+#define E_MAIL_LABEL_ACTION_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_MAIL_LABEL_ACTION, EMailLabelActionPrivate))
+
+struct _EMailLabelActionPrivate {
+ gint placeholder;
+};
+
+static gpointer parent_class;
+
+static void
+mail_label_action_menu_item_realize_cb (GtkWidget *menu_item)
+{
+ GtkAction *action;
+ GtkActivatable *activatable;
+ GtkWidget *container;
+ GtkWidget *widget;
+ const gchar *stock_id;
+
+ activatable = GTK_ACTIVATABLE (menu_item);
+ action = gtk_activatable_get_related_action (activatable);
+ g_return_if_fail (E_IS_MAIL_LABEL_ACTION (action));
+
+ /* Prevent GtkMenuItem's sync_action_properties() method from
+ * destroying our hack. Instead we use EBindings to keep the
+ * label and image in sync with the action. */
+ gtk_activatable_set_use_action_appearance (activatable, FALSE);
+
+ /* Remove the menu item's child widget. */
+ widget = gtk_bin_get_child (GTK_BIN (menu_item));
+ gtk_widget_destroy (widget);
+
+ /* Now add our own child widget. */
+
+ widget = gtk_hbox_new (FALSE, 3);
+ gtk_container_add (GTK_CONTAINER (menu_item), widget);
+ gtk_widget_show (widget);
+
+ container = widget;
+
+ /*stock_id = gtk_action_get_stock_id (action);
+ widget = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU);*/
+ widget = gtk_action_create_icon (action, GTK_ICON_SIZE_MENU);
+ gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
+ gtk_widget_show (widget);
+
+ /* XXX GtkImage calls it "stock", not "stock-id". */
+ /*e_mutual_binding_new (action, "stock-id", widget, "stock");*/
+
+ widget = gtk_label_new (NULL);
+ gtk_label_set_use_underline (GTK_LABEL (widget), TRUE);
+ gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
+ gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
+ gtk_widget_show (widget);
+
+ e_mutual_binding_new (action, "label", widget, "label");
+}
+
+static GtkWidget *
+mail_label_action_create_menu_item (GtkAction *action)
+{
+ GtkWidget *menu_item;
+
+ menu_item = gtk_check_menu_item_new ();
+
+ g_signal_connect (
+ menu_item, "realize",
+ G_CALLBACK (mail_label_action_menu_item_realize_cb), NULL);
+
+ return menu_item;
+}
+
+static void
+mail_label_action_class_init (EMailLabelActionClass *class)
+{
+ GtkActionClass *action_class;
+
+ parent_class = g_type_class_peek_parent (class);
+ g_type_class_add_private (class, sizeof (EMailLabelActionPrivate));
+
+ action_class = GTK_ACTION_CLASS (class);
+ action_class->create_menu_item = mail_label_action_create_menu_item;
+}
+
+static void
+mail_label_action_init (EMailLabelAction *action)
+{
+ action->priv = E_MAIL_LABEL_ACTION_GET_PRIVATE (action);
+}
+
+GType
+e_mail_label_action_get_type (void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0)) {
+ static const GTypeInfo type_info = {
+ sizeof (EMailLabelActionClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) mail_label_action_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL, /* class_data */
+ sizeof (EMailLabelAction),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) mail_label_action_init,
+ NULL /* value_table */
+ };
+
+ type = g_type_register_static (
+ GTK_TYPE_TOGGLE_ACTION,
+ "EMailLabelAction", &type_info, 0);
+ }
+
+ return type;
+}
+
+EMailLabelAction *
+e_mail_label_action_new (const gchar *name,
+ const gchar *label,
+ const gchar *tooltip,
+ const gchar *stock_id)
+{
+ g_return_val_if_fail (name != NULL, NULL);
+
+ return g_object_new (
+ E_TYPE_MAIL_LABEL_ACTION,
+ "name", name, "label", label,
+ "tooltip", tooltip, "stock-id", stock_id, NULL);
+}
diff --git a/mail/e-mail-label-action.h b/mail/e-mail-label-action.h
new file mode 100644
index 0000000000..1b681f15db
--- /dev/null
+++ b/mail/e-mail-label-action.h
@@ -0,0 +1,73 @@
+/*
+ * e-mail-label-action.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ */
+
+/* This is a toggle action whose menu item shows a checkbox, icon and
+ * label. Use of this thing for anything besides the label submenu in
+ * the message list popup menu is discouraged, which is why this class
+ * was not given a more generic name. */
+
+#ifndef E_MAIL_LABEL_ACTION_H
+#define E_MAIL_LABEL_ACTION_H
+
+#include <gtk/gtk.h>
+
+/* Standard GObject macros */
+#define E_TYPE_MAIL_LABEL_ACTION \
+ (e_mail_label_action_get_type ())
+#define E_MAIL_LABEL_ACTION(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), E_TYPE_MAIL_LABEL_ACTION, EMailLabelAction))
+#define E_MAIL_LABEL_ACTION_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), E_TYPE_MAIL_LABEL_ACTION, EMailLabelActionClass))
+#define E_IS_MAIL_LABEL_ACTION(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), E_TYPE_MAIL_LABEL_ACTION))
+#define E_IS_MAIL_LABEL_ACTION_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((cls), E_TYPE_MAIL_LABEL_ACTION))
+#define E_MAIL_LABEL_ACTION_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), E_TYPE_MAIL_LABEL_ACTION, EMailLabelActionClass))
+
+G_BEGIN_DECLS
+
+typedef struct _EMailLabelAction EMailLabelAction;
+typedef struct _EMailLabelActionClass EMailLabelActionClass;
+typedef struct _EMailLabelActionPrivate EMailLabelActionPrivate;
+
+struct _EMailLabelAction {
+ GtkToggleAction parent;
+ EMailLabelActionPrivate *priv;
+};
+
+struct _EMailLabelActionClass {
+ GtkToggleActionClass parent_class;
+};
+
+GType e_mail_label_action_get_type (void);
+EMailLabelAction *
+ e_mail_label_action_new (const gchar *name,
+ const gchar *label,
+ const gchar *tooltip,
+ const gchar *stock_id);
+
+#endif /* E_MAIL_LABEL_ACTION_H */
diff --git a/modules/mail/e-mail-shell-view-actions.c b/modules/mail/e-mail-shell-view-actions.c
index 07fdf8f366..3473d2a727 100644
--- a/modules/mail/e-mail-shell-view-actions.c
+++ b/modules/mail/e-mail-shell-view-actions.c
@@ -1729,7 +1729,7 @@ e_mail_shell_view_update_popup_labels (EMailShellView *mail_shell_view)
valid = gtk_tree_model_get_iter_first (tree_model, &iter);
while (valid) {
- GtkToggleAction *toggle_action;
+ EMailLabelAction *label_action;
GtkAction *action;
gchar *action_name;
gchar *stock_id;
@@ -1745,25 +1745,26 @@ e_mail_shell_view_update_popup_labels (EMailShellView *mail_shell_view)
action_name = g_strdup_printf ("mail-label-%d", ii);
/* XXX Add a tooltip! */
- toggle_action = gtk_toggle_action_new (
+ label_action = e_mail_label_action_new (
action_name, label, NULL, stock_id);
g_object_set_data_full (
- G_OBJECT (toggle_action), "tag",
+ G_OBJECT (label_action), "tag",
tag, (GDestroyNotify) g_free);
/* Configure the action before we connect to signals. */
mail_shell_view_update_label_action (
- toggle_action, message_list, uids, tag);
+ GTK_TOGGLE_ACTION (label_action),
+ message_list, uids, tag);
g_signal_connect (
- toggle_action, "toggled",
+ label_action, "toggled",
G_CALLBACK (action_mail_label_cb), mail_shell_view);
/* The action group takes ownership of the action. */
- action = GTK_ACTION (toggle_action);
+ action = GTK_ACTION (label_action);
gtk_action_group_add_action (action_group, action);
- g_object_unref (toggle_action);
+ g_object_unref (label_action);
gtk_ui_manager_add_ui (
ui_manager, merge_id, path, action_name,
diff --git a/modules/mail/e-mail-shell-view-private.h b/modules/mail/e-mail-shell-view-private.h
index bf86f33720..6142b6e9d8 100644
--- a/modules/mail/e-mail-shell-view-private.h
+++ b/modules/mail/e-mail-shell-view-private.h
@@ -40,6 +40,7 @@
#include "widgets/misc/e-popup-action.h"
#include "widgets/menus/gal-view-instance.h"
+#include "e-mail-label-action.h"
#include "e-mail-label-dialog.h"
#include "e-mail-label-list-store.h"
#include "e-mail-local.h"