make the quicksearch clear button more active and useful
[claws.git] / src / gtk / quicksearch.c
index 33c883ed29c2e6e2a943c331e0e9399a11dfaa7b..10cfbf3b9e5839e2ca43c945ff9dd1c230348283 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2018 Colin Leroy and the Claws Mail team
+ * Copyright (C) 1999-2020 the Claws Mail team and Colin Leroy
  *
  * 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
@@ -28,9 +28,7 @@
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 
-#if !GTK_CHECK_VERSION(3, 0, 0)
 #include "gtkcmoptionmenu.h"
-#endif
 #include "utils.h"
 #include "combobox.h"
 #include "menu.h"
@@ -58,9 +56,7 @@ struct _QuickSearch
 {
        GtkWidget                       *hbox_search;
        GtkWidget                       *search_type;
-#if !GTK_CHECK_VERSION(3, 0, 0)
        GtkWidget                       *search_type_opt;
-#endif
        GtkWidget                       *search_string_entry;
        GtkWidget                       *search_condition_expression;
        GtkWidget                       *search_description;
@@ -221,14 +217,12 @@ gboolean quicksearch_is_fast(QuickSearch *quicksearch)
 
 static void quicksearch_set_type(QuickSearch *quicksearch, gint type)
 {
-#if !GTK_CHECK_VERSION(3, 0, 0)
        gint index;
        quicksearch->request.type = type;
        index = menu_find_option_menu_index(GTK_CMOPTION_MENU(quicksearch->search_type_opt), 
                                        GINT_TO_POINTER(type),
                                        NULL);
        gtk_cmoption_menu_set_history(GTK_CMOPTION_MENU(quicksearch->search_type_opt), index);  
-#endif
 }
 
 static gchar *quicksearch_get_text(QuickSearch * quicksearch)
@@ -485,6 +479,10 @@ static gchar *search_descr_strings[] = {
        "c S",   N_("messages carbon-copied to S"),
        "C S",   N_("message is either To: or Cc: to S"),
        "D",     N_("deleted messages"), /** how I can filter deleted messages **/
+       "da \"YYYY-MM-dd HH:mm:ss\"",  N_("messages whose date is after requested date "
+                                         "(time is optional)"),
+       "db \"YYYY-MM-dd HH:mm:ss\"",  N_("messages whose date is before requested date "
+                                         "(time is optional)"),
        "e S",   N_("messages which contain S in the Sender field"),
        "E S",   N_("true if execute \"S\" succeeds"),
        "f S",   N_("messages originating from user S"),
@@ -551,9 +549,6 @@ static gboolean clear_search_cb(GtkMenuItem *widget, gpointer data)
 {
        QuickSearch *quicksearch = (QuickSearch *)data;
 
-       if (!quicksearch->active)
-               return TRUE;
-
        quicksearch_set(quicksearch, prefs_common.summary_quicksearch_type, "");
 
        return TRUE;
@@ -590,12 +585,16 @@ static gboolean search_condition_expr(GtkMenuItem *widget, gpointer data)
                        mainwindow_get_mainwindow()->summaryview->quicksearch != NULL,
                        FALSE);
 
-       /* re-use the current quicksearch value if it's a condition expression,
-          otherwise ignore it silently */
+       /* re-use the current quicksearch value, expanding it so it also works
+        * with extended symbols */
        cond_str = quicksearch_get_text(mainwindow_get_mainwindow()->summaryview->quicksearch);
 
        if (*cond_str != '\0') {
-               matchers = matcher_parser_get_cond((gchar*)cond_str, NULL);
+               gchar *newstr = advsearch_expand_search_string(cond_str);
+
+               if (newstr && newstr[0] != '\0')
+                       matchers = matcher_parser_get_cond(newstr, FALSE);
+               g_free(newstr);
        }
 
        prefs_matcher_open(matchers, search_condition_expr_done);
@@ -643,9 +642,7 @@ QuickSearch *quicksearch_new()
        QuickSearch *quicksearch;
 
        GtkWidget *hbox_search;
-#if !GTK_CHECK_VERSION(3, 0, 0)
        GtkWidget *search_type_opt;
-#endif
        GtkWidget *search_type;
        GtkWidget *search_string_entry;
        GtkWidget *search_hbox;
@@ -673,11 +670,9 @@ QuickSearch *quicksearch_new()
        /* quick search */
        hbox_search = gtk_hbox_new(FALSE, 0);
 
-#if !GTK_CHECK_VERSION(3, 0, 0)
        search_type_opt = gtk_cmoption_menu_new();
        gtk_widget_show(search_type_opt);
        gtk_box_pack_start(GTK_BOX(hbox_search), search_type_opt, FALSE, FALSE, 0);
-#endif
 
        search_type = gtk_menu_new();
        MENUITEM_ADD (search_type, menuitem,
@@ -755,11 +750,9 @@ QuickSearch *quicksearch_new()
                         G_CALLBACK(searchtype_autorun_changed),
                         quicksearch);
 
-#if !GTK_CHECK_VERSION(3, 0, 0)
        gtk_cmoption_menu_set_menu(GTK_CMOPTION_MENU(search_type_opt), search_type);
 
        quicksearch->search_type_opt = search_type_opt;
-#endif
        quicksearch_set_type(quicksearch, prefs_common.summary_quicksearch_type);
 
        gtk_widget_show(search_type);
@@ -965,21 +958,19 @@ static void quicksearch_set_active(QuickSearch *quicksearch, gboolean active)
                error = TRUE;
 
        if (active) {
-               gtk_widget_set_sensitive(quicksearch->clear_search, TRUE);
-                       gtk_widget_modify_base(
-                               gtk_bin_get_child(GTK_BIN((quicksearch->search_string_entry))),
-                               GTK_STATE_NORMAL, error ? &qs_error_bgcolor : &qs_active_bgcolor);
-                       gtk_widget_modify_text(
-                               gtk_bin_get_child(GTK_BIN((quicksearch->search_string_entry))),
-                               GTK_STATE_NORMAL, error ? &qs_error_color : &qs_active_color);
+               gtk_widget_modify_base(
+                       gtk_bin_get_child(GTK_BIN((quicksearch->search_string_entry))),
+                       GTK_STATE_NORMAL, error ? &qs_error_bgcolor : &qs_active_bgcolor);
+               gtk_widget_modify_text(
+                       gtk_bin_get_child(GTK_BIN((quicksearch->search_string_entry))),
+                       GTK_STATE_NORMAL, error ? &qs_error_color : &qs_active_color);
        } else {
-               gtk_widget_set_sensitive(quicksearch->clear_search, FALSE);
-                       gtk_widget_modify_base(
-                               gtk_bin_get_child(GTK_BIN((quicksearch->search_string_entry))),
-                               GTK_STATE_NORMAL, NULL);
-                       gtk_widget_modify_text(
-                               gtk_bin_get_child(GTK_BIN((quicksearch->search_string_entry))),
-                               GTK_STATE_NORMAL, NULL);
+               gtk_widget_modify_base(
+                       gtk_bin_get_child(GTK_BIN((quicksearch->search_string_entry))),
+                       GTK_STATE_NORMAL, NULL);
+               gtk_widget_modify_text(
+                       gtk_bin_get_child(GTK_BIN((quicksearch->search_string_entry))),
+                       GTK_STATE_NORMAL, NULL);
        }
 
        if (!active) {