Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/FolderManager/FileItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 12 additions & 6 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
);
}

Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -473,7 +476,10 @@ namespace Scratch {
});

document_view.realize.connect (() => {
restore_opened_documents ();
if (restore_docs) {
restore_opened_documents ();
}

document_view.update_outline_visible ();
});

Expand Down
2 changes: 1 addition & 1 deletion src/Widgets/DocumentView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down