Refactored dimming rules calls
[modest] / src / modest-ui-actions.c
index 95c7023..432e45b 100644 (file)
@@ -560,9 +560,9 @@ modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
                                gtk_tree_path_free (prev_path);                         
                }
                
-               /* Update window dimming state */
+               /* Update toolbar dimming state */
                if (main_window)
-                       modest_ui_actions_check_window_dimming_rules (MODEST_WINDOW (main_window));
+                       modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
 
                /* Free */
                g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
@@ -813,6 +813,26 @@ modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
        modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL);
 }
 
+void
+modest_ui_actions_on_new_msg_or_folder (GtkAction *action, ModestWindow *win)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (win));
+
+       /* Check first if the header view has the focus */
+       if (MODEST_IS_MAIN_WINDOW (win)) {
+               GtkWidget *w;
+               w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
+                                                        MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
+               if (gtk_widget_is_focus (w)) {
+                       modest_ui_actions_on_new_folder (action, MODEST_MAIN_WINDOW(win));
+                       return;
+               }
+       }
+
+       modest_ui_actions_on_new_msg (action, win);
+}
+
+
 gboolean 
 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
                                       TnyHeader *header,
@@ -982,9 +1002,9 @@ open_msg_cb (ModestMailOperation *mail_op,
                gtk_widget_show_all (GTK_WIDGET(win));
        }
 
-       /* Update window dimming state */
+       /* Update toolbar dimming state */
        if (MODEST_IS_MAIN_WINDOW (parent_win)) {
-               modest_ui_actions_check_window_dimming_rules (MODEST_WINDOW (parent_win));
+               modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
        }
 
 cleanup:
@@ -1220,7 +1240,7 @@ open_msgs_from_headers (TnyList *headers, ModestWindow *win)
 
        /* Connect to the account and perform */
        if (uncached_msgs > 0) {
-               modest_platform_connect_and_perform ((GtkWindow *) win, g_object_ref (account), 
+               modest_platform_connect_and_perform ((GtkWindow *) win, TRUE, g_object_ref (account), 
                                                     open_msgs_performer, g_object_ref (not_opened_headers));
        } else {
                /* Call directly the performer, do not need to connect */
@@ -1769,7 +1789,8 @@ modest_ui_actions_do_send_receive (const gchar *account_name,
                                                                     TNY_ACCOUNT_TYPE_STORE);
 
        /* Invoke the connect and perform */
-       modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL, info->account, 
+       modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL, 
+                                            (win) ? TRUE : FALSE, info->account, 
                                             do_send_receive_performer, info);
 }
 
@@ -1966,8 +1987,8 @@ modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
        if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
            gtk_widget_grab_focus (GTK_WIDGET(header_view));
 
-       /* Update window dimming state */
-       modest_ui_actions_check_window_dimming_rules (MODEST_WINDOW (main_window));
+       /* Update toolbar dimming state */
+       modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
 }
 
 void
@@ -2130,8 +2151,8 @@ modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
                }
        }
 
-       /* Update window dimming state */
-       modest_ui_actions_check_window_dimming_rules (MODEST_WINDOW (main_window));
+       /* Update toolbar dimming state */
+       modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
 }
 
 void 
@@ -2691,6 +2712,7 @@ modest_ui_actions_create_folder(GtkWidget *parent_window,
        if (parent_folder) {
                /* The parent folder will be freed in the callback */
                modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window), 
+                                                              TRUE,
                                                               parent_folder,
                                                               create_folder_performer, 
                                                               parent_folder);
@@ -2842,7 +2864,7 @@ modest_ui_actions_on_rename_folder (GtkAction *action,
                        RenameFolderInfo *rename_folder_data = g_new0 (RenameFolderInfo, 1);
                        rename_folder_data->folder = folder;
                        rename_folder_data->new_name = folder_name;
-                       modest_platform_connect_if_remote_and_perform (GTK_WINDOW(main_window), 
+                       modest_platform_connect_if_remote_and_perform (GTK_WINDOW(main_window), TRUE,
                                        folder, on_rename_folder_performer, rename_folder_data);
                }
        }
@@ -2947,6 +2969,7 @@ delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
                g_object_ref (G_OBJECT (info->folder));
                TnyAccount *account = tny_folder_get_account (TNY_FOLDER (folder));
                modest_platform_connect_if_remote_and_perform (GTK_WINDOW (main_window), 
+                                                              TRUE,
                                                               TNY_FOLDER_STORE (account), 
                                                               on_delete_folder_cb, info);
                g_object_unref (account);
@@ -3533,7 +3556,7 @@ modest_ui_actions_on_select_all (GtkAction *action,
 
                /* Enable window dimming management */
                modest_window_enable_dimming (MODEST_WINDOW(window));
-               modest_ui_actions_check_window_dimming_rules (MODEST_WINDOW (window));
+               modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
        }
 
 }
@@ -4608,9 +4631,11 @@ on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window,
                        info->delete_original, 
                        folder_move_to_cb, 
                        helper);
-       
-       modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view),
-                       TNY_FOLDER (info->dst_folder), TRUE);
+
+       if (modest_mail_operation_get_status (mail_op) == MODEST_MAIL_OPERATION_STATUS_SUCCESS) {       
+               modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view),
+                                                 TNY_FOLDER (info->dst_folder), TRUE);
+       }
        
        /* Unref mail operation */
        g_object_unref (G_OBJECT (mail_op));
@@ -4668,7 +4693,7 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
                        info->folder_view = folder_view;
                        g_object_ref (G_OBJECT (info->src_folder));
                        g_object_ref (G_OBJECT (info->dst_folder));
-                       modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), 
+                       modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), TRUE,
                                    TNY_FOLDER_STORE (dst_folder), on_move_folder_cb, info);
                }
        } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
@@ -4687,7 +4712,7 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
                }
                if (do_xfer) /* Transfer messages */ {
                        g_object_ref (dst_folder);
-                       modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), 
+                       modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), TRUE,
                                        TNY_FOLDER_STORE (dst_folder), xfer_messages_from_move_to_cb, dst_folder);
                }
        }
@@ -4731,7 +4756,7 @@ modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
 
        if (do_xfer) {
                g_object_ref (dst_folder);
-               modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), 
+               modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), TRUE,
                                TNY_FOLDER_STORE (dst_folder), xfer_messages_from_move_to_cb, dst_folder);
         }
        g_object_unref (account);
@@ -4962,7 +4987,7 @@ modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
        g_object_unref (iter);
 
        /* Connect and perform the message retrieval */
-       modest_platform_connect_and_perform ((GtkWindow *) window, 
+       modest_platform_connect_and_perform ((GtkWindow *) window, TRUE,
                                             g_object_ref (account), 
                                             retrieve_msg_contents_performer, 
                                             g_object_ref (headers));
@@ -4973,12 +4998,111 @@ modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
 }
 
 void
-modest_ui_actions_check_window_dimming_rules (ModestWindow *window)
+modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */
+       modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_TOOLBAR);
+}
+
+void
+modest_ui_actions_check_menu_dimming_rules (ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */
+       modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_MENU);
+}
+
+void
+modest_ui_actions_on_email_menu_activated (GtkAction *action,
+                                         ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+       
+       /* Update dimmed */
+       modest_ui_actions_check_menu_dimming_rules (window);
+}
+
+void
+modest_ui_actions_on_edit_menu_activated (GtkAction *action,
+                                         ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */
+       modest_ui_actions_check_menu_dimming_rules (window);
+}
+
+void
+modest_ui_actions_on_view_menu_activated (GtkAction *action,
+                                         ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */
+       modest_ui_actions_check_menu_dimming_rules (window);
+}
+
+void
+modest_ui_actions_on_format_menu_activated (GtkAction *action,
+                                           ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */
+       modest_ui_actions_check_menu_dimming_rules (window);
+}
+
+void
+modest_ui_actions_on_tools_menu_activated (GtkAction *action,
+                                         ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */
+       modest_ui_actions_check_menu_dimming_rules (window);
+}
+
+void
+modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
+                                         ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */
+       modest_ui_actions_check_menu_dimming_rules (window);
+}
+
+void
+modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
+                                                ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */
+       modest_ui_actions_check_menu_dimming_rules (window);
+}
+
+void
+modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
+                                                    ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */
+       modest_ui_actions_check_menu_dimming_rules (window);
+}
+
+void
+modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
+                                                    ModestWindow *window)
 {
        g_return_if_fail (MODEST_IS_WINDOW (window));
 
-       /* Update dimmed */     
-       modest_window_check_dimming_rules_group (window, "ModestWindowDimmingRules");   
+       /* Update dimmed */
+       modest_ui_actions_check_menu_dimming_rules (window);
 }
 
 void