[gnome-builder/wip/gtk4-port: 591/1774] libide/gui: add observation page helpers




commit 631ce67817e0ae960d8c43d7029bf56267e74fb7
Author: Christian Hergert <chergert redhat com>
Date:   Mon Apr 18 06:20:49 2022 -0700

    libide/gui: add observation page helpers
    
    Same as for IdePane, but for pages. More useful for transient pages that
    you don't care if the user can save or not when shutting down.

 src/libide/gui/ide-page.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++
 src/libide/gui/ide-page.h | 10 ++++++++++
 2 files changed, 60 insertions(+)
---
diff --git a/src/libide/gui/ide-page.c b/src/libide/gui/ide-page.c
index 89cb30be1..5eb630cf9 100644
--- a/src/libide/gui/ide-page.c
+++ b/src/libide/gui/ide-page.c
@@ -599,3 +599,53 @@ ide_page_get_position (IdePage *self)
 
   return position;
 }
+
+void
+ide_page_destroy (IdePage *self)
+{
+  GtkWidget *frame;
+
+  g_return_if_fail (IDE_IS_PAGE (self));
+
+  if ((frame = gtk_widget_get_ancestor (GTK_WIDGET (self), PANEL_TYPE_FRAME)))
+    panel_frame_remove (PANEL_FRAME (frame), PANEL_WIDGET (self));
+}
+
+void
+ide_page_observe (IdePage  *self,
+                  IdePage **location)
+{
+  g_return_if_fail (IDE_IS_PAGE (self));
+  g_return_if_fail (location != NULL);
+
+  *location = self;
+  g_signal_connect_swapped (self,
+                            "destroyed",
+                            G_CALLBACK (g_nullify_pointer),
+                            location);
+}
+
+void
+ide_page_unobserve (IdePage  *self,
+                    IdePage **location)
+{
+  g_return_if_fail (IDE_IS_PAGE (self));
+  g_return_if_fail (location != NULL);
+
+  g_signal_handlers_disconnect_by_func (self,
+                                        G_CALLBACK (g_nullify_pointer),
+                                        location);
+  *location = NULL;
+}
+
+void
+ide_clear_page (IdePage **location)
+{
+  IdePage *self = *location;
+
+  if (self == NULL)
+    return;
+
+  ide_page_unobserve (self, location);
+  ide_page_destroy (self);
+}
diff --git a/src/libide/gui/ide-page.h b/src/libide/gui/ide-page.h
index b708a163e..b462d1121 100644
--- a/src/libide/gui/ide-page.h
+++ b/src/libide/gui/ide-page.h
@@ -97,5 +97,15 @@ void              ide_page_set_progress          (IdePage              *self,
                                                   IdeNotification      *notification);
 IDE_AVAILABLE_IN_ALL
 IdePanelPosition *ide_page_get_position          (IdePage              *self);
+IDE_AVAILABLE_IN_ALL
+void              ide_page_observe               (IdePage              *self,
+                                                  IdePage             **location);
+IDE_AVAILABLE_IN_ALL
+void              ide_page_unobserve             (IdePage              *self,
+                                                  IdePage             **location);
+IDE_AVAILABLE_IN_ALL
+void              ide_page_destroy               (IdePage              *self);
+IDE_AVAILABLE_IN_ALL
+void              ide_clear_page                 (IdePage             **location);
 
 G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]