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'
This commit is contained in:
Arx Cruz 2014-10-21 18:30:35 +02:00
parent b44b2fb33d
commit 15e2759668
3 changed files with 30 additions and 0 deletions

View File

@ -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;

View File

@ -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);
}

View File

@ -132,6 +132,7 @@ typedef struct {
gchar *separator;
gboolean multi;
gboolean editable;
gboolean mid_search;
gchar *print_column;
gchar *hide_column;
const gchar **data;