From 302765fca993b17236a378bd55785dd344169636 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sat, 14 Jan 2023 18:49:28 +0000 Subject: [PATCH] Only restore documents for first window. --- src/Application.vala | 8 ++------ src/FolderManager/FileItem.vala | 2 +- src/MainWindow.vala | 18 ++++++++++++------ src/Widgets/DocumentView.vala | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 42bbb8324d..61a876042f 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -130,9 +130,9 @@ namespace Scratch { var window = get_last_window (); if (window != null && create_new_window) { create_new_window = false; - this.new_window (); + window = new MainWindow (false); // Will NOT restore documents in additional windows } else if (window == null) { - window = this.new_window (); // Will restore documents if required + window = new MainWindow (true); // Will restore documents if required window.show (); } else { window.present (); @@ -166,10 +166,6 @@ namespace Scratch { return windows.length () > 0 ? windows.last ().data as MainWindow : null; } - public MainWindow new_window () { - return new MainWindow (this); - } - public static int main (string[] args) { return new Application ().run (args); } diff --git a/src/FolderManager/FileItem.vala b/src/FolderManager/FileItem.vala index 44f862e2cb..294fc95041 100644 --- a/src/FolderManager/FileItem.vala +++ b/src/FolderManager/FileItem.vala @@ -30,7 +30,7 @@ namespace Scratch.FolderManager { public override Gtk.Menu? get_context_menu () { var new_window_menuitem = new Gtk.MenuItem.with_label (_("New Window")); new_window_menuitem.activate.connect (() => { - var new_window = ((Scratch.Application) GLib.Application.get_default ()).new_window (); + var new_window = new MainWindow (false); var doc = new Scratch.Services.Document (new_window.actions, file.file); new_window.open_document (doc, true); diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 10b3844940..b4fd7343c4 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -24,7 +24,8 @@ namespace Scratch { public const int FONT_SIZE_MIN = 7; private const uint MAX_SEARCH_TEXT_LENGTH = 255; - public weak Scratch.Application app { get; construct; } + public Scratch.Application app { get; private set; } + public bool restore_docs { get; construct; } public Scratch.Widgets.DocumentView document_view; @@ -144,12 +145,11 @@ namespace Scratch { { ACTION_RESTORE_PROJECT_DOCS, action_restore_project_docs, "s"} }; - public MainWindow (Scratch.Application scratch_app) { + public MainWindow (bool restore_docs) { Object ( - application: scratch_app, - app: scratch_app, icon_name: Constants.PROJECT_NAME, - title: _("Code") + title: _("Code"), + restore_docs: restore_docs ); } @@ -203,6 +203,9 @@ namespace Scratch { } construct { + application = ((Gtk.Application)(GLib.Application.get_default ())); + app = (Scratch.Application)application; + weak Gtk.IconTheme default_theme = Gtk.IconTheme.get_default (); default_theme.add_resource_path ("/io/elementary/code"); @@ -473,7 +476,10 @@ namespace Scratch { }); document_view.realize.connect (() => { - restore_opened_documents (); + if (restore_docs) { + restore_opened_documents (); + } + document_view.update_outline_visible (); }); diff --git a/src/Widgets/DocumentView.vala b/src/Widgets/DocumentView.vala index da37ca8fa8..30ed6016e6 100644 --- a/src/Widgets/DocumentView.vala +++ b/src/Widgets/DocumentView.vala @@ -387,7 +387,7 @@ public class Scratch.Widgets.DocumentView : Granite.Widgets.DynamicNotebook { private void on_doc_moved (Granite.Widgets.Tab tab, int x, int y) { var doc = tab as Services.Document; - var other_window = window.app.new_window (); + var other_window = new MainWindow (false); other_window.move (x, y); // We need to make sure switch back to the main thread