2007-06-12 [colin] 2.9.2cvs57
authorColin Leroy <colin@colino.net>
Tue, 12 Jun 2007 16:48:32 +0000 (16:48 +0000)
committerColin Leroy <colin@colino.net>
Tue, 12 Jun 2007 16:48:32 +0000 (16:48 +0000)
* po/POTFILES.in
* src/Makefile.am
* src/folderview.c
* src/prefs_common.c
* src/prefs_common.h
* src/prefs_summaries.c
* src/prefs_summary_open.c
* src/prefs_summary_open.h
* src/summaryview.c
Make "when entering a folder" actions more personalisable

12 files changed:
ChangeLog
PATCHSETS
configure.ac
po/POTFILES.in
src/Makefile.am
src/folderview.c
src/prefs_common.c
src/prefs_common.h
src/prefs_summaries.c
src/prefs_summary_open.c [new file with mode: 0644]
src/prefs_summary_open.h [new file with mode: 0644]
src/summaryview.c

index 6200138..b912b4e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2007-06-12 [colin]     2.9.2cvs57
+
+       * po/POTFILES.in
+       * src/Makefile.am
+       * src/folderview.c
+       * src/prefs_common.c
+       * src/prefs_common.h
+       * src/prefs_summaries.c
+       * src/prefs_summary_open.c
+       * src/prefs_summary_open.h
+       * src/summaryview.c
+               Make "when entering a folder" actions more personalisable
+
 2007-06-12 [wwp]       2.9.2cvs56
 
        * tools/README
index 0d896e8..08e55bc 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.1.2.5 -r 1.1.2.6 src/prefs_logging.c;  ) > 2.9.2cvs54.patchset
 ( cvs diff -u -r 1.30.2.20 -r 1.30.2.21 tools/README;  ) > 2.9.2cvs55.patchset
 ( cvs diff -u -r 1.30.2.21 -r 1.30.2.22 tools/README;  ) > 2.9.2cvs56.patchset
+( cvs diff -u -r 1.53.2.26 -r 1.53.2.27 po/POTFILES.in;  cvs diff -u -r 1.155.2.64 -r 1.155.2.65 src/Makefile.am;  cvs diff -u -r 1.207.2.163 -r 1.207.2.164 src/folderview.c;  cvs diff -u -r 1.204.2.136 -r 1.204.2.137 src/prefs_common.c;  cvs diff -u -r 1.103.2.83 -r 1.103.2.84 src/prefs_common.h;  cvs diff -u -r 1.1.2.41 -r 1.1.2.42 src/prefs_summaries.c;  diff -u /dev/null src/prefs_summary_open.c;  diff -u /dev/null src/prefs_summary_open.h;  cvs diff -u -r 1.395.2.303 -r 1.395.2.304 src/summaryview.c;  ) > 2.9.2cvs57.patchset
index f1b8e32..0a91c4a 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=2
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=56
+EXTRA_VERSION=57
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 00f0df2..6f65c0f 100644 (file)
@@ -120,6 +120,7 @@ src/prefs_send.c
 src/prefs_spelling.c
 src/prefs_summaries.c
 src/prefs_summary_column.c
+src/prefs_summary_open.c
 src/prefs_template.c
 src/prefs_themes.c
 src/prefs_toolbar.c
index a786932..7693fc2 100644 (file)
@@ -121,6 +121,7 @@ claws_mail_SOURCES = \
        prefs_spelling.c \
        prefs_summaries.c \
        prefs_summary_column.c \
+       prefs_summary_open.c \
        prefs_folder_column.c \
        prefs_template.c \
        prefs_themes.c \
@@ -264,6 +265,7 @@ claws_mailinclude_HEADERS = \
        prefs_spelling.h \
        prefs_summaries.h \
        prefs_summary_column.h \
+       prefs_summary_open.h \
        prefs_folder_column.h \
        prefs_template.h \
        prefs_themes.h \
index 0c40b7e..f53d945 100644 (file)
@@ -889,10 +889,10 @@ void folderview_select_next_marked(FolderView *folderview)
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        GtkCTreeNode *node = NULL;
-       SelectOnEntry last_sel = prefs_common.select_on_entry;
+       EntryAction last_summary_select_prio = prefs_common.summary_select_prio[0];
        gboolean last_open = prefs_common.always_show_msg;
        
-       prefs_common.select_on_entry = SELECTONENTRY_MNU;
+       prefs_common.summary_select_prio[0] = ACTION_MARKED;
        prefs_common.always_show_msg = TRUE;
 
        if ((node = folderview_find_next_marked(ctree, folderview->opened))
@@ -910,7 +910,7 @@ void folderview_select_next_marked(FolderView *folderview)
                folderview_select_node(folderview, node);
 
 out:
-       prefs_common.select_on_entry = last_sel;
+       prefs_common.summary_select_prio[0] = last_summary_select_prio;
        prefs_common.always_show_msg = last_open;
 }
 
@@ -937,10 +937,10 @@ void folderview_select_next_unread(FolderView *folderview, gboolean force_open)
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        GtkCTreeNode *node = NULL;
-       SelectOnEntry last_sel = prefs_common.select_on_entry;
+       EntryAction last_summary_select_prio = prefs_common.summary_select_prio[0];
        gboolean last_open = prefs_common.always_show_msg;
        
-       prefs_common.select_on_entry = SELECTONENTRY_UNM;
+       prefs_common.summary_select_prio[0] = ACTION_UNREAD;
        prefs_common.always_show_msg = force_open ? TRUE : last_open;
 
        if ((node = folderview_find_next_unread(ctree, folderview->opened))
@@ -958,7 +958,7 @@ void folderview_select_next_unread(FolderView *folderview, gboolean force_open)
                folderview_select_node(folderview, node);
 
 out:
-       prefs_common.select_on_entry = last_sel;
+       prefs_common.summary_select_prio[0] = last_summary_select_prio;
        prefs_common.always_show_msg = last_open;
 }
 
@@ -985,10 +985,10 @@ void folderview_select_next_new(FolderView *folderview)
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        GtkCTreeNode *node = NULL;
-       SelectOnEntry last_sel = prefs_common.select_on_entry;
+       EntryAction last_summary_select_prio = prefs_common.summary_select_prio[0];
        gboolean last_open = prefs_common.always_show_msg;
        
-       prefs_common.select_on_entry = SELECTONENTRY_NUM;
+       prefs_common.summary_select_prio[0] = ACTION_NEW;
        prefs_common.always_show_msg = TRUE;
 
        if ((node = folderview_find_next_new(ctree, folderview->opened))
@@ -1006,7 +1006,7 @@ void folderview_select_next_new(FolderView *folderview)
                folderview_select_node(folderview, node);
 
 out:
-       prefs_common.select_on_entry = last_sel;
+       prefs_common.summary_select_prio[0] = last_summary_select_prio;
        prefs_common.always_show_msg = last_open;
 }
 
index d9c7016..904f955 100644 (file)
@@ -714,8 +714,22 @@ static PrefParam param[] = {
        {"always_show_message_when_selected", "FALSE",
         &prefs_common.always_show_msg,
         P_BOOL, NULL, NULL, NULL},
-       {"select_on_entry", "2", &prefs_common.select_on_entry,
+       {"select_on_entry", "3", &prefs_common.select_on_entry,
         P_ENUM, NULL, NULL, NULL},
+
+       {"summary_select_prio1", "0", &prefs_common.summary_select_prio[0], P_ENUM,
+        NULL, NULL, NULL},
+       {"summary_select_prio2", "0", &prefs_common.summary_select_prio[1], P_ENUM,
+        NULL, NULL, NULL},
+       {"summary_select_prio3", "0", &prefs_common.summary_select_prio[2], P_ENUM,
+        NULL, NULL, NULL},
+       {"summary_select_prio4", "0", &prefs_common.summary_select_prio[3], P_ENUM,
+        NULL, NULL, NULL},
+       {"summary_select_prio5", "0", &prefs_common.summary_select_prio[4], P_ENUM,
+        NULL, NULL, NULL},
+       {"summary_select_prio6", "0", &prefs_common.summary_select_prio[5], P_ENUM,
+        NULL, NULL, NULL},
+
        {"mark_as_read_on_new_window", "FALSE",
         &prefs_common.mark_as_read_on_new_window,
         P_BOOL, NULL, NULL, NULL},
index 29b8859..cdd8ecb 100644 (file)
@@ -74,6 +74,17 @@ typedef enum
        SELECTONENTRY_LAST
 } SelectOnEntry;
 
+typedef enum
+{
+       ACTION_UNSET = 0, /* for backward compatibility */
+       ACTION_MARKED,
+       ACTION_NEW,
+       ACTION_UNREAD,
+       ACTION_LAST_OPENED,
+       ACTION_LAST_LIST,
+       ACTION_NOTHING
+} EntryAction;
+
 typedef enum
 {
        NEXTUNREADMSGDIALOG_ALWAYS,
@@ -327,6 +338,9 @@ struct _PrefsCommon
        gboolean mark_as_read_delay;
        gboolean immediate_exec;
        SelectOnEntry select_on_entry;
+
+       EntryAction summary_select_prio[6];
+
        NextUnreadMsgDialogShow next_unread_msg_dialog;
        gboolean add_address_by_click;
        gchar *pixmap_theme_path;
index 7d45cdb..48d3d60 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "prefs_common.h"
 #include "prefs_gtk.h"
+#include "prefs_summary_open.h"
 #include "prefs_summary_column.h"
 #include "prefs_folder_column.h"
 
@@ -62,7 +63,6 @@ typedef struct _SummariesPage
        GtkWidget *spinbtn_mark_as_read_delay;
        GtkWidget *checkbtn_immedexec;
        GtkWidget *checkbtn_ask_mark_all_read;
-       GtkWidget *optmenu_select_on_entry;
        GtkWidget *optmenu_nextunreadmsgdialog;
 
 } SummariesPage;
@@ -333,10 +333,11 @@ static void prefs_summaries_create_widget(PrefsPage *_page, GtkWindow *window,
        GtkWidget *label, *label_fill;
        GtkWidget *menu;
        GtkWidget *menuitem;
-       GtkWidget *optmenu_select_on_entry;
        GtkWidget *optmenu_nextunreadmsgdialog;
        GtkWidget *folderview_frame;
        GtkWidget *summaryview_frame;
+       GtkWidget *button_edit_actions;
+
        GtkTooltips *tooltips;
 
        tooltips = gtk_tooltips_new();
@@ -413,32 +414,13 @@ static void prefs_summaries_create_widget(PrefsPage *_page, GtkWindow *window,
        gtk_widget_show (hbox1);
        gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, TRUE, 0);
 
-       label = gtk_label_new (_("When entering a folder"));
-       gtk_widget_show (label);
-       gtk_box_pack_start(GTK_BOX(hbox1), label, FALSE, FALSE, 0);
-
-       optmenu_select_on_entry = gtk_option_menu_new ();
-       gtk_widget_show (optmenu_select_on_entry);
-       
-       menu = gtk_menu_new ();
-       MENUITEM_ADD (menu, menuitem, _("Do nothing"), SELECTONENTRY_NOTHING);
-       MENUITEM_ADD (menu, menuitem, _("Select first unread (or new or marked) message"),
-                     SELECTONENTRY_UNM);
-       MENUITEM_ADD (menu, menuitem, _("Select first unread (or marked or new) message"),
-                     SELECTONENTRY_UMN);
-       MENUITEM_ADD (menu, menuitem, _("Select first new (or unread or marked) message"),
-                     SELECTONENTRY_NUM);
-       MENUITEM_ADD (menu, menuitem, _("Select first new (or marked or unread) message"),
-                     SELECTONENTRY_NMU);
-       MENUITEM_ADD (menu, menuitem, _("Select first marked (or new or unread) message"),
-                     SELECTONENTRY_MNU);
-       MENUITEM_ADD (menu, menuitem, _("Select first marked (or unread or new) message"),
-                     SELECTONENTRY_MUN);
-       MENUITEM_ADD (menu, menuitem, _("Select last opened message"),
-                     SELECTONENTRY_LAST);
-
-       gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_select_on_entry), menu);
-       gtk_box_pack_start(GTK_BOX(hbox1), optmenu_select_on_entry, FALSE, FALSE, 0);
+       button_edit_actions = gtk_button_new_with_label(_("Set default selection when entering a folder"));
+       gtk_widget_show (button_edit_actions);
+       gtk_box_pack_start (GTK_BOX (hbox1), button_edit_actions,
+                         FALSE, TRUE, 0);
+       g_signal_connect (G_OBJECT (button_edit_actions), "clicked",
+                         G_CALLBACK (prefs_summary_open_open),
+                         NULL);
 
        /* Next Unread Message Dialog */
        hbox1 = gtk_hbox_new (FALSE, 10);
@@ -594,8 +576,6 @@ static void prefs_summaries_create_widget(PrefsPage *_page, GtkWindow *window,
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_ask_mark_all_read),
                        prefs_common.ask_mark_all_read);
 
-       gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu_select_on_entry),
-                       prefs_common.select_on_entry);
        gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu_nextunreadmsgdialog),
                        prefs_common.next_unread_msg_dialog);
 
@@ -612,7 +592,6 @@ static void prefs_summaries_create_widget(PrefsPage *_page, GtkWindow *window,
        prefs_summaries->spinbtn_mark_as_read_delay = spinbtn_mark_as_read_delay;
        prefs_summaries->checkbtn_immedexec = checkbtn_immedexec;
        prefs_summaries->checkbtn_ask_mark_all_read = checkbtn_ask_mark_all_read;
-       prefs_summaries->optmenu_select_on_entry = optmenu_select_on_entry;
        prefs_summaries->optmenu_nextunreadmsgdialog = optmenu_nextunreadmsgdialog;
 
        prefs_summaries->page.widget = vbox1;
@@ -656,11 +635,6 @@ static void prefs_summaries_save(PrefsPage *_page)
        prefs_common.mark_as_read_delay = gtk_spin_button_get_value_as_int(
                        GTK_SPIN_BUTTON(page->spinbtn_mark_as_read_delay));
 
-       menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_select_on_entry));
-       menuitem = gtk_menu_get_active(GTK_MENU(menu));
-       prefs_common.select_on_entry = GPOINTER_TO_INT
-               (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
-       
        menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_nextunreadmsgdialog));
        menuitem = gtk_menu_get_active(GTK_MENU(menu));
        prefs_common.next_unread_msg_dialog = GPOINTER_TO_INT
diff --git a/src/prefs_summary_open.c b/src/prefs_summary_open.c
new file mode 100644 (file)
index 0000000..6dfa513
--- /dev/null
@@ -0,0 +1,656 @@
+/*
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include "defs.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "prefs_gtk.h"
+#include "prefs_summary_open.h"
+#include "prefs_common.h"
+#include "manage_window.h"
+#include "alertpanel.h"
+#include "displayheader.h"
+#include "utils.h"
+#include "gtkutils.h"
+
+enum {
+       PREFS_SUMMARY_OPEN_HEADER,
+       PREFS_SUMMARY_OPEN_DATA,
+       N_PREFS_SUMMARY_OPEN_COLUMNS
+};
+
+static struct SummaryOpen {
+       GtkWidget *window;
+
+       GtkWidget *ok_btn;
+       GtkWidget *cancel_btn;
+
+       GtkWidget *possible_actions_list_view;
+       GtkWidget *actions_list_view;
+} summaryopen;
+
+/* widget creating functions */
+static void prefs_summary_open_create  (void);
+
+static void prefs_summary_open_set_dialog      (void);
+static void prefs_summary_open_set_list        (void);
+
+/* callback functions */
+static void prefs_summary_open_register_cb     (GtkButton      *btn,
+                                                gpointer        hidden_data);
+static void prefs_summary_open_delete_cb       (GtkButton      *btn,
+                                                gpointer        list_view_data);
+static void prefs_summary_open_up              (void);
+static void prefs_summary_open_down            (void);
+
+static gboolean prefs_summary_open_key_pressed (GtkWidget      *widget,
+                                                        GdkEventKey    *event,
+                                                        gpointer        data);
+static void prefs_summary_open_ok              (void);
+static void prefs_summary_open_cancel          (void);
+static gint prefs_summary_open_deleted (GtkWidget      *widget,
+                                                GdkEventAny    *event,
+                                                gpointer        data);
+
+
+static GtkListStore *prefs_summary_open_create_store   (void);
+static void prefs_summary_open_insert_action           (GtkListStore *store,
+                                                        gchar *name,
+                                                        gint act);
+static GtkWidget *prefs_summary_open_list_view_create  (const gchar *name);
+static void prefs_summary_open_create_list_view_columns        (GtkWidget *list_view, 
+                                                        const gchar *name);
+static void actions_list_model_row_changed             (GtkTreeModel *model, 
+                                                        GtkTreePath *path, 
+                                                        GtkTreeIter *iter, 
+                                                        GtkTreeView *list_view);
+                                                        
+static void drag_begin (GtkTreeView *list_view,
+                        GdkDragContext *context,
+                        gpointer data);
+
+static void drag_end   (GtkTreeView *list_view,
+                        GdkDragContext *context,
+                        gpointer data);
+
+static EntryAction saved_summary_select_prio[6];
+
+static gchar *action_name[7] = 
+{        ("UNSET (!)"),
+        N_("Go to first marked email"),
+        N_("Go to first new email"),
+        N_("Go to first unread email"),
+        N_("Go to last opened email"),
+        N_("Go to last email in the list"),
+        N_("Do nothing")
+};
+
+const gchar *prefs_summary_open_get_label(int act)
+{
+       return gettext(action_name[act]);
+}
+
+void prefs_summary_open_open(void)
+{
+       int i = 0;
+       if (!summaryopen.window) {
+               prefs_summary_open_create();
+       }
+
+       manage_window_set_transient(GTK_WINDOW(summaryopen.window));
+       gtk_widget_grab_focus(summaryopen.ok_btn);
+
+       prefs_summary_open_set_dialog();
+       
+       for (i = 0; i < 6; i++)
+               saved_summary_select_prio[i] = prefs_common.summary_select_prio[i];
+
+       gtk_widget_show(summaryopen.window);
+}
+
+static void prefs_summary_open_create(void)
+{
+       GtkWidget *window;
+       GtkWidget *vbox;
+       GtkWidget *btn_hbox;
+       GtkWidget *ok_btn;
+       GtkWidget *cancel_btn;
+       GtkWidget *confirm_area;
+
+       GtkWidget *vbox1;
+
+       GtkWidget *hbox1;
+
+       GtkWidget *btn_vbox;
+       GtkWidget *reg_btn;
+       GtkWidget *del_btn;
+       GtkWidget *up_btn;
+       GtkWidget *down_btn;
+
+       GtkWidget *list_view_hbox;
+       GtkWidget *list_view_hbox1;
+       GtkWidget *list_view_hbox2;
+       GtkWidget *list_view_scrolledwin;
+       GtkWidget *possible_actions_list_view;
+       GtkWidget *actions_list_view;
+       
+       window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_summary_open");
+       gtk_container_set_border_width (GTK_CONTAINER (window), 8);
+       gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
+       gtk_window_set_modal (GTK_WINDOW (window), TRUE);
+       gtk_window_set_resizable(GTK_WINDOW (window), TRUE);
+
+       vbox = gtk_vbox_new (FALSE, 6);
+       gtk_widget_show (vbox);
+       gtk_container_add (GTK_CONTAINER (window), vbox);
+
+       btn_hbox = gtk_hbox_new (FALSE, 8);
+       gtk_widget_show (btn_hbox);
+       gtk_box_pack_end (GTK_BOX (vbox), btn_hbox, FALSE, FALSE, 0);
+
+       gtkut_stock_button_set_create(&confirm_area, &cancel_btn, GTK_STOCK_CANCEL,
+                                     &ok_btn, GTK_STOCK_OK,
+                                     NULL, NULL);
+       gtk_widget_show (confirm_area);
+       gtk_box_pack_end (GTK_BOX(btn_hbox), confirm_area, FALSE, FALSE, 0);
+       gtk_widget_grab_default (ok_btn);
+
+       gtk_window_set_title (GTK_WINDOW(window),
+                             _("Action on folder opening"));
+       MANAGE_WINDOW_SIGNALS_CONNECT(window);
+       g_signal_connect (G_OBJECT(window), "delete_event",
+                         G_CALLBACK(prefs_summary_open_deleted),
+                         NULL);
+       g_signal_connect (G_OBJECT(window), "key_press_event",
+                         G_CALLBACK(prefs_summary_open_key_pressed),
+                         NULL);
+       g_signal_connect (G_OBJECT(ok_btn), "clicked",
+                         G_CALLBACK(prefs_summary_open_ok),
+                         NULL);
+       g_signal_connect (G_OBJECT(cancel_btn), "clicked",
+                         G_CALLBACK(prefs_summary_open_cancel),
+                         NULL);
+
+       vbox1 = gtk_vbox_new (FALSE, VSPACING);
+       gtk_widget_show (vbox1);
+       gtk_box_pack_start (GTK_BOX (vbox), vbox1, TRUE, TRUE, 0);
+       gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
+
+       hbox1 = gtk_hbox_new (FALSE, 8);
+       gtk_widget_show (hbox1);
+       gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, TRUE, 0);
+
+       /* display headers list */
+
+       list_view_hbox = gtk_hbox_new (FALSE, 10);
+       gtk_widget_show (list_view_hbox);
+       gtk_box_pack_start (GTK_BOX (vbox1), list_view_hbox, TRUE, TRUE, 0);
+
+       list_view_hbox1 = gtk_hbox_new (FALSE, 8);
+       gtk_widget_show (list_view_hbox1);
+       gtk_box_pack_start (GTK_BOX (list_view_hbox), list_view_hbox1, TRUE, TRUE, 0);
+
+       list_view_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
+       gtk_widget_set_size_request (list_view_scrolledwin, 200, 210);
+       gtk_widget_show (list_view_scrolledwin);
+       gtk_box_pack_start (GTK_BOX (list_view_hbox1), list_view_scrolledwin,
+                           TRUE, TRUE, 0);
+       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (list_view_scrolledwin),
+                                       GTK_POLICY_AUTOMATIC,
+                                       GTK_POLICY_AUTOMATIC);
+       gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(list_view_scrolledwin),
+                                           GTK_SHADOW_IN);
+
+       possible_actions_list_view = prefs_summary_open_list_view_create
+                               (_("Possible actions"));
+       gtk_widget_show (possible_actions_list_view);
+       gtk_container_add(GTK_CONTAINER(list_view_scrolledwin), possible_actions_list_view);
+
+       btn_vbox = gtk_vbox_new (FALSE, 8);
+       gtk_widget_show (btn_vbox);
+       gtk_box_pack_start (GTK_BOX (list_view_hbox1), btn_vbox, FALSE, FALSE, 0);
+
+       reg_btn = gtk_button_new_from_stock (GTK_STOCK_ADD);
+       gtk_widget_show (reg_btn);
+       gtk_box_pack_start (GTK_BOX (btn_vbox), reg_btn, FALSE, TRUE, 0);
+       g_signal_connect (G_OBJECT (reg_btn), "clicked",
+                         G_CALLBACK (prefs_summary_open_register_cb),
+                         possible_actions_list_view);
+       del_btn = gtk_button_new_from_stock (GTK_STOCK_REMOVE);
+       gtk_widget_show (del_btn);
+       gtk_box_pack_start (GTK_BOX (btn_vbox), del_btn, FALSE, TRUE, 0);
+
+       /* actions list */
+
+       list_view_hbox2 = gtk_hbox_new (FALSE, 8);
+       gtk_widget_show (list_view_hbox2);
+       gtk_box_pack_start (GTK_BOX (list_view_hbox), list_view_hbox2, TRUE, TRUE, 0);
+
+       list_view_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
+       gtk_widget_set_size_request (list_view_scrolledwin, 200, 210);
+       gtk_widget_show (list_view_scrolledwin);
+       gtk_box_pack_start (GTK_BOX (list_view_hbox2), list_view_scrolledwin,
+                           TRUE, TRUE, 0);
+       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (list_view_scrolledwin),
+                                       GTK_POLICY_AUTOMATIC,
+                                       GTK_POLICY_AUTOMATIC);
+       gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(list_view_scrolledwin),
+                                           GTK_SHADOW_IN);
+
+       actions_list_view = prefs_summary_open_list_view_create
+                                       (_("Action on folder opening"));
+       g_signal_connect (G_OBJECT (del_btn), "clicked",
+                         G_CALLBACK (prefs_summary_open_delete_cb),
+                         actions_list_view);
+       gtk_widget_show (actions_list_view);
+       gtk_container_add (GTK_CONTAINER (list_view_scrolledwin),
+                          actions_list_view);
+
+       gtk_tree_view_set_reorderable(GTK_TREE_VIEW(actions_list_view), TRUE);
+       g_signal_connect(G_OBJECT(actions_list_view), "drag_begin",                      
+                        G_CALLBACK(drag_begin),
+                        actions_list_view);
+                        
+       g_signal_connect(G_OBJECT(actions_list_view), "drag_end",                        
+                        G_CALLBACK(drag_end),
+                        actions_list_view);
+       
+       btn_vbox = gtk_vbox_new (FALSE, 8);
+       gtk_widget_show (btn_vbox);
+       gtk_box_pack_start (GTK_BOX (list_view_hbox2), btn_vbox, FALSE, FALSE, 0);
+
+       up_btn = gtk_button_new_from_stock (GTK_STOCK_GO_UP);
+       gtk_widget_show (up_btn);
+       gtk_box_pack_start (GTK_BOX (btn_vbox), up_btn, FALSE, FALSE, 0);
+       g_signal_connect (G_OBJECT (up_btn), "clicked",
+                         G_CALLBACK (prefs_summary_open_up), NULL);
+
+       down_btn = gtk_button_new_from_stock (GTK_STOCK_GO_DOWN);
+       gtk_widget_show (down_btn);
+       gtk_box_pack_start (GTK_BOX (btn_vbox), down_btn, FALSE, FALSE, 0);
+       g_signal_connect (G_OBJECT (down_btn), "clicked",
+                         G_CALLBACK (prefs_summary_open_down), NULL);
+       
+
+       gtk_widget_show_all(window);
+
+       summaryopen.window        = window;
+       summaryopen.ok_btn        = ok_btn;
+       summaryopen.cancel_btn    = cancel_btn;
+
+       summaryopen.possible_actions_list_view        = possible_actions_list_view;
+       summaryopen.actions_list_view = actions_list_view;
+}
+
+#define SET_PRIO(p_one,p_two,p_three,p_four) {                         \
+       prefs_common.summary_select_prio[0] = p_one;                    \
+       prefs_common.summary_select_prio[1] = p_two;                    \
+       prefs_common.summary_select_prio[2] = p_three;                  \
+       prefs_common.summary_select_prio[3] = p_four;                   \
+       prefs_common.summary_select_prio[4] = ACTION_UNSET;             \
+       prefs_common.summary_select_prio[5] = ACTION_UNSET;             \
+}                                                      
+
+void prefs_summary_open_set_defaults(void)
+{
+       switch (prefs_common.select_on_entry) {
+               case SELECTONENTRY_MNU:
+                       SET_PRIO(ACTION_MARKED, ACTION_NEW, ACTION_UNREAD, ACTION_LAST_LIST); break;
+               case SELECTONENTRY_MUN:
+                       SET_PRIO(ACTION_MARKED, ACTION_UNREAD, ACTION_NEW, ACTION_LAST_LIST); break;
+               case SELECTONENTRY_NMU:
+                       SET_PRIO(ACTION_NEW, ACTION_MARKED, ACTION_UNREAD, ACTION_LAST_LIST); break;
+               case SELECTONENTRY_NUM:
+                       SET_PRIO(ACTION_NEW, ACTION_UNREAD, ACTION_MARKED, ACTION_LAST_LIST); break;
+               case SELECTONENTRY_UNM:
+                       SET_PRIO(ACTION_UNREAD, ACTION_NEW, ACTION_MARKED, ACTION_LAST_LIST); break;
+               case SELECTONENTRY_UMN:
+                       SET_PRIO(ACTION_UNREAD, ACTION_MARKED, ACTION_NEW, ACTION_LAST_LIST); break;
+               case SELECTONENTRY_LAST:
+                       SET_PRIO(ACTION_LAST_OPENED, ACTION_LAST_LIST, ACTION_UNSET, ACTION_UNSET); break;
+               case SELECTONENTRY_NOTHING:
+                       SET_PRIO(ACTION_LAST_LIST, ACTION_UNSET, ACTION_UNSET, ACTION_UNSET); break;
+               default:
+                       break;
+       }
+}
+static void prefs_summary_open_set_dialog(void)
+{
+       GtkTreeView *possible_list_view = GTK_TREE_VIEW(summaryopen.possible_actions_list_view);
+       GtkTreeView *actions_list_view = GTK_TREE_VIEW(summaryopen.actions_list_view);
+       GtkTreeModel *model_poss, *model_act;
+       int i = 0;
+       gboolean set = FALSE;
+       gboolean used[7] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE};
+
+       model_poss = gtk_tree_view_get_model(possible_list_view);
+       model_act = gtk_tree_view_get_model(actions_list_view);
+
+       gtk_list_store_clear(GTK_LIST_STORE(model_poss));
+       gtk_list_store_clear(GTK_LIST_STORE(model_act));
+
+fill:
+       for (i = 0; i < 6; i++) {
+               EntryAction act = prefs_common.summary_select_prio[i];
+
+               if (act == ACTION_UNSET) 
+                       continue;
+               
+               set = TRUE;
+               used[act] = TRUE;
+               prefs_summary_open_insert_action(GTK_LIST_STORE
+                                       (model_act), action_name[act], act);    
+       }
+       if (!set) {
+               /* backward compat */
+               prefs_summary_open_set_defaults();
+               goto fill;
+       }
+
+       for (i = ACTION_MARKED; i <= ACTION_NOTHING; i++) {
+               if (!used[i]) {
+                       prefs_summary_open_insert_action(GTK_LIST_STORE
+                                       (model_poss), action_name[i], i);       
+               }
+       }
+}
+
+static void prefs_summary_open_set_list(void)
+{
+       gint row = 0;
+       gpointer data;
+       GtkTreeModel *model;
+       GtkTreeIter iter;
+
+
+       model = gtk_tree_view_get_model(GTK_TREE_VIEW(summaryopen.actions_list_view));
+       while (gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
+               gtk_tree_model_get(model, &iter, PREFS_SUMMARY_OPEN_DATA, &data, -1);
+               prefs_common.summary_select_prio[row] = GPOINTER_TO_INT(data);
+               row++;                          
+       }
+       for (; row < 6; row++) {
+               prefs_common.summary_select_prio[row] = ACTION_UNSET;
+       }
+}
+
+static void prefs_summary_open_delete_cb(GtkButton *btn, gpointer list_view_data)
+{
+       GtkTreeView *list_view = GTK_TREE_VIEW(list_view_data);
+       gpointer data;
+       GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(list_view));
+       GtkTreeSelection *selection = gtk_tree_view_get_selection(list_view);
+       GtkTreeIter iter;
+       GtkTreeView *possible_list_view = GTK_TREE_VIEW(summaryopen.possible_actions_list_view);
+       GtkTreeModel *model, *model_poss;
+       gint i;
+
+       model = gtk_tree_view_get_model(list_view);
+       model_poss = gtk_tree_view_get_model(possible_list_view);
+
+       if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
+               return;
+
+       gtk_tree_model_get(model, &iter, PREFS_SUMMARY_OPEN_DATA, &data, -1);
+       if (!data) 
+               return;
+
+       gtk_list_store_remove(store, &iter);
+
+       i = GPOINTER_TO_INT(data);
+       prefs_summary_open_insert_action(GTK_LIST_STORE
+                                       (model_poss), action_name[i], i);       
+       
+       prefs_summary_open_set_list();
+}
+
+static void prefs_summary_open_register_cb(GtkButton *btn, gpointer list_view_data)
+{
+       GtkTreeView *possible_list_view = GTK_TREE_VIEW(list_view_data);
+       GtkTreeView *list_view = GTK_TREE_VIEW(summaryopen.actions_list_view);
+       gpointer data;
+       GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(possible_list_view));
+       GtkTreeSelection *selection = gtk_tree_view_get_selection(possible_list_view);
+       GtkTreeIter iter;
+       GtkTreeModel *model, *model_poss;
+       gint i;
+
+       model = gtk_tree_view_get_model(list_view);
+       model_poss = gtk_tree_view_get_model(possible_list_view);
+
+       if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
+               return;
+
+       gtk_tree_model_get(model_poss, &iter, PREFS_SUMMARY_OPEN_DATA, &data, -1);
+       if (!data) 
+               return;
+
+       gtk_list_store_remove(store, &iter);
+
+       i = GPOINTER_TO_INT(data);
+       prefs_summary_open_insert_action(GTK_LIST_STORE
+                                       (model), action_name[i], i);    
+       
+       prefs_summary_open_set_list();
+}
+
+static void prefs_summary_open_up(void)
+{
+       GtkTreePath *prev, *sel, *try;
+       GtkTreeIter isel;
+       GtkListStore *store = NULL;
+       GtkTreeModel *model = NULL;
+       GtkTreeIter iprev;
+       
+       if (!gtk_tree_selection_get_selected
+               (gtk_tree_view_get_selection
+                       (GTK_TREE_VIEW(summaryopen.actions_list_view)),
+                &model,        
+                &isel))
+               return;
+       store = (GtkListStore *)model;
+       sel = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &isel);
+       if (!sel)
+               return;
+       
+       /* no move if we're at row 0... */
+       try = gtk_tree_path_copy(sel);
+       if (!gtk_tree_path_prev(try)) {
+               gtk_tree_path_free(try);
+               gtk_tree_path_free(sel);
+               return;
+       }
+
+       prev = try;
+       gtk_tree_model_get_iter(GTK_TREE_MODEL(store),
+                               &iprev, prev);
+       gtk_list_store_swap(store, &iprev, &isel);
+
+       gtk_tree_path_free(sel);
+       gtk_tree_path_free(prev);
+       prefs_summary_open_set_list();
+}
+
+static void prefs_summary_open_down(void)
+{
+       GtkListStore *store = NULL;
+       GtkTreeModel *model = NULL;
+       GtkTreeIter next, sel;
+       GtkTreePath *try;
+       
+       if (!gtk_tree_selection_get_selected
+               (gtk_tree_view_get_selection
+                       (GTK_TREE_VIEW(summaryopen.actions_list_view)),
+                &model,
+                &sel))
+               return;
+       store = (GtkListStore *)model;
+       try = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &sel);
+       if (!try) 
+               return;
+       
+       next = sel;
+       if (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &next))
+               gtk_list_store_swap(store, &next, &sel);
+               
+       gtk_tree_path_free(try);
+       prefs_summary_open_set_list();
+}
+
+static gboolean prefs_summary_open_key_pressed(GtkWidget *widget,
+                                            GdkEventKey *event,
+                                            gpointer data)
+{
+       if (event && event->keyval == GDK_Escape)
+               prefs_summary_open_cancel();
+       return FALSE;
+}
+
+static void prefs_summary_open_ok(void)
+{
+       int i = 0;
+       for (i = 0; i < 6; i++)
+               saved_summary_select_prio[i] = prefs_common.summary_select_prio[i];
+
+       gtk_widget_hide(summaryopen.window);
+}
+
+static void prefs_summary_open_cancel(void)
+{
+       int i = 0;
+       for (i = 0; i < 6; i++)
+               prefs_common.summary_select_prio[i] = saved_summary_select_prio[i];
+
+       gtk_widget_hide(summaryopen.window);
+}
+
+static gint prefs_summary_open_deleted(GtkWidget *widget, GdkEventAny *event,
+                                        gpointer data)
+{
+       prefs_summary_open_cancel();
+       return TRUE;
+}
+
+static GtkListStore *prefs_summary_open_create_store(void)
+{
+       return gtk_list_store_new(N_PREFS_SUMMARY_OPEN_COLUMNS,
+                                 G_TYPE_STRING,
+                                 G_TYPE_POINTER,
+                                 -1);
+}
+
+static void prefs_summary_open_insert_action(GtkListStore *store,
+                                              gchar *name,
+                                              gint dp)
+{
+       GtkTreeIter iter;
+
+       /* add new */
+       gtk_list_store_append(store, &iter);
+       gtk_list_store_set(store, &iter,
+                          PREFS_SUMMARY_OPEN_HEADER,
+                          gettext(name),
+                          PREFS_SUMMARY_OPEN_DATA, GINT_TO_POINTER(dp),
+                          -1);
+}
+
+static GtkWidget *prefs_summary_open_list_view_create(const gchar *name)
+{
+       GtkWidget *list_view;
+       GtkTreeSelection *selector;
+       GtkTreeModel *model;
+
+       model = GTK_TREE_MODEL(prefs_summary_open_create_store());
+       list_view = gtk_tree_view_new_with_model(model);
+       g_object_unref(G_OBJECT(model));
+       
+       gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(list_view),
+                                    prefs_common.use_stripes_everywhere);
+       
+       selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
+       gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
+
+       prefs_summary_open_create_list_view_columns(GTK_WIDGET(list_view), name);
+
+       return list_view;
+}
+
+static void prefs_summary_open_create_list_view_columns(GtkWidget *list_view, 
+                                                    const gchar *name)
+{
+       GtkTreeViewColumn *column;
+       GtkCellRenderer *renderer;
+
+       renderer = gtk_cell_renderer_text_new();
+       column = gtk_tree_view_column_new_with_attributes
+               (name, renderer, "text", PREFS_SUMMARY_OPEN_HEADER, NULL);
+       gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);          
+}
+
+/*!
+ *\brief       Called as a result of a drag & drop
+ */
+static void actions_list_model_row_changed(GtkTreeModel *model, 
+                                          GtkTreePath *path, 
+                                          GtkTreeIter *iter, 
+                                          GtkTreeView *list_view)
+{
+}
+
+/*!
+ *\brief       Called as a result of a gtk_list_store_swap()
+ */
+static void drag_begin(GtkTreeView *list_view,
+                     GdkDragContext *context,
+                     gpointer data)
+{
+       /* XXX unfortunately a completed drag & drop does not emit 
+        * a "rows_reordered" signal, but a "row_changed" signal.
+        * So during drag and drop, listen to "row_changed", and
+        * update the account list accordingly */
+
+       GtkTreeModel *model = gtk_tree_view_get_model(list_view);
+       g_signal_connect(G_OBJECT(model), "row_changed",
+                        G_CALLBACK(actions_list_model_row_changed),
+                        list_view);
+}
+
+static void drag_end(GtkTreeView *list_view,
+                   GdkDragContext *context,
+                   gpointer data)
+{
+       GtkTreeModel *model = gtk_tree_view_get_model(list_view);
+       g_signal_handlers_disconnect_by_func(G_OBJECT(model),
+                                            G_CALLBACK(actions_list_model_row_changed),
+                                            list_view);
+       prefs_summary_open_set_list();
+}
+
diff --git a/src/prefs_summary_open.h b/src/prefs_summary_open.h
new file mode 100644 (file)
index 0000000..bfe6594
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __PREFS_SUMMARY_OPEN_H__
+#define __PREFS_SUMMARY_OPEN_H__
+
+void prefs_summary_open_open           (void);
+void prefs_summary_open_set_defaults   (void);
+const gchar *summary_open_get_label    (int act);
+
+#endif /* __PREFS_SUMMARY_OPEN_H__ */
index 56be5f8..554a5c8 100644 (file)
@@ -59,6 +59,7 @@
 #include "sourcewindow.h"
 #include "prefs_common.h"
 #include "prefs_summary_column.h"
+#include "prefs_summary_open.h"
 #include "prefs_filtering.h"
 #include "account.h"
 #include "compose.h"
@@ -1312,85 +1313,64 @@ gboolean summary_show(SummaryView *summaryview, FolderItem *item)
                        gtk_ctree_node_moveto(ctree, node, 0, 0.5, 0);
                }
        } else {
-               switch (prefs_common.select_on_entry) {
-                       case SELECTONENTRY_MNU:
-                               node = summary_find_next_flagged_msg(summaryview, NULL,
-                                                                    MSG_MARKED, FALSE);
-                               if (node == NULL)
-                                       node = summary_find_next_flagged_msg(summaryview, NULL,
-                                                                    MSG_NEW, FALSE);
-                               if (node == NULL)
-                                       node = summary_find_next_flagged_msg(summaryview, NULL,
-                                                                    MSG_UNREAD, FALSE);
-                               break;
-                       case SELECTONENTRY_MUN:
-                               node = summary_find_next_flagged_msg(summaryview, NULL,
-                                                                    MSG_MARKED, FALSE);
-                               if (node == NULL)
-                                       node = summary_find_next_flagged_msg(summaryview, NULL,
-                                                                    MSG_UNREAD, FALSE);
-                               if (node == NULL)
-                                       node = summary_find_next_flagged_msg(summaryview, NULL,
-                                                                    MSG_NEW, FALSE);
-                               break;
-                       case SELECTONENTRY_NMU:
-                               node = summary_find_next_flagged_msg(summaryview, NULL,
-                                                                    MSG_NEW, FALSE);
-                               if (node == NULL)
-                                       node = summary_find_next_flagged_msg(summaryview, NULL,
-                                                                    MSG_MARKED, FALSE);
-                               if (node == NULL)
-                                       node = summary_find_next_flagged_msg(summaryview, NULL,
-                                                                    MSG_UNREAD, FALSE);
+               /* backward compat */
+               int i = 0;
+               gboolean set = FALSE, stop = FALSE;
+               for (i = 0; i < 6; i++) {
+                       EntryAction act = prefs_common.summary_select_prio[i];
+
+                       if (act != ACTION_UNSET) {
+                               set = TRUE;
                                break;
-                       case SELECTONENTRY_NUM:
+                       }
+               }
+               if (!set)
+                       prefs_summary_open_set_defaults();
+
+               for (i = 0; i < 6 && node == NULL; i++) {
+                       EntryAction act = prefs_common.summary_select_prio[i];
+                       
+                       switch(act) {
+                       case ACTION_MARKED:
                                node = summary_find_next_flagged_msg(summaryview, NULL,
-                                                                    MSG_NEW, FALSE);
-                               if (node == NULL)
-                                       node = summary_find_next_flagged_msg(summaryview, NULL,
-                                                                    MSG_UNREAD, FALSE);
-                               if (node == NULL)
-                                       node = summary_find_next_flagged_msg(summaryview, NULL,
-                                                                    MSG_MARKED, FALSE);
+                                            MSG_MARKED, FALSE);
                                break;
-                       case SELECTONENTRY_UNM:
+                       case ACTION_NEW:
                                node = summary_find_next_flagged_msg(summaryview, NULL,
-                                                                    MSG_UNREAD, FALSE);
-                               if (node == NULL)
-                                       node = summary_find_next_flagged_msg(summaryview, NULL,
-                                                                    MSG_NEW, FALSE);
-                               if (node == NULL)
-                                       node = summary_find_next_flagged_msg(summaryview, NULL,
-                                                                    MSG_MARKED, FALSE);
+                                            MSG_NEW, FALSE);
                                break;
-                       case SELECTONENTRY_UMN:
+                       case ACTION_UNREAD:
                                node = summary_find_next_flagged_msg(summaryview, NULL,
-                                                                    MSG_UNREAD, FALSE);
-                               if (node == NULL)
-                                       node = summary_find_next_flagged_msg(summaryview, NULL,
-                                                                    MSG_MARKED, FALSE);
-                               if (node == NULL)
-                                       node = summary_find_next_flagged_msg(summaryview, NULL,
-                                                                    MSG_NEW, FALSE);
+                                            MSG_UNREAD, FALSE);
                                break;
-                       case SELECTONENTRY_LAST:
+                       case ACTION_LAST_OPENED:
                                if (summaryview->folder_item) {
                                        node = summary_find_msg_by_msgnum(summaryview, 
                                                        summaryview->folder_item->last_seen);
                                }
                                break;
-                       default:
+                       case ACTION_LAST_LIST:
+                               if (GTK_CLIST(ctree)->row_list != NULL) {
+                                       node = gtk_ctree_node_nth
+                                               (ctree,
+                                                item->sort_type == SORT_DESCENDING
+                                                ? 0 : GTK_CLIST(ctree)->rows - 1);
+                               }
+                               break;
+                       case ACTION_NOTHING:
+                       case ACTION_UNSET:
                                node = NULL;
-               }
-
-               if (node == NULL && GTK_CLIST(ctree)->row_list != NULL) {
-                       node = gtk_ctree_node_nth
-                               (ctree,
-                                item->sort_type == SORT_DESCENDING
-                                ? 0 : GTK_CLIST(ctree)->rows - 1);
+                               stop = TRUE;
+                               break;
+                       }
+                       
+                       if (stop || node)
+                               break;
                }
+
                summary_unlock(summaryview);
-               summary_select_node(summaryview, node,
+               if (node)
+                       summary_select_node(summaryview, node,
                                    prefs_common.always_show_msg,
                                    TRUE);
                summary_lock(summaryview);