Fix #779: Add search by path
authorgusrĀ  <>
Tue, 23 Jun 2020 09:32:15 +0000 (10:32 +0100)
committerColin Clark <colin.clark@cclark.uk>
Tue, 23 Jun 2020 09:32:15 +0000 (10:32 +0100)
https://github.com/BestImageViewer/geeqie/pull/779

doc/docbook/GuideImageSearchSearch.xml
src/search.c

index 6b7c83d..25d6d20 100644 (file)
     <variablelist>\r
       <varlistentry>\r
         <term>\r
-          <guilabel>File name</guilabel>\r
+          <guilabel>File</guilabel>\r
         </term>\r
         <listitem>\r
-          The search will match if the entered text appears within the file name, or if the text exactly matches the file name, depending on the method selected from the drop down menu. The text comparison can be made to be case sensitive by enabling the Match case checkbox.\r
+          If "name is" is selected, the search will match if the text exactly matches the file name. If "name contains" or "path contains" is selected, the search will match if the entered text appears within the file name or path.<para/>The text comparison can be made to be case sensitive by enabling the Match case checkbox.\r
           <para />\r
-          If "contains" is selected,\r
+          If "contains" or "path contains" is selected,\r
           <link linkend="GuideReferencePCRE">Perl Compatible Regular Expressions</link>\r
           are used.\r
         </listitem>\r
index 987c45a..38c10b0 100644 (file)
@@ -69,6 +69,9 @@ typedef enum {
        SEARCH_MATCH_NONE,
        SEARCH_MATCH_EQUAL,
        SEARCH_MATCH_CONTAINS,
+       SEARCH_MATCH_NAME_EQUAL,
+       SEARCH_MATCH_NAME_CONTAINS,
+       SEARCH_MATCH_PATH_CONTAINS,
        SEARCH_MATCH_UNDER,
        SEARCH_MATCH_OVER,
        SEARCH_MATCH_BETWEEN,
@@ -271,8 +274,9 @@ static const MatchList text_search_menu_path[] = {
 };
 
 static const MatchList text_search_menu_name[] = {
-       { N_("contains"),       SEARCH_MATCH_CONTAINS },
-       { N_("is"),             SEARCH_MATCH_EQUAL }
+       { N_("name contains"),  SEARCH_MATCH_NAME_CONTAINS },
+       { N_("name is"),        SEARCH_MATCH_NAME_EQUAL },
+       { N_("path contains"),  SEARCH_MATCH_PATH_CONTAINS }
 };
 
 static const MatchList text_search_menu_size[] = {
@@ -1949,7 +1953,7 @@ static gboolean search_file_next(SearchData *sd)
                tested = TRUE;
                match = FALSE;
 
-               if (sd->match_name == SEARCH_MATCH_EQUAL)
+               if (sd->match_name == SEARCH_MATCH_NAME_EQUAL)
                        {
                        if (sd->search_name_match_case)
                                {
@@ -1960,16 +1964,25 @@ static gboolean search_file_next(SearchData *sd)
                                match = (g_ascii_strcasecmp(fd->name, sd->search_name) == 0);
                                }
                        }
-               else if (sd->match_name == SEARCH_MATCH_CONTAINS)
+               else if (sd->match_name == SEARCH_MATCH_NAME_CONTAINS || sd->match_name == SEARCH_MATCH_PATH_CONTAINS)
                        {
+                       const gchar *fd_name_or_path;
+                       if (sd->match_name == SEARCH_MATCH_NAME_CONTAINS)
+                               {
+                               fd_name_or_path = fd->name;
+                               }
+                       else
+                               {
+                               fd_name_or_path = fd->path;
+                               }
                        if (sd->search_name_match_case)
                                {
-                               match = g_regex_match(sd->search_name_regex, fd->name, 0, NULL);
+                               match = g_regex_match(sd->search_name_regex, fd_name_or_path, 0, NULL);
                                }
                        else
                                {
                                /* sd->search_name is converted in search_start() */
-                               gchar *haystack = g_utf8_strdown(fd->name, -1);
+                               gchar *haystack = g_utf8_strdown(fd_name_or_path, -1);
                                match = g_regex_match(sd->search_name_regex, haystack, 0, NULL);
                                g_free(haystack);
                                }
@@ -3287,7 +3300,7 @@ void search_new(FileData *dir_fd, FileData *example_file)
 
        sd->search_type = SEARCH_MATCH_NONE;
 
-       sd->match_name = SEARCH_MATCH_CONTAINS;
+       sd->match_name = SEARCH_MATCH_NAME_CONTAINS;
        sd->match_size = SEARCH_MATCH_EQUAL;
        sd->match_date = SEARCH_MATCH_EQUAL;
        sd->match_dimensions = SEARCH_MATCH_EQUAL;
@@ -3380,7 +3393,7 @@ void search_new(FileData *dir_fd, FileData *example_file)
 
        /* Search for file name */
        hbox = menu_choice(sd->box_search, &sd->check_name, &sd->menu_name,
-                          _("File name"), &sd->match_name_enable,
+                          _("File"), &sd->match_name_enable,
                           text_search_menu_name, sizeof(text_search_menu_name) / sizeof(MatchList),
                           G_CALLBACK(menu_choice_name_cb), sd);
        combo = history_combo_new(&sd->entry_name, "", "search_name", -1);
@@ -3388,7 +3401,7 @@ void search_new(FileData *dir_fd, FileData *example_file)
        gtk_widget_show(combo);
        pref_checkbox_new_int(hbox, _("Match case"),
                              sd->search_name_match_case, &sd->search_name_match_case);
-       gtk_widget_set_tooltip_text(GTK_WIDGET(combo), "When set to \"contains\", this field uses Perl Compatible Regular Expressions.\ne.g. use \n.*\\.jpg\n and not \n*.jpg\n\nSee the Help file.");
+       gtk_widget_set_tooltip_text(GTK_WIDGET(combo), "When set to \"contains\" or \"path contains\", this field uses Perl Compatible Regular Expressions.\ne.g. use \n.*\\.jpg\n and not \n*.jpg\n\nSee the Help file.");
 
        /* Search for file size */
        hbox = menu_choice(sd->box_search, &sd->check_size, &sd->menu_size,