[gnome-text-editor] session: track all new documents for changes



commit 13b67259c062c3dbbf2164d7425de389c1e34527
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jan 10 12:31:06 2022 -0800

    session: track all new documents for changes
    
    We happened to get into a situation where we weren't getting new document
    changes to mark our state invalid. This ensures we do by handling it when
    adding a page rather than when adding a document (which might get bypassed
    if we create the page in another fashion).

 src/editor-session.c | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)
---
diff --git a/src/editor-session.c b/src/editor-session.c
index 6257489..a77b2c3 100644
--- a/src/editor-session.c
+++ b/src/editor-session.c
@@ -681,6 +681,16 @@ editor_session_create_window (EditorSession *self)
   return window;
 }
 
+static void
+editor_session_document_changed_cb (EditorSession  *self,
+                                    EditorDocument *document)
+{
+  g_assert (EDITOR_IS_SESSION (self));
+  g_assert (EDITOR_IS_DOCUMENT (document));
+
+  _editor_session_mark_dirty (self);
+}
+
 /**
  * editor_session_add_page:
  * @self: an #EditorSession
@@ -700,6 +710,8 @@ editor_session_add_page (EditorSession *self,
                          EditorWindow  *window,
                          EditorPage    *page)
 {
+  EditorDocument *document;
+
   g_return_if_fail (EDITOR_IS_SESSION (self));
   g_return_if_fail (EDITOR_IS_WINDOW (window));
   g_return_if_fail (EDITOR_IS_PAGE (page));
@@ -710,6 +722,14 @@ editor_session_add_page (EditorSession *self,
   g_assert (window != NULL);
   g_assert (EDITOR_IS_WINDOW (window));
 
+  /* Update session state when the document changes */
+  document = editor_page_get_document (page);
+  g_signal_connect_object (document,
+                           "changed",
+                           G_CALLBACK (editor_session_document_changed_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+
   g_ptr_array_add (self->pages, g_object_ref (page));
 
   _editor_window_add_page (window, page);
@@ -724,16 +744,6 @@ editor_session_add_page (EditorSession *self,
   _editor_session_mark_dirty (self);
 }
 
-static void
-editor_session_document_changed_cb (EditorSession  *self,
-                                    EditorDocument *document)
-{
-  g_assert (EDITOR_IS_SESSION (self));
-  g_assert (EDITOR_IS_DOCUMENT (document));
-
-  _editor_session_mark_dirty (self);
-}
-
 /**
  * editor_session_add_document:
  * @self: an #EditorSession
@@ -765,12 +775,6 @@ editor_session_add_document (EditorSession  *self,
   page = editor_page_new_for_document (document);
   editor_session_add_page (self, window, page);
 
-  g_signal_connect_object (document,
-                           "changed",
-                           G_CALLBACK (editor_session_document_changed_cb),
-                           self,
-                           G_CONNECT_SWAPPED);
-
   return page;
 }
 


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