* src/modest-ui-actions.c
[modest] / src / maemo / modest-msg-edit-window.c
index 0830961..bab1cb5 100644 (file)
@@ -138,8 +138,10 @@ static void modest_msg_edit_window_clipboard_owner_change (GtkClipboard *clipboa
 static void update_window_title (ModestMsgEditWindow *window);
 static void update_dimmed (ModestMsgEditWindow *window);
 static void update_paste_dimming (ModestMsgEditWindow *window);
+static void update_copy_cut_dimming (ModestMsgEditWindow *window);
 static void update_select_all_dimming (ModestMsgEditWindow *window);
 static void update_zoom_dimming (ModestMsgEditWindow *window);
+static void update_send_dimming (ModestMsgEditWindow *window);
 
 /* Find toolbar */
 static void modest_msg_edit_window_find_toolbar_search (GtkWidget *widget,
@@ -2642,30 +2644,19 @@ static void
 recpt_field_changed (GtkTextBuffer *buffer,
                  ModestMsgEditWindow *editor)
 {
-       ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (editor);
-       ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (editor);
-       GtkTextBuffer *to_buffer, *cc_buffer, *bcc_buffer;
-       gboolean dim = FALSE;
-       GtkAction *action;
-
-       to_buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->to_field));
-       cc_buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->cc_field));
-       bcc_buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->bcc_field));
-       
-       dim = ((gtk_text_buffer_get_char_count (to_buffer) + 
-               gtk_text_buffer_get_char_count (cc_buffer) +
-               gtk_text_buffer_get_char_count (bcc_buffer)) == 0);
-                       
-       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ToolbarSend");
-       gtk_action_set_sensitive (action, !dim);
-       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EmailMenu/SendMenu");
-       gtk_action_set_sensitive (action, !dim);
+        update_send_dimming (editor);
 }
 
 static void  
 send_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor)
 {
-       hildon_banner_show_information (NULL, NULL, _("mcen_ib_add_recipients_first"));
+       ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (editor);
+        const gchar *subject = gtk_entry_get_text (GTK_ENTRY (priv->subject_field));
+        if (subject == NULL || subject[0] == '\0') {
+                hildon_banner_show_information (NULL, NULL, _("mcen_ib_subject_or_body_not_modified"));
+        } else {
+                hildon_banner_show_information (NULL, NULL, _("mcen_ib_add_recipients_first"));
+        }
 }
 
 static void
@@ -2772,8 +2763,6 @@ modest_msg_edit_window_clipboard_owner_change (GtkClipboard *clipboard,
        ModestWindowPrivate *parent_priv;
        ModestMsgEditWindowPrivate *priv;
        GtkAction *action;
-       gboolean has_selection;
-       GtkWidget *focused;
        GList *selected_attachments = NULL;
        gint n_att_selected = 0;
 
@@ -2782,13 +2771,6 @@ modest_msg_edit_window_clipboard_owner_change (GtkClipboard *clipboard,
 
        if (!GTK_WIDGET_VISIBLE (window))
                return;
-       has_selection = gtk_clipboard_wait_for_targets (clipboard, NULL, NULL);
-       focused = gtk_window_get_focus (GTK_WINDOW (window));
-
-       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/CutMenu");
-       gtk_action_set_sensitive (action, (has_selection) && (!MODEST_IS_ATTACHMENTS_VIEW (focused)));
-       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/CopyMenu");
-       gtk_action_set_sensitive (action, (has_selection) && (!MODEST_IS_ATTACHMENTS_VIEW (focused)));
 
        selected_attachments = modest_attachments_view_get_selection (MODEST_ATTACHMENTS_VIEW (priv->attachments_view));
        n_att_selected = g_list_length (selected_attachments);
@@ -2797,6 +2779,7 @@ modest_msg_edit_window_clipboard_owner_change (GtkClipboard *clipboard,
        action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/AttachmentsMenu/RemoveAttachmentsMenu");
        gtk_action_set_sensitive (action, n_att_selected == 1);
        
+       update_copy_cut_dimming (window);
        update_paste_dimming (window);
 }
 
@@ -2822,6 +2805,7 @@ subject_field_changed (GtkEditable *editable,
        ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
        update_window_title (window);
        gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
+        update_send_dimming (window);
 }
 
 static void  
@@ -3030,6 +3014,33 @@ modest_msg_edit_window_find_toolbar_close (GtkWidget *widget,
 
 
 static void 
+update_copy_cut_dimming (ModestMsgEditWindow *window)
+{
+       ModestWindowPrivate *parent_priv = NULL;
+       ModestMsgEditWindowPrivate *priv = NULL;
+       GtkClipboard *clipboard = NULL;
+       GtkAction *action = NULL;
+       gboolean has_selection = FALSE;
+       GtkWidget *focused = NULL;
+       gchar *selection = NULL;
+
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+       parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+       clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+       focused = gtk_window_get_focus (GTK_WINDOW (window));
+
+       has_selection = gtk_clipboard_wait_for_targets (clipboard, NULL, NULL);
+
+       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/CutMenu");
+       gtk_action_set_sensitive (action, (has_selection) && (!MODEST_IS_ATTACHMENTS_VIEW (focused)));
+       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/CopyMenu");
+       gtk_action_set_sensitive (action, (has_selection) && (!MODEST_IS_ATTACHMENTS_VIEW (focused)));
+
+       if (selection != NULL) 
+               g_free(selection);
+}
+
+static void 
 update_paste_dimming (ModestMsgEditWindow *window)
 {
        ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
@@ -3097,12 +3108,40 @@ update_zoom_dimming (ModestMsgEditWindow *window)
 }
 
 static void
+update_send_dimming (ModestMsgEditWindow *window)
+{
+        ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+        ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+        GtkTextBuffer *to_buffer, *cc_buffer, *bcc_buffer;
+        const gchar *subject;
+       gboolean dim = FALSE;
+       GtkAction *action;
+
+       to_buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->to_field));
+       cc_buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->cc_field));
+       bcc_buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->bcc_field));
+        subject = gtk_entry_get_text (GTK_ENTRY (priv->subject_field));
+
+       dim = ((gtk_text_buffer_get_char_count (to_buffer) +
+               gtk_text_buffer_get_char_count (cc_buffer) +
+               gtk_text_buffer_get_char_count (bcc_buffer)) == 0);
+
+        dim = dim || (subject == NULL || subject[0] == '\0');
+
+       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ToolbarSend");
+       gtk_action_set_sensitive (action, !dim);
+       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EmailMenu/SendMenu");
+       gtk_action_set_sensitive (action, !dim);
+}
+
+static void
 edit_menu_activated (GtkAction *action,
                     gpointer userdata)
 {
        ModestMsgEditWindow *window = MODEST_MSG_EDIT_WINDOW (userdata);
 
        update_select_all_dimming (window);
+       update_copy_cut_dimming (window);
        update_paste_dimming (window);
 }
 static void