[gnome-builder] devhelp: Add page autosaving support



commit abdd8637f326a6d076949b8ff82de941d593b3cc
Author: vanadiae <vanadiae35 gmail com>
Date:   Mon Jul 12 22:17:31 2021 +0200

    devhelp: Add page autosaving support

 src/plugins/devhelp/gbp-devhelp-page.c          | 24 ++++++++++++++++++++++--
 src/plugins/devhelp/gbp-devhelp-session-addin.c | 13 +++++++++++++
 2 files changed, 35 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/devhelp/gbp-devhelp-page.c b/src/plugins/devhelp/gbp-devhelp-page.c
index add040e43..13d68a44c 100644
--- a/src/plugins/devhelp/gbp-devhelp-page.c
+++ b/src/plugins/devhelp/gbp-devhelp-page.c
@@ -60,10 +60,11 @@ gbp_devhelp_page_set_uri (GbpDevhelpPage *self,
 {
   g_return_if_fail (GBP_IS_DEVHELP_PAGE (self));
 
-  if (uri == NULL)
+  if (uri == NULL || g_strcmp0 (uri, gbp_devhelp_page_get_uri (self)) == 0)
     return;
 
   webkit_web_view_load_uri (self->web_view1, uri);
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_URI]);
 }
 
 /**
@@ -149,6 +150,24 @@ gbp_devhelp_page_set_property (GObject      *object,
     }
 }
 
+static void
+gbp_devhelp_page_get_property (GObject    *object,
+                               guint       prop_id,
+                               GValue     *value,
+                               GParamSpec *pspec)
+{
+  GbpDevhelpPage *self = GBP_DEVHELP_PAGE (object);
+
+  switch (prop_id)
+    {
+    case PROP_URI:
+      g_value_set_string (value, gbp_devhelp_page_get_uri (self));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
 static void
 gbp_devhelp_search_reveal (GbpDevhelpPage *self)
 {
@@ -176,6 +195,7 @@ gbp_devhelp_page_class_init (GbpDevhelpPageClass *klass)
   IdePageClass *view_class = IDE_PAGE_CLASS (klass);
 
   object_class->set_property = gbp_devhelp_page_set_property;
+  object_class->get_property = gbp_devhelp_page_get_property;
 
   view_class->create_split = gbp_devhelp_page_create_split;
 
@@ -184,7 +204,7 @@ gbp_devhelp_page_class_init (GbpDevhelpPageClass *klass)
                          "Uri",
                          "The uri of the documentation.",
                          NULL,
-                         (G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY));
 
   signals [SEARCH_REVEAL] =
     g_signal_new_class_handler ("search-reveal",
diff --git a/src/plugins/devhelp/gbp-devhelp-session-addin.c b/src/plugins/devhelp/gbp-devhelp-session-addin.c
index 500d6e6a1..c03bff2e6 100644
--- a/src/plugins/devhelp/gbp-devhelp-session-addin.c
+++ b/src/plugins/devhelp/gbp-devhelp-session-addin.c
@@ -127,6 +127,18 @@ gbp_devhelp_session_addin_can_save_page (IdeSessionAddin *addin,
   return GBP_IS_DEVHELP_PAGE (page);
 }
 
+static char **
+gbp_devhelp_session_addin_get_autosave_properties (IdeSessionAddin *addin)
+{
+  GStrvBuilder *builder = NULL;
+
+  g_assert (GBP_IS_DEVHELP_SESSION_ADDIN (addin));
+
+  builder = g_strv_builder_new ();
+  g_strv_builder_add (builder, "uri");
+  return g_strv_builder_end (builder);
+}
+
 static void
 session_addin_iface_init (IdeSessionAddinInterface *iface)
 {
@@ -135,6 +147,7 @@ session_addin_iface_init (IdeSessionAddinInterface *iface)
   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;
+  iface->get_autosave_properties = gbp_devhelp_session_addin_get_autosave_properties;
 }
 
 G_DEFINE_TYPE_WITH_CODE (GbpDevhelpSessionAddin, gbp_devhelp_session_addin, IDE_TYPE_OBJECT,


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