[evolution] Don't update the message list when right-clicking on a folder.



commit 1cd5fb6de35c30eb1965c9847a808aefac325778
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Oct 28 09:06:15 2009 -0400

    Don't update the message list when right-clicking on a folder.
    
    After the folder's context menu closes the folder tree selection jumps
    back to the folder whose contents are showing in the message list.
    Suggested by Philippe LeCavalier on evolution-list.

 doc/reference/shell/tmpl/e-shell-view.sgml |    1 +
 mail/e-mail-reader.c                       |   10 +++++--
 mail/em-folder-tree.c                      |   16 +++++++++-
 modules/mail/e-mail-shell-view-private.c   |   41 +++++++++++++++++++++++++++-
 modules/mail/e-mail-shell-view.c           |   25 ++++++++++++++---
 shell/e-shell-view.c                       |    6 +++-
 shell/e-shell-view.h                       |    2 +-
 7 files changed, 89 insertions(+), 12 deletions(-)
---
diff --git a/doc/reference/shell/tmpl/e-shell-view.sgml b/doc/reference/shell/tmpl/e-shell-view.sgml
index 94b4509..79e8b86 100644
--- a/doc/reference/shell/tmpl/e-shell-view.sgml
+++ b/doc/reference/shell/tmpl/e-shell-view.sgml
@@ -286,6 +286,7 @@ EShellView
 @shell_view: 
 @widget_path: 
 @event: 
+ Returns: 
 
 
 <!-- ##### FUNCTION e_shell_view_new_view_instance ##### -->
diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c
index ff7cd9f..2f07a27 100644
--- a/mail/e-mail-reader.c
+++ b/mail/e-mail-reader.c
@@ -1934,14 +1934,18 @@ mail_reader_set_folder (EMailReader *reader,
 	html_display = e_mail_reader_get_html_display (reader);
 	message_list = e_mail_reader_get_message_list (reader);
 
+	if (message_list->folder != NULL)
+		mail_sync_folder (message_list->folder, NULL, NULL);
+
+	/* Skip the rest if we're already viewing the folder. */
+	if (g_strcmp0 (folder_uri, message_list->folder_uri) == 0)
+		return;
+
 	outgoing = folder != NULL && folder_uri != NULL && (
 		em_utils_folder_is_drafts (folder, folder_uri) ||
 		em_utils_folder_is_outbox (folder, folder_uri) ||
 		em_utils_folder_is_sent (folder, folder_uri));
 
-	if (message_list->folder != NULL)
-		mail_sync_folder (message_list->folder, NULL, NULL);
-
 	em_format_format (EM_FORMAT (html_display), NULL, NULL, NULL);
 	message_list_set_folder (message_list, folder, folder_uri, outgoing);
 
diff --git a/mail/em-folder-tree.c b/mail/em-folder-tree.c
index 187522f..a4f9140 100644
--- a/mail/em-folder-tree.c
+++ b/mail/em-folder-tree.c
@@ -109,6 +109,9 @@ struct _EMFolderTreePrivate {
 	gboolean skip_double_click;
 
 	GtkCellRenderer *text_renderer;
+
+	/* Signal handler IDs */
+	gulong selection_changed_handler_id;
 };
 
 enum {
@@ -599,6 +602,7 @@ folder_tree_button_press_event (GtkWidget *widget,
 	GtkTreeSelection *selection;
 	GtkTreeView *tree_view;
 	GtkTreePath *path;
+	gulong handler_id;
 
 	priv = EM_FOLDER_TREE_GET_PRIVATE (widget);
 
@@ -618,9 +622,14 @@ folder_tree_button_press_event (GtkWidget *widget,
 		&path, NULL, NULL, NULL))
 		goto chainup;
 
-	/* select/focus the row that was right-clicked */
+	/* Select and focus the row that was right-clicked, but prevent
+	 * a "folder-selected" signal emission since this does not count
+	 * as a folder selection in the sense we mean. */
+	handler_id = priv->selection_changed_handler_id;
+	g_signal_handler_block (selection, handler_id);
 	gtk_tree_selection_select_path (selection, path);
 	gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
+	g_signal_handler_unblock (selection, handler_id);
 
 	gtk_tree_path_free (path);
 
@@ -835,6 +844,7 @@ folder_tree_init (EMFolderTree *folder_tree)
 	GtkTreeSelection *selection;
 	GHashTable *select_uris_table;
 	EMFolderTreeModel *model;
+	gulong handler_id;
 
 	select_uris_table = g_hash_table_new (g_str_hash, g_str_equal);
 
@@ -846,9 +856,11 @@ folder_tree_init (EMFolderTree *folder_tree)
 
 	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_tree));
 
-	g_signal_connect_swapped (
+	handler_id = g_signal_connect_swapped (
 		selection, "changed",
 		G_CALLBACK (folder_tree_selection_changed_cb), folder_tree);
+
+	folder_tree->priv->selection_changed_handler_id = handler_id;
 }
 
 GType
diff --git a/modules/mail/e-mail-shell-view-private.c b/modules/mail/e-mail-shell-view-private.c
index dd124f4..d28de5a 100644
--- a/modules/mail/e-mail-shell-view-private.c
+++ b/modules/mail/e-mail-shell-view-private.c
@@ -95,13 +95,52 @@ exit:
 }
 
 static void
+mail_shell_view_folder_tree_selection_done_cb (EMailShellView *mail_shell_view,
+                                               GtkWidget *menu)
+{
+	EMailShellSidebar *mail_shell_sidebar;
+	EMFolderTree *folder_tree;
+	MessageList *message_list;
+	EMailReader *reader;
+	const gchar *list_uri;
+	gchar *tree_uri;
+
+	reader = E_MAIL_READER (mail_shell_view->priv->mail_shell_content);
+	message_list = e_mail_reader_get_message_list (reader);
+
+	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
+	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
+
+	list_uri = message_list->folder_uri;
+	tree_uri = em_folder_tree_get_selected_uri (folder_tree);
+
+	/* If the folder tree and message list disagree on the current
+	 * folder, reset the folder tree to match the message list. */
+	if (g_strcmp0 (tree_uri, list_uri) != 0)
+		em_folder_tree_set_selected (folder_tree, list_uri, FALSE);
+
+	g_free (tree_uri);
+
+	/* Disconnect from the "selection-done" signal. */
+	g_signal_handlers_disconnect_by_func (
+		menu, mail_shell_view_folder_tree_selection_done_cb,
+		mail_shell_view);
+}
+
+static void
 mail_shell_view_folder_tree_popup_event_cb (EShellView *shell_view,
                                             GdkEventButton *event)
 {
+	GtkWidget *menu;
 	const gchar *widget_path;
 
 	widget_path = "/mail-folder-popup";
-	e_shell_view_show_popup_menu (shell_view, widget_path, event);
+	menu = e_shell_view_show_popup_menu (shell_view, widget_path, event);
+
+	g_signal_connect_swapped (
+		menu, "selection-done",
+		G_CALLBACK (mail_shell_view_folder_tree_selection_done_cb),
+		shell_view);
 }
 
 static gboolean
diff --git a/modules/mail/e-mail-shell-view.c b/modules/mail/e-mail-shell-view.c
index d331c08..7ce6833 100644
--- a/modules/mail/e-mail-shell-view.c
+++ b/modules/mail/e-mail-shell-view.c
@@ -399,11 +399,12 @@ static void
 mail_shell_view_update_actions (EShellView *shell_view)
 {
 	EMailShellView *mail_shell_view;
+	EMailShellContent *mail_shell_content;
 	EMailShellSidebar *mail_shell_sidebar;
-	EShellContent *shell_content;
 	EShellSidebar *shell_sidebar;
 	EShellWindow *shell_window;
 	EMFolderTree *folder_tree;
+	EMailReader *reader;
 	EAccount *account = NULL;
 	GtkAction *action;
 	const gchar *label;
@@ -420,13 +421,15 @@ mail_shell_view_update_actions (EShellView *shell_view)
 	gboolean folder_is_store;
 	gboolean folder_is_trash;
 	gboolean folder_has_unread_rec = FALSE;
+	gboolean folder_tree_and_message_list_agree = TRUE;
 
 	mail_shell_view = E_MAIL_SHELL_VIEW (shell_view);
 
 	shell_window = e_shell_view_get_shell_window (shell_view);
 
-	shell_content = e_shell_view_get_shell_content (shell_view);
-	e_mail_reader_update_actions (E_MAIL_READER (shell_content));
+	mail_shell_content = mail_shell_view->priv->mail_shell_content;
+	reader = E_MAIL_READER (mail_shell_content);
+	e_mail_reader_update_actions (reader);
 
 	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
 	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
@@ -450,6 +453,18 @@ mail_shell_view_update_actions (EShellView *shell_view)
 	uri = em_folder_tree_get_selected_uri (folder_tree);
 	if (uri != NULL) {
 		EMFolderTreeModel *model;
+		MessageList *message_list;
+
+		/* XXX If the user right-clicks on a folder other than what
+		 *     the message list is showing, disable folder rename.
+		 *     Between fetching the CamelFolder asynchronously and
+		 *     knowing when NOT to move the folder tree selection
+		 *     back to where it was to avoid cancelling the inline
+		 *     folder tree editing, it's just too hairy to try to
+		 *     get right.  So we're punting. */
+		message_list = e_mail_reader_get_message_list (reader);
+		folder_tree_and_message_list_agree =
+			(g_strcmp0 (uri, message_list->folder_uri) == 0);
 
 		account = mail_config_get_account_by_source_url (uri);
 
@@ -516,7 +531,9 @@ mail_shell_view_update_actions (EShellView *shell_view)
 	gtk_action_set_sensitive (action, sensitive);
 
 	action = ACTION (MAIL_FOLDER_RENAME);
-	sensitive = !folder_is_store && folder_can_be_deleted;
+	sensitive =
+		!folder_is_store && folder_can_be_deleted &&
+		folder_tree_and_message_list_agree;
 	gtk_action_set_sensitive (action, sensitive);
 
 	action = ACTION (MAIL_FOLDER_UNSUBSCRIBE);
diff --git a/shell/e-shell-view.c b/shell/e-shell-view.c
index 0bfa17c..3e8bd94 100644
--- a/shell/e-shell-view.c
+++ b/shell/e-shell-view.c
@@ -1137,8 +1137,10 @@ e_shell_view_update_actions (EShellView *shell_view)
  * The #EShellView::update-actions signal is emitted just prior to
  * showing the menu to give @shell_view and any plugins that extend
  * @shell_view a chance to update the menu's actions.
+ *
+ * Returns: the popup menu being displayed
  **/
-void
+GtkWidget *
 e_shell_view_show_popup_menu (EShellView *shell_view,
                               const gchar *widget_path,
                               GdkEventButton *event)
@@ -1162,6 +1164,8 @@ e_shell_view_show_popup_menu (EShellView *shell_view,
 		gtk_menu_popup (
 			GTK_MENU (menu), NULL, NULL, NULL, NULL,
 			0, gtk_get_current_event_time ());
+
+	return menu;
 }
 
 /**
diff --git a/shell/e-shell-view.h b/shell/e-shell-view.h
index cc40b76..7b8fb13 100644
--- a/shell/e-shell-view.h
+++ b/shell/e-shell-view.h
@@ -180,7 +180,7 @@ GKeyFile *	e_shell_view_get_state_key_file	(EShellView *shell_view);
 void		e_shell_view_set_state_dirty	(EShellView *shell_view);
 void		e_shell_view_execute_search	(EShellView *shell_view);
 void		e_shell_view_update_actions	(EShellView *shell_view);
-void		e_shell_view_show_popup_menu	(EShellView *shell_view,
+GtkWidget *	e_shell_view_show_popup_menu	(EShellView *shell_view,
 						 const gchar *widget_path,
 						 GdkEventButton *event);
 GalViewInstance *



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