[gnome-builder] libide-gui: minimal port of session to GTK 4
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide-gui: minimal port of session to GTK 4
- Date: Tue, 12 Jul 2022 06:39:12 +0000 (UTC)
commit d7c349801713bdadeab7747bd5fcd894034b3706
Author: Christian Hergert <chergert redhat com>
Date: Mon Jul 11 21:44:19 2022 -0700
libide-gui: minimal port of session to GTK 4
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 | 76 +++++-------------------------------
4 files changed, 41 insertions(+), 107 deletions(-)
---
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..1f69a27e7 100644
--- a/src/libide/gui/ide-session.c
+++ b/src/libide/gui/ide-session.c
@@ -23,15 +23,14 @@
#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"
-#include "ide-gui-private.h"
-
struct _IdeSession
{
IdeObject parent_instance;
@@ -338,19 +337,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;
}
@@ -668,8 +666,6 @@ on_session_cache_loaded_cb (GObject *object,
* the point it was last saved (typically upon shutdown). This includes
* open documents and editor splits to the degree possible. Adding support
* for a new page type requires implementing an #IdeSessionAddin.
- *
- * Since: 41
*/
void
ide_session_restore_async (IdeSession *self,
@@ -777,55 +773,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 +867,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 +890,9 @@ 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,
+ gpointer user_data)
{
- IdePage *page = IDE_PAGE (widget);
IdeTask *task = user_data;
IdeSessionAddin *addin;
SavePage *save_page = NULL;
@@ -989,8 +935,6 @@ foreach_page_in_grid_save_cb (GtkWidget *widget,
* This function will save the position and content of the pages in the @grid,
* which can then be restored with ide_session_restore_async(), asking the
* content of the pages to the appropriate #IdeSessionAddin.
- *
- * Since: 41
*/
void
ide_session_save_async (IdeSession *self,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]