[gnome-builder] editor: Add editor page autosaving support



commit 7aac27d9eb3668bbbb207b10ed7778352e80b5dd
Author: vanadiae <vanadiae35 gmail com>
Date:   Mon Jul 12 22:17:43 2021 +0200

    editor: Add editor page autosaving support

 src/libide/editor/ide-editor-page.c           | 29 +++++++++++++++++++++++++++
 src/plugins/editor/gbp-editor-session-addin.c | 20 ++++++++++++++++++
 2 files changed, 49 insertions(+)
---
diff --git a/src/libide/editor/ide-editor-page.c b/src/libide/editor/ide-editor-page.c
index 67f5c162d..0eb20d13b 100644
--- a/src/libide/editor/ide-editor-page.c
+++ b/src/libide/editor/ide-editor-page.c
@@ -38,6 +38,7 @@ enum {
   PROP_0,
   PROP_AUTO_HIDE_MAP,
   PROP_BUFFER,
+  PROP_BUFFER_FILE,
   PROP_SEARCH,
   PROP_SHOW_MAP,
   PROP_VIEW,
@@ -535,6 +536,16 @@ ide_editor_page_update_map (IdeEditorPage *self)
   g_object_unref (self->map);
 }
 
+static void
+ide_editor_page_buffer_notify_file (IdeEditorPage *self,
+                                    GParamSpec    *pspec,
+                                    gpointer       user_data)
+{
+  g_assert (IDE_IS_EDITOR_PAGE (self));
+
+
+}
+
 static void
 search_revealer_notify_reveal_child (IdeEditorPage *self,
                                      GParamSpec    *pspec,
@@ -860,6 +871,9 @@ ide_editor_page_get_property (GObject    *object,
       g_value_set_object (value, ide_editor_page_get_buffer (self));
       break;
 
+    case PROP_BUFFER_FILE:
+      g_value_set_object (value, ide_buffer_get_file (self->buffer));
+      break;
     case PROP_VIEW:
       g_value_set_object (value, ide_editor_page_get_view (self));
       break;
@@ -929,6 +943,16 @@ ide_editor_page_class_init (IdeEditorPageClass *klass)
                          IDE_TYPE_BUFFER,
                          (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
 
+  /* It's really just there to get notify:: support for the buffer's file property
+   * but through the page, for the session addin.
+   */
+  properties [PROP_BUFFER_FILE] =
+    g_param_spec_object ("buffer-file",
+                         "Buffer file",
+                         "The buffer file for the view's buffer",
+                         G_TYPE_FILE,
+                         (G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
+
   properties [PROP_SEARCH] =
     g_param_spec_object ("search",
                          "Search",
@@ -990,6 +1014,11 @@ ide_editor_page_init (IdeEditorPage *self)
 
   self->destroy_cancellable = g_cancellable_new ();
 
+  g_signal_connect_swapped (self->buffer,
+                            "notify::file",
+                            G_CALLBACK (ide_editor_page_buffer_notify_file),
+                            self);
+
   /* Setup signals to monitor on the buffer. */
   self->buffer_signals = dzl_signal_group_new (IDE_TYPE_BUFFER);
 
diff --git a/src/plugins/editor/gbp-editor-session-addin.c b/src/plugins/editor/gbp-editor-session-addin.c
index 63690f353..b37a0a0ad 100644
--- a/src/plugins/editor/gbp-editor-session-addin.c
+++ b/src/plugins/editor/gbp-editor-session-addin.c
@@ -240,9 +240,28 @@ static gboolean
 gbp_editor_session_addin_can_save_page (IdeSessionAddin *addin,
                                         IdePage         *page)
 {
+  g_assert (GBP_IS_EDITOR_SESSION_ADDIN (addin));
+
   return IDE_IS_EDITOR_PAGE (page);
 }
 
+static char **
+gbp_editor_session_addin_get_autosave_properties (IdeSessionAddin *addin)
+{
+  GStrvBuilder *builder = NULL;
+
+  g_assert (GBP_IS_EDITOR_SESSION_ADDIN (addin));
+
+  builder = g_strv_builder_new ();
+  /* This is not an ideal property to pick, but the editor page file URI is burried
+   * in the buffer property. In GTK 4 we'll likely be able to use GtkExpression to
+   * really access the URI in the buffer.
+   */
+  g_strv_builder_add (builder, "buffer-file");
+
+  return g_strv_builder_end (builder);
+}
+
 static void
 session_addin_iface_init (IdeSessionAddinInterface *iface)
 {
@@ -251,6 +270,7 @@ session_addin_iface_init (IdeSessionAddinInterface *iface)
   iface->restore_page_async = gbp_editor_session_addin_restore_page_async;
   iface->restore_page_finish = gbp_editor_session_addin_restore_page_finish;
   iface->can_save_page = gbp_editor_session_addin_can_save_page;
+  iface->get_autosave_properties = gbp_editor_session_addin_get_autosave_properties;
 }
 
 G_DEFINE_TYPE_WITH_CODE (GbpEditorSessionAddin, gbp_editor_session_addin, IDE_TYPE_OBJECT,


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