]> granicus.if.org Git - handbrake/commitdiff
LinGui: add search function to language popups
authorJohn Stebbins <jstebbins.hb@gmail.com>
Mon, 11 Jun 2018 22:15:01 +0000 (15:15 -0700)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Mon, 11 Jun 2018 22:15:01 +0000 (15:15 -0700)
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.

gtk/src/callbacks.c
gtk/src/hb-backend.c

index 94e3f8b2c42baadab425b5cc8cd9f5b7d0736b32..a1091c0cd096ded74190b5b176a6e3b1a7d33410 100644 (file)
@@ -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;
+}
index 3d947c8c149625b4c63d42ba48126e90f013f64c..433e21bfca2f4e471e57f5230217197c4ec11b09 100644 (file)
@@ -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*