[gnome-builder/wip/gtk4-port: 338/736] libide/gui: add API to get most recent workspace frame




commit 4662fb8b72ff34721495fb611753938910177b89
Author: Christian Hergert <chergert redhat com>
Date:   Sat Apr 2 02:16:02 2022 -0700

    libide/gui: add API to get most recent workspace frame

 src/libide/gui/ide-primary-workspace.c | 11 +++++++
 src/libide/gui/ide-workspace.c         | 31 +++++++++++++++++++
 src/libide/gui/ide-workspace.h         | 54 ++++++++++++++++++----------------
 3 files changed, 71 insertions(+), 25 deletions(-)
---
diff --git a/src/libide/gui/ide-primary-workspace.c b/src/libide/gui/ide-primary-workspace.c
index 1e46e7e72..9ad1353f1 100644
--- a/src/libide/gui/ide-primary-workspace.c
+++ b/src/libide/gui/ide-primary-workspace.c
@@ -195,6 +195,16 @@ ide_primary_workspace_add_pane (IdeWorkspace     *workspace,
     }
 }
 
+static IdeFrame *
+ide_primary_workspace_get_most_recent_frame (IdeWorkspace *workspace)
+{
+  IdePrimaryWorkspace *self = (IdePrimaryWorkspace *)workspace;
+
+  g_assert (IDE_IS_PRIMARY_WORKSPACE (self));
+
+  return IDE_FRAME (panel_grid_get_most_recent_frame (PANEL_GRID (self->grid)));
+}
+
 static void
 ide_primary_workspace_class_init (IdePrimaryWorkspaceClass *klass)
 {
@@ -206,6 +216,7 @@ ide_primary_workspace_class_init (IdePrimaryWorkspaceClass *klass)
   workspace_class->context_set = ide_primary_workspace_context_set;
   workspace_class->add_page = ide_primary_workspace_add_page;
   workspace_class->add_pane = ide_primary_workspace_add_pane;
+  workspace_class->get_most_recent_frame = ide_primary_workspace_get_most_recent_frame;
 
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/libide-gui/ui/ide-primary-workspace.ui");
   gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, add_button);
diff --git a/src/libide/gui/ide-workspace.c b/src/libide/gui/ide-workspace.c
index f27eb6538..dce5380ca 100644
--- a/src/libide/gui/ide-workspace.c
+++ b/src/libide/gui/ide-workspace.c
@@ -415,6 +415,20 @@ ide_workspace_realize (GtkWidget *widget)
     gtk_window_maximize (GTK_WINDOW (self));
 }
 
+static IdeFrame *
+ide_workspace_real_get_most_recent_frame (IdeWorkspace *self)
+{
+  IdePage *page;
+
+  g_assert (IDE_IS_WORKSPACE (self));
+
+  if (!(page = ide_workspace_get_most_recent_page (self)))
+    return NULL;
+
+  return IDE_FRAME (gtk_widget_get_ancestor (GTK_WIDGET (page), IDE_TYPE_FRAME));
+
+}
+
 static void
 ide_workspace_dispose (GObject *object)
 {
@@ -498,6 +512,7 @@ ide_workspace_class_init (IdeWorkspaceClass *klass)
   klass->agree_to_close_finish = ide_workspace_agree_to_close_finish;
   klass->restore_size = ide_workspace_restore_size;
   klass->save_size = ide_workspace_save_size;
+  klass->get_most_recent_frame = ide_workspace_real_get_most_recent_frame;
 
   /**
    * IdeWorkspace:context:
@@ -685,6 +700,22 @@ ide_workspace_get_most_recent_page (IdeWorkspace *self)
   return NULL;
 }
 
+/**
+ * ide_workspace_get_most_recent_frame:
+ * @self: a #IdeWorkspace
+ *
+ * Gets the most recently selected frame.
+ *
+ * Returns: (transfer none) (nullable): an #IdeFrame or %NULL
+ */
+IdeFrame *
+ide_workspace_get_most_recent_frame (IdeWorkspace *self)
+{
+  g_return_val_if_fail (IDE_IS_WORKSPACE (self), NULL);
+
+  return IDE_WORKSPACE_GET_CLASS (self)->get_most_recent_frame (self);
+}
+
 void
 _ide_workspace_add_page_mru (IdeWorkspace *self,
                              GList        *mru_link)
diff --git a/src/libide/gui/ide-workspace.h b/src/libide/gui/ide-workspace.h
index 529fe5d0d..c79d5641e 100644
--- a/src/libide/gui/ide-workspace.h
+++ b/src/libide/gui/ide-workspace.h
@@ -29,6 +29,7 @@
 #include <libide-core.h>
 #include <libide-projects.h>
 
+#include "ide-frame.h"
 #include "ide-header-bar.h"
 #include "ide-page.h"
 #include "ide-pane.h"
@@ -50,31 +51,32 @@ struct _IdeWorkspaceClass
 
   const gchar *kind;
 
-  void     (*context_set)           (IdeWorkspace         *self,
-                                     IdeContext           *context);
-  void     (*foreach_page)          (IdeWorkspace         *self,
-                                     IdePageCallback       callback,
-                                     gpointer              user_data);
-  IdePage *(*get_most_recent_page)  (IdeWorkspace         *self);
-  void     (*agree_to_close_async)  (IdeWorkspace         *self,
-                                     GCancellable         *cancellable,
-                                     GAsyncReadyCallback   callback,
-                                     gpointer              user_data);
-  gboolean (*agree_to_close_finish) (IdeWorkspace         *self,
-                                     GAsyncResult         *result,
-                                     GError              **error);
-  void     (*add_pane)              (IdeWorkspace         *self,
-                                     IdePane              *pane,
-                                     IdePanelPosition     *position);
-  void     (*add_page)              (IdeWorkspace         *self,
-                                     IdePage              *page,
-                                     IdePanelPosition     *position);
-  void     (*restore_size)          (IdeWorkspace         *self,
-                                     int                   width,
-                                     int                   height);
-  gboolean (*save_size)             (IdeWorkspace         *self,
-                                     int                  *width,
-                                     int                  *height);
+  void      (*context_set)           (IdeWorkspace         *self,
+                                      IdeContext           *context);
+  void      (*foreach_page)          (IdeWorkspace         *self,
+                                      IdePageCallback       callback,
+                                      gpointer              user_data);
+  IdePage  *(*get_most_recent_page)  (IdeWorkspace         *self);
+  IdeFrame *(*get_most_recent_frame) (IdeWorkspace         *self);
+  void      (*agree_to_close_async)  (IdeWorkspace         *self,
+                                      GCancellable         *cancellable,
+                                      GAsyncReadyCallback   callback,
+                                      gpointer              user_data);
+  gboolean  (*agree_to_close_finish) (IdeWorkspace         *self,
+                                      GAsyncResult         *result,
+                                      GError              **error);
+  void      (*add_pane)              (IdeWorkspace         *self,
+                                      IdePane              *pane,
+                                      IdePanelPosition     *position);
+  void      (*add_page)              (IdeWorkspace         *self,
+                                      IdePage              *page,
+                                      IdePanelPosition     *position);
+  void      (*restore_size)          (IdeWorkspace         *self,
+                                      int                   width,
+                                      int                   height);
+  gboolean  (*save_size)             (IdeWorkspace         *self,
+                                      int                  *width,
+                                      int                  *height);
 };
 
 IDE_AVAILABLE_IN_ALL
@@ -93,6 +95,8 @@ void          ide_workspace_foreach_page             (IdeWorkspace      *self,
 IDE_AVAILABLE_IN_ALL
 IdePage      *ide_workspace_get_most_recent_page     (IdeWorkspace      *self);
 IDE_AVAILABLE_IN_ALL
+IdeFrame     *ide_workspace_get_most_recent_frame    (IdeWorkspace      *self);
+IDE_AVAILABLE_IN_ALL
 void          ide_workspace_add_pane                 (IdeWorkspace      *self,
                                                       IdePane           *pane,
                                                       IdePanelPosition  *position);


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