[gnome-text-editor] document: add an EditorDocument::save signal



commit 82ee3c6a0090aa7323aa2f45d6c1384e0e6a9400
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jan 10 12:32:31 2022 -0800

    document: add an EditorDocument::save signal
    
    This new save signal is emitted before saving the file to the drafts
    directory or to the underlying storage. This can be helpful if you only
    want to perform an operation when the document is already doing an
    expensive operation like writing to disk.
    
    It's a good time to calcuate expensive operations.

 src/editor-document.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
---
diff --git a/src/editor-document.c b/src/editor-document.c
index fd29b82..39bc386 100644
--- a/src/editor-document.c
+++ b/src/editor-document.c
@@ -95,8 +95,22 @@ enum {
   N_PROPS
 };
 
+enum {
+  SAVE,
+  N_SIGNALS
+};
+
 static GParamSpec *properties [N_PROPS];
 static GSettings *shared_settings;
+static guint signals [N_SIGNALS];
+
+static void
+editor_document_emit_save (EditorDocument *self)
+{
+  g_assert (EDITOR_IS_DOCUMENT (self));
+
+  g_signal_emit (self, signals [SAVE], 0);
+}
 
 static GtkSourceLanguage *
 guess_language (GtkSourceLanguageManager *manager,
@@ -546,6 +560,21 @@ editor_document_class_init (EditorDocumentClass *klass)
                          (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
   g_object_class_install_properties (object_class, N_PROPS, properties);
+
+  /**
+   * EditorDocument::save:
+   * @self: a #EditorDocument
+   *
+   * The "save" signal is emitted right before the document
+   * is about to be saved.
+   */
+  signals [SAVE] = g_signal_new ("save",
+                                 G_TYPE_FROM_CLASS (klass),
+                                 G_SIGNAL_RUN_LAST,
+                                 0,
+                                 NULL, NULL,
+                                 NULL,
+                                 G_TYPE_NONE, 0);
 }
 
 static void
@@ -730,6 +759,8 @@ _editor_document_save_draft_async (EditorDocument      *self,
       return;
     }
 
+  editor_document_emit_save (self);
+
   self->needs_autosave = FALSE;
 
   /* First tell the session to track this draft */
@@ -945,6 +976,8 @@ _editor_document_save_async (EditorDocument      *self,
   g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
   g_return_if_fail (self->draft_id != NULL);
 
+  editor_document_emit_save (self);
+
   insert = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (self));
   gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (self), &iter, insert);
 


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