From 15e2759668a1d17bb1570a890bf294aaa796cbf5 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Tue, 21 Oct 2014 18:30:35 +0200 Subject: [PATCH] Bug #685051 Adding --mid-search option to --list This will enable users to find a row with a text matching the middle of the row. Consider the following list: Little piggy one Little piggy two Little piggy three As a user I would expect that entering 'th' would focus the last row, because it's the first one that contains 'th' --- src/option.c | 15 +++++++++++++++ src/tree.c | 14 ++++++++++++++ src/zenity.h | 1 + 3 files changed, 30 insertions(+) diff --git a/src/option.c b/src/option.c index c1e3a77..e11c1ba 100644 --- a/src/option.c +++ b/src/option.c @@ -83,6 +83,7 @@ static gchar *zenity_list_print_column; static gchar *zenity_list_hide_column; static gboolean zenity_list_hide_header; static gboolean zenity_list_imagelist; +static gboolean zenity_list_mid_search; #ifdef HAVE_LIBNOTIFY /* Notification Dialog Options */ @@ -651,6 +652,15 @@ static GOptionEntry list_options[] = { N_("Hides the column headers"), NULL }, + { + "mid-search", + '\0', + G_OPTION_FLAG_NOALIAS, + G_OPTION_ARG_NONE, + &zenity_list_mid_search, + N_("Change list default search function searching for text in the middle, not on the beginning"), + NULL + }, { NULL } @@ -1531,6 +1541,7 @@ zenity_list_pre_callback (GOptionContext *context, zenity_list_hide_header = FALSE; zenity_list_print_column = NULL; zenity_list_hide_column = NULL; + zenity_list_mid_search = FALSE; return TRUE; } @@ -1876,6 +1887,7 @@ zenity_list_post_callback (GOptionContext *context, results->tree_data->hide_column = zenity_list_hide_column; results->tree_data->hide_header = zenity_list_hide_header; results->tree_data->separator = zenity_general_separator; + results->tree_data->mid_search = zenity_list_mid_search; } else { if (zenity_list_columns) zenity_option_error (zenity_option_get_name (list_options, &zenity_list_columns), @@ -1904,6 +1916,9 @@ zenity_list_post_callback (GOptionContext *context, if (zenity_list_hide_header) zenity_option_error (zenity_option_get_name (list_options, &zenity_list_hide_header), ERROR_SUPPORT); + if (zenity_list_mid_search) + zenity_option_error (zenity_option_get_name (list_options, &zenity_list_mid_search), + ERROR_SUPPORT); } return TRUE; diff --git a/src/tree.c b/src/tree.c index a8b324f..819f9a8 100644 --- a/src/tree.c +++ b/src/tree.c @@ -298,6 +298,17 @@ zenity_tree_fill_entries (GtkTreeView *tree_view, } } +static gboolean +zenity_mid_search_func (GtkTreeModel *model, gint column, + const gchar *key, GtkTreeIter *iter, + gpointer search_data) +{ + gchar *iter_string = NULL; + gtk_tree_model_get (model, iter, column, &iter_string, -1); + return ! g_strrstr (g_utf8_strdown(iter_string, -1), + g_utf8_strdown(key, -1)) != NULL; +} + static void zenity_cell_edited_callback (GtkCellRendererText *cell, const gchar *path_string, @@ -564,6 +575,9 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) zenity_util_show_dialog (dialog, data->attach); + if (tree_data->mid_search) + gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(tree_view), (GtkTreeViewSearchEqualFunc) zenity_mid_search_func, model, NULL); + if(data->timeout_delay > 0) { g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, dialog); } diff --git a/src/zenity.h b/src/zenity.h index 4cf7a04..4b3214d 100644 --- a/src/zenity.h +++ b/src/zenity.h @@ -132,6 +132,7 @@ typedef struct { gchar *separator; gboolean multi; gboolean editable; + gboolean mid_search; gchar *print_column; gchar *hide_column; const gchar **data;