diff --git a/src/Application.vala b/src/Application.vala index 42bbb8324d..c8e8aa869c 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -129,10 +129,10 @@ namespace Scratch { protected override void activate () { var window = get_last_window (); if (window != null && create_new_window) { + window = new MainWindow (false); // Will *not* restore documents create_new_window = false; - this.new_window (); } 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 fef536c599..099a51919a 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -24,7 +24,11 @@ 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 { + return (Scratch.Application)application; + } + } public Scratch.Widgets.DocumentView document_view; @@ -132,13 +136,25 @@ namespace Scratch { { ACTION_NEW_BRANCH, action_new_branch, "s" } }; - public MainWindow (Scratch.Application scratch_app) { + public MainWindow (bool restore_docs) { Object ( - application: scratch_app, - app: scratch_app, + application: (Gtk.Application)(GLib.Application.get_default ()), icon_name: Constants.PROJECT_NAME, title: _("Code") ); + + document_view.realize.connect (() => { + if (restore_docs) { + restore_opened_documents (); + } + + Idle.add (() => { + document_view.request_placeholder_if_empty (); + return Source.REMOVE; + }); + }); + + show_all (); // Do not show document view until realize signal connected } static construct { @@ -257,8 +273,6 @@ namespace Scratch { } sidebar.bind_property ("visible", toolbar.choose_project_revealer, "reveal-child"); - // Show/Hide widgets - show_all (); toolbar.templates_button.visible = (plugins.plugin_iface.template_manager.template_available); plugins.plugin_iface.template_manager.notify["template_available"].connect (() => { @@ -326,7 +340,6 @@ namespace Scratch { folder_manager_view = new FolderManager.FileView (); sidebar.add_tab (folder_manager_view); - folder_manager_view.show_all (); folder_manager_view.select.connect ((a) => { var file = new Scratch.FolderManager.File (a); @@ -411,10 +424,6 @@ namespace Scratch { hook_func (); }); - document_view.realize.connect (() => { - restore_opened_documents (); - }); - document_view.request_placeholder.connect (() => { content_stack.visible_child = welcome_view; title = _("Code"); @@ -495,11 +504,6 @@ namespace Scratch { } } } - - Idle.add (() => { - document_view.request_placeholder_if_empty (); - return Source.REMOVE; - }); } private bool on_key_pressed (Gdk.EventKey event) { diff --git a/src/Services/GitManager.vala b/src/Services/GitManager.vala index 99a28b72e4..9bd8f4a195 100644 --- a/src/Services/GitManager.vala +++ b/src/Services/GitManager.vala @@ -45,15 +45,15 @@ namespace Scratch.Services { } public MonitoredRepository? add_project (FolderManager.ProjectFolderItem root_folder) { - project_liststore.insert_sorted (root_folder, (CompareDataFunc) project_sort_func); - var root_path = root_folder.file.file.get_path (); try { var git_repo = Ggit.Repository.open (root_folder.file.file); + // Only add projects that are not already in open in sidebar if (project_gitrepo_map.has_key (root_path)) { return project_gitrepo_map.@get (root_path); } + project_liststore.insert_sorted (root_folder, (CompareDataFunc) project_sort_func); var monitored_repo = new MonitoredRepository (git_repo); project_gitrepo_map.@set (root_path, monitored_repo); return project_gitrepo_map.@get (root_path); diff --git a/src/Widgets/DocumentView.vala b/src/Widgets/DocumentView.vala index 9a3969b12c..f09b058298 100644 --- a/src/Widgets/DocumentView.vala +++ b/src/Widgets/DocumentView.vala @@ -366,7 +366,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