Skip to content

Commit

Permalink
[GTK4 Prep] Use actions for New Window menu item in FileItem (#1456)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinkiama authored Jul 25, 2024
1 parent 59f3b66 commit 7194d09
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/FolderManager/FileItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,10 @@ namespace Scratch.FolderManager {
action_target = new Variant.string (file.file.get_parent ().get_path ())
};

var new_window_menuitem = new Gtk.MenuItem.with_label (_("New Window"));
new_window_menuitem.activate.connect (() => {
var new_window = new MainWindow (false);
var doc = new Scratch.Services.Document (new_window.actions, file.file);

new_window.open_document (doc, true);
});
var new_window_menuitem = new Gtk.MenuItem.with_label (_("New Window")) {
action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_OPEN_IN_NEW_WINDOW,
action_target = file.path
};

var other_menuitem = new Gtk.MenuItem.with_label (_("Other Application…")) {
action_name = FileView.ACTION_PREFIX + FileView.ACTION_SHOW_APP_CHOOSER,
Expand Down
15 changes: 15 additions & 0 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ namespace Scratch {
public const string ACTION_RESTORE_PROJECT_DOCS = "action_restore_project_docs";
public const string ACTION_MOVE_TAB_TO_NEW_WINDOW = "action_move_tab_to_new_window";
public const string ACTION_RESTORE_CLOSED_TAB = "action_restore_closed_tab";
public const string ACTION_OPEN_IN_NEW_WINDOW = "action-open-in-new-window";

public static Gee.MultiMap<string, string> action_accelerators = new Gee.HashMultiMap<string, string> ();
private static string base_title;
Expand Down Expand Up @@ -163,6 +164,7 @@ namespace Scratch {
{ ACTION_RESTORE_PROJECT_DOCS, action_restore_project_docs, "s"},
{ ACTION_MOVE_TAB_TO_NEW_WINDOW, action_move_tab_to_new_window },
{ ACTION_RESTORE_CLOSED_TAB, action_restore_closed_tab, "s" },
{ ACTION_OPEN_IN_NEW_WINDOW, action_open_in_new_window, "s" },
};

public MainWindow (bool restore_docs) {
Expand Down Expand Up @@ -975,6 +977,19 @@ namespace Scratch {
}
}

private void action_open_in_new_window (SimpleAction action, Variant? param) {
var path = param.get_string ();
if (path == "") {
return;
}

var new_window = new MainWindow (false);
var file = File.new_for_path (path);
var doc = new Scratch.Services.Document (new_window.actions, file);

new_window.open_document (doc, true);
}

private void action_open_folder (SimpleAction action, Variant? param) {
var path = param.get_string ();
if (path == "") {
Expand Down

0 comments on commit 7194d09

Please sign in to comment.