[PATCH] : improve (a bit) search feature



	Hi all,
here is a patch that cleans up the search code a bit : I have put all 
find/search features in a new file to declutter the src/main-window.c file 
a bit. I also add the possibility to use a regex for the criterium. Next I 
plan to let the user choose a filter to specifiy the search criteria (this 
is esp. useful if you do frequently the same complex search, so you set up 
a filter for once and use it after). Comments?
Bye
Manu
diff -u /home/manu/prog/balsa-cvs/balsa/libbalsa/filter-funcs.c balsa-current/libbalsa/filter-funcs.c
--- /home/manu/prog/balsa-cvs/balsa/libbalsa/filter-funcs.c	Sun Feb 24 16:27:43 2002
+++ balsa-current/libbalsa/filter-funcs.c	Sat May 11 12:56:59 2002
@@ -207,8 +207,8 @@
  *
  * Position filter_errno (by calling condition_regcomp)
  */
-static void
-condition_compile_regexs(LibBalsaCondition* cond)
+void
+libbalsa_condition_compile_regexs(LibBalsaCondition* cond)
 {
     GSList * regex;
 
@@ -281,7 +281,7 @@
     if (fil->conditions) {
 	GSList * lst;
 	for (lst=fil->conditions;lst && filter_errno==FILTER_NOERR;lst=g_slist_next(lst))
-	    condition_compile_regexs((LibBalsaCondition*) lst->data);
+	    libbalsa_condition_compile_regexs((LibBalsaCondition*) lst->data);
 	if (filter_errno != FILTER_NOERR) {
 	    gchar * errorstring =
                 g_strdup_printf("Unable to compile filter %s", fil->name);
diff -u /home/manu/prog/balsa-cvs/balsa/libbalsa/filter-funcs.h balsa-current/libbalsa/filter-funcs.h
--- /home/manu/prog/balsa-cvs/balsa/libbalsa/filter-funcs.h	Mon Nov 26 10:07:00 2001
+++ balsa-current/libbalsa/filter-funcs.h	Sat May 11 12:53:16 2002
@@ -44,7 +44,7 @@
 LibBalsaCondition* libbalsa_condition_clone(LibBalsaCondition* cnd);
 void libbalsa_condition_regex_free(LibBalsaConditionRegex *, gpointer);
 void regexs_free(GSList *);
-
+void libbalsa_condition_compile_regexs(LibBalsaCondition* cond);
 /* Filters */
 /* Free a filter
  * free_condition is a gint into a gpointer : if <>0 the function frees filter conditions also
diff -uN /home/manu/prog/balsa-cvs/balsa/src/Makefile.am balsa-current/src/Makefile.am
--- /home/manu/prog/balsa-cvs/balsa/src/Makefile.am	Fri Apr 26 17:50:33 2002
+++ balsa-current/src/Makefile.am	Sat May 11 11:14:23 2002
@@ -28,6 +28,8 @@
 	filter-run-callbacks.c	\
 	filter-run-dialog.c	\
 	filter-run.h		\
+	find-search.c		\
+	find-search.h		\
 	folder-conf.c		\
 	folder-conf.h		\
 	information-dialog.c	\
diff -uN /home/manu/prog/balsa-cvs/balsa/src/find-search.c balsa-current/src/find-search.c
--- /home/manu/prog/balsa-cvs/balsa/src/find-search.c	Thu Jan  1 01:00:00 1970
+++ balsa-current/src/find-search.c	Sat May 11 13:34:01 2002
@@ -0,0 +1,255 @@
+/* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
+/* vim:set ts=4 sw=4 ai et: */
+/* Balsa E-Mail Client
+ * Copyright (C) 1997-2002 Stuart Parmenter and others,
+ *                         See the file AUTHORS for a list.
+ *
+ * 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, 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., 59 Temple Place - Suite 330, Boston, MA  
+ * 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <gnome.h>
+
+#include "filter.h"
+#include "filter-funcs.h"
+#include "balsa-index.h"
+#include "find-search.h"
+
+static GtkToggleButton*
+add_check_button(GtkWidget* table, const gchar* label, gint x, gint y);
+
+static GtkToggleButton*
+add_check_button(GtkWidget* table, const gchar* label, gint x, gint y)
+{
+    GtkWidget* res = gtk_check_button_new_with_label(label);
+    gtk_table_attach(GTK_TABLE(table),
+                     res,
+                     x, x+1, y, y+1,
+                     GTK_FILL | GTK_SHRINK | GTK_EXPAND, GTK_SHRINK, 2, 2);
+    return GTK_TOGGLE_BUTTON(res);
+}
+
+gint find_real(BalsaIndex * bindex,gboolean again)
+{
+    /* FIXME : later we could do a search based on a complete filter */
+    static LibBalsaFilter * f=NULL;
+    /* Condition set up for the search, it will be of type
+       CONDITION_NONE if nothing has been set up */
+    static LibBalsaCondition * cnd=NULL;
+    static gboolean reverse=FALSE;
+
+    GSList * conditions;
+
+    if (!cnd) {
+	cnd=libbalsa_condition_new();
+        CONDITION_SETMATCH(cnd,CONDITION_MATCH_FROM);
+        CONDITION_SETMATCH(cnd,CONDITION_MATCH_SUBJECT);
+    }
+
+
+    /* first search, so set up the match rule(s) */
+    if (!again || (!f && cnd->type==CONDITION_NONE)) {
+	GnomeDialog* dia=
+            GNOME_DIALOG(gnome_dialog_new(_("Search a message"),
+                                          GNOME_STOCK_BUTTON_OK,
+                                          GNOME_STOCK_BUTTON_CANCEL,
+                                          NULL));
+	GtkWidget *reverse_button, *search_entry, *w, *page, *table;
+	GtkToggleButton *matching_body, *matching_from;
+        GtkToggleButton *matching_to, *matching_cc, *matching_subject;
+	GtkRadioButton * regex_type,* simple_type;
+	GSList * rb_group;
+	gint res=-1;
+	
+	gnome_dialog_close_hides(dia,TRUE);
+
+	/* FIXME : we'll set up this callback later when selecting
+	   filters has been enabled
+	   gtk_signal_connect(GTK_OBJECT(dia),"clicked",
+	   find_dialog_button_cb,&f);
+	*/
+	reverse_button = gtk_check_button_new_with_label(_("Reverse search"));
+
+	page = gtk_table_new(2, 1, FALSE);
+
+	w = gtk_frame_new(_("Search for:"));
+	gtk_frame_set_label_align(GTK_FRAME(w), GTK_POS_LEFT, GTK_POS_TOP);
+	gtk_frame_set_shadow_type(GTK_FRAME(w), GTK_SHADOW_ETCHED_IN);
+	gtk_table_attach(GTK_TABLE(page),w,0, 1, 0, 1,
+			 GTK_FILL | GTK_SHRINK | GTK_EXPAND, GTK_SHRINK, 2, 2);
+
+	table=gtk_table_new(3, 1, FALSE);
+	gtk_container_add(GTK_CONTAINER(w), table);
+	
+	search_entry = gtk_entry_new_with_max_length(30);
+	gtk_table_attach(GTK_TABLE(table),search_entry,0, 1, 0, 1,
+			 GTK_FILL | GTK_SHRINK | GTK_EXPAND, GTK_SHRINK, 2, 2);
+	
+	simple_type = GTK_RADIO_BUTTON(gtk_radio_button_new_with_label(NULL,_("substring search")));
+	rb_group= gtk_radio_button_group(simple_type);
+	regex_type  = GTK_RADIO_BUTTON(gtk_radio_button_new_with_label(rb_group,_("Regular Exp. search")));	
+	gtk_table_attach(GTK_TABLE(table),
+			 GTK_WIDGET(simple_type),
+			 0, 1, 1, 2,
+			 GTK_FILL | GTK_SHRINK | GTK_EXPAND, GTK_SHRINK, 2, 2);
+	gtk_table_attach(GTK_TABLE(table),
+			 GTK_WIDGET(regex_type),
+			 0, 1, 2, 3,
+			 GTK_FILL | GTK_SHRINK | GTK_EXPAND, GTK_SHRINK, 2, 2);
+	
+
+	/* builds the toggle buttons to specify fields concerned by
+         * the search. */
+    
+	w = gtk_frame_new(_("In:"));
+	gtk_frame_set_label_align(GTK_FRAME(w), GTK_POS_LEFT, GTK_POS_TOP);
+	gtk_frame_set_shadow_type(GTK_FRAME(w), GTK_SHADOW_ETCHED_IN);
+	gtk_table_attach(GTK_TABLE(page),
+			 w,
+			 1, 2, 0, 1,
+			 GTK_FILL | GTK_SHRINK | GTK_EXPAND, GTK_SHRINK, 5, 5);
+    
+	table = gtk_table_new(3, 2, TRUE);
+	gtk_container_add(GTK_CONTAINER(w), table);
+		
+	matching_body    = add_check_button(table, _("Body"),    0, 0);
+        matching_subject = add_check_button(table, _("Subject"), 1, 0);
+	matching_from    = add_check_button(table, _("From:"),   0, 1);
+	matching_to      = add_check_button(table, _("To:"),     1, 1);
+	matching_cc      = add_check_button(table, _("Cc:"),     0, 2);
+
+	gtk_box_pack_start(GTK_BOX(dia->vbox), page, FALSE, FALSE, 2);
+
+	gtk_box_pack_start(GTK_BOX(dia->vbox), gtk_hseparator_new(), 
+                           FALSE, FALSE, 2);
+	gtk_box_pack_start(GTK_BOX(dia->vbox), reverse_button,TRUE,TRUE,0);
+	gtk_widget_show_all(dia->vbox);
+
+	if ((cnd->type==CONDITION_SIMPLE) && cnd->match.string)
+	    gtk_entry_set_text(GTK_ENTRY(search_entry),cnd->match.string);
+	else if ((cnd->type==CONDITION_REGEX) && 
+		 cnd->match.regexs && cnd->match.regexs->data &&
+		 ((LibBalsaConditionRegex *)cnd->match.regexs->data)->string)
+	    gtk_entry_set_text(GTK_ENTRY(search_entry),
+			       ((LibBalsaConditionRegex *)cnd->match.regexs->data)->string);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(reverse_button),reverse);
+	gtk_toggle_button_set_active(matching_body,
+				     CONDITION_CHKMATCH(cnd,
+                                                        CONDITION_MATCH_BODY));
+	gtk_toggle_button_set_active(matching_to,
+				     CONDITION_CHKMATCH(cnd,
+                                                        CONDITION_MATCH_TO));
+	gtk_toggle_button_set_active(matching_from,
+				     CONDITION_CHKMATCH(cnd,CONDITION_MATCH_FROM));
+	gtk_toggle_button_set_active(matching_subject,
+				     CONDITION_CHKMATCH(cnd,CONDITION_MATCH_SUBJECT));
+	gtk_toggle_button_set_active(matching_cc,
+				     CONDITION_CHKMATCH(cnd,CONDITION_MATCH_CC));
+
+	if (cnd) {
+	    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(regex_type),
+					 cnd->type==CONDITION_REGEX);	    
+	    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(simple_type),
+					 (cnd->type==CONDITION_SIMPLE)
+					 || cnd->type==CONDITION_NONE);
+	}
+
+        gtk_widget_grab_focus(search_entry);
+        gnome_dialog_editable_enters(dia, GTK_EDITABLE(search_entry));
+        gnome_dialog_set_default(dia, 0);
+
+	if (gnome_dialog_run(dia)==0) {
+	    /* OK --> Process the search dialog fields */
+	    cnd->match_fields=CONDITION_EMPTY;
+	    if (gtk_toggle_button_get_active(matching_body))
+		CONDITION_SETMATCH(cnd,CONDITION_MATCH_BODY);
+	    if (gtk_toggle_button_get_active(matching_to))
+		CONDITION_SETMATCH(cnd,CONDITION_MATCH_TO);
+	    if (gtk_toggle_button_get_active(matching_subject))
+		CONDITION_SETMATCH(cnd,CONDITION_MATCH_SUBJECT);
+	    if (gtk_toggle_button_get_active(matching_from))
+		CONDITION_SETMATCH(cnd,CONDITION_MATCH_FROM);
+	    if (gtk_toggle_button_get_active(matching_cc))
+		CONDITION_SETMATCH(cnd,CONDITION_MATCH_CC);
+	    if (cnd->match_fields!=CONDITION_EMPTY && gtk_entry_get_text(GTK_ENTRY(search_entry))[0]) {
+		reverse=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(reverse_button));
+		
+		/* Free all condition */
+		switch (cnd->type) {
+		case CONDITION_SIMPLE:
+		    g_free(cnd->match.string);
+		    break;
+		case CONDITION_REGEX:
+		    regexs_free(cnd->match.regexs);
+		default:;
+		}
+		
+		if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(simple_type))) {
+		    cnd->match.string =
+			g_strdup(gtk_entry_get_text(GTK_ENTRY(search_entry)));
+		    cnd->type=CONDITION_SIMPLE;
+		    res=1;
+		}
+		else {
+		    LibBalsaConditionRegex * new_reg = libbalsa_condition_regex_new();
+		    
+		    new_reg->string = g_strdup(gtk_entry_get_text(GTK_ENTRY(search_entry)));
+		    cnd->match.regexs = g_slist_prepend(NULL,new_reg);
+		    cnd->type=CONDITION_REGEX;
+		    libbalsa_condition_compile_regexs(cnd);
+		    if (filter_errno != FILTER_NOERR) {
+			gchar * errorstring =
+			    g_strdup_printf(_("Unable to compile search Reg. Exp."));
+			filter_perror(errorstring);
+			g_free(errorstring);
+		    }
+		    else res=1;
+		}
+	    
+		/* FIXME : We should print error messages, but for
+		 * that we should first make find dialog non-modal
+		 * balsa_information(LIBBALSA_INFORMATION_ERROR,_("You
+		 * must specify at least one field to look in"));
+		 * *balsa_information(LIBBALSA_INFORMATION_ERROR,_("You
+		 * must provide a non-empty string")); */
+	    }
+	}
+	else res=0;
+	gtk_widget_destroy(GTK_WIDGET(dia));
+	/* Here ok==TRUE means OK button was pressed, search is valid so let's go
+	 * else cancel was pressed return */
+	if (res!=1) return res;
+    }
+
+    if (f) {
+	GSList * lst=g_slist_append(NULL,f);
+	if (!filters_prepare_to_run(lst)) return -1;
+	g_slist_free(lst);
+	conditions=f->conditions;
+    }
+    else conditions=g_slist_append(NULL,cnd);
+
+    balsa_index_find(bindex,
+                     f ? f->conditions_op : FILTER_OP_OR,
+                     conditions, reverse);
+
+    /* FIXME : See if this does not lead to a segfault because of
+       balsa_index_scan_info */
+    if (!f) g_slist_free(conditions);
+    return again ? 0 : 1;
+}
diff -uN /home/manu/prog/balsa-cvs/balsa/src/find-search.h balsa-current/src/find-search.h
--- /home/manu/prog/balsa-cvs/balsa/src/find-search.h	Thu Jan  1 01:00:00 1970
+++ balsa-current/src/find-search.h	Sat May 11 11:43:04 2002
@@ -0,0 +1,30 @@
+/* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
+/* vim:set ts=4 sw=4 ai et: */
+/* Balsa E-Mail Client
+ * Copyright (C) 1997-2002 Stuart Parmenter and others,
+ *                         See the file AUTHORS for a list.
+ *
+ * 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, 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., 59 Temple Place - Suite 330, Boston, MA  
+ * 02111-1307, USA.
+ */
+
+#include <glib.h>
+
+/* Returns values : 
+   -1 : the find again menu must be set to inactive
+   1  : the ------------------------------ active
+   0  : the -------------------- stay unchanged
+*/
+gint find_real(BalsaIndex * bindex,gboolean again);
diff -uN /home/manu/prog/balsa-cvs/balsa/src/main-window.c balsa-current/src/main-window.c
--- /home/manu/prog/balsa-cvs/balsa/src/main-window.c	Fri Apr 26 17:50:33 2002
+++ balsa-current/src/main-window.c	Sat May 11 11:52:29 2002
@@ -41,6 +41,7 @@
 #include "balsa-index.h"
 #include "balsa-mblist.h"
 #include "balsa-message.h"
+#include "find-search.h"
 #include "folder-conf.h"
 #include "mailbox-conf.h"
 #include "main-window.h"
@@ -201,7 +202,6 @@
 
 static void select_part_cb(BalsaMessage * bm, gpointer data);
 
-static void find_real(BalsaIndex * bindex,gboolean again);
 static void find_cb(GtkWidget * widget, gpointer data);
 static void find_again_cb(GtkWidget * widget, gpointer data);
 static void filter_dlg_cb(GtkWidget * widget, gpointer data);
@@ -357,6 +357,7 @@
     GNOMEUIINFO_MENU_SELECT_ALL_ITEM(select_all_cb, NULL),
     GNOMEUIINFO_SEPARATOR,
     GNOMEUIINFO_MENU_FIND_ITEM(find_cb, NULL),
+#define MENU_EDIT_FIND_AGAIN_POS 4
     GNOMEUIINFO_MENU_FIND_AGAIN_ITEM(find_again_cb, NULL),
     /*  GNOMEUIINFO_MENU_REPLACE_ITEM(NULL, NULL); */
 /*     GNOMEUIINFO_SEPARATOR, */
@@ -843,7 +844,7 @@
                         GTK_SIGNAL_FUNC (notebook_drag_received_cb), NULL);
     gtk_signal_connect (GTK_OBJECT (window->notebook), "drag-motion",
                         GTK_SIGNAL_FUNC (notebook_drag_motion_cb), NULL);
-   balsa_app.notebook = window->notebook;
+    balsa_app.notebook = window->notebook;
 
     scroll = gtk_scrolled_window_new(NULL, NULL);
     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
@@ -2514,175 +2515,16 @@
     gtk_widget_show(GTK_WIDGET(ab));
 }
 
-static GtkToggleButton*
-add_check_button(GtkWidget* table, const gchar* label, gint x, gint y)
-{
-    GtkWidget* res = gtk_check_button_new_with_label(label);
-    gtk_table_attach(GTK_TABLE(table),
-                     res,
-                     x, x+1, y, y+1,
-                     GTK_FILL | GTK_SHRINK | GTK_EXPAND, GTK_SHRINK, 2, 2);
-    return GTK_TOGGLE_BUTTON(res);
-}
-
-static void 
-find_real(BalsaIndex * bindex,gboolean again)
-{
-    /* FIXME : later we could do a search based on a complete filter */
-    static LibBalsaFilter * f=NULL;
-    /* Condition set up for the search, it will be of type
-       CONDITION_NONE if nothing has been set up */
-    static LibBalsaCondition * cnd=NULL;
-    GSList * conditions;
-    static gboolean reverse=FALSE;
-
-    if (!cnd) {
-	cnd=libbalsa_condition_new();
-        CONDITION_SETMATCH(cnd,CONDITION_MATCH_FROM);
-        CONDITION_SETMATCH(cnd,CONDITION_MATCH_SUBJECT);
-    }
-
-
-    /* first search, so set up the match rule(s) */
-    if (!again || (!f && cnd->type==CONDITION_NONE)) {
-	GnomeDialog* dia=
-            GNOME_DIALOG(gnome_dialog_new(_("Search a message"),
-                                          GNOME_STOCK_BUTTON_OK,
-                                          GNOME_STOCK_BUTTON_CANCEL,
-                                          NULL));
-	GtkWidget *reverse_button, *search_entry, *w, *page, *table;
-	GtkToggleButton *matching_body, *matching_from;
-        GtkToggleButton *matching_to, *matching_cc, *matching_subject;
-	gint ok;
-	
-	gnome_dialog_close_hides(dia,TRUE);
-
-	/* FIXME : we'll set up this callback later when selecting
-	   filters has been enabled
-	   gtk_signal_connect(GTK_OBJECT(dia),"clicked",
-	   find_dialog_button_cb,&f);
-	*/
-	reverse_button = gtk_check_button_new_with_label(_("Reverse search"));
-
-	page=gtk_table_new(2, 1, FALSE);
-	w = gtk_label_new(_("Search for:"));
-	gtk_table_attach(GTK_TABLE(page),w,0, 1, 0, 1,
-			 GTK_FILL | GTK_SHRINK | GTK_EXPAND, GTK_SHRINK, 2, 2);
-	search_entry = gtk_entry_new_with_max_length(30);
-	gtk_table_attach(GTK_TABLE(page),search_entry,1, 2, 0, 1,
-			 GTK_FILL | GTK_SHRINK | GTK_EXPAND, GTK_SHRINK, 2, 2);
-	gtk_box_pack_start(GTK_BOX(dia->vbox), page, FALSE, FALSE, 2);
-
-	/* builds the toggle buttons to specify fields concerned by
-         * the search. */
-	page = gtk_table_new(3, 7, FALSE);
-    
-	w = gtk_frame_new(_("In:"));
-	gtk_frame_set_label_align(GTK_FRAME(w), GTK_POS_LEFT, GTK_POS_TOP);
-	gtk_frame_set_shadow_type(GTK_FRAME(w), GTK_SHADOW_ETCHED_IN);
-	gtk_table_attach(GTK_TABLE(page),
-			 w,
-			 0, 3, 0, 2,
-			 GTK_FILL | GTK_SHRINK | GTK_EXPAND, GTK_SHRINK, 5, 5);
-    
-	table = gtk_table_new(3, 3, TRUE);
-	gtk_container_add(GTK_CONTAINER(w), table);
-		
-	matching_body    = add_check_button(table, _("Body"),    0, 0);
-	matching_to      = add_check_button(table, _("To:"),     1, 0);
-	matching_from    = add_check_button(table, _("From:"),   1, 1);
-        matching_subject = add_check_button(table, _("Subject"), 2, 0);
-	matching_cc      = add_check_button(table, _("Cc:"),     2, 1);
-	gtk_box_pack_start(GTK_BOX(dia->vbox), page, FALSE, FALSE, 2);
-
-	gtk_box_pack_start(GTK_BOX(dia->vbox), gtk_hseparator_new(), 
-                           FALSE, FALSE, 2);
-	gtk_box_pack_start(GTK_BOX(dia->vbox), reverse_button,TRUE,TRUE,0);
-	gtk_widget_show_all(dia->vbox);
-
-	if (cnd->match.string)
-	    gtk_entry_set_text(GTK_ENTRY(search_entry),cnd->match.string);
-	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(reverse_button),reverse);
-	gtk_toggle_button_set_active(matching_body,
-				     CONDITION_CHKMATCH(cnd,
-                                                        CONDITION_MATCH_BODY));
-	gtk_toggle_button_set_active(matching_to,
-				     CONDITION_CHKMATCH(cnd,
-                                                        CONDITION_MATCH_TO));
-	gtk_toggle_button_set_active(matching_from,
-				     CONDITION_CHKMATCH(cnd,CONDITION_MATCH_FROM));
-	gtk_toggle_button_set_active(matching_subject,
-				     CONDITION_CHKMATCH(cnd,CONDITION_MATCH_SUBJECT));
-	gtk_toggle_button_set_active(matching_cc,
-				     CONDITION_CHKMATCH(cnd,CONDITION_MATCH_CC));
-
-        gtk_widget_grab_focus(search_entry);
-        gnome_dialog_editable_enters(dia, GTK_EDITABLE(search_entry));
-        gnome_dialog_set_default(dia, 0);
-	do {
-	    ok=gnome_dialog_run(dia);
-	    if (ok==0) {
-		reverse=GTK_TOGGLE_BUTTON(reverse_button)->active;
-		g_free(cnd->match.string);
-		cnd->match.string =
-                    g_strdup(gtk_entry_get_text(GTK_ENTRY(search_entry)));
-		cnd->match_fields=CONDITION_EMPTY;
-
-		if (gtk_toggle_button_get_active(matching_body))
-		    CONDITION_SETMATCH(cnd,CONDITION_MATCH_BODY);
-		if (gtk_toggle_button_get_active(matching_to))
-		    CONDITION_SETMATCH(cnd,CONDITION_MATCH_TO);
-		if (gtk_toggle_button_get_active(matching_subject))
-		    CONDITION_SETMATCH(cnd,CONDITION_MATCH_SUBJECT);
-		if (gtk_toggle_button_get_active(matching_from))
-		    CONDITION_SETMATCH(cnd,CONDITION_MATCH_FROM);
-		if (gtk_toggle_button_get_active(matching_cc))
-		    CONDITION_SETMATCH(cnd,CONDITION_MATCH_CC);
-		if (cnd->match_fields!=CONDITION_EMPTY && cnd->match.string[0])
-
-		    /* FIXME : We should print error messages, but for
-		     * that we should first make find dialog non-modal
-		     * balsa_information(LIBBALSA_INFORMATION_ERROR,_("You
-		     * must specify at least one field to look in"));
-		     * *balsa_information(LIBBALSA_INFORMATION_ERROR,_("You
-		     * must provide a non-empty string")); */
-
-		    ok=1;
-		else ok=-1;
-	    }
-	    else ok=-1;
-	}
-	while (ok==0);
-	gtk_widget_destroy(GTK_WIDGET(dia));
-	/* Here ok==1 means OK button was pressed, search is valid so let's go
-	 * else cancel was pressed return */
-	if (ok!=1) return;
-	cnd->type=CONDITION_SIMPLE;
-    }
-
-    if (f) {
-	GSList * lst=g_slist_append(NULL,f);
-	if (!filters_prepare_to_run(lst)) return;
-	g_slist_free(lst);
-	conditions=f->conditions;
-    }
-    else conditions=g_slist_append(NULL,cnd);
-
-    balsa_index_find(bindex,
-                     f ? f->conditions_op : FILTER_OP_OR,
-                     conditions, reverse);
-
-    /* FIXME : See if this does not lead to a segfault because of
-       balsa_index_scan_info */
-    if (!f) g_slist_free(conditions);
-}
-
 static void
 find_cb(GtkWidget * widget,gpointer data)
 {
     GtkWidget * bindex;
-    if ((bindex=balsa_window_find_current_index(BALSA_WINDOW(data))))
-	find_real(BALSA_INDEX(bindex),FALSE);
+    if ((bindex=balsa_window_find_current_index(BALSA_WINDOW(data)))) {
+	gint fagain=find_real(BALSA_INDEX(bindex),FALSE);
+	if (fagain)
+	    gtk_widget_set_sensitive(edit_menu[MENU_EDIT_FIND_AGAIN_POS].widget,
+				     fagain==-1 ? FALSE : TRUE);
+    }
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]