[anjal] Right click implementation over message list



commit 77ecd1c2a2df1997ecb1a61c101b8f02a81a88f8
Author: Srinivasa Ragavan <sragavan novell com>
Date:   Tue Mar 31 15:11:21 2009 +0530

    Right click implementation over message list
---
 src/mail-folder-view.c |  145 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 143 insertions(+), 2 deletions(-)

diff --git a/src/mail-folder-view.c b/src/mail-folder-view.c
index 7de3ba0..d686aa6 100644
--- a/src/mail-folder-view.c
+++ b/src/mail-folder-view.c
@@ -27,6 +27,7 @@
 #include "mail-view.h"
 #include "mail-folder-view.h"
 #include "mail/em-folder-tree.h"
+#include "mail/em-popup.h"
 #include "mail/mail-mt.h"
 #include "mail/mail-ops.h"
 #include "misc/e-spinner.h"
@@ -68,6 +69,8 @@ enum {
 
 static const char * mfv_get_selected_uid (GtkTreeView *tree, MailFolderView *mfv);
 static const char *unread_image = ANJAL_IMAGEDIR"unread.png";
+static void mfv_message_activated (GtkTreeView       *tree_view,  GtkTreePath       *path, GtkTreeViewColumn *column,  MailFolderView *shell);
+static void mfv_delete (MailFolderView *mfv, gboolean del);
 
 static guint signals[LAST_SIGNAL] = { 0 };
 
@@ -817,6 +820,137 @@ mfv_get_selected_info (GtkTreeView *tree, MailFolderView *mfv)
 	 return em_tree_store_get_info_from_iter(mfv->model, &iter);
 }
 
+static GPtrArray *
+mfv_get_selected_threads (MailFolderView *mfv)
+{
+	GtkTreeSelection *sel = gtk_tree_view_get_selection (mfv->tree);
+	GList *slist = gtk_tree_selection_get_selected_rows (sel, NULL);
+	GList *tmp;
+	GPtrArray *uids = g_ptr_array_new ();
+	GtkTreeIter iter;
+	
+	tmp = slist;
+	while (tmp) {
+		 GtkTreePath *path = (GtkTreePath *)tmp->data;
+		 gtk_tree_model_get_iter (mfv->model, &iter, path);
+		 g_ptr_array_add (uids, g_strdup(em_tree_store_get_uid_from_iter (mfv->model, &iter)));
+		 tmp = tmp->next;
+	}
+	g_list_foreach (slist, gtk_tree_path_free, NULL);
+	g_list_free (slist);
+
+	return uids;
+}
+
+static void
+mfv_popup_open_new_tab (EPopup *ep, EPopupItem *pitem, void *data)
+{
+	 MailFolderView *mfv = (MailFolderView *)data;
+	 MailConvView *mcv = NULL;
+	 GtkTreeIter iter;
+	 GPtrArray *uids;	 
+	 GtkTreeSelection *sel = gtk_tree_view_get_selection (mfv->tree);
+	 
+	 gtk_tree_selection_get_selected (sel, NULL, &iter);
+
+	 g_signal_emit (mfv, signals[MESSAGE_NEW], 0, &mcv);
+	 if (!mcv)
+		  return FALSE;
+	 
+	 uids = em_tree_store_get_child_sorted_tree (mfv->model, &iter);
+	 mail_conv_view_set_thread (mcv, mfv->priv->folder, uids);
+}
+
+static void
+mfv_popup_open_current_tab (EPopup *ep, EPopupItem *pitem, void *data)
+{
+	 MailFolderView *mfv = (MailFolderView *)data;
+	 GtkTreeIter iter;
+	 GtkTreeSelection *sel = gtk_tree_view_get_selection (mfv->tree);
+	 GtkTreePath *path;
+	 
+	 gtk_tree_selection_get_selected (sel, NULL, &iter);
+	 path = gtk_tree_model_get_path (mfv->model, &iter);
+	 mfv_message_activated (mfv->tree,  path, NULL,  mfv);
+	 gtk_tree_path_free (path);
+}
+
+static void
+mfv_popup_delete (EPopup *ep, EPopupItem *pitem, void *data)
+{
+	 MailFolderView *mfv = (MailFolderView *)data;
+	 mfv_delete (mfv, TRUE);
+}
+
+static void
+mfv_popup_undelete (EPopup *ep, EPopupItem *pitem, void *data)
+{
+	 MailFolderView *mfv = (MailFolderView *)data;
+	 mfv_delete (mfv, FALSE);
+}
+
+static EPopupItem mfv_popup_items[] = {
+//	{ E_POPUP_ITEM, "10.emfv.00", N_("_Reply to Sender"), emfv_popup_reply_sender, NULL, "mail-reply-sender", EM_POPUP_SELECT_ONE },
+//	{ E_POPUP_ITEM, "10.emfv.01", N_("Reply to _All"), emfv_popup_reply_all, NULL, "mail-reply-all", EM_POPUP_SELECT_ONE },
+//	{ E_POPUP_ITEM, "10.emfv.02", N_("_Forward"), emfv_popup_forward, NULL, "mail-forward", EM_POPUP_SELECT_MANY },
+	{ E_POPUP_ITEM, "10.mfv.00", N_("_Open in New Tab"), mfv_popup_open_new_tab, NULL, "stock_mail-open", EM_POPUP_SELECT_ONE },
+	{ E_POPUP_ITEM, "10.mfv.01", N_("_Open in This Tab"), mfv_popup_open_current_tab, NULL, "stock_mail-open", EM_POPUP_SELECT_ONE },
+	{ E_POPUP_BAR, "40.mfv", NULL, NULL, NULL, NULL },
+	{ E_POPUP_ITEM, "40.mfv.00", N_("_Delete"), mfv_popup_delete, NULL, "edit-delete", EM_POPUP_SELECT_DELETE },
+	{ E_POPUP_ITEM, "40.mfv.01", N_("U_ndelete"), mfv_popup_undelete, NULL, NULL, EM_POPUP_SELECT_UNDELETE },
+	{ E_POPUP_BAR, "50.mfv", NULL, NULL, NULL, NULL },
+//	{ E_POPUP_ITEM, "50.mfv.00", N_("Mar_k as Read"), emfv_popup_mark_read, NULL, "mail-mark-read", EM_POPUP_SELECT_MARK_READ|EM_FOLDER_VIEW_SELECT_LISTONLY },
+//	{ E_POPUP_ITEM, "50.mfv.01", N_("Mark as _Unread"), emfv_popup_mark_unread, NULL, "mail-mark-unread", EM_POPUP_SELECT_MARK_UNREAD|EM_FOLDER_VIEW_SELECT_LISTONLY },
+//	{ E_POPUP_ITEM, "50.mfv.02", N_("Mark as _Important"), emfv_popup_mark_important, NULL, "mail-mark-important", EM_POPUP_SELECT_MARK_IMPORTANT|EM_FOLDER_VIEW_SELECT_LISTONLY },
+//	{ E_POPUP_ITEM, "50.mfv.03", N_("Mark as Un_important"), emfv_popup_mark_unimportant, NULL, NULL, EM_POPUP_SELECT_MARK_UNIMPORTANT|EM_FOLDER_VIEW_SELECT_LISTONLY },
+//	{ E_POPUP_ITEM, "50.mfv.04", N_("Mark as _Junk"), emfv_popup_mark_junk, NULL, "mail-mark-junk", EM_POPUP_SELECT_MANY|EM_FOLDER_VIEW_SELECT_LISTONLY|EM_POPUP_SELECT_JUNK },
+//	{ E_POPUP_ITEM, "50.mfv.05", N_("Mark as _Not Junk"), emfv_popup_mark_nojunk, NULL, "mail-mark-notjunk", EM_POPUP_SELECT_MANY|EM_FOLDER_VIEW_SELECT_LISTONLY|EM_POPUP_SELECT_NOT_JUNK },
+
+};
+
+static void
+mfv_popup_items_free(EPopup *ep, GSList *items, void *data)
+{
+	g_slist_free(items);
+}
+
+static void
+mfv_popup (MailFolderView *mfv, GdkEvent *event)
+{
+	GSList *menus = NULL, *l, *label_list = NULL;
+	GtkMenu *menu;
+	EMPopup *emp;
+	EMPopupTargetSelect *t;
+	int i;
+	GtkTreePath *path = NULL;
+
+	if (gtk_tree_view_get_path_at_pos (mfv->tree, event->button.x, event->button.y, &path, NULL, NULL, NULL)) {
+		 GtkTreeSelection *sel = gtk_tree_view_get_selection (mfv->tree);
+		 gtk_tree_selection_select_path (sel, path);
+		 gtk_tree_path_free (path);
+	}
+	
+	/** @HookPoint-EMPopup: Message List Context Menu
+	 * @Id: org.gnome.evolution.anjal.mail.folderview.popup.select
+	 * @Type: EMPopup
+	 * @Target: EMPopupTargetSelect
+	 *
+	 * This is the context menu shown on the message list.
+	 */
+	emp = em_popup_new("org.gnome.evolution.anjal.mail.folderview.popup");
+	t = em_popup_target_new_select(emp, mfv->priv->folder, mfv->uri, mfv_get_selected_threads(mfv));
+	t->target.widget = (GtkWidget *)mfv;
+
+	for (i=0;i<G_N_ELEMENTS(mfv_popup_items); i++)
+		 menus = g_slist_prepend(menus, &mfv_popup_items[i]);
+
+	e_popup_add_items((EPopup *)emp, menus, NULL, mfv_popup_items_free, mfv);
+	menu = e_popup_create_menu_once((EPopup *)emp, (EPopupTarget *)t, 0);
+
+	gtk_menu_popup(menu, NULL, NULL, NULL, NULL, event->button.button, event->button.time);
+	
+}
+
 static gboolean
 mfv_button_clicked (GtkWidget *w, GdkEventButton *event, MailFolderView *mfv)
 {
@@ -835,8 +969,12 @@ mfv_button_clicked (GtkWidget *w, GdkEventButton *event, MailFolderView *mfv)
 				mail_conv_view_set_thread (mcv, mfv->priv->folder, uids);
 			}
 			gtk_tree_path_free(path);
-		}
+		} 
 		return TRUE;
+	} else if (event->button == 3) {
+			 /* Right click */
+			 mfv_popup (mfv, event);
+			 return TRUE;
 	}
 	return FALSE;
 }
@@ -1019,7 +1157,8 @@ mail_folder_view_construct (MailFolderView *shell)
 	GtkTreeViewColumn *column;
 	GtkCellRenderer *cell;
 	GtkCellRenderer *hbox, *vbox;
-
+	GtkTreeSelection *sel;
+	
 	viewbox = gtk_vbox_new (FALSE, 0);
 	gtk_widget_show (viewbox);
 	infolabel = gtk_label_new (_("Please select a folder on the folder tree"));
@@ -1046,6 +1185,8 @@ mail_folder_view_construct (MailFolderView *shell)
 	gtk_widget_show (shell);
 	
 	shell->tree = (GtkTreeView *)gtk_tree_view_new ();
+	sel  = gtk_tree_view_get_selection (shell->tree);
+//	gtk_tree_selection_set_mode (sel, GTK_SELECTION_MULTIPLE);
 	gtk_tree_view_set_enable_search (shell->tree, FALSE);
 	gtk_container_add (priv->view_scroller, shell->tree);
 	gtk_tree_view_set_fixed_height_mode (shell->tree, TRUE);



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