[gnome-builder/wip/gtk4-port: 310/736] libide/gui: add helper to add page to workspace




commit 6fe781ead7bd47f113b38ea596f856fe401b1057
Author: Christian Hergert <chergert redhat com>
Date:   Fri Apr 1 01:53:52 2022 -0700

    libide/gui: add helper to add page to workspace

 src/libide/gui/ide-primary-workspace.c  | 52 +++++++++++++++++++++++++++++++--
 src/libide/gui/ide-primary-workspace.ui |  2 +-
 src/libide/gui/ide-workspace.c          | 17 ++++++++++-
 src/libide/gui/ide-workspace.h          |  7 +++++
 4 files changed, 73 insertions(+), 5 deletions(-)
---
diff --git a/src/libide/gui/ide-primary-workspace.c b/src/libide/gui/ide-primary-workspace.c
index 288c3c5a9..1e46e7e72 100644
--- a/src/libide/gui/ide-primary-workspace.c
+++ b/src/libide/gui/ide-primary-workspace.c
@@ -58,6 +58,7 @@ struct _IdePrimaryWorkspace
   PanelPaned         *edge_start;
   PanelPaned         *edge_end;
   PanelPaned         *edge_bottom;
+  IdeGrid            *grid;
 };
 
 G_DEFINE_FINAL_TYPE (IdePrimaryWorkspace, ide_primary_workspace, IDE_TYPE_WORKSPACE)
@@ -85,6 +86,49 @@ ide_primary_workspace_context_set (IdeWorkspace *workspace,
                             G_BINDING_SYNC_CREATE);
 }
 
+static void
+ide_primary_workspace_add_page (IdeWorkspace     *workspace,
+                                IdePage          *page,
+                                IdePanelPosition *position)
+{
+  IdePrimaryWorkspace *self = (IdePrimaryWorkspace *)workspace;
+  PanelFrame *frame;
+  PanelDockPosition edge;
+  guint column;
+  guint row;
+
+  g_assert (IDE_IS_PRIMARY_WORKSPACE (self));
+  g_assert (IDE_IS_PAGE (page));
+  g_assert (position != NULL);
+
+  ide_panel_position_get_edge (position, &edge);
+
+  switch (edge)
+    {
+    case PANEL_DOCK_POSITION_START:
+    case PANEL_DOCK_POSITION_END:
+    case PANEL_DOCK_POSITION_BOTTOM:
+    case PANEL_DOCK_POSITION_TOP:
+    default:
+      g_warning ("Primary workspace only supports center position");
+      return;
+
+    case PANEL_DOCK_POSITION_CENTER:
+      break;
+    }
+
+  if (!ide_panel_position_get_column (position, &column))
+    column = 0;
+
+  if (!ide_panel_position_get_row (position, &row))
+    row = 0;
+
+  frame = panel_grid_column_get_row (panel_grid_get_column (PANEL_GRID (self->grid), column), row);
+
+  /* TODO: Handle depth */
+  panel_frame_add (frame, PANEL_WIDGET (page));
+}
+
 static void
 ide_primary_workspace_add_pane (IdeWorkspace     *workspace,
                                 IdePane          *pane,
@@ -160,16 +204,18 @@ ide_primary_workspace_class_init (IdePrimaryWorkspaceClass *klass)
   ide_workspace_class_set_kind (workspace_class, "primary");
 
   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;
 
   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);
+  gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, edge_bottom);
+  gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, edge_end);
+  gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, edge_start);
+  gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, grid);
   gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, header_bar);
   gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, project_title);
   gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, run_button);
-  gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, edge_start);
-  gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, edge_end);
-  gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, edge_bottom);
 
   g_type_ensure (IDE_TYPE_GRID);
   g_type_ensure (IDE_TYPE_NOTIFICATIONS_BUTTON);
diff --git a/src/libide/gui/ide-primary-workspace.ui b/src/libide/gui/ide-primary-workspace.ui
index bbf7e4a7b..ab550e306 100644
--- a/src/libide/gui/ide-primary-workspace.ui
+++ b/src/libide/gui/ide-primary-workspace.ui
@@ -62,7 +62,7 @@
         <property name="reveal-start">true</property>
         <property name="vexpand">true</property>
         <child type="center">
-          <object class="IdeGrid">
+          <object class="IdeGrid" id="grid">
           </object>
         </child>
         <child type="start">
diff --git a/src/libide/gui/ide-workspace.c b/src/libide/gui/ide-workspace.c
index 8f6241f73..8e44984bf 100644
--- a/src/libide/gui/ide-workspace.c
+++ b/src/libide/gui/ide-workspace.c
@@ -692,6 +692,22 @@ ide_workspace_addin_find_by_module_name (IdeWorkspace *workspace,
   return IDE_WORKSPACE_ADDIN (ret);
 }
 
+void
+ide_workspace_add_page (IdeWorkspace     *self,
+                        IdePage          *page,
+                        IdePanelPosition *position)
+{
+  g_return_if_fail (IDE_IS_WORKSPACE (self));
+  g_return_if_fail (IDE_IS_PAGE (page));
+  g_return_if_fail (position != NULL);
+
+  if (IDE_WORKSPACE_GET_CLASS (self)->add_page)
+    IDE_WORKSPACE_GET_CLASS (self)->add_page (self, page, position);
+  else
+    g_critical ("%s does not support adding pages",
+                G_OBJECT_TYPE_NAME (self));
+}
+
 void
 ide_workspace_add_pane (IdeWorkspace     *self,
                         IdePane          *pane,
@@ -706,7 +722,6 @@ ide_workspace_add_pane (IdeWorkspace     *self,
   else
     g_critical ("%s does not support adding panels",
                 G_OBJECT_TYPE_NAME (self));
-
 }
 
 static void
diff --git a/src/libide/gui/ide-workspace.h b/src/libide/gui/ide-workspace.h
index 541dc0f4d..529fe5d0d 100644
--- a/src/libide/gui/ide-workspace.h
+++ b/src/libide/gui/ide-workspace.h
@@ -66,6 +66,9 @@ struct _IdeWorkspaceClass
   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);
@@ -93,5 +96,9 @@ IDE_AVAILABLE_IN_ALL
 void          ide_workspace_add_pane                 (IdeWorkspace      *self,
                                                       IdePane           *pane,
                                                       IdePanelPosition  *position);
+IDE_AVAILABLE_IN_ALL
+void          ide_workspace_add_page                 (IdeWorkspace      *self,
+                                                      IdePage           *pane,
+                                                      IdePanelPosition  *position);
 
 G_END_DECLS


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