Fix #1124: Search in keyboard preferences tab
authorColin Clark <colin.clark@cclark.uk>
Thu, 29 Jun 2023 09:40:59 +0000 (10:40 +0100)
committerColin Clark <colin.clark@cclark.uk>
Thu, 29 Jun 2023 09:40:59 +0000 (10:40 +0100)
https://github.com/BestImageViewer/geeqie/issues/1124

Click anywhere in a column and type.

doc/docbook/GuideOptionsKeyboard.xml
src/preferences.cc

index a13124d..26f80fb 100644 (file)
@@ -5,4 +5,5 @@
   <para>The data displayed may be ordered by clicking at the top of each column.</para>
   <para>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.</para>
   <para>Only shortcuts in the main window can be redefined. Shortcuts in other windows are fixed.</para>
+  <para>A text search may be made in any of the columns. Click anywhere in a column and type characters. The search is case-insensitive</para>
 </section>
index ac28876..0ea8083 100644 (file)
@@ -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);