Skip to content
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;
}
43 changes: 43 additions & 0 deletions src/Launcher.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class Dock.Launcher : Gtk.Box {
public const string ACTION_PREFIX = ACTION_GROUP_PREFIX + ".";
public const string PINNED_ACTION = "pinned";
public const string APP_ACTION = "action.%s";
private const string CLOSE_WINDOWS_LABEL = "Close All Windows";
private const string CLOSE_WINDOWS_ACTION = "close-instances";

public App app { get; construct; }

Expand Down Expand Up @@ -259,9 +261,13 @@ public class Dock.Launcher : Gtk.Box {
app.notify["running"].connect (update_running_revealer);
update_running_revealer ();

app.notify["running"].connect(close_all_instances);
close_all_instances();

var drop_target_file = new Gtk.DropTarget (typeof (File), COPY);
add_controller (drop_target_file);


drop_target_file.enter.connect ((x, y) => {
var _launcher_manager = LauncherManager.get_default ();
if (_launcher_manager.added_launcher != null) {
Expand Down Expand Up @@ -336,6 +342,43 @@ public class Dock.Launcher : Gtk.Box {
}
}

private void close_all_instances(){
if (app.running) {
if (app.action_group.lookup_action(CLOSE_WINDOWS_ACTION) != null) {
return;
}

var close_item = new GLib.MenuItem(_(CLOSE_WINDOWS_LABEL), ACTION_PREFIX + CLOSE_WINDOWS_ACTION);
app.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 app.windows) {
desktop_integration.close_window.begin(win.uid, null);
}

app.windows.clear();
});

close_action.set_enabled(true);
app.action_group.add_action(close_action);
}else{
for (int i = 0; i < app.menu_model.get_n_items(); i++) {
var attribute = app.menu_model.get_item_attribute_value(i, "label", null);
var label = attribute != null ? attribute.get_string() : null;
if (label == _(CLOSE_WINDOWS_LABEL)) {
app.menu_model.remove(i); // Remove menu
break;
}
}
if (app.action_group.lookup_action(CLOSE_WINDOWS_ACTION) != null) {
app.action_group.remove_action(CLOSE_WINDOWS_ACTION);
}
}
}

private void animate_launch () {
if (bounce_up.state == PLAYING || bounce_down.state == PLAYING) {
return;
Expand Down
Loading