[gnome-builder] grid: cull empty grid boxes when last item is closed
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] grid: cull empty grid boxes when last item is closed
- Date: Mon, 18 Dec 2017 00:07:01 +0000 (UTC)
commit c67733b542a18d9cff5be8faecafef1aefb4dcc5
Author: Christian Hergert <chergert redhat com>
Date: Sun Dec 17 16:06:31 2017 -0800
grid: cull empty grid boxes when last item is closed
src/libide/layout/ide-layout-grid.c | 88 +++++++++++++++++++++++++++++++++++
1 files changed, 88 insertions(+), 0 deletions(-)
---
diff --git a/src/libide/layout/ide-layout-grid.c b/src/libide/layout/ide-layout-grid.c
index afa2f01..ea9b528 100644
--- a/src/libide/layout/ide-layout-grid.c
+++ b/src/libide/layout/ide-layout-grid.c
@@ -67,6 +67,12 @@ typedef struct
* be used directly, only for pointer comparison.
*/
IdeLayoutView *_last_focused_view;
+
+ /*
+ * A GSource that is used to remove empty stacks that are unnecessary
+ * (after a last stack item is removed).
+ */
+ guint cull_source;
} IdeLayoutGridPrivate;
typedef struct
@@ -117,6 +123,74 @@ static GParamSpec *properties [N_PROPS];
static guint signals [N_SIGNALS];
static void
+ide_layout_grid_cull (IdeLayoutGrid *self)
+{
+ guint n_columns;
+
+ g_assert (IDE_IS_LAYOUT_GRID (self));
+
+ n_columns = dzl_multi_paned_get_n_children (DZL_MULTI_PANED (self));
+
+ for (guint i = n_columns; i > 0; i--)
+ {
+ IdeLayoutGridColumn *column;
+ guint n_stacks;
+
+ column = IDE_LAYOUT_GRID_COLUMN (dzl_multi_paned_get_nth_child (DZL_MULTI_PANED (self), i - 1));
+ n_stacks = dzl_multi_paned_get_n_children (DZL_MULTI_PANED (column));
+
+ if (n_columns == 1 && n_stacks == 1)
+ return;
+
+ for (guint j = n_stacks; j > 0; j--)
+ {
+ IdeLayoutStack *stack;
+ guint n_items;
+
+ stack = IDE_LAYOUT_STACK (dzl_multi_paned_get_nth_child (DZL_MULTI_PANED (column), j - 1));
+ n_items = g_list_model_get_n_items (G_LIST_MODEL (stack));
+
+ if (n_items == 0)
+ gtk_widget_destroy (GTK_WIDGET (stack));
+ }
+
+ if (dzl_multi_paned_get_n_children (DZL_MULTI_PANED (column)) == 0)
+ gtk_widget_destroy (GTK_WIDGET (column));
+ }
+}
+
+static gboolean
+ide_layout_grid_do_cull (gpointer data)
+{
+ IdeLayoutGrid *self = data;
+ IdeLayoutGridPrivate *priv = ide_layout_grid_get_instance_private (self);
+
+ g_assert (IDE_IS_LAYOUT_GRID (self));
+
+ priv->cull_source = 0;
+
+ ide_layout_grid_cull (self);
+
+ return G_SOURCE_REMOVE;
+}
+
+static void
+ide_layout_grid_queue_cull (IdeLayoutGrid *self)
+{
+ IdeLayoutGridPrivate *priv = ide_layout_grid_get_instance_private (self);
+
+ g_assert (IDE_IS_LAYOUT_GRID (self));
+
+ if (priv->cull_source != 0)
+ return;
+
+ priv->cull_source = gdk_threads_add_idle_full (G_PRIORITY_HIGH,
+ ide_layout_grid_do_cull,
+ g_object_ref (self),
+ g_object_unref);
+}
+
+static void
ide_layout_grid_update_actions (IdeLayoutGrid *self)
{
guint n_children;
@@ -663,6 +737,17 @@ ide_layout_grid_grab_focus (GtkWidget *widget)
}
static void
+ide_layout_grid_destroy (GtkWidget *widget)
+{
+ IdeLayoutGrid *self = (IdeLayoutGrid *)widget;
+ IdeLayoutGridPrivate *priv = ide_layout_grid_get_instance_private (self);
+
+ dzl_clear_source (&priv->cull_source);
+
+ GTK_WIDGET_CLASS (ide_layout_grid_parent_class)->destroy (widget);
+}
+
+static void
ide_layout_grid_finalize (GObject *object)
{
IdeLayoutGrid *self = (IdeLayoutGrid *)object;
@@ -732,6 +817,7 @@ ide_layout_grid_class_init (IdeLayoutGridClass *klass)
object_class->get_property = ide_layout_grid_get_property;
object_class->set_property = ide_layout_grid_set_property;
+ widget_class->destroy = ide_layout_grid_destroy;
widget_class->drag_data_received = ide_layout_grid_drag_data_received;
widget_class->drag_motion = ide_layout_grid_drag_motion;
widget_class->drag_leave = ide_layout_grid_drag_leave;
@@ -1243,6 +1329,8 @@ ide_layout_grid_stack_items_changed (IdeLayoutGrid *self,
ide_object_notify_in_main (G_OBJECT (self), properties [PROP_CURRENT_VIEW]);
+ ide_layout_grid_queue_cull (self);
+
return;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]