From 99aa4caeef1f7c2985431e3e15f95563a30fb354 Mon Sep 17 00:00:00 2001 From: =?utf8?q?gusr=C2=A0?= <> Date: Tue, 23 Jun 2020 10:32:15 +0100 Subject: [PATCH] Fix #779: Add search by path https://github.com/BestImageViewer/geeqie/pull/779 --- doc/docbook/GuideImageSearchSearch.xml | 6 ++--- src/search.c | 31 ++++++++++++++++++-------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/doc/docbook/GuideImageSearchSearch.xml b/doc/docbook/GuideImageSearchSearch.xml index 6b7c83d9..25d6d20d 100644 --- a/doc/docbook/GuideImageSearchSearch.xml +++ b/doc/docbook/GuideImageSearchSearch.xml @@ -80,12 +80,12 @@ - File name + File - 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. + 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.The text comparison can be made to be case sensitive by enabling the Match case checkbox. - If "contains" is selected, + If "contains" or "path contains" is selected, Perl Compatible Regular Expressions are used. diff --git a/src/search.c b/src/search.c index 987c45a8..38c10b08 100644 --- a/src/search.c +++ b/src/search.c @@ -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, -- 2.20.1