Fix Reply from mainwindow menu and toolbar when mainwindow's
[claws.git] / src / mainwindow.c
index 367e4a03afb9c9fce5776041f57534086ca309af..30376f0b6c17d2819f0b153bfd230fe9878c1671 100644 (file)
@@ -1,6 +1,6 @@
 /*
    Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
-   Copyright (C) 1999-2016 Hiroyuki Yamamoto and the Claws Mail team
+   Copyright (C) 1999-2018 the Claws Mail team and Hiroyuki Yamamoto
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -30,6 +30,7 @@
 #include "folderview.h"
 #include "folder_item_prefs.h"
 #include "foldersel.h"
+#include "quicksearch.h"
 #include "summaryview.h"
 #include "summary_search.h"
 #include "messageview.h"
@@ -921,27 +922,8 @@ static GtkRadioActionEntry mainwin_radio_dec_entries[] =
 };
 
 static gboolean offline_ask_sync = TRUE;
-static guint lastkey;
 static gboolean is_obscured = FALSE;
 
-static gboolean main_window_accel_activate (GtkAccelGroup *accelgroup,
-                                            GObject *arg1,
-                                            guint value,
-                                            GdkModifierType mod,
-                                            gpointer user_data) 
-{
-       MainWindow *mainwin = (MainWindow *)user_data;
-
-       if (mainwin->summaryview &&
-           mainwin->summaryview->quicksearch &&
-           quicksearch_has_focus(mainwin->summaryview->quicksearch) &&
-           (mod == 0 || mod == GDK_SHIFT_MASK)) {
-               quicksearch_pass_key(mainwin->summaryview->quicksearch, lastkey, mod);
-               return TRUE;
-       }
-       return FALSE;
-}
-
 #define N_COLOR_LABELS colorlabel_get_color_count()
 
 static void mainwindow_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_item,
@@ -1379,14 +1361,19 @@ static gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
                                    gpointer data)
 {
        MainWindow *mainwin = (MainWindow*) data;
-       
+
        if (!mainwin || !event) 
                return FALSE;
 
        if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
        {
-               lastkey = event->keyval;
-               return FALSE;
+               GtkWidget *entry =
+                       quicksearch_get_entry(mainwin->summaryview->quicksearch);
+               gboolean handled;
+               g_signal_emit_by_name(entry, "key-press-event", event, &handled);
+               if (handled) {
+                       return TRUE;
+               }
        }
 
        switch (event->keyval) {
@@ -1460,7 +1447,7 @@ MainWindow *main_window_create()
 
        /* main window */
        window = GTK_WIDGET(gtkut_window_new(GTK_WINDOW_TOPLEVEL, "mainwindow"));
-       gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION_FRIENDLY);
+       gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
        gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
 #ifdef GENERIC_UMPC
        prefs_common.layout_mode = SMALL_LAYOUT;
@@ -2174,10 +2161,7 @@ MainWindow *main_window_create()
 #define        ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win)                        \
        gtk_window_add_accel_group                                      \
                (GTK_WINDOW(win),                                       \
-                gtk_ui_manager_get_accel_group(gtkut_ui_manager()));   \
-       g_signal_connect(G_OBJECT(gtk_ui_manager_get_accel_group(gtkut_ui_manager())), \
-                       "accel_activate",                               \
-                       G_CALLBACK(main_window_accel_activate), mainwin);
+                gtk_ui_manager_get_accel_group(gtkut_ui_manager()));
 
        ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
        
@@ -2642,9 +2626,9 @@ static void main_window_show_cur_account(MainWindow *mainwin)
                           : _("none"));
 
        if (cur_account)
-               buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION_FRIENDLY);
+               buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
        else
-               buf = g_strdup(PROG_VERSION_FRIENDLY);
+               buf = g_strdup(PROG_VERSION);
        gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
        g_free(buf);
 
@@ -3381,6 +3365,18 @@ do { \
        cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/Message/CheckSignature", 
                                   mimepart_selected && mainwin->messageview->mimeview->signed_part);
 
+       sensitive = TRUE;
+       if (mimepart_selected) {
+               MimeInfo *partinfo = messageview_get_selected_mime_part(mainwin->messageview);
+
+               if (partinfo && (partinfo->type == MIMETYPE_MESSAGE ||
+                                partinfo->type == MIMETYPE_IMAGE ||
+                                partinfo->type == MIMETYPE_MULTIPART)) {
+                       sensitive = FALSE;
+               }
+       }
+       cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/Part/AsText", sensitive);
+
        main_window_menu_callback_unblock(mainwin);
 }
 
@@ -3886,8 +3882,7 @@ void main_window_destroy_all(void)
 
                /* free toolbar stuff */
                toolbar_clear_list(TOOLBAR_MAIN);
-               TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
-               TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
+               toolbar_destroy(mainwin->toolbar);
 
                summaryview_destroy(mainwin->summaryview);
                mainwin->folderview->mainwin = NULL;
@@ -4125,7 +4120,15 @@ static void main_window_reply_cb(GtkAction *gaction, gpointer data)
 
        msginfo_list = summary_get_selection(mainwin->summaryview);
        cm_return_if_fail(msginfo_list != NULL);
-       compose_reply_from_messageview(msgview, msginfo_list, action);
+
+       if (!summary_has_opened_message(mainwin->summaryview)) {
+               compose_reply_from_messageview(NULL, msginfo_list, action);
+       } else if (summary_is_opened_message_selected(mainwin->summaryview)) {
+               compose_reply_from_messageview(msgview, msginfo_list, action);
+       } else {
+               compose_reply_from_messageview(msgview, NULL, action);
+       }
+
        g_slist_free(msginfo_list);
 }
 
@@ -4217,6 +4220,8 @@ void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
                online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
        offline_ask_sync = TRUE;
 
+       inc_reset_offline_override_timers();
+
        switching = FALSE;
 }
 
@@ -4657,29 +4662,26 @@ static void set_folder_display_item_cb(GtkAction *action, gpointer data)
 static void sort_summary_cb(GtkAction *action, GtkRadioAction *current, gpointer data)
 {
        MainWindow *mainwin = (MainWindow *)data;
-       FolderItem *item = mainwin->summaryview->folder_item;
        gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
 
        if (mainwin->menu_lock_count) return;
 
-       if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current)) && item) {
+       if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current))) {
                summary_sort(mainwin->summaryview, (FolderSortKey)value,
-                            item->sort_type);
-               item->sort_key = value;
+                            mainwin->summaryview->sort_type);
        }
 }
 
 static void sort_summary_type_cb(GtkAction *gaction, GtkRadioAction *current, gpointer data)
 {
        MainWindow *mainwin = (MainWindow *)data;
-       FolderItem *item = mainwin->summaryview->folder_item;
        gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
 
        if (mainwin->menu_lock_count) return;
 
-       if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current)) && item)
+       if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current)))
                summary_sort(mainwin->summaryview,
-                            item->sort_key, (FolderSortType)value);
+                            mainwin->summaryview->sort_key, (FolderSortType)value);
 }
 
 static void attract_by_subject_cb(GtkAction *action, gpointer data)
@@ -5080,7 +5082,7 @@ static void prefs_account_open_cb(GtkAction *action, gpointer data)
        if (!cur_account) {
                new_account_cb(NULL, mainwin);
        } else {
-               account_open(cur_account);
+               account_open(cur_account, FALSE);
        }
 }