[gtk/matthiasc/for-master: 4/6] filechooser: Fix gtk_file_chooser_set_choice




commit 1d34f955a270cba02beb0f3b4c5900122c7088e0
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Sep 20 12:01:52 2020 -0400

    filechooser: Fix gtk_file_chooser_set_choice
    
    This broke when it was ported to GtkDropDown.

 gtk/gtkfilechooserwidget.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index 39d9001541..ed5b6f8939 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -7933,7 +7933,9 @@ gtk_file_chooser_widget_add_choice (GtkFileChooser  *chooser,
       box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
       gtk_box_append (GTK_BOX (box), gtk_label_new (label));
 
-      combo = gtk_drop_down_new_from_strings ((const char * const *)options);
+      combo = gtk_drop_down_new_from_strings ((const char * const *)option_labels);
+      g_object_set_data_full (G_OBJECT (combo), "options",
+                              g_strdupv ((char **)options), (GDestroyNotify)g_strfreev);
       g_hash_table_insert (impl->choices, g_strdup (id), combo);
       gtk_box_append (GTK_BOX (box), combo);
 
@@ -7988,19 +7990,20 @@ gtk_file_chooser_widget_set_choice (GtkFileChooser  *chooser,
 
   widget = (GtkWidget *)g_hash_table_lookup (impl->choices, id);
 
-  if (GTK_IS_DROP_DOWN (widget))
+  if (GTK_IS_BOX (widget))
     {
-      guint i, n;
-      GListModel *model;
+      guint i;
+      const char **choices;
+      GtkWidget *dropdown;
+
+      dropdown = gtk_widget_get_last_child (widget);
 
-      model = gtk_drop_down_get_model (GTK_DROP_DOWN (widget));
-      n = g_list_model_get_n_items (model);
-      for (i = 0; i < n; i++)
+      choices = (const char **) g_object_get_data (G_OBJECT (dropdown), "choices");
+      for (i = 0; choices[i]; i++)
         {
-          const char *string = gtk_string_list_get_string (GTK_STRING_LIST (model), i);
-          if (strcmp (string, option) == 0)
+          if (strcmp (option, choices[i]) == 0)
             {
-              gtk_drop_down_set_selected (GTK_DROP_DOWN (widget), i);
+              gtk_drop_down_set_selected (GTK_DROP_DOWN (dropdown), i);
               break;
             }
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]