[gtk/matthiasc/for-master: 3/3] filechooserwidget: Use dropdown api better
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/for-master: 3/3] filechooserwidget: Use dropdown api better
- Date: Sun, 12 Jul 2020 14:22:50 +0000 (UTC)
commit fcf072f556a4e692d4b3d9e28180627e142bbaee
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Jul 12 10:20:52 2020 -0400
filechooserwidget: Use dropdown api better
We now have GtkStringList, so we can implement
the choice api a little cleaner with it.
gtk/gtkfilechooserwidget.c | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index 7607ba9dbb..904ac0129a 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -89,6 +89,7 @@
#include "gtkshortcuttrigger.h"
#include "gtkshortcutaction.h"
#include "gtkshortcut.h"
+#include "gtkstringlist.h"
#include <cairo-gobject.h>
@@ -7947,6 +7948,7 @@ gtk_file_chooser_widget_add_choice (GtkFileChooser *chooser,
{
GtkWidget *box;
GtkWidget *combo;
+ GListModel *model;
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_box_append (GTK_BOX (box), gtk_label_new (label));
@@ -7955,8 +7957,9 @@ gtk_file_chooser_widget_add_choice (GtkFileChooser *chooser,
g_hash_table_insert (impl->choices, g_strdup (id), combo);
gtk_box_append (GTK_BOX (box), combo);
- 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);
+ model = G_LIST_MODEL (gtk_string_list_new ((const char * const *)options));
+ gtk_drop_down_set_model (GTK_DROP_DOWN (combo), model);
+ g_object_unref (model);
widget = box;
}
@@ -8011,11 +8014,15 @@ gtk_file_chooser_widget_set_choice (GtkFileChooser *chooser,
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++)
+ guint i, n;
+ GListModel *model;
+
+ model = gtk_drop_down_get_model (GTK_DROP_DOWN (widget));
+ n = g_list_model_get_n_items (model);
+ for (i = 0; i < n; i++)
{
- if (strcmp (options[i], option) == 0)
+ const char *string = gtk_string_list_get_string (GTK_STRING_LIST (model), i);
+ if (strcmp (string, option) == 0)
{
gtk_drop_down_set_selected (GTK_DROP_DOWN (widget), i);
break;
@@ -8039,11 +8046,10 @@ gtk_file_chooser_widget_get_choice (GtkFileChooser *chooser,
widget = (GtkWidget *)g_hash_table_lookup (impl->choices, id);
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];
+ gpointer selected = gtk_drop_down_get_selected_item (GTK_DROP_DOWN (widget));
+ if (GTK_IS_STRING_OBJECT (selected))
+ return gtk_string_object_get_string (GTK_STRING_OBJECT (selected));
+ return NULL;
}
else if (GTK_IS_TOGGLE_BUTTON (widget))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]