[gnome-builder/wip/gtk4-port: 126/1774] libide/gui: incremental work on porting grid to libpanel
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 126/1774] libide/gui: incremental work on porting grid to libpanel
- Date: Mon, 11 Jul 2022 22:30:57 +0000 (UTC)
commit 2d37ea7aa8b47ece1f391b01bf5cfa184017b453
Author: Christian Hergert <chergert redhat com>
Date: Mon Mar 28 20:10:43 2022 -0700
libide/gui: incremental work on porting grid to libpanel
src/libide/gui/ide-frame.c | 29 --------
src/libide/gui/ide-frame.h | 6 +-
src/libide/gui/ide-grid.c | 137 +++++++++++++++++++++++++++++++++++
src/libide/gui/ide-grid.h | 61 ++++++++++++++++
src/libide/gui/ide-page.h | 3 -
src/libide/gui/ide-session-addin.c | 12 ---
src/libide/gui/ide-session-addin.h | 57 ++++++++-------
src/libide/gui/ide-session-private.h | 3 +-
src/libide/gui/ide-session.c | 73 ++++---------------
src/libide/gui/libide-gui.h | 6 +-
src/libide/gui/meson.build | 2 +
11 files changed, 249 insertions(+), 140 deletions(-)
---
diff --git a/src/libide/gui/ide-frame.c b/src/libide/gui/ide-frame.c
index e5cfb97c7..08a371023 100644
--- a/src/libide/gui/ide-frame.c
+++ b/src/libide/gui/ide-frame.c
@@ -200,35 +200,6 @@ ide_frame_new (void)
return g_object_new (IDE_TYPE_FRAME, NULL);
}
-/**
- * ide_frame_foreach_page:
- * @self: a #IdeFrame
- * @callback: (scope call) (closure user_data): A callback for each page
- * @user_data: user data for @callback
- *
- * This function will call @callback for every page found in @self.
- */
-void
-ide_frame_foreach_page (IdeFrame *self,
- IdePageCallback callback,
- gpointer user_data)
-{
- guint n_pages;
-
- g_return_if_fail (IDE_IS_FRAME (self));
- g_return_if_fail (callback != NULL);
-
- n_pages = panel_frame_get_n_pages (PANEL_FRAME (self));
-
- /* Iterate backwards to allow removing of page */
- for (guint i = n_pages; i > 0; i--)
- {
- PanelWidget *widget = panel_frame_get_page (PANEL_FRAME (self), i - 1);
-
- callback (IDE_PAGE (widget), user_data);
- }
-}
-
/**
* ide_frame_addin_find_by_module_name:
* @frame: An #IdeFrame
diff --git a/src/libide/gui/ide-frame.h b/src/libide/gui/ide-frame.h
index 8d8c6a570..69bc349a8 100644
--- a/src/libide/gui/ide-frame.h
+++ b/src/libide/gui/ide-frame.h
@@ -36,10 +36,6 @@ IDE_AVAILABLE_IN_ALL
G_DECLARE_FINAL_TYPE (IdeFrame, ide_frame, IDE, FRAME, PanelFrame)
IDE_AVAILABLE_IN_ALL
-GtkWidget *ide_frame_new (void);
-IDE_AVAILABLE_IN_ALL
-void ide_frame_foreach_page (IdeFrame *self,
- IdePageCallback callback,
- gpointer user_data);
+GtkWidget *ide_frame_new (void);
G_END_DECLS
diff --git a/src/libide/gui/ide-grid.c b/src/libide/gui/ide-grid.c
new file mode 100644
index 000000000..a80b504fb
--- /dev/null
+++ b/src/libide/gui/ide-grid.c
@@ -0,0 +1,137 @@
+/* ide-grid.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-grid"
+
+#include "config.h"
+
+#include "ide-frame.h"
+#include "ide-grid.h"
+
+struct _IdeGrid
+{
+ PanelGrid parent_instance;
+};
+
+typedef struct
+{
+ IdePage *page;
+ guint column;
+ guint row;
+ guint depth;
+} PageInfo;
+
+G_DEFINE_TYPE (IdeGrid, ide_grid, PANEL_TYPE_GRID)
+
+static PanelFrame *
+ide_grid_real_create_frame (PanelGrid *grid)
+{
+ return PANEL_FRAME (ide_frame_new ());
+}
+
+static void
+ide_grid_class_init (IdeGridClass *klass)
+{
+ PanelGridClass *grid_class = PANEL_GRID_CLASS (klass);
+
+ grid_class->create_frame = ide_grid_real_create_frame;
+}
+
+static void
+ide_grid_init (IdeGrid *self)
+{
+}
+
+GtkWidget *
+ide_grid_new (void)
+{
+ return g_object_new (IDE_TYPE_GRID, NULL);
+}
+
+void
+ide_grid_foreach_page (IdeGrid *self,
+ IdePageCallback callback,
+ gpointer user_data)
+{
+ g_autoptr(GArray) pages = NULL;
+ guint n_columns;
+
+ g_return_if_fail (IDE_IS_GRID (self));
+ g_return_if_fail (callback != NULL);
+
+ pages = g_array_new (FALSE, FALSE, sizeof (PageInfo));
+ n_columns = panel_grid_get_n_columns (PANEL_GRID (self));
+
+ for (guint i = 0; i < n_columns; i++)
+ {
+ PanelGridColumn *column = panel_grid_get_column (PANEL_GRID (self), i);
+ guint n_rows = panel_grid_column_get_n_rows (column);
+
+ for (guint j = 0; j < n_rows; j++)
+ {
+ PanelFrame *frame = panel_grid_column_get_row (column, j);
+ guint n_pages = panel_frame_get_n_pages (frame);
+
+ for (guint k = 0; k < n_pages; k++)
+ {
+ PanelWidget *widget = panel_frame_get_page (frame, k);
+
+ if (IDE_IS_PAGE (widget))
+ {
+ PageInfo info = { IDE_PAGE (widget), i, j, k };
+ g_array_append_val (pages, info);
+ }
+ }
+ }
+ }
+
+ for (guint i = 0; i < pages->len; i++)
+ {
+ const PageInfo *info = &g_array_index (pages, PageInfo, i);
+ callback (info->page, info->column, info->row, info->depth, user_data);
+ }
+}
+
+guint
+ide_grid_count_pages (IdeGrid *self)
+{
+ guint count = 0;
+ guint n_columns;
+
+ g_return_val_if_fail (IDE_IS_GRID (self), 0);
+
+ n_columns = panel_grid_get_n_columns (PANEL_GRID (self));
+
+ for (guint i = 0; i < n_columns; i++)
+ {
+ PanelGridColumn *column = panel_grid_get_column (PANEL_GRID (self), i);
+ guint n_rows = panel_grid_column_get_n_rows (column);
+
+ for (guint j = 0; j < n_rows; j++)
+ {
+ PanelFrame *frame = panel_grid_column_get_row (column, j);
+ guint n_pages = panel_frame_get_n_pages (frame);
+
+ count += n_pages;
+ }
+ }
+
+ return count;
+}
diff --git a/src/libide/gui/ide-grid.h b/src/libide/gui/ide-grid.h
new file mode 100644
index 000000000..ea0b4b3fa
--- /dev/null
+++ b/src/libide/gui/ide-grid.h
@@ -0,0 +1,61 @@
+/* ide-grid.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>
+
+#include "ide-page.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_GRID (ide_grid_get_type())
+
+typedef void (*IdePageCallback) (IdePage *page,
+ guint column,
+ guint row,
+ guint depth,
+ gpointer user_data);
+
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (IdeGrid, ide_grid, IDE, GRID, PanelGrid)
+
+IDE_AVAILABLE_IN_ALL
+GtkWidget *ide_grid_new (void);
+IDE_AVAILABLE_IN_ALL
+guint ide_grid_count_pages (IdeGrid *self);
+IDE_AVAILABLE_IN_ALL
+void ide_grid_get_page_position (IdeGrid *self,
+ IdePage *page,
+ guint *column,
+ guint *row,
+ guint *depth);
+IDE_AVAILABLE_IN_ALL
+void ide_grid_foreach_page (IdeGrid *self,
+ IdePageCallback callback,
+ gpointer user_data);
+
+G_END_DECLS
diff --git a/src/libide/gui/ide-page.h b/src/libide/gui/ide-page.h
index 6172fb7bb..939e7d4d0 100644
--- a/src/libide/gui/ide-page.h
+++ b/src/libide/gui/ide-page.h
@@ -35,9 +35,6 @@ G_BEGIN_DECLS
IDE_AVAILABLE_IN_ALL
G_DECLARE_DERIVABLE_TYPE (IdePage, ide_page, IDE, PAGE, PanelWidget)
-typedef void (*IdePageCallback) (IdePage *page,
- gpointer user_data);
-
struct _IdePageClass
{
PanelWidgetClass parent_class;
diff --git a/src/libide/gui/ide-session-addin.c b/src/libide/gui/ide-session-addin.c
index 64d9a86a8..a57bdb89e 100644
--- a/src/libide/gui/ide-session-addin.c
+++ b/src/libide/gui/ide-session-addin.c
@@ -112,8 +112,6 @@ ide_session_addin_default_init (IdeSessionAddinInterface *iface)
*
* The resulting state will be provided when restoring the page
* at a future time with ide_session_addin_restore_page_async().
- *
- * Since: 41
*/
void
ide_session_addin_save_page_async (IdeSessionAddin *self,
@@ -141,8 +139,6 @@ ide_session_addin_save_page_async (IdeSessionAddin *self,
*
* Returns: (transfer full) (nullable): a #GVariant or %NULL if an error prevented
* from saving the page.
- *
- * Since: 41
*/
GVariant *
ide_session_addin_save_page_finish (IdeSessionAddin *self,
@@ -166,8 +162,6 @@ ide_session_addin_save_page_finish (IdeSessionAddin *self,
* Asynchronously requests that addin @self restore a page's session state with
* the provided state, previously saved by this addin using
* ide_session_addin_save_page_async(). This only happens when opening a project.
- *
- * Since: 41
*/
void
ide_session_addin_restore_page_async (IdeSessionAddin *self,
@@ -191,8 +185,6 @@ ide_session_addin_restore_page_async (IdeSessionAddin *self,
*
* Returns: (transfer full) (nullable): the created page for the saved state, or %NULL if an error
* prevented from restoring the page.
- *
- * Since: 41
*/
IdePage *
ide_session_addin_restore_page_finish (IdeSessionAddin *self,
@@ -216,8 +208,6 @@ ide_session_addin_restore_page_finish (IdeSessionAddin *self,
* this @page.
*
* Returns: whether @self supports saving @page.
- *
- * Since: 41
*/
gboolean
ide_session_addin_can_save_page (IdeSessionAddin *self,
@@ -245,8 +235,6 @@ ide_session_addin_can_save_page (IdeSessionAddin *self,
*
* Returns: (array zero-terminated=1) (element-type utf8) (nullable) (transfer full):
* A %NULL terminated array of properties names, or %NULL.
- *
- * Since: 41.0
*/
char **
ide_session_addin_get_autosave_properties (IdeSessionAddin *self)
diff --git a/src/libide/gui/ide-session-addin.h b/src/libide/gui/ide-session-addin.h
index bf313a821..2372c506c 100644
--- a/src/libide/gui/ide-session-addin.h
+++ b/src/libide/gui/ide-session-addin.h
@@ -1,6 +1,6 @@
/* ide-session-addin.h
*
- * Copyright 2018-2019 Christian Hergert <chergert redhat com>
+ * Copyright 2018-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
@@ -25,64 +25,65 @@
#endif
#include <libide-core.h>
-#include <libide-gui.h>
+
+#include "ide-page.h"
G_BEGIN_DECLS
-#define IDE_TYPE_SESSION_ADDIN (ide_session_addin_get_type ())
+#define IDE_TYPE_SESSION_ADDIN (ide_session_addin_get_type())
-IDE_AVAILABLE_IN_41
+IDE_AVAILABLE_IN_ALL
G_DECLARE_INTERFACE (IdeSessionAddin, ide_session_addin, IDE, SESSION_ADDIN, IdeObject)
struct _IdeSessionAddinInterface
{
GTypeInterface parent;
- void (*save_page_async) (IdeSessionAddin *self,
- IdePage *page,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
- GVariant *(*save_page_finish) (IdeSessionAddin *self,
- GAsyncResult *result,
- GError **error);
- void (*restore_page_async) (IdeSessionAddin *self,
- GVariant *state,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
- IdePage *(*restore_page_finish) (IdeSessionAddin *self,
- GAsyncResult *result,
- GError **error);
- gboolean (*can_save_page) (IdeSessionAddin *self,
- IdePage *page);
+ void (*save_page_async) (IdeSessionAddin *self,
+ IdePage *page,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ GVariant *(*save_page_finish) (IdeSessionAddin *self,
+ GAsyncResult *result,
+ GError **error);
+ void (*restore_page_async) (IdeSessionAddin *self,
+ GVariant *state,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ IdePage *(*restore_page_finish) (IdeSessionAddin *self,
+ GAsyncResult *result,
+ GError **error);
+ gboolean (*can_save_page) (IdeSessionAddin *self,
+ IdePage *page);
char **(*get_autosave_properties) (IdeSessionAddin *self);
};
-IDE_AVAILABLE_IN_41
+IDE_AVAILABLE_IN_ALL
void ide_session_addin_save_page_async (IdeSessionAddin *self,
IdePage *page,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
-IDE_AVAILABLE_IN_41
+IDE_AVAILABLE_IN_ALL
GVariant *ide_session_addin_save_page_finish (IdeSessionAddin *self,
GAsyncResult *result,
GError **error);
-IDE_AVAILABLE_IN_41
+IDE_AVAILABLE_IN_ALL
void ide_session_addin_restore_page_async (IdeSessionAddin *self,
GVariant *state,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
-IDE_AVAILABLE_IN_41
+IDE_AVAILABLE_IN_ALL
IdePage *ide_session_addin_restore_page_finish (IdeSessionAddin *self,
GAsyncResult *result,
GError **error);
-IDE_AVAILABLE_IN_41
+IDE_AVAILABLE_IN_ALL
gboolean ide_session_addin_can_save_page (IdeSessionAddin *self,
IdePage *page);
-IDE_AVAILABLE_IN_41
+IDE_AVAILABLE_IN_ALL
char **ide_session_addin_get_autosave_properties (IdeSessionAddin *self);
G_END_DECLS
diff --git a/src/libide/gui/ide-session-private.h b/src/libide/gui/ide-session-private.h
index dc0af564a..5dc4a26b3 100644
--- a/src/libide/gui/ide-session-private.h
+++ b/src/libide/gui/ide-session-private.h
@@ -21,7 +21,8 @@
#pragma once
#include <libide-core.h>
-#include <libide-gui.h>
+
+#include "ide-grid.h"
G_BEGIN_DECLS
diff --git a/src/libide/gui/ide-session.c b/src/libide/gui/ide-session.c
index cbf126db8..3cf544a1e 100644
--- a/src/libide/gui/ide-session.c
+++ b/src/libide/gui/ide-session.c
@@ -23,10 +23,11 @@
#include "config.h"
#include <libpeas/peas.h>
+
#include <libide-plugins.h>
-#include <libide-gui.h>
#include <libide-threading.h>
+#include "ide-frame.h"
#include "ide-session-addin.h"
#include "ide-session-private.h"
@@ -338,19 +339,18 @@ restore_pages_to_grid (GArray *r_items,
for (guint i = 0; i < r_items->len; i++)
{
RestoreItem *item = &g_array_index (r_items, RestoreItem, i);
- IdeGridColumn *column;
- IdeFrame *stack;
+ PanelGridColumn *column;
+ PanelFrame *frame;
/* Ignore pages that couldn't be restored. */
if (item->restored_page == NULL)
continue;
/* This relies on the fact that the items are sorted. */
- column = ide_grid_get_nth_column (grid, item->column);
- stack = _ide_grid_get_nth_stack_for_column (grid, column, item->row);
+ column = panel_grid_get_column (PANEL_GRID (grid), item->column);
+ frame = panel_grid_column_get_row (column, item->row);
- gtk_container_add (GTK_CONTAINER (stack),
- GTK_WIDGET (item->restored_page));
+ panel_frame_add (frame, PANEL_WIDGET (item->restored_page));
}
IDE_EXIT;
}
@@ -777,55 +777,6 @@ on_state_saved_to_cache_file_cb (GObject *object,
IDE_EXIT;
}
-static void
-get_page_position (IdePage *page,
- guint *out_column,
- guint *out_row,
- guint *out_depth)
-{
- GtkWidget *frame_pages_stack;
- GtkWidget *frame;
- GtkWidget *grid_column;
- GtkWidget *grid;
-
- g_assert (IDE_IS_PAGE (page));
- g_assert (out_column != NULL);
- g_assert (out_row != NULL);
- g_assert (out_depth != NULL);
-
- frame_pages_stack = gtk_widget_get_ancestor (GTK_WIDGET (page), GTK_TYPE_STACK);
- frame = gtk_widget_get_ancestor (GTK_WIDGET (frame_pages_stack), IDE_TYPE_FRAME);
- grid_column = gtk_widget_get_ancestor (GTK_WIDGET (frame), IDE_TYPE_GRID_COLUMN);
- grid = gtk_widget_get_ancestor (GTK_WIDGET (grid_column), IDE_TYPE_GRID);
-
- /* When this page is the currently visible one for this frame, we want to keep it on top when
- * restoring so that there's no need to switch back to the pages we were working on. We need to
- * do this because the stack's "position" child property only refers to the order in which the
- * pages were initially opened, not the most-recently-used order.
- */
- if (ide_frame_get_visible_child (IDE_FRAME (frame)) == page)
- {
- *out_depth = g_list_model_get_n_items (G_LIST_MODEL (frame));
- }
- else
- {
- gtk_container_child_get (GTK_CONTAINER (frame_pages_stack), GTK_WIDGET (page),
- "position", out_depth,
- NULL);
- *out_depth = MAX (*out_depth, 0);
- }
-
- gtk_container_child_get (GTK_CONTAINER (grid_column), GTK_WIDGET (frame),
- "index", out_row,
- NULL);
- *out_row = MAX (*out_row, 0);
-
- gtk_container_child_get (GTK_CONTAINER (grid), GTK_WIDGET (grid_column),
- "index", out_column,
- NULL);
- *out_column = MAX (*out_column, 0);
-}
-
typedef struct {
IdeTask *task;
IdePage *page;
@@ -920,7 +871,7 @@ on_session_addin_page_saved_cb (GObject *object,
g_assert (!g_variant_is_floating (page_state));
- get_page_position (page, &frame_column, &frame_row, &frame_depth);
+ ide_grid_get_page_position (s->grid, page, &frame_column, &frame_row, &frame_depth);
g_variant_dict_init (&state_dict, NULL);
g_variant_dict_insert (&state_dict, "column", "u", frame_column);
@@ -943,10 +894,12 @@ on_session_addin_page_saved_cb (GObject *object,
}
static void
-foreach_page_in_grid_save_cb (GtkWidget *widget,
- gpointer user_data)
+foreach_page_in_grid_save_cb (IdePage *page,
+ guint column,
+ guint row,
+ guint depth,
+ gpointer user_data)
{
- IdePage *page = IDE_PAGE (widget);
IdeTask *task = user_data;
IdeSessionAddin *addin;
SavePage *save_page = NULL;
diff --git a/src/libide/gui/libide-gui.h b/src/libide/gui/libide-gui.h
index b150afafc..d02e2d9e1 100644
--- a/src/libide/gui/libide-gui.h
+++ b/src/libide/gui/libide-gui.h
@@ -20,8 +20,10 @@
#pragma once
-#include <gtk/gtk.h>
+#include <adwaita.h>
+
#include <libide-core.h>
+#include <libide-gtk.h>
#include <libide-io.h>
#include <libide-projects.h>
#include <libide-threading.h>
@@ -35,10 +37,10 @@
#include "ide-frame.h"
#include "ide-frame-addin.h"
#include "ide-header-bar.h"
+#include "ide-grid.h"
#include "ide-gui-global.h"
#include "ide-header-bar.h"
#include "ide-marked-view.h"
-#include "ide-menu-manager.h"
#include "ide-notifications-button.h"
#include "ide-omni-bar-addin.h"
#include "ide-omni-bar.h"
diff --git a/src/libide/gui/meson.build b/src/libide/gui/meson.build
index 46a3418b7..7c7a8cbc7 100644
--- a/src/libide/gui/meson.build
+++ b/src/libide/gui/meson.build
@@ -13,6 +13,7 @@ libide_gui_public_headers = [
'ide-config-view-addin.h',
'ide-environment-editor.h',
'ide-frame-addin.h',
+ 'ide-grid.h',
'ide-gui-global.h',
'ide-header-bar.h',
'ide-marked-view.h',
@@ -85,6 +86,7 @@ libide_gui_public_sources = [
'ide-environment-editor.c',
'ide-frame-addin.c',
'ide-frame.c',
+ 'ide-grid.c',
'ide-gui-global.c',
'ide-header-bar.c',
'ide-marked-view.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]