Added dimming rules for edit window menu
[modest] / src / hildon2 / modest-msg-edit-window.c
index b12f2e1..031db11 100644 (file)
@@ -306,6 +306,9 @@ struct _ModestMsgEditWindowPrivate {
        gboolean    sent;
 
        GtkWidget   *app_menu;
+       GtkWidget   *cc_button;
+       GtkWidget   *bcc_button;
+       GtkWidget   *find_toolbar_button;
 };
 
 #define MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
@@ -1134,7 +1137,6 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich)
        TnyHeaderFlags priority_flags;
        TnyFolder *msg_folder;
        gboolean is_html = FALSE;
-       GtkAction *action;
        gboolean field_view_set;
        
        g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self));
@@ -1153,7 +1155,6 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich)
        if (to)
                modest_recpt_editor_set_recipients (MODEST_RECPT_EDITOR (priv->to_field),  to);
 
-       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ViewCcFieldMenu");
        field_view_set = TRUE;
        if (cc) {
                modest_recpt_editor_set_recipients (MODEST_RECPT_EDITOR (priv->cc_field),  cc);
@@ -1164,10 +1165,8 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich)
                gtk_widget_hide (priv->cc_caption);
                field_view_set = FALSE;
        }
-       if (action)
-               gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), field_view_set);
+       hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->cc_button), field_view_set);
 
-       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ViewBccFieldMenu");
        field_view_set = TRUE;
        if (bcc) {
                modest_recpt_editor_set_recipients (MODEST_RECPT_EDITOR (priv->bcc_field), bcc);
@@ -1178,8 +1177,7 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich)
                gtk_widget_hide (priv->bcc_caption);
                field_view_set = FALSE;
        }
-       if (action)
-               gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), field_view_set);
+       hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->bcc_button), field_view_set);
 
 
        if (subject)
@@ -3453,12 +3451,11 @@ static void
 modest_msg_edit_window_find_toolbar_close (GtkWidget *widget,
                                           ModestMsgEditWindow *window)
 {
-       GtkToggleAction *toggle;
-       ModestWindowPrivate *parent_priv;
-       parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+       ModestMsgEditWindowPrivate *priv;
+
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(window);
 
-       toggle = GTK_TOGGLE_ACTION (gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ToolsMenu/FindInMessageMenu"));
-       gtk_toggle_action_set_active (toggle, FALSE);
+       hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->find_toolbar_button), FALSE);
 }
 
 gboolean 
@@ -3897,6 +3894,21 @@ static void on_message_settings (GtkAction *action,
        modest_msg_edit_window_show_msg_settings_dialog (window);
 }
 
+
+static void add_button_to_menu (ModestMsgEditWindow *self,
+                               HildonAppMenu *menu,
+                               GtkButton *button,
+                               ModestDimmingRulesGroup *group,
+                               GCallback dimming_callback)
+{
+       if (dimming_callback)
+               modest_dimming_rules_group_add_widget_rule (group,
+                                                           GTK_WIDGET (button),
+                                                           dimming_callback,
+                                                           MODEST_WINDOW (self));
+       hildon_app_menu_append (menu, GTK_BUTTON (button));
+}
+
 static void add_to_menu (ModestMsgEditWindow *self,
                         HildonAppMenu *menu,
                         gchar *label,
@@ -3909,12 +3921,37 @@ static void add_to_menu (ModestMsgEditWindow *self,
        button = gtk_button_new_with_label (label);
        g_signal_connect_after (G_OBJECT (button), "clicked",
                                callback, (gpointer) self);
-       if (dimming_callback)
-               modest_dimming_rules_group_add_widget_rule (group,
-                                                           button,
-                                                           dimming_callback,
-                                                           MODEST_WINDOW (self));
-       hildon_app_menu_append (menu, GTK_BUTTON (button));
+       add_button_to_menu (self, menu, GTK_BUTTON (button), group, dimming_callback);
+}
+
+static void
+on_cc_button_toggled (HildonCheckButton *button,
+                     ModestMsgEditWindow *window)
+{
+       g_return_if_fail (MODEST_MSG_EDIT_WINDOW (window));
+
+       modest_msg_edit_window_show_cc (MODEST_MSG_EDIT_WINDOW (window),
+                                       hildon_check_button_get_active (button));
+}
+
+static void
+on_bcc_button_toggled (HildonCheckButton *button,
+                     ModestMsgEditWindow *window)
+{
+       g_return_if_fail (MODEST_MSG_EDIT_WINDOW (window));
+
+       modest_msg_edit_window_show_bcc (MODEST_MSG_EDIT_WINDOW (window),
+                                       hildon_check_button_get_active (button));
+}
+
+static void
+on_find_toolbar_button_toggled (HildonCheckButton *button,
+                               ModestMsgEditWindow *window)
+{
+       g_return_if_fail (MODEST_MSG_EDIT_WINDOW (window));
+       modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window),
+                                                   hildon_check_button_get_active (button));
+
 }
 
 static void 
@@ -3934,21 +3971,42 @@ setup_menu (ModestMsgEditWindow *self, ModestDimmingRulesGroup *group)
                     group, NULL);
        add_to_menu (self, HILDON_APP_MENU (priv->app_menu), _("mcen_me_inbox_undo"),
                     G_CALLBACK (modest_ui_actions_on_undo),
-                    group, NULL);
-
-       /* TODO: Show/Hide CC/BCC check buttons */
+                    group, G_CALLBACK (modest_ui_dimming_rules_on_undo));
+
+       priv->cc_button = hildon_check_button_new (0);
+       gtk_button_set_label (GTK_BUTTON (priv->cc_button), _("mcen_me_editor_showcc"));
+       hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->cc_button),
+                                       FALSE);
+       add_button_to_menu (self, HILDON_APP_MENU (priv->app_menu), GTK_BUTTON (priv->cc_button),
+                           group, NULL);
+       g_signal_connect (G_OBJECT (priv->cc_button), "toggled",
+                         G_CALLBACK (on_cc_button_toggled), (gpointer) self);
+       priv->bcc_button = hildon_check_button_new (0);
+       gtk_button_set_label (GTK_BUTTON (priv->bcc_button), _("mcen_me_editor_showbcc"));
+       hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->bcc_button),
+                                       FALSE);
+       add_button_to_menu (self, HILDON_APP_MENU (priv->app_menu), GTK_BUTTON (priv->bcc_button),
+                           group, NULL);
+       g_signal_connect (G_OBJECT (priv->bcc_button), "toggled",
+                         G_CALLBACK (on_bcc_button_toggled), (gpointer) self);
 
        add_to_menu (self, HILDON_APP_MENU (priv->app_menu), _("mcen_me_editor_attach_inlineimage"),
                     G_CALLBACK (modest_ui_actions_on_insert_image),
-                    group, NULL);
+                    group, G_CALLBACK (modest_ui_dimming_rules_on_set_style));
        add_to_menu (self, HILDON_APP_MENU (priv->app_menu), _("mcen_me_inbox_remove_attachments"),
                     G_CALLBACK (modest_ui_actions_on_remove_attachments),
-                    group, NULL);
+                    group, G_CALLBACK (modest_ui_dimming_rules_on_editor_remove_attachment));
        add_to_menu (self, HILDON_APP_MENU (priv->app_menu), _("TODO: Message settings..."),
                     G_CALLBACK (on_message_settings),
                     group, NULL);
-
-       /* TODO: find in toolbar check button */
+       priv->find_toolbar_button = hildon_check_button_new (0);
+       gtk_button_set_label (GTK_BUTTON (priv->find_toolbar_button), _("mcen_me_viewer_find"));
+       hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->find_toolbar_button),
+                                       FALSE);
+       add_button_to_menu (self, HILDON_APP_MENU (priv->app_menu), GTK_BUTTON (priv->find_toolbar_button),
+                           group, NULL);
+       g_signal_connect (G_OBJECT (priv->find_toolbar_button), "toggled",
+                         G_CALLBACK (on_find_toolbar_button_toggled), (gpointer) self);
 
        hildon_stackable_window_set_main_menu (HILDON_STACKABLE_WINDOW (self), 
                                               HILDON_APP_MENU (priv->app_menu));