[gnome-builder/wip/gtk4-port: 511/736] libide/gui: add helper to get page position




commit 6eafbcf325bd9c698cf40f1fc84d6df84566e5d9
Author: Christian Hergert <chergert redhat com>
Date:   Thu Apr 7 14:45:55 2022 -0700

    libide/gui: add helper to get page position

 src/libide/gui/ide-page.c | 40 ++++++++++++++++++++++++++++++++++++
 src/libide/gui/ide-page.h | 52 +++++++++++++++++++++++++----------------------
 2 files changed, 68 insertions(+), 24 deletions(-)
---
diff --git a/src/libide/gui/ide-page.c b/src/libide/gui/ide-page.c
index eec130d86..89cb30be1 100644
--- a/src/libide/gui/ide-page.c
+++ b/src/libide/gui/ide-page.c
@@ -559,3 +559,43 @@ ide_page_set_progress (IdePage         *self,
                           priv->progress_bar, "fraction",
                           G_BINDING_SYNC_CREATE);
 }
+
+/**
+ * ide_page_get_position:
+ * @self: a #IdePage
+ *
+ * Gets the position of a page within the workspace.
+ *
+ * Returns: (transfer full) (nullable): an #IdePanelPosition or %NULL
+ *   if the page is not rooted.
+ */
+IdePanelPosition *
+ide_page_get_position (IdePage *self)
+{
+  IdePanelPosition *position;
+  GtkWidget *frame;
+  guint n_pages;
+
+  g_return_val_if_fail (IDE_IS_PAGE (self), NULL);
+
+  if (!(frame = gtk_widget_get_ancestor (GTK_WIDGET (self), IDE_TYPE_FRAME)))
+    return NULL;
+
+  if (!(position = ide_frame_get_position (IDE_FRAME (frame))))
+    return NULL;
+
+  n_pages = panel_frame_get_n_pages (PANEL_FRAME (frame));
+
+  for (guint i = 0; i < n_pages; i++)
+    {
+      if (panel_frame_get_page (PANEL_FRAME (frame), i) == PANEL_WIDGET (self))
+        {
+          ide_panel_position_set_depth (position, i);
+          return position;
+        }
+    }
+
+  g_critical ("Failed to find page within frame");
+
+  return position;
+}
diff --git a/src/libide/gui/ide-page.h b/src/libide/gui/ide-page.h
index 427c32049..b708a163e 100644
--- a/src/libide/gui/ide-page.h
+++ b/src/libide/gui/ide-page.h
@@ -28,6 +28,8 @@
 
 #include <libide-core.h>
 
+#include "ide-panel-position.h"
+
 G_BEGIN_DECLS
 
 #define IDE_TYPE_PAGE (ide_page_get_type())
@@ -57,41 +59,43 @@ struct _IdePageClass
 };
 
 IDE_AVAILABLE_IN_ALL
-gboolean       ide_page_get_can_split         (IdePage              *self);
+gboolean          ide_page_get_can_split         (IdePage              *self);
+IDE_AVAILABLE_IN_ALL
+void              ide_page_set_can_split         (IdePage              *self,
+                                                  gboolean              can_split);
 IDE_AVAILABLE_IN_ALL
-void           ide_page_set_can_split         (IdePage              *self,
-                                               gboolean              can_split);
+IdePage          *ide_page_create_split          (IdePage              *self);
 IDE_AVAILABLE_IN_ALL
-IdePage       *ide_page_create_split          (IdePage              *self);
+gboolean          ide_page_get_failed            (IdePage              *self);
 IDE_AVAILABLE_IN_ALL
-gboolean       ide_page_get_failed            (IdePage              *self);
+void              ide_page_set_failed            (IdePage              *self,
+                                                  gboolean              failed);
 IDE_AVAILABLE_IN_ALL
-void           ide_page_set_failed            (IdePage              *self,
-                                               gboolean              failed);
+const gchar      *ide_page_get_menu_id           (IdePage              *self);
 IDE_AVAILABLE_IN_ALL
-const gchar   *ide_page_get_menu_id           (IdePage              *self);
+void              ide_page_set_menu_id           (IdePage              *self,
+                                                  const gchar          *menu_id);
 IDE_AVAILABLE_IN_ALL
-void           ide_page_set_menu_id           (IdePage              *self,
-                                               const gchar          *menu_id);
+void              ide_page_agree_to_close_async  (IdePage              *self,
+                                                  GCancellable         *cancellable,
+                                                  GAsyncReadyCallback   callback,
+                                                  gpointer              user_data);
 IDE_AVAILABLE_IN_ALL
-void           ide_page_agree_to_close_async  (IdePage              *self,
-                                               GCancellable         *cancellable,
-                                               GAsyncReadyCallback   callback,
-                                               gpointer              user_data);
+gboolean          ide_page_agree_to_close_finish (IdePage              *self,
+                                                  GAsyncResult         *result,
+                                                  GError              **error);
 IDE_AVAILABLE_IN_ALL
-gboolean       ide_page_agree_to_close_finish (IdePage              *self,
-                                               GAsyncResult         *result,
-                                               GError              **error);
+void              ide_page_mark_used             (IdePage              *self);
 IDE_AVAILABLE_IN_ALL
-void           ide_page_mark_used             (IdePage              *self);
+void              ide_page_report_error          (IdePage              *self,
+                                                  const gchar          *format,
+                                                  ...) G_GNUC_PRINTF (2, 3);
 IDE_AVAILABLE_IN_ALL
-void           ide_page_report_error          (IdePage              *self,
-                                               const gchar          *format,
-                                               ...) G_GNUC_PRINTF (2, 3);
+GFile            *ide_page_get_file_or_directory (IdePage              *self);
 IDE_AVAILABLE_IN_ALL
-GFile         *ide_page_get_file_or_directory (IdePage              *self);
+void              ide_page_set_progress          (IdePage              *self,
+                                                  IdeNotification      *notification);
 IDE_AVAILABLE_IN_ALL
-void           ide_page_set_progress          (IdePage              *self,
-                                               IdeNotification      *notification);
+IdePanelPosition *ide_page_get_position          (IdePage              *self);
 
 G_END_DECLS


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