[gtk/stack-fixes] Test fixes
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/stack-fixes] Test fixes
- Date: Sat, 9 Feb 2019 00:02:12 +0000 (UTC)
commit 91f5b712cfdd85ee3d08855334624cf63d073521
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Feb 8 19:01:11 2019 -0500
Test fixes
It turns out that GtkSingleSelection will sometimes have a
selected value of 0, even when there is no child at that
position (because the model is empty). Deal with it.
gtk/gtkstack.c | 8 ++++----
gtk/gtkstackswitcher.c | 4 ++--
2 files changed, 6 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c
index f6e69f6fb0..cd2148a4a8 100644
--- a/gtk/gtkstack.c
+++ b/gtk/gtkstack.c
@@ -2249,15 +2249,15 @@ transform_from (GBinding *binding,
guint selected;
selected = g_value_get_uint (from_value);
- if (selected == GTK_INVALID_LIST_POSITION)
- g_value_set_object (to_value, NULL);
- else
+ if (selected < g_list_model_get_n_items (G_LIST_MODEL (priv->pages)))
{
GtkWidget *child;
child = g_list_model_get_item (G_LIST_MODEL (priv->pages), selected);
g_value_set_object (to_value, child);
+ return TRUE;
}
- return TRUE;
+ else
+ return FALSE;
}
/**
diff --git a/gtk/gtkstackswitcher.c b/gtk/gtkstackswitcher.c
index c626f65d6f..e25850bf59 100644
--- a/gtk/gtkstackswitcher.c
+++ b/gtk/gtkstackswitcher.c
@@ -362,7 +362,7 @@ populate_switcher (GtkStackSwitcher *self)
}
selected = gtk_single_selection_get_selected (GTK_SINGLE_SELECTION (priv->pages));
- if (selected != GTK_INVALID_LIST_POSITION)
+ if (selected < g_list_model_get_n_items (G_LIST_MODEL (priv->pages)))
{
widget = g_list_model_get_item (G_LIST_MODEL (priv->pages), selected);
button = g_hash_table_lookup (priv->buttons, widget);
@@ -418,7 +418,7 @@ selection_changed_cb (GtkSelectionModel *model,
GtkWidget *button;
selected = gtk_single_selection_get_selected (GTK_SINGLE_SELECTION (model));
- if (selected == GTK_INVALID_LIST_POSITION)
+ if (g_list_model_get_n_items (G_LIST_MODEL (model)) <= selected)
return;
child = g_list_model_get_item (G_LIST_MODEL (model), selected);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]