[gnome-text-editor] app: avoid restoring full session handling open request



commit fd6f70275d0d6c90ed0423844d418e774808d71c
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jan 28 11:42:27 2022 -0800

    app: avoid restoring full session handling open request
    
    If we get a request to open a file through the GApplicationClass virtual
    method, we should avoid restoring the session so the user just sees the
    file they requested and not a full session. This should make things a bit
    less annoying when opening new files from Nautilus or when launching from
    the command-line.
    
    Related #278

 src/editor-application.c | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)
---
diff --git a/src/editor-application.c b/src/editor-application.c
index 72dbb61..44e8637 100644
--- a/src/editor-application.c
+++ b/src/editor-application.c
@@ -125,21 +125,33 @@ editor_application_open (GApplication  *application,
   for (guint i = 0; i < n_files; i++)
     g_ptr_array_add (ar, g_file_dup (files[i]));
 
-  /* Restore the session first if there are no windows */
-  if (!_editor_session_did_restore (self->session))
-    {
-      g_application_hold (application);
-      editor_session_restore_async (self->session,
-                                    NULL,
-                                    editor_application_restore_cb,
-                                    g_steal_pointer (&ar));
-    }
-  else if (ar->len > 0)
+  /* If we're being asked to open files via this interface,
+   * we want to ignore restoring the previous session because
+   * the user has either provided a filename on the command line
+   * or has opened a file from something like Nautilus or another
+   * default file-handler situation.
+   *
+   * We either have 1) already restored a session, or 2) dont
+   * need to and instead should just show the window. However,
+   * in the case of #2, we need to at least restore our recent
+   * files so the sidebar can continue working. This is done by
+   * setting the restore_pages within EditorSession to FALSE.
+   */
+
+  if (_editor_session_did_restore (self->session))
     {
       editor_session_open_files (self->session,
                                  (GFile **)ar->pdata,
                                  ar->len);
+      return;
     }
+
+  g_application_hold (application);
+  _editor_session_set_restore_pages (self->session, FALSE);
+  editor_session_restore_async (self->session,
+                                NULL,
+                                editor_application_restore_cb,
+                                g_steal_pointer (&ar));
 }
 
 static gboolean


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