Skip to content
23 changes: 23 additions & 0 deletions src/App.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class Dock.App : Object {
private const string PINNED_ACTION = "pinned";
private const string SWITCHEROO_ACTION = "switcheroo";
private const string APP_ACTION = "action.%s";
private const string CLOSE_WINDOWS_LABEL = "Close All Windows";
private const string CLOSE_WINDOWS_ACTION = "close-instances";

public signal void launched () {
if (!running && app_info.get_boolean ("StartupNotify")) {
Expand Down Expand Up @@ -120,6 +122,27 @@ public class Dock.App : Object {
pinned_action.set_state (pinned);
LauncherManager.get_default ().sync_pinned ();
});

var close_item = new GLib.MenuItem (_(CLOSE_WINDOWS_LABEL), ACTION_PREFIX + CLOSE_WINDOWS_ACTION);
Copy link
Member

@lenemter lenemter Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't add Close All Windows as a constant, it's untranslatable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, one can if it is marked as N_,
So it has to be:

    private const string CLOSE_WINDOWS_LABEL = N_("Close All Windows");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I don't see the benefit of a constant here

close_item.set_attribute ("hidden-when", "s", "action-disabled");
menu_model.append_item (close_item);

var close_action = new SimpleAction (CLOSE_WINDOWS_ACTION, null);
close_action.activate.connect (() => {
var desktop_integration = LauncherManager.get_default ().desktop_integration;
foreach (var win in windows) {
desktop_integration.close_window.begin (win.uid);
}
});
action_group.add_action (close_action);

notify["running"].connect (() => {
if (running) {
close_action.set_enabled (true);
} else {
close_action.set_enabled (false);
}
});
}

public void launch (AppLaunchContext context, string? action = null, bool? use_preferred_gpu = true) {
Expand Down
1 change: 1 addition & 0 deletions src/DesktopIntegration.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ public interface Dock.DesktopIntegration : GLib.Object {
public abstract async Window[] get_windows () throws GLib.DBusError, GLib.IOError;
public abstract async void show_windows_for (string app_id) throws GLib.DBusError, GLib.IOError;
public abstract async void focus_window (uint64 uid) throws GLib.DBusError, GLib.IOError;
public abstract async void close_window (uint64 uid) throws GLib.DBusError, GLib.IOError;
}