From: Colin Clark Date: Thu, 29 Jun 2023 09:40:59 +0000 (+0100) Subject: Fix #1124: Search in keyboard preferences tab X-Git-Tag: v2.2~242 X-Git-Url: http://geeqie.org/cgi-bin/gitweb.cgi?p=geeqie.git;a=commitdiff_plain;h=f3122147d414ffdef7b8b0b82a17f079e41394cc Fix #1124: Search in keyboard preferences tab https://github.com/BestImageViewer/geeqie/issues/1124 Click anywhere in a column and type. --- diff --git a/doc/docbook/GuideOptionsKeyboard.xml b/doc/docbook/GuideOptionsKeyboard.xml index a13124df..26f80fb7 100644 --- a/doc/docbook/GuideOptionsKeyboard.xml +++ b/doc/docbook/GuideOptionsKeyboard.xml @@ -5,4 +5,5 @@ The data displayed may be ordered by clicking at the top of each column. To change or create a new short-cut, double click on the KEY column of the relevant item. The text displayed will change to "New accelerator...". Press the key combination required for this action. Only shortcuts in the main window can be redefined. Shortcuts in other windows are fixed. + A text search may be made in any of the columns. Click anywhere in a column and type characters. The search is case-insensitive diff --git a/src/preferences.cc b/src/preferences.cc index ac28876e..0ea80833 100644 --- a/src/preferences.cc +++ b/src/preferences.cc @@ -3672,6 +3672,43 @@ static void config_tab_behavior(GtkWidget *notebook) } /* accelerators tab */ + +static gboolean accel_search_function_cb(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer UNUSED(data)) +{ + gboolean ret = TRUE; + gchar *key_nocase; + gchar *text; + gchar *text_nocase; + + gtk_tree_model_get(model, iter, column, &text, -1); + text_nocase = g_utf8_casefold(text, -1); + key_nocase = g_utf8_casefold(key, -1); + + if (g_strstr_len(text_nocase, -1, key_nocase)) + { + ret = FALSE; + } + + g_free(key_nocase); + g_free(text); + g_free(text_nocase); + + return ret; +} + +static void accel_row_activated_cb(GtkTreeView *tree_view, GtkTreePath *UNUSED(path), GtkTreeViewColumn *column, gpointer UNUSED(user_data)) +{ + GList *list; + gint col_num = 0; + + list = gtk_tree_view_get_columns(tree_view); + col_num = g_list_index(list, column); + + g_list_free(list); + + gtk_tree_view_set_search_column(tree_view, col_num); +} + static void config_tab_accelerators(GtkWidget *notebook) { GtkWidget *hbox; @@ -3758,6 +3795,13 @@ static void config_tab_accelerators(GtkWidget *notebook) gtk_tree_view_column_set_resizable(column, TRUE); gtk_tree_view_append_column(GTK_TREE_VIEW(accel_view), column); + /* Search on text in column */ + gtk_tree_view_set_activate_on_single_click(GTK_TREE_VIEW(accel_view), TRUE); + g_signal_connect(accel_view, "row_activated", G_CALLBACK(accel_row_activated_cb), accel_store); + gtk_tree_view_set_enable_search(GTK_TREE_VIEW(accel_view), TRUE); + gtk_tree_view_set_search_column(GTK_TREE_VIEW(accel_view), AE_TOOLTIP); + gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(accel_view), accel_search_function_cb, nullptr, nullptr); + accel_store_populate(); gtk_container_add(GTK_CONTAINER(scrolled), accel_view); gtk_widget_show(accel_view);