summaryrefslogtreecommitdiffstats
path: root/gtk
diff options
context:
space:
mode:
authorJohn Stebbins <[email protected]>2018-06-11 15:15:01 -0700
committerJohn Stebbins <[email protected]>2018-06-11 15:15:01 -0700
commit3368d37a980f5f31182fca5c22e175f444ccae9f (patch)
treed3fb7ad4f7a3fb994f0a5cb1185c04625883da13 /gtk
parent41a339fc64c06f104f8925a1c741bc9c5d28a8e4 (diff)
LinGui: add search function to language popups
The language list is long and displays native names while sorted by English names, so it is difficult to find a language. This adds the ability to "search" for a language based on it's initial character. Typing a character will jump to the next entry that starts with that character in its native name.
Diffstat (limited to 'gtk')
-rw-r--r--gtk/src/callbacks.c45
-rw-r--r--gtk/src/hb-backend.c3
2 files changed, 48 insertions, 0 deletions
diff --git a/gtk/src/callbacks.c b/gtk/src/callbacks.c
index 94e3f8b2c..a1091c0cd 100644
--- a/gtk/src/callbacks.c
+++ b/gtk/src/callbacks.c
@@ -5885,3 +5885,48 @@ void ghb_container_empty(GtkContainer *c)
{
gtk_container_foreach(c, container_empty_cb, NULL);
}
+
+G_MODULE_EXPORT gboolean
+combo_search_key_press_cb(
+ GtkWidget *widget,
+ GdkEvent *event,
+ signal_user_data_t *ud)
+{
+ GtkComboBox * combo = GTK_COMBO_BOX(widget);
+ GtkTreeModel * model = GTK_TREE_MODEL(gtk_combo_box_get_model(combo));
+ GtkTreeIter iter, prev_iter;
+ gchar * lang;
+ guint keyval;
+ gunichar key_char;
+ gunichar first_char;
+ int pos = 0, count = 2048;
+
+ ghb_event_get_keyval(event, &keyval);
+ key_char = g_unichar_toupper(gdk_keyval_to_unicode(keyval));
+ if (gtk_combo_box_get_active_iter(combo, &iter))
+ {
+ while (pos <= count)
+ {
+ pos++;
+ prev_iter = iter;
+ if (!gtk_tree_model_iter_next(model, &iter))
+ {
+ GtkTreePath * path = gtk_tree_model_get_path(model, &prev_iter);
+ gint * ind = gtk_tree_path_get_indices(path);;
+
+ count = ind[0];
+ gtk_tree_path_free(path);
+ gtk_tree_model_get_iter_first(model, &iter);
+ }
+ gtk_tree_model_get(model, &iter, 0, &lang, -1);
+ first_char = g_unichar_toupper(g_utf8_get_char(lang));
+ g_free(lang);
+ if (first_char == key_char)
+ {
+ gtk_combo_box_set_active_iter(combo, &iter);
+ break;
+ }
+ }
+ }
+ return FALSE;
+}
diff --git a/gtk/src/hb-backend.c b/gtk/src/hb-backend.c
index 3d947c8c1..433e21bfc 100644
--- a/gtk/src/hb-backend.c
+++ b/gtk/src/hb-backend.c
@@ -2016,6 +2016,8 @@ srt_codeset_opts_set(signal_user_data_t *ud, const gchar *name,
}
}
+extern G_MODULE_EXPORT void combo_search_key_press_cb(void);
+
static void
language_opts_set(signal_user_data_t *ud, const gchar *name,
void *opts, const void* data)
@@ -2048,6 +2050,7 @@ language_opts_set(signal_user_data_t *ud, const gchar *name,
3, (gdouble)ii,
-1);
}
+ g_signal_connect(combo, "key-press-event", combo_search_key_press_cb, ud);
}
gchar*