[gtk+/wip/combo: 8/11] Fixes for item removal with groups
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/combo: 8/11] Fixes for item removal with groups
- Date: Fri, 26 Dec 2014 05:21:07 +0000 (UTC)
commit e77687bd076b09b60bb8e7dbd23a0dd4bd0380f4
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Dec 25 22:59:41 2014 -0500
Fixes for item removal with groups
gtk/gtkcombo.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 84 insertions(+), 16 deletions(-)
---
diff --git a/gtk/gtkcombo.c b/gtk/gtkcombo.c
index 06d7821..1fbc50c 100644
--- a/gtk/gtkcombo.c
+++ b/gtk/gtkcombo.c
@@ -299,8 +299,7 @@ static gboolean button_key_press (GtkWidget *widget,
static void reset_popover (GtkWidget *popover,
GtkCombo *combo);
static void collapse (GtkCombo *combo,
- GtkWidget *list,
- GtkWidget *revealer);
+ GtkWidget *list);
static void expand (GtkCombo *combo,
GtkWidget *list);
static void list_header_func (GtkListBoxRow *row,
@@ -803,7 +802,7 @@ reset_popover (GtkWidget *widget,
gtk_stack_set_visible_child_name (GTK_STACK (combo->stack), "list");
gtk_entry_set_text (GTK_ENTRY (combo->search_entry), "");
gtk_widget_hide (combo->search_revealer);
- collapse (combo, combo->list, combo->search_revealer);
+ collapse (combo, combo->list);
gtk_entry_set_text (GTK_ENTRY (combo->custom_entry), "");
}
@@ -812,6 +811,7 @@ typedef struct
GtkCombo *combo;
const gchar *id;
GtkWidget *row;
+ GtkWidget *group_row;
} ForeachData;
static void
@@ -831,6 +831,41 @@ find_row (GtkWidget *row,
}
static void
+find_row_in_group (GtkWidget *row,
+ gpointer data)
+{
+ ForeachData *d = data;
+ const gchar *id;
+ const gchar *group;
+
+ if (d->row)
+ return;
+
+ group = (const gchar *)g_object_get_data (G_OBJECT (row), "group");
+ if (group && g_strcmp0 (group, "list") != 0)
+ {
+ GtkWidget *list;
+
+ list = group_get_list (d->combo, group);
+ gtk_container_foreach (GTK_CONTAINER (list), find_row, d);
+
+ if (d->row)
+ d->group_row = row;
+ }
+
+ if (d->row)
+ return;
+
+ if (!GTK_IS_COMBO_ROW (row))
+ return;
+
+ id = gtk_combo_row_get_id (GTK_COMBO_ROW (row));
+
+ if (g_strcmp0 (id, d->id) == 0)
+ d->row = row;
+}
+
+static void
add_to_list (GtkWidget *list,
const gchar *id,
const gchar *sort,
@@ -857,6 +892,18 @@ add_to_list (GtkWidget *list,
}
}
+static void
+count_items (GtkWidget *widget,
+ gpointer data)
+{
+ gint *count = data;
+
+ if (!GTK_IS_COMBO_ROW (widget))
+ return;
+
+ (*count)++;
+}
+
static gboolean
remove_from_list (GtkCombo *combo,
const gchar *id)
@@ -865,11 +912,33 @@ remove_from_list (GtkCombo *combo,
data.id = id;
data.row = NULL;
- gtk_container_foreach (GTK_CONTAINER (combo->list), find_row, &data);
+ data.group_row = NULL;
+ gtk_container_foreach (GTK_CONTAINER (combo->list), find_row_in_group, &data);
if (data.row)
{
- gtk_container_remove (GTK_CONTAINER (combo->list), data.row);
+ GtkWidget *list;
+ GtkWidget *tab;
+
+ list = gtk_widget_get_parent (data.row);
+ gtk_container_remove (GTK_CONTAINER (list), data.row);
+
+ if (data.group_row)
+ {
+ gint count = 0;
+ gtk_container_foreach (GTK_CONTAINER (list), count_items, &count);
+ if (count == 0)
+ {
+ tab = gtk_widget_get_ancestor (list, GTK_TYPE_FRAME);
+ gtk_container_remove (GTK_CONTAINER (combo->stack), tab);
+ gtk_container_remove (GTK_CONTAINER (combo->list), data.group_row);
+ }
+ else
+ collapse (combo, list);
+ }
+ else
+ collapse (combo, list);
+
return TRUE;
}
@@ -977,7 +1046,7 @@ list_row_activated (GtkListBox *list,
if (group)
{
if (g_strcmp0 (group, "list") != 0)
- collapse (combo, group_get_list (combo, group), NULL);
+ collapse (combo, group_get_list (combo, group));
gtk_stack_set_visible_child_name (GTK_STACK (combo->stack), group);
return;
}
@@ -1072,8 +1141,7 @@ show_few (GtkWidget *widget, gpointer data)
static void
collapse (GtkCombo *combo,
- GtkWidget *list,
- GtkWidget *revealer)
+ GtkWidget *list)
{
gint count;
GtkWidget *show_more;
@@ -1083,16 +1151,16 @@ collapse (GtkCombo *combo,
gtk_container_foreach (GTK_CONTAINER (list), show_few, &count);
if (count < 7)
{
- if (revealer)
- gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), FALSE);
+ if (list == combo->list)
+ gtk_revealer_set_reveal_child (GTK_REVEALER (combo->search_revealer), FALSE);
gtk_widget_hide (show_more);
}
else
{
- if (revealer)
+ if (list == combo->list)
{
- gtk_widget_show (revealer);
- gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), TRUE);
+ gtk_widget_show (combo->search_revealer);
+ gtk_revealer_set_reveal_child (GTK_REVEALER (combo->search_revealer), TRUE);
}
gtk_widget_show (show_more);
}
@@ -1317,7 +1385,7 @@ gtk_combo_add (GtkCombo *combo,
g_return_if_fail (GTK_IS_COMBO (combo));
add_to_list (combo->list, id, sort, text);
- collapse (combo, combo->list, combo->search_revealer);
+ collapse (combo, combo->list);
}
/**
@@ -1344,7 +1412,7 @@ gtk_combo_remove (GtkCombo *combo,
if (g_strcmp0 (id, combo->active) == 0)
set_active (combo, NULL);
- collapse (combo, combo->list, combo->search_revealer);
+ collapse (combo, combo->list);
}
/**
@@ -1558,5 +1626,5 @@ gtk_combo_add_with_group (GtkCombo *combo,
list = ensure_group (combo, group);
add_to_list (list, id, sort, text);
- collapse (combo, list, NULL);
+ collapse (combo, list);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]