[evolution/kill-bonobo] Kill EMMenu and EMPopup.



commit 45d475c31b2dbda8033021984ba9a429b9eddf51
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sun Aug 9 20:03:24 2009 -0400

    Kill EMMenu and EMPopup.
    
    Also finish adapting Templates plugin to EPluginUI.
    It was still leaning pretty hard on EMPopup.

 mail/Makefile.am                                  |    4 -
 mail/em-folder-tree.c                             |    5 +-
 mail/em-folder-utils.c                            |    1 -
 mail/em-format-html-display.c                     |   15 +-
 mail/em-menu.c                                    |  354 ---------------
 mail/em-menu.h                                    |  121 ------
 mail/em-popup.c                                   |  472 ---------------------
 mail/em-popup.h                                   |  261 ------------
 mail/message-list.c                               |    5 +-
 plugins/email-custom-header/email-custom-header.c |    1 -
 plugins/external-editor/external-editor.c         |    1 -
 plugins/face/face.c                               |    1 -
 plugins/mail-to-task/mail-to-task.c               |    2 -
 plugins/templates/org-gnome-templates.eplug.xml   |   36 +-
 plugins/templates/templates.c                     |  387 ++++++++++-------
 shell/e-shell-window-private.c                    |   11 +-
 shell/e-shell-window.c                            |   11 -
 ui/Makefile.am                                    |   10 +-
 ui/evolution-mail-global.xml                      |  149 -------
 ui/evolution-mail-list.xml                        |  154 -------
 ui/evolution-mail-message.xml                     |  426 -------------------
 ui/evolution-mail-messagedisplay.xml              |   74 ----
 ui/evolution-mail.ui                              |    2 +
 ui/evolution.xml                                  |  199 ---------
 24 files changed, 283 insertions(+), 2419 deletions(-)
---
diff --git a/mail/Makefile.am b/mail/Makefile.am
index 5f8372f..53b5bca 100644
--- a/mail/Makefile.am
+++ b/mail/Makefile.am
@@ -71,8 +71,6 @@ mailinclude_HEADERS =					\
 	em-icon-stream.h				\
 	em-inline-filter.h				\
 	em-junk-hook.h					\
-	em-menu.h					\
-	em-popup.h					\
 	em-search-context.h				\
 	em-subscribe-editor.h				\
 	em-sync-stream.h				\
@@ -131,8 +129,6 @@ libevolution_mail_la_SOURCES =				\
 	em-icon-stream.c				\
 	em-inline-filter.c				\
 	em-junk-hook.c					\
-	em-menu.c					\
-	em-popup.c					\
 	em-search-context.c				\
 	em-subscribe-editor.c				\
 	em-sync-stream.c				\
diff --git a/mail/em-folder-tree.c b/mail/em-folder-tree.c
index cadb8fe..a3813ca 100644
--- a/mail/em-folder-tree.c
+++ b/mail/em-folder-tree.c
@@ -65,7 +65,6 @@
 #include "mail-vfolder.h"
 
 #include "em-utils.h"
-#include "em-popup.h"
 #include "em-folder-tree.h"
 #include "em-folder-utils.h"
 #include "em-folder-selector.h"
@@ -1384,6 +1383,7 @@ tree_drag_data_action(struct _DragDataReceivedAsync *m)
 	mail_msg_unordered_push (m);
 }
 
+#if 0  /* KILL-BONOBO */
 static void
 emft_drop_popup_copy(EPopup *ep, EPopupItem *item, gpointer data)
 {
@@ -1509,6 +1509,7 @@ tree_drag_data_received(GtkWidget *widget, GdkDragContext *context, gint x, gint
 		tree_drag_data_action(m);
 	}
 }
+#endif
 
 static gboolean
 is_special_local_folder (const gchar *name)
@@ -1952,7 +1953,9 @@ em_folder_tree_enable_drag_and_drop (EMFolderTree *emft)
 	g_signal_connect (tree_view, "drag-begin", G_CALLBACK (tree_drag_begin), emft);
 	g_signal_connect (tree_view, "drag-data-delete", G_CALLBACK (tree_drag_data_delete), emft);
 	g_signal_connect (tree_view, "drag-data-get", G_CALLBACK (tree_drag_data_get), emft);
+#if 0  /* KILL-BONOBO */
 	g_signal_connect (tree_view, "drag-data-received", G_CALLBACK (tree_drag_data_received), emft);
+#endif
 	g_signal_connect (tree_view, "drag-drop", G_CALLBACK (tree_drag_drop), emft);
 	g_signal_connect (tree_view, "drag-end", G_CALLBACK (tree_drag_end), emft);
 	g_signal_connect (tree_view, "drag-leave", G_CALLBACK (tree_drag_leave), emft);
diff --git a/mail/em-folder-utils.c b/mail/em-folder-utils.c
index e483942..700e445 100644
--- a/mail/em-folder-utils.c
+++ b/mail/em-folder-utils.c
@@ -61,7 +61,6 @@
 #include "mail-folder-cache.h"
 
 #include "em-utils.h"
-#include "em-popup.h"
 #include "em-folder-tree.h"
 #include "em-folder-tree-model.h"
 #include "em-folder-utils.h"
diff --git a/mail/em-format-html-display.c b/mail/em-format-html-display.c
index 270db0e..a15b0d6 100644
--- a/mail/em-format-html-display.c
+++ b/mail/em-format-html-display.c
@@ -78,7 +78,6 @@
 #include "em-format-html-display.h"
 #include "em-icon-stream.h"
 #include "em-utils.h"
-#include "em-popup.h"
 #include "widgets/misc/e-attachment-button.h"
 #include "widgets/misc/e-attachment-view.h"
 
@@ -841,6 +840,7 @@ efhd_can_process_attachment (GtkWidget *button)
 	return efh && efh->state != EM_FORMAT_HTML_STATE_RENDERING;
 }
 
+#if 0  /* KILL-BONOBO */
 /* if it hasn't been processed yet, format the attachment */
 static void
 efhd_attachment_show(EPopup *ep, EPopupItem *item, gpointer data)
@@ -975,6 +975,7 @@ efhd_attachment_popup_menu(GtkWidget *w, struct _attach_puri *info)
 {
 	return efhd_attachment_popup(w, NULL, info);
 }
+#endif
 
 /* ********************************************************************** */
 
@@ -1132,9 +1133,13 @@ efhd_image_unallocate (struct _EMFormatPURI * puri)
 	struct _attach_puri *info = (struct _attach_puri *) puri;
 	g_signal_handlers_disconnect_by_func(info->html, efhd_image_resized, info);
 
+#if 0  /* KILL-BONOBO */
 	g_signal_handlers_disconnect_by_func(info->event_box, efhd_image_popup, info);
+#endif
 	g_signal_handlers_disconnect_by_func(info->event_box, efhd_change_cursor, info);
+#if 0  /* KILL-BONOBO */
 	g_signal_handlers_disconnect_by_func(info->event_box, efhd_attachment_popup_menu, info);
+#endif
 	g_signal_handlers_disconnect_by_func(info->event_box, efhd_image_fit_width, info);
 }
 
@@ -1185,9 +1190,13 @@ efhd_attachment_image(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObjec
 	g_signal_connect(box, "drag-data-get", G_CALLBACK(efhd_drag_data_get), pobject);
 	g_signal_connect (box, "drag-data-delete", G_CALLBACK(efhd_drag_data_delete), pobject);
 
+#if 0  /* KILL-BONOBO */
 	g_signal_connect(box, "button_press_event", G_CALLBACK(efhd_image_popup), info);
+#endif
 	g_signal_connect(box, "enter-notify-event", G_CALLBACK(efhd_change_cursor), info);
+#if 0  /* KILL-BONOBO */
 	g_signal_connect(box, "popup_menu", G_CALLBACK(efhd_attachment_popup_menu), info);
+#endif
 	g_signal_connect(box, "button-press-event", G_CALLBACK(efhd_image_fit_width), info);
 
 	g_object_set_data (G_OBJECT (box), "efh", efh);
@@ -1244,9 +1253,11 @@ efhd_attachment_button(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObje
 
 	g_object_set_data (G_OBJECT (widget), "efh", efh);
 
+#if 0  /* KILL-BONOBO */
 	g_signal_connect (
 		widget, "notify::expanded",
 		G_CALLBACK (efhd_attachment_button_expanded), info);
+#endif
 
 	return TRUE;
 }
@@ -1407,9 +1418,11 @@ efhd_attachment_optional(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPOb
 	a11y = gtk_widget_get_accessible (button);
 	atk_object_set_name (a11y, _("Attachment"));
 
+#if 0  /* KILL-BONOBO */
 	g_signal_connect(button, "button_press_event", G_CALLBACK(efhd_attachment_popup), info);
 	g_signal_connect(button, "popup_menu", G_CALLBACK(efhd_attachment_popup_menu), info);
 	g_signal_connect(button, "clicked", G_CALLBACK(efhd_attachment_popup_menu), info);
+#endif
 	gtk_box_pack_start(GTK_BOX (mainbox), button, FALSE, FALSE, 6);
 
 	gtk_widget_show_all(mainbox);
diff --git a/mail/message-list.c b/mail/message-list.c
index ce1b201..b80431d 100644
--- a/mail/message-list.c
+++ b/mail/message-list.c
@@ -70,7 +70,6 @@
 #include "table/e-cell-hbox.h"
 
 #include "e-mail-label-list-store.h"
-#include "em-popup.h"
 #include "em-utils.h"
 #include "mail-config.h"
 #include "mail-mt.h"
@@ -2156,6 +2155,7 @@ ml_drop_action(struct _drop_msg *m)
 	mail_msg_unordered_push (m);
 }
 
+#if 0  /* KILL-BONOBO */
 static void
 ml_drop_popup_copy(EPopup *ep, EPopupItem *item, gpointer data)
 {
@@ -2241,6 +2241,7 @@ ml_tree_drag_data_received (ETree *tree, gint row, ETreePath path, gint col,
 		ml_drop_action(m);
 	}
 }
+#endif
 
 struct search_child_struct {
 	gboolean found;
@@ -2709,8 +2710,10 @@ message_list_construct (MessageList *message_list)
 			     ml_drop_types, sizeof(ml_drop_types)/sizeof(ml_drop_types[0]),
 			     GDK_ACTION_MOVE|GDK_ACTION_COPY|GDK_ACTION_ASK);
 
+#if 0  /* KILL-BONOBO */
 	g_signal_connect(message_list->tree, "tree_drag_data_received",
 			 G_CALLBACK(ml_tree_drag_data_received), message_list);
+#endif
 	g_signal_connect(message_list->tree, "drag-motion", G_CALLBACK(ml_tree_drag_motion), message_list);
 }
 
diff --git a/plugins/email-custom-header/email-custom-header.c b/plugins/email-custom-header/email-custom-header.c
index 81dd24d..4e76f97 100644
--- a/plugins/email-custom-header/email-custom-header.c
+++ b/plugins/email-custom-header/email-custom-header.c
@@ -29,7 +29,6 @@
 #include <gconf/gconf-client.h>
 #include <e-util/e-error.h>
 #include <glade/glade.h>
-#include "mail/em-menu.h"
 #include "mail/em-utils.h"
 #include "mail/em-event.h"
 #include "composer/e-msg-composer.h"
diff --git a/plugins/external-editor/external-editor.c b/plugins/external-editor/external-editor.c
index dcd8165..2342651 100644
--- a/plugins/external-editor/external-editor.c
+++ b/plugins/external-editor/external-editor.c
@@ -26,7 +26,6 @@
 #include <config.h>
 #endif
 
-#include <mail/em-menu.h>
 #include <mail/em-config.h>
 #include <mail/em-composer-utils.h>
 #include <mail/mail-config.h>
diff --git a/plugins/face/face.c b/plugins/face/face.c
index 6bbc7bb..1bb56c2 100644
--- a/plugins/face/face.c
+++ b/plugins/face/face.c
@@ -28,7 +28,6 @@
 #include "composer/e-msg-composer.h"
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
-#include <mail/em-menu.h>
 #include <e-util/e-error.h>
 #include <e-util/e-util.h>
 
diff --git a/plugins/mail-to-task/mail-to-task.c b/plugins/mail-to-task/mail-to-task.c
index 3613694..16c1ab5 100644
--- a/plugins/mail-to-task/mail-to-task.c
+++ b/plugins/mail-to-task/mail-to-task.c
@@ -46,8 +46,6 @@
 #include <camel/camel-stream-mem.h>
 #include <camel/camel-utf8.h>
 
-#include <mail/em-menu.h>
-#include <mail/em-popup.h>
 #include <mail/em-utils.h>
 #include <mail/em-format-html.h>
 #include <mail/mail-config.h>
diff --git a/plugins/templates/org-gnome-templates.eplug.xml b/plugins/templates/org-gnome-templates.eplug.xml
index 02b1414..b4b8a81 100644
--- a/plugins/templates/org-gnome-templates.eplug.xml
+++ b/plugins/templates/org-gnome-templates.eplug.xml
@@ -7,30 +7,22 @@
         _name="Templates">
         <_description>Drafts based template plugin</_description>
         <author name="Bharath Acharya" email="abharath novell com"/>
-	<author name="Diego Escalante Urrelo" email="diegoe gnome org"/>
+        <author name="Diego Escalante Urrelo" email="diegoe gnome org"/>
 
-        <!-- hook into the mail popup menu -->
-        <hook class="org.gnome.evolution.mail.popup:1.0">
-            <menu 
-                id="org.gnome.evolution.mail.folderview.popup" 
-                target="select"
-                factory="org_gnome_templates_popup">
-            </menu>
+        <hook class="org.gnome.evolution.ui:1.0">
+          <ui-manager id="org.gnome.evolution.shell"/>
+          <ui-manager id="org.gnome.evolution.composer">
+            <menubar name='main-menu'>
+              <placeholder name='pre-edit-menu'>
+                <menu action='file-menu'>
+                  <placeholder name="template-holder">
+                    <menuitem action="template"/>
+                  </placeholder>
+                </menu>
+              </placeholder>
+            </menubar>
+          </ui-manager>
         </hook>
-
-	<hook class="org.gnome.evolution.ui:1.0">
-		<ui-manager id="org.gnome.evolution.composer">
-			<menubar name='main-menu'>
-				<placeholder name='pre-edit-menu'>
-      					<menu action='file-menu'>
-						<placeholder name="template-holder">
-							<menuitem action="Template"/>
-						</placeholder>
-					</menu>
-				</placeholder>
-			</menubar>
-		</ui-manager>
-	</hook>
     </e-plugin>
 </e-plugin-list>
 
diff --git a/plugins/templates/templates.c b/plugins/templates/templates.c
index 78a0cf4..89496b5 100644
--- a/plugins/templates/templates.c
+++ b/plugins/templates/templates.c
@@ -27,6 +27,7 @@
 #include <glib/gi18n.h>
 #include <string.h>
 
+#include <glade/glade.h>
 #include <gconf/gconf-client.h>
 
 #include <e-util/e-config.h>
@@ -35,13 +36,15 @@
 #include <camel/camel-stream-mem.h>
 
 #include <mail/e-mail-local.h>
+#include <mail/e-mail-reader.h>
 #include <mail/em-composer-utils.h>
-#include <mail/em-popup.h>
 #include <mail/mail-session.h>
 #include <mail/mail-ops.h>
+#include <mail/message-list.h>
 #include <e-util/e-error.h>
 #include <e-util/e-plugin.h>
-#include <glade/glade.h>
+#include <e-util/e-util.h>
+#include <shell/e-shell-view.h>
 
 #include <composer/e-msg-composer.h>
 
@@ -63,32 +66,10 @@ enum {
 	CLUE_N_COLUMNS
 };
 
-typedef struct {
-    CamelMimeMessage *msg;
-    EMPopupTargetSelect *t;
-} UserData;
-
-static gchar * get_content	(CamelMimeMessage *message);
-
-static void reply_with_template	(EPopup *ep, EPopupItem *item, gpointer data);
-
-static void popup_free		(EPopup *ep, GSList *l, gpointer data);
-
-static GSList *fill_submenu	(CamelStore *store,
-				CamelFolderInfo *info,
-				GSList *list,
-				EMPopupTargetSelect *t);
-
-static GSList *append_to_menu	(CamelFolder *folder,
-				GPtrArray *uids,
-				GSList *list,
-				EMPopupTargetSelect *t);
-
-void org_gnome_templates_popup	(EPlugin *ep, EMPopupTargetSelect *t);
-
 GtkWidget *e_plugin_lib_get_configure_widget	(EPlugin *epl);
 
-gboolean e_plugin_ui_init	(GtkUIManager *ui_manager, EMsgComposer *composer);
+gboolean e_plugin_ui_init	(GtkUIManager *ui_manager, GObject *object);
+gint e_plugin_lib_enable	(EPlugin *plugin, gboolean enabled);
 
 /* Thanks to attachment reminder plugin for this*/
 static void commit_changes (UIData *ui);
@@ -102,6 +83,8 @@ static void  value_cell_edited_callback (GtkCellRendererText *cell, gchar *path_
 static gboolean clue_foreach_check_isempty (GtkTreeModel *model, GtkTreePath
 					*path, GtkTreeIter *iter, UIData *ui);
 
+static gboolean plugin_enabled;
+
 static void
 selection_changed (GtkTreeSelection *selection, UIData *ui)
 {
@@ -496,32 +479,23 @@ get_content (CamelMimeMessage *message)
 }
 
 static void
-reply_with_template (EPopup *ep, EPopupItem *item, gpointer data)
+action_reply_with_template_cb (GtkAction *action,
+                               CamelMimeMessage *message)
 {
-	CamelMimeMessage *new, *template, *reply_to;
-	CamelFolder *templates_folder;
+	CamelMimeMessage *new, *template;
+	CamelFolder *folder;
 	struct _camel_header_raw *header;
-	UserData *userdata = item->user_data;
 	gchar *cont;
 
-	/* We get the templates folder and all the uids of the messages in there */
-	templates_folder = e_mail_local_get_folder (E_MAIL_FOLDER_TEMPLATES);
-
-	/* Get from the currently selected folder, the currently selected message */
-	reply_to = camel_folder_get_message (userdata->t->folder,
-			g_ptr_array_index (userdata->t->uids, 0),
-			NULL);
-
-	/* The message we'll be using has been stored when building the menu */
-	template = userdata->msg;
+	folder = e_mail_local_get_folder (E_MAIL_FOLDER_TEMPLATES);
+	template = g_object_get_data (G_OBJECT (action), "template");
 
 	/* The new message we are creating */
 	new = camel_mime_message_new();
 
 	/* Add the headers from the message we are replying to, so CC and that
-	 * stuff is preserved.
-	 */
-	header = ((CamelMimePart *)reply_to)->headers;
+	 * stuff is preserved. */
+	header = ((CamelMimePart *)message)->headers;
 	while (header) {
 		if (g_ascii_strncasecmp (header->name, "content-", 8) != 0) {
 			camel_medium_add_header((CamelMedium *) new,
@@ -538,7 +512,7 @@ reply_with_template (EPopup *ep, EPopupItem *item, gpointer data)
 
 	/* Set the To: field to the same To: field of the message we are replying to. */
 	camel_mime_message_set_recipients (new, CAMEL_RECIPIENT_TYPE_TO,
-			camel_mime_message_get_from (reply_to));
+			camel_mime_message_get_from (message));
 
 	/* Copy the CC and BCC from the template.*/
 	camel_mime_message_set_recipients (new, CAMEL_RECIPIENT_TYPE_CC,
@@ -551,160 +525,148 @@ reply_with_template (EPopup *ep, EPopupItem *item, gpointer data)
 			cont, (gint) g_utf8_strlen(cont, -1), "text");
 
 	/* Create the composer */
-	em_utils_edit_message (new, templates_folder);
+	em_utils_edit_message (new, folder);
 
 	camel_object_unref(new);
 }
 
 static void
-popup_free (EPopup *ep, GSList *l, gpointer data)
+build_template_menus_recurse (GtkUIManager *ui_manager,
+                              GtkActionGroup *action_group,
+                              const gchar *menu_path,
+                              guint *action_count,
+                              guint merge_id,
+                              CamelFolderInfo *folder_info,
+                              CamelMimeMessage *message)
 {
-	g_slist_free (l);
-}
+	CamelStore *store;
 
-static GSList
-*append_to_menu (CamelFolder *folder, GPtrArray *uids, GSList *list, EMPopupTargetSelect *t)
-{
-	gint i;
+	store = e_mail_local_get_store ();
 
-	for (i = 0; i < uids->len; i++) {
-		const gchar *subject;
+	while (folder_info != NULL) {
+		CamelFolder *folder;
+		GPtrArray *uids;
+		GtkAction *action;
+		const gchar *action_label;
+		gchar *action_name;
 		gchar *path;
-		EPopupItem *item;
-		CamelMimeMessage *message;
-		UserData *user_data;
-		const gchar *uid;
-
-		uid = g_strdup (g_ptr_array_index (uids, i));
-
-		/* Same as in fill_submenu */
-		if (!g_str_has_suffix (folder->name, "Templates"))
-			path = g_strdup_printf ("80.%s", folder->full_name);
-		else
-			path = g_strdup ("80.Templates");
-
-		/* If this uid is trashed, ignore it */
-		if (camel_folder_get_message_flags (folder, uid) & CAMEL_MESSAGE_DELETED)
-			continue;
+		guint ii;
 
-		/* Get the message for this uid */
-		message = camel_folder_get_message (folder,
-				uid,
-				NULL);
+		folder = camel_store_get_folder (
+			store, folder_info->full_name, 0, NULL);
 
-		subject = camel_mime_message_get_subject (message);
+		action_name = g_strdup_printf (
+			"templates-menu-%d", *action_count);
+		*action_count = *action_count + 1;
 
-		/* Create the menu item for it */
-		item = g_slice_alloc0(sizeof(*item));
-		item->type = E_POPUP_ITEM;
-		item->path = g_strdup_printf ("%s/%02d", path, i);
-		item->label = g_strdup ((strlen(subject) > 0) ? subject : _("No title"));
-		item->visible = EM_POPUP_SELECT_MANY | EM_POPUP_SELECT_ONE;
+		/* To avoid having a Templates dir, we ignore the top level */
+		if (g_str_has_suffix (folder->name, "Templates"))
+			action_label = _("Templates");
+		else
+			action_label = folder->name;
 
-		/* Make some info available to the callback */
-		user_data = g_slice_new(UserData);
-		user_data->msg = message;
-		user_data->t = t;
+		action = gtk_action_new (
+			action_name, action_label, NULL, NULL);
 
-		item->user_data = user_data;
-		item->activate = reply_with_template;
+		gtk_action_group_add_action (action_group, action);
 
-		list = g_slist_prepend (list, item);
-	}
+		g_debug ("Adding %s/%s", menu_path, action_name);
 
-	return list;
-}
+		gtk_ui_manager_add_ui (
+			ui_manager, merge_id, menu_path, action_name,
+			action_name, GTK_UI_MANAGER_MENU, FALSE);
 
-static GSList
-*fill_submenu (CamelStore *store, CamelFolderInfo *info, GSList *list, EMPopupTargetSelect *t)
-{
-	while (info) {
-		CamelFolder *folder;
-		GPtrArray *uids;
-		EPopupItem *item;
+		path = g_strdup_printf ("%s/%s", menu_path, action_name);
 
-		folder = camel_store_get_folder (store, info->full_name, 0, NULL);
+		g_object_unref (action);
+		g_free (action_name);
 
-		item = g_slice_alloc0(sizeof(*item));
-		item->type = E_POPUP_SUBMENU;
-		item->label = folder->name;
-		item->visible = EM_POPUP_SELECT_MANY | EM_POPUP_SELECT_ONE;
+		/* Add submenus, if any. */
+		if (folder_info->child != NULL)
+			build_template_menus_recurse (
+				ui_manager, action_group,
+				path, action_count, merge_id,
+				folder_info->child, message);
 
-		/* To avoid having a Templates dir, we ignore the top level */
-		if (!g_str_has_suffix (folder->name, "Templates"))
-			item->path = g_strdup_printf ("80.%s", folder->full_name);
-		else
-			item->path = g_strdup ("80.Templates");
+		/* Get the UIDs for this folder and add them to the menu. */
+		uids = camel_folder_get_uids (folder);
+		for (ii = 0; ii < uids->len; ii++) {
+			CamelMimeMessage *template;
+			const gchar *uid = uids->pdata[ii];
+			guint32 flags;
 
-		list = g_slist_prepend (list, item);
+			/* If the UIDs is marked for deletion, skip it. */
+			flags = camel_folder_get_message_flags (folder, uid);
+			if (flags & CAMEL_MESSAGE_DELETED)
+				continue;
 
-		/* Get the uids for this folder and fill them in the menu */
-		uids = camel_folder_get_uids (folder);
-		list = append_to_menu (folder, uids, list, t);
-		camel_folder_free_uids (folder, uids);
+			template = camel_folder_get_message (folder, uid, NULL);
+			camel_object_ref (template);
 
-		/* If the folder has a child, call this function again */
-		if (info->child) {
-			list = fill_submenu (store, info->child, list, t);
-		}
+			action_label =
+				camel_mime_message_get_subject (template);
+			if (action_label == NULL || *action_label == '\0')
+				action_label = _("No Title");
 
-		info = info->next;
-	}
+			action_name = g_strdup_printf (
+				"templates-item-%d", *action_count);
+			*action_count = *action_count + 1;
 
-	return list;
-}
+			action = gtk_action_new (
+				action_name, action_label, NULL, NULL);
 
-void
-org_gnome_templates_popup (EPlugin *ep, EMPopupTargetSelect *t)
-{
-	CamelFolder *templates_folder;
-	CamelFolderInfo *templates_info;
-	CamelStore *store;
+			g_object_set_data_full (
+				G_OBJECT (action), "template", template,
+				(GDestroyNotify) camel_object_unref);
 
-	GSList *list = NULL;
+			g_signal_connect (
+				action, "activate",
+				G_CALLBACK (action_reply_with_template_cb),
+				message);
 
-	/* We get the templates folder and all the uids of the messages in there */
-	store = e_mail_local_get_store ();
+			gtk_action_group_add_action (action_group, action);
 
-	templates_folder = e_mail_local_get_folder (E_MAIL_FOLDER_TEMPLATES);
+			g_debug ("Adding %s/%s", path, action_name);
 
-	templates_info = camel_store_get_folder_info (
-		store, templates_folder->full_name,
-		CAMEL_STORE_FOLDER_INFO_RECURSIVE |
-		CAMEL_STORE_FOLDER_INFO_FAST, NULL);
+			gtk_ui_manager_add_ui (
+				ui_manager, merge_id, path, action_name,
+				action_name, GTK_UI_MANAGER_MENUITEM, FALSE);
 
-	/* Get subfolders and fill it */
-	list = fill_submenu (store, templates_info, list, t);
+			g_object_unref (action);
+			g_free (action_name);
+		}
+		camel_folder_free_uids (folder, uids);
 
-	e_popup_add_items (t->target.popup, list, NULL, popup_free, NULL);
+		g_free (path);
 
-	return;
+		folder_info = folder_info->next;
+	}
 }
 
 static void
 action_template_cb (GtkAction *action,
-		EMsgComposer *composer)
+                    EMsgComposer *composer)
 {
 	CamelMessageInfo *info;
 	CamelMimeMessage *msg;
-	CamelFolder *templates_folder;
+	CamelFolder *folder;
+
+	/* Get the templates folder and all UIDs of the messages there. */
+	folder = e_mail_local_get_folder (E_MAIL_FOLDER_TEMPLATES);
 
-	/* We get the templates folder and all the uids of the messages in there */
-	templates_folder = e_mail_local_get_folder (E_MAIL_FOLDER_TEMPLATES);
 	msg = e_msg_composer_get_message_draft (composer);
 	info = camel_message_info_new (NULL);
 
 	/* FIXME: what's the ~0 for? :) */
-	camel_message_info_set_flags (info, CAMEL_MESSAGE_SEEN | CAMEL_MESSAGE_DRAFT, ~0);
+	camel_message_info_set_flags (
+		info, CAMEL_MESSAGE_SEEN | CAMEL_MESSAGE_DRAFT, ~0);
 
-	mail_append_mail (templates_folder, msg, info, NULL, composer);
-
-	return;
+	mail_append_mail (folder, msg, info, NULL, composer);
 }
 
-static GtkActionEntry entries[] = {
+static GtkActionEntry composer_entries[] = {
 
-	{ "Template",
+	{ "template",
 	  GTK_STOCK_SAVE,
 	  N_("Save as _Template"),
 	  "<Shift><Control>t",
@@ -712,9 +674,73 @@ static GtkActionEntry entries[] = {
 	  G_CALLBACK (action_template_cb) }
 };
 
-gboolean
-e_plugin_ui_init (GtkUIManager *ui_manager,
-                  EMsgComposer *composer)
+static void
+update_actions_cb (EShellView *shell_view)
+{
+	EShellContent *shell_content;
+	EShellWindow *shell_window;
+	GtkActionGroup *action_group;
+	GtkUIManager *ui_manager;
+	MessageList *message_list;
+	CamelMimeMessage *message;
+	CamelFolderInfo *folder_info;
+	CamelFolder *folder;
+	CamelStore *store;
+	EMailReader *reader;
+	GPtrArray *uids;
+	guint action_count = 0;
+	guint merge_id;
+	gpointer data;
+
+	shell_content = e_shell_view_get_shell_content (shell_view);
+	shell_window = e_shell_view_get_shell_window (shell_view);
+
+	ui_manager = e_shell_window_get_ui_manager (shell_window);
+	action_group = e_lookup_action_group (ui_manager, "templates");
+	data = g_object_get_data (G_OBJECT (action_group), "merge-id");
+	merge_id = GPOINTER_TO_UINT (data);
+	g_return_if_fail (merge_id > 0);
+
+	gtk_ui_manager_remove_ui (ui_manager, merge_id);
+	e_action_group_remove_all_actions (action_group);
+
+	if (!plugin_enabled)
+		return;
+
+	reader = E_MAIL_READER (shell_content);
+	message_list = e_mail_reader_get_message_list (reader);
+
+	folder = message_list->folder;
+	uids = message_list_get_selected (message_list);
+
+	if (uids->len != 1)
+		goto exit;
+
+	/* This is the source message to use in replying with a template. */
+	message = camel_folder_get_message (folder, uids->pdata[0], NULL);
+
+	/* Now recursively build template submenus in the pop-up menu. */
+
+	store = e_mail_local_get_store ();
+	folder = e_mail_local_get_folder (E_MAIL_FOLDER_TEMPLATES);
+
+	folder_info = camel_store_get_folder_info (
+		store, folder->full_name,
+		CAMEL_STORE_FOLDER_INFO_RECURSIVE |
+		CAMEL_STORE_FOLDER_INFO_FAST, NULL);
+
+	build_template_menus_recurse (
+		ui_manager, action_group,
+		"/mail-message-popup/mail-message-templates",
+		&action_count, merge_id, folder_info, message);
+
+exit:
+	em_utils_uids_free (uids);
+}
+
+static gboolean
+init_composer_actions (GtkUIManager *ui_manager,
+                       EMsgComposer *composer)
 {
 	GtkhtmlEditor *editor;
 
@@ -723,7 +749,62 @@ e_plugin_ui_init (GtkUIManager *ui_manager,
 	/* Add actions to the "composer" action group. */
 	gtk_action_group_add_actions (
 		gtkhtml_editor_get_action_group (editor, "composer"),
-		entries, G_N_ELEMENTS (entries), composer);
+		composer_entries, G_N_ELEMENTS (composer_entries), composer);
 
 	return TRUE;
 }
+
+static gboolean
+init_shell_actions (GtkUIManager *ui_manager,
+                    EShellWindow *shell_window)
+{
+	EShellView *shell_view;
+	GtkActionGroup *action_group;
+	guint merge_id;
+
+	shell_view = e_shell_window_get_shell_view (shell_window, "mail");
+
+	/* This is where we keep dynamically-built menu items. */
+	e_shell_window_add_action_group (shell_window, "templates");
+	action_group = e_lookup_action_group (ui_manager, "templates");
+
+	merge_id = gtk_ui_manager_new_merge_id (ui_manager);
+
+	g_object_set_data (
+		G_OBJECT (action_group), "merge-id",
+		GUINT_TO_POINTER (merge_id));
+
+	g_signal_connect (
+		shell_view, "update-actions",
+		G_CALLBACK (update_actions_cb), NULL);
+}
+
+gboolean
+e_plugin_ui_init (GtkUIManager *ui_manager,
+                  GObject *object)
+{
+	/* XXX This is a scenario I hadn't considered when designing
+	 *     EPluginUI: two different UI manager IDs with different
+	 *     closures sharing the same plugin entry point.  We know
+	 *     the closures are both GObjects so we query the type.
+	 *     Awkward, but it should work for now. */
+
+	if (E_IS_MSG_COMPOSER (object))
+		return init_composer_actions (
+			ui_manager, E_MSG_COMPOSER (object));
+
+	if (E_IS_SHELL_WINDOW (object))
+		return init_shell_actions (
+			ui_manager, E_SHELL_WINDOW (object));
+
+	return FALSE;
+}
+
+gint
+e_plugin_lib_enable (EPlugin *plugin,
+                     gboolean enabled)
+{
+	plugin_enabled = enabled;
+
+	return 0;
+}
diff --git a/shell/e-shell-window-private.c b/shell/e-shell-window-private.c
index 7161743..1eb5eed 100644
--- a/shell/e-shell-window-private.c
+++ b/shell/e-shell-window-private.c
@@ -212,6 +212,8 @@ e_shell_window_private_init (EShellWindow *shell_window)
 	merge_id = gtk_ui_manager_new_merge_id (priv->ui_manager);
 	priv->gal_view_merge_id = merge_id;
 
+	gtk_window_set_title (GTK_WINDOW (shell_window), _("Evolution"));
+
 	e_shell_window_actions_init (shell_window);
 
 	accel_group = gtk_ui_manager_get_accel_group (priv->ui_manager);
@@ -335,10 +337,12 @@ e_shell_window_private_constructed (EShellWindow *shell_window)
 	EShellSettings *shell_settings;
 	EShell *shell;
 	GConfBridge *bridge;
-	GtkActionGroup *action_group;
 	GtkAction *action;
+	GtkActionGroup *action_group;
+	GtkUIManager *ui_manager;
 	GObject *object;
 	const gchar *key;
+	const gchar *id;
 
 	shell = e_shell_window_get_shell (shell_window);
 	shell_settings = e_shell_get_shell_settings (shell);
@@ -427,6 +431,11 @@ e_shell_window_private_constructed (EShellWindow *shell_window)
 	gconf_bridge_bind_property (bridge, key, object, "active");
 
 	shell_window_init_switcher_style (shell_window);
+
+	id = "org.gnome.evolution.shell";
+	ui_manager = e_shell_window_get_ui_manager (shell_window);
+	e_plugin_ui_register_manager (ui_manager, id, shell_window);
+	e_plugin_ui_enable_manager (ui_manager, id);
 }
 
 void
diff --git a/shell/e-shell-window.c b/shell/e-shell-window.c
index c838235..1939209 100644
--- a/shell/e-shell-window.c
+++ b/shell/e-shell-window.c
@@ -335,20 +335,9 @@ shell_window_class_init (EShellWindowClass *class)
 static void
 shell_window_init (EShellWindow *shell_window)
 {
-	GtkUIManager *ui_manager;
-	const gchar *id;
-
 	shell_window->priv = E_SHELL_WINDOW_GET_PRIVATE (shell_window);
 
-	gtk_window_set_title (GTK_WINDOW (shell_window), _("Evolution"));
-
 	e_shell_window_private_init (shell_window);
-
-	ui_manager = e_shell_window_get_ui_manager (shell_window);
-
-	id = "org.gnome.evolution.shell";
-	e_plugin_ui_register_manager (ui_manager, id, shell_window);
-	e_plugin_ui_enable_manager (ui_manager, id);
 }
 
 GType
diff --git a/ui/Makefile.am b/ui/Makefile.am
index ebae928..a57b470 100644
--- a/ui/Makefile.am
+++ b/ui/Makefile.am
@@ -1,10 +1,3 @@
-XML_FILES =					\
-	evolution.xml				\
-	evolution-mail-message.xml		\
-	evolution-mail-list.xml			\
-	evolution-mail-global.xml		\
-	evolution-mail-messagedisplay.xml
-
 UI_FILES =					\
 	evolution-calendars.ui			\
 	evolution-contacts.ui			\
@@ -14,11 +7,10 @@ UI_FILES =					\
 	evolution-shell.ui			\
 	evolution-tasks.ui
 
-evolutionui_DATA = $(UI_FILES) $(XML_FILES)
+evolutionui_DATA = $(UI_FILES)
 
 EXTRA_DIST =					\
 	$(UI_FILES)				\
-	$(XML_FILES)				\
 	ChangeLog.pre-1-4
 
 -include $(top_srcdir)/git.mk
diff --git a/ui/evolution-mail.ui b/ui/evolution-mail.ui
index c676cf5..4c607c9 100644
--- a/ui/evolution-mail.ui
+++ b/ui/evolution-mail.ui
@@ -109,6 +109,8 @@
       <menuitem action='mail-label-new'/>
     </menu>
     <separator/>
+    <placeholder name='mail-message-templates'/>
+    <separator/>
     <placeholder name='mail-message-popup-actions'/>
   </popup>
   <popup name='mail-search-options'>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]