[gnome-builder/wip/gtk4-port] libide/gui: add API to add panels to workspace



commit e7973580708c1910eddfa4410192e3610ddeeeb6
Author: Christian Hergert <chergert redhat com>
Date:   Wed Mar 30 01:31:56 2022 -0700

    libide/gui: add API to add panels to workspace

 src/libide/gui/ide-panel-position.c | 137 ++++++++++++++++++++++++++++++++++++
 src/libide/gui/ide-panel-position.h |  64 +++++++++++++++++
 src/libide/gui/ide-workspace.c      |  17 +++++
 src/libide/gui/ide-workspace.h      |   9 +++
 src/libide/gui/libide-gui.h         |   1 +
 src/libide/gui/meson.build          |   2 +
 6 files changed, 230 insertions(+)
---
diff --git a/src/libide/gui/ide-panel-position.c b/src/libide/gui/ide-panel-position.c
new file mode 100644
index 000000000..34f29b485
--- /dev/null
+++ b/src/libide/gui/ide-panel-position.c
@@ -0,0 +1,137 @@
+/* ide-panel-position.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "ide-panel-position"
+
+#include "config.h"
+
+#include "ide-panel-position.h"
+
+struct _IdePanelPosition
+{
+  guint column : 8;
+  guint row : 8;
+  guint depth : 9;
+  PanelDockPosition edge : 3;
+  guint column_set : 1;
+  guint row_set : 1;
+  guint depth_set : 1;
+  guint edge_set : 1;
+};
+
+IdePanelPosition *
+ide_panel_position_new (void)
+{
+  return g_slice_new0 (IdePanelPosition);
+}
+
+void
+ide_panel_position_free (IdePanelPosition *self)
+{
+  g_slice_free (IdePanelPosition, self);
+}
+
+gboolean
+ide_panel_position_get_edge (IdePanelPosition  *self,
+                             PanelDockPosition *edge)
+{
+  g_return_val_if_fail (self != NULL, FALSE);
+
+  if (edge != NULL)
+    *edge = self->edge;
+
+  return self->edge_set;
+}
+
+void
+ide_panel_position_set_edge (IdePanelPosition  *self,
+                             PanelDockPosition  edge)
+{
+  g_return_if_fail (self != NULL);
+
+  self->edge = edge;
+  self->edge_set = TRUE;
+}
+
+gboolean
+ide_panel_position_get_column (IdePanelPosition *self,
+                               guint            *column)
+{
+  g_return_val_if_fail (self != NULL, FALSE);
+
+  if (column != NULL)
+    *column = self->column;
+
+  return self->column_set;
+}
+
+void
+ide_panel_position_set_column (IdePanelPosition *self,
+                               guint             column)
+{
+  g_return_if_fail (self != NULL);
+
+  self->column = column;
+  self->column_set = TRUE;
+}
+
+gboolean
+ide_panel_position_get_row (IdePanelPosition *self,
+                            guint            *row)
+{
+  g_return_val_if_fail (self != NULL, FALSE);
+
+  if (row != NULL)
+    *row = self->row;
+
+  return self->row_set;
+}
+
+void
+ide_panel_position_set_row (IdePanelPosition *self,
+                            guint             row)
+{
+  g_return_if_fail (self != NULL);
+
+  self->row = row;
+  self->row_set = TRUE;
+}
+
+gboolean
+ide_panel_position_get_depth (IdePanelPosition *self,
+                              guint            *depth)
+{
+  g_return_val_if_fail (self != NULL, FALSE);
+
+  if (depth != NULL)
+    *depth = self->depth;
+
+  return self->depth_set;
+}
+
+void
+ide_panel_position_set_depth (IdePanelPosition *self,
+                              guint             depth)
+{
+  g_return_if_fail (self != NULL);
+
+  self->depth = depth;
+  self->depth_set = TRUE;
+}
diff --git a/src/libide/gui/ide-panel-position.h b/src/libide/gui/ide-panel-position.h
new file mode 100644
index 000000000..b60181cf0
--- /dev/null
+++ b/src/libide/gui/ide-panel-position.h
@@ -0,0 +1,64 @@
+/* ide-panel-position.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#if !defined (IDE_GUI_INSIDE) && !defined (IDE_GUI_COMPILATION)
+# error "Only <libide-gui.h> can be included directly."
+#endif
+
+#include <libpanel.h>
+
+#include <libide-core.h>
+
+G_BEGIN_DECLS
+
+typedef struct _IdePanelPosition IdePanelPosition;
+
+IDE_AVAILABLE_IN_ALL
+IdePanelPosition *ide_panel_position_new        (void);
+IDE_AVAILABLE_IN_ALL
+void              ide_panel_position_free       (IdePanelPosition  *self);
+IDE_AVAILABLE_IN_ALL
+gboolean          ide_panel_position_get_edge   (IdePanelPosition  *self,
+                                                 PanelDockPosition *edge);
+IDE_AVAILABLE_IN_ALL
+void              ide_panel_position_set_edge   (IdePanelPosition  *self,
+                                                 PanelDockPosition  edge);
+IDE_AVAILABLE_IN_ALL
+gboolean          ide_panel_position_get_row    (IdePanelPosition  *self,
+                                                 guint             *row);
+IDE_AVAILABLE_IN_ALL
+void              ide_panel_position_set_row    (IdePanelPosition  *self,
+                                                 guint              row);
+IDE_AVAILABLE_IN_ALL
+gboolean          ide_panel_position_get_column (IdePanelPosition  *self,
+                                                 guint             *column);
+IDE_AVAILABLE_IN_ALL
+void              ide_panel_position_set_column (IdePanelPosition  *self,
+                                                 guint              column);
+IDE_AVAILABLE_IN_ALL
+gboolean          ide_panel_position_get_depth  (IdePanelPosition  *self,
+                                                 guint             *depth);
+IDE_AVAILABLE_IN_ALL
+void              ide_panel_position_set_depth  (IdePanelPosition  *self,
+                                                 guint              depth);
+
+G_END_DECLS
diff --git a/src/libide/gui/ide-workspace.c b/src/libide/gui/ide-workspace.c
index 4685e40b7..33dee41fe 100644
--- a/src/libide/gui/ide-workspace.c
+++ b/src/libide/gui/ide-workspace.c
@@ -662,6 +662,23 @@ ide_workspace_addin_find_by_module_name (IdeWorkspace *workspace,
   return IDE_WORKSPACE_ADDIN (ret);
 }
 
+void
+ide_workspace_add_pane (IdeWorkspace     *self,
+                        IdePane          *pane,
+                        IdePanelPosition *position)
+{
+  g_return_if_fail (IDE_IS_WORKSPACE (self));
+  g_return_if_fail (IDE_IS_PANE (pane));
+  g_return_if_fail (position != NULL);
+
+  if (IDE_WORKSPACE_GET_CLASS (self)->add_pane)
+    IDE_WORKSPACE_GET_CLASS (self)->add_pane (self, pane, position);
+  else
+    g_critical ("%s does not support adding panels",
+                G_OBJECT_TYPE_NAME (self));
+
+}
+
 static void
 ide_workspace_add_child (GtkBuildable *buildable,
                          GtkBuilder   *builder,
diff --git a/src/libide/gui/ide-workspace.h b/src/libide/gui/ide-workspace.h
index e6fd3ff6a..a536ea66c 100644
--- a/src/libide/gui/ide-workspace.h
+++ b/src/libide/gui/ide-workspace.h
@@ -31,6 +31,8 @@
 
 #include "ide-header-bar.h"
 #include "ide-page.h"
+#include "ide-pane.h"
+#include "ide-panel-position.h"
 
 G_BEGIN_DECLS
 
@@ -61,6 +63,9 @@ struct _IdeWorkspaceClass
   gboolean (*agree_to_close_finish) (IdeWorkspace         *self,
                                      GAsyncResult         *result,
                                      GError              **error);
+  void     (*add_pane)              (IdeWorkspace         *self,
+                                     IdePane              *pane,
+                                     IdePanelPosition     *position);
 
   /*< private >*/
   gpointer _reserved[8];
@@ -81,5 +86,9 @@ void          ide_workspace_foreach_page             (IdeWorkspace      *self,
                                                       gpointer           user_data);
 IDE_AVAILABLE_IN_ALL
 IdePage      *ide_workspace_get_most_recent_page     (IdeWorkspace      *self);
+IDE_AVAILABLE_IN_ALL
+void          ide_workspace_add_pane                 (IdeWorkspace      *self,
+                                                      IdePane           *pane,
+                                                      IdePanelPosition  *position);
 
 G_END_DECLS
diff --git a/src/libide/gui/libide-gui.h b/src/libide/gui/libide-gui.h
index 38030fa78..4bf7d818c 100644
--- a/src/libide/gui/libide-gui.h
+++ b/src/libide/gui/libide-gui.h
@@ -45,6 +45,7 @@
 # include "ide-omni-bar.h"
 # include "ide-page.h"
 # include "ide-pane.h"
+# include "ide-panel-position.h"
 # include "ide-preferences-addin.h"
 # include "ide-preferences-window.h"
 # include "ide-primary-workspace.h"
diff --git a/src/libide/gui/meson.build b/src/libide/gui/meson.build
index 2a9bc1025..0f9f1d9e2 100644
--- a/src/libide/gui/meson.build
+++ b/src/libide/gui/meson.build
@@ -22,6 +22,7 @@ libide_gui_public_headers = [
   'ide-omni-bar.h',
   'ide-page.h',
   'ide-pane.h',
+  'ide-panel-position.h',
   'ide-preferences-addin.h',
   'ide-preferences-window.h',
   'ide-primary-workspace.h',
@@ -83,6 +84,7 @@ libide_gui_public_sources = [
   'ide-omni-bar.c',
   'ide-page.c',
   'ide-pane.c',
+  'ide-panel-position.c',
   'ide-primary-workspace.c',
   'ide-preferences-addin.c',
   'ide-preferences-window.c',


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