[gtk/prop-list: 42/70] filechooser: Use a dropdown for choices
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/prop-list: 42/70] filechooser: Use a dropdown for choices
- Date: Sun, 22 Dec 2019 03:27:00 +0000 (UTC)
commit 863b89c0ac0c967a50643ad1562897109ae42ebd
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Dec 21 21:06:50 2019 -0500
filechooser: Use a dropdown for choices
gtk/gtkfilechooserwidget.c | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index 452c3714db..8e53a71527 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -30,7 +30,6 @@
#include "gtkcellrenderertext.h"
#include "gtkcheckmenuitem.h"
#include "gtkdropdown.h"
-#include "gtkcomboboxtext.h"
#include "gtkcssnumbervalueprivate.h"
#include "gtkdragsource.h"
#include "gtkdragdest.h"
@@ -8701,18 +8700,16 @@ gtk_file_chooser_widget_add_choice (GtkFileChooser *chooser,
{
GtkWidget *box;
GtkWidget *combo;
- int i;
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_container_add (GTK_CONTAINER (box), gtk_label_new (label));
- combo = gtk_combo_box_text_new ();
+ combo = gtk_drop_down_new ();
g_hash_table_insert (priv->choices, g_strdup (id), combo);
gtk_container_add (GTK_CONTAINER (box), combo);
- for (i = 0; options[i]; i++)
- gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo),
- options[i], option_labels[i]);
+ gtk_drop_down_set_from_strings (GTK_DROP_DOWN (combo), option_labels);
+ g_object_set_data_full (G_OBJECT (combo), "options", g_strdupv ((char **)options),
(GDestroyNotify)g_strfreev);
widget = box;
}
@@ -8767,8 +8764,19 @@ gtk_file_chooser_widget_set_choice (GtkFileChooser *chooser,
widget = (GtkWidget *)g_hash_table_lookup (priv->choices, id);
- if (GTK_IS_COMBO_BOX (widget))
- gtk_combo_box_set_active_id (GTK_COMBO_BOX (widget), option);
+ if (GTK_IS_DROP_DOWN (widget))
+ {
+ guint i;
+ const char **options = (const char **)g_object_get_data (G_OBJECT (widget), "options");
+ for (i = 0; options[i]; i++)
+ {
+ if (strcmp (options[i], option) == 0)
+ {
+ gtk_drop_down_set_selected (GTK_DROP_DOWN (widget), i);
+ break;
+ }
+ }
+ }
else if (GTK_IS_TOGGLE_BUTTON (widget))
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), g_str_equal (option, "true"));
}
@@ -8785,8 +8793,14 @@ gtk_file_chooser_widget_get_choice (GtkFileChooser *chooser,
return NULL;
widget = (GtkWidget *)g_hash_table_lookup (priv->choices, id);
- if (GTK_IS_COMBO_BOX (widget))
- return gtk_combo_box_get_active_id (GTK_COMBO_BOX (widget));
+ if (GTK_IS_DROP_DOWN (widget))
+ {
+ const char **options = (const char **)g_object_get_data (G_OBJECT (widget), "options");
+ guint selected = gtk_drop_down_get_selected (GTK_DROP_DOWN (widget));
+ if (selected == GTK_INVALID_LIST_POSITION)
+ return NULL;
+ return options[selected];
+ }
else if (GTK_IS_TOGGLE_BUTTON (widget))
return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)) ? "true" : "false";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]