[gnome-builder] devhelp: Add support for restoring devhelp pages
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] devhelp: Add support for restoring devhelp pages
- Date: Thu, 8 Jul 2021 20:55:53 +0000 (UTC)
commit f043c931eda6cbcbb797348d83aadf105f13ded6
Author: vanadiae <vanadiae35 gmail com>
Date: Thu Jul 8 22:27:22 2021 +0200
devhelp: Add support for restoring devhelp pages
Now that we have the new session API, it's easy to add support for new IdePage
types.
src/plugins/devhelp/devhelp-plugin.c | 4 +
src/plugins/devhelp/gbp-devhelp-page.c | 14 +++
src/plugins/devhelp/gbp-devhelp-page.h | 1 +
src/plugins/devhelp/gbp-devhelp-session-addin.c | 155 ++++++++++++++++++++++++
src/plugins/devhelp/gbp-devhelp-session-addin.h | 32 +++++
src/plugins/devhelp/meson.build | 1 +
6 files changed, 207 insertions(+)
---
diff --git a/src/plugins/devhelp/devhelp-plugin.c b/src/plugins/devhelp/devhelp-plugin.c
index 72c5b2fed..8ee15b794 100644
--- a/src/plugins/devhelp/devhelp-plugin.c
+++ b/src/plugins/devhelp/devhelp-plugin.c
@@ -26,6 +26,7 @@
#include "gbp-devhelp-editor-addin.h"
#include "gbp-devhelp-hover-provider.h"
#include "gbp-devhelp-frame-addin.h"
+#include "gbp-devhelp-session-addin.h"
_IDE_EXTERN void
_gbp_devhelp_register_types (PeasObjectModule *module)
@@ -39,4 +40,7 @@ _gbp_devhelp_register_types (PeasObjectModule *module)
peas_object_module_register_extension_type (module,
IDE_TYPE_FRAME_ADDIN,
GBP_TYPE_DEVHELP_FRAME_ADDIN);
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_SESSION_ADDIN,
+ GBP_TYPE_DEVHELP_SESSION_ADDIN);
}
diff --git a/src/plugins/devhelp/gbp-devhelp-page.c b/src/plugins/devhelp/gbp-devhelp-page.c
index 8bcfc86c3..add040e43 100644
--- a/src/plugins/devhelp/gbp-devhelp-page.c
+++ b/src/plugins/devhelp/gbp-devhelp-page.c
@@ -66,6 +66,20 @@ gbp_devhelp_page_set_uri (GbpDevhelpPage *self,
webkit_web_view_load_uri (self->web_view1, uri);
}
+/**
+ * gbp_devhelp_page_get_uri:
+ * @self: a #GbpDevhelpPage
+ *
+ * Returns: (nullable): the documentation URI loaded for page @self
+ */
+const char *
+gbp_devhelp_page_get_uri (GbpDevhelpPage *self)
+{
+ g_return_val_if_fail (GBP_IS_DEVHELP_PAGE (self), NULL);
+
+ return webkit_web_view_get_uri (self->web_view1);
+}
+
static void
gbp_devhelp_page_notify_title (GbpDevhelpPage *self,
GParamSpec *pspec,
diff --git a/src/plugins/devhelp/gbp-devhelp-page.h b/src/plugins/devhelp/gbp-devhelp-page.h
index 69a32b10f..b5d51eeae 100644
--- a/src/plugins/devhelp/gbp-devhelp-page.h
+++ b/src/plugins/devhelp/gbp-devhelp-page.h
@@ -30,5 +30,6 @@ G_DECLARE_FINAL_TYPE (GbpDevhelpPage, gbp_devhelp_page, GBP, DEVHELP_PAGE, IdePa
void gbp_devhelp_page_set_uri (GbpDevhelpPage *self,
const gchar *uri);
+const char *gbp_devhelp_page_get_uri (GbpDevhelpPage *self);
G_END_DECLS
diff --git a/src/plugins/devhelp/gbp-devhelp-session-addin.c b/src/plugins/devhelp/gbp-devhelp-session-addin.c
new file mode 100644
index 000000000..516f228a3
--- /dev/null
+++ b/src/plugins/devhelp/gbp-devhelp-session-addin.c
@@ -0,0 +1,155 @@
+/* gbp-devhelp-session-addin.c
+ *
+ * Copyright 2021 vanadiae <vanadiae35 gmail 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 "gbp-devhelp-session-addin"
+
+#include "config.h"
+
+#include <libide-threading.h>
+
+#include "gbp-devhelp-session-addin.h"
+
+#include "gbp-devhelp-page.h"
+
+struct _GbpDevhelpSessionAddin
+{
+ IdeObject parent_instance;
+};
+
+static void
+gbp_devhelp_session_addin_save_page_async (IdeSessionAddin *addin,
+ IdePage *page,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_autoptr(IdeTask) task = NULL;
+ GVariantDict state_dict;
+ const char *page_uri;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_MAIN_THREAD ());
+ g_assert (GBP_IS_DEVHELP_SESSION_ADDIN (addin));
+ g_assert (GBP_IS_DEVHELP_PAGE (page));
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ task = ide_task_new (addin, cancellable, callback, user_data);
+ ide_task_set_source_tag (task, gbp_devhelp_session_addin_save_page_async);
+
+ page_uri = gbp_devhelp_page_get_uri (GBP_DEVHELP_PAGE (page));
+ g_variant_dict_init (&state_dict, NULL);
+ g_variant_dict_insert (&state_dict, "uri", "s", page_uri ? page_uri : "");
+
+#if IDE_ENABLE_TRACE
+ IDE_TRACE_MSG ("Saving devhelp page URI \"%s\"", uri);
+#endif
+
+ ide_task_return_pointer (task, g_variant_take_ref (g_variant_dict_end (&state_dict)), g_variant_unref);
+
+ IDE_EXIT;
+}
+
+static GVariant *
+gbp_devhelp_session_addin_save_page_finish (IdeSessionAddin *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_assert (GBP_IS_DEVHELP_SESSION_ADDIN (self));
+ g_assert (IDE_IS_TASK (result));
+
+ return ide_task_propagate_pointer (IDE_TASK (result), error);
+}
+
+static void
+gbp_devhelp_session_addin_restore_page_async (IdeSessionAddin *addin,
+ GVariant *state,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_autoptr(IdeTask) task = NULL;
+ GVariantDict state_dict;
+ const char *uri;
+
+ g_assert (GBP_IS_DEVHELP_SESSION_ADDIN (addin));
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+ g_assert (g_variant_is_of_type (state, G_VARIANT_TYPE_VARDICT));
+
+ task = ide_task_new (addin, cancellable, callback, user_data);
+ ide_task_set_source_tag (task, gbp_devhelp_session_addin_restore_page_async);
+
+ g_variant_dict_init (&state_dict, state);
+ g_variant_dict_lookup (&state_dict, "uri", "&s", &uri);
+ g_assert (uri != NULL);
+
+#if IDE_ENABLE_TRACE
+ IDE_TRACE_MSG ("Restoring devhelp page URI \"%s\"", uri);
+#endif
+
+ ide_task_return_pointer (task,
+ g_object_new (GBP_TYPE_DEVHELP_PAGE,
+ "uri", uri,
+ "visible", TRUE,
+ NULL),
+ g_object_unref);
+}
+
+static IdePage *
+gbp_devhelp_session_addin_restore_page_finish (IdeSessionAddin *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_assert (GBP_IS_DEVHELP_SESSION_ADDIN (self));
+ g_assert (IDE_IS_TASK (result));
+
+ return ide_task_propagate_pointer (IDE_TASK (result), error);
+}
+
+static gboolean
+gbp_devhelp_session_addin_can_save_page (IdeSessionAddin *addin,
+ IdePage *page)
+{
+ return GBP_IS_DEVHELP_PAGE (page);
+}
+
+static void
+session_addin_iface_init (IdeSessionAddinInterface *iface)
+{
+ iface->save_page_async = gbp_devhelp_session_addin_save_page_async;
+ iface->save_page_finish = gbp_devhelp_session_addin_save_page_finish;
+ iface->restore_page_async = gbp_devhelp_session_addin_restore_page_async;
+ iface->restore_page_finish = gbp_devhelp_session_addin_restore_page_finish;
+ iface->can_save_page = gbp_devhelp_session_addin_can_save_page;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpDevhelpSessionAddin, gbp_devhelp_session_addin, IDE_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_SESSION_ADDIN, session_addin_iface_init))
+
+static void
+gbp_devhelp_session_addin_class_init (GbpDevhelpSessionAddinClass *klass)
+{
+}
+
+static void
+gbp_devhelp_session_addin_init (GbpDevhelpSessionAddin *self)
+{
+}
diff --git a/src/plugins/devhelp/gbp-devhelp-session-addin.h b/src/plugins/devhelp/gbp-devhelp-session-addin.h
new file mode 100644
index 000000000..e744611cf
--- /dev/null
+++ b/src/plugins/devhelp/gbp-devhelp-session-addin.h
@@ -0,0 +1,32 @@
+/* gbp-devhelp-session-addin.h
+ *
+ * Copyright 2021 vanadiae <vanadiae35 gmail 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
+
+#include <ide-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_DEVHELP_SESSION_ADDIN (gbp_devhelp_session_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpDevhelpSessionAddin, gbp_devhelp_session_addin, GBP, DEVHELP_SESSION_ADDIN,
IdeObject)
+
+G_END_DECLS
diff --git a/src/plugins/devhelp/meson.build b/src/plugins/devhelp/meson.build
index 359161db1..11d24bdb0 100644
--- a/src/plugins/devhelp/meson.build
+++ b/src/plugins/devhelp/meson.build
@@ -16,6 +16,7 @@ plugins_sources += files([
'gbp-devhelp-menu-button.c',
'gbp-devhelp-page.c',
'gbp-devhelp-search.c',
+ 'gbp-devhelp-session-addin.c',
])
plugin_devhelp_resources = gnome.compile_resources(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]