Add ungrouped icon context action to quit all windows on taskbar

gh-1640 gh-1657
This commit is contained in:
Charles Gagnon
2025-04-13 11:50:39 -04:00
parent 03b34b110b
commit ff9ce4df99

View File

@@ -905,7 +905,7 @@ export const TaskbarAppIcon = GObject.registerClass(
Main.uiGroup.add_child(this._menu.actor) Main.uiGroup.add_child(this._menu.actor)
this._menuManager.addMenu(this._menu) this._menuManager.addMenu(this._menu)
} }
this._menu.updateQuitText() this._menu.updateQuitItems()
this.emit('menu-state-changed', true) this.emit('menu-state-changed', true)
@@ -1917,6 +1917,11 @@ export class TaskbarSecondaryMenu extends AppMenu.AppMenu {
this._enableFavorites = true this._enableFavorites = true
this._showSingleWindows = true this._showSingleWindows = true
if (source.window)
this._quitAllItem = this.addAction('QuitAll', () =>
this._quitFromTaskbar(true),
)
// replace quit item // replace quit item
delete this._quitItem delete this._quitItem
this._quitItem = this.addAction(_('Quit'), () => this._quitFromTaskbar()) this._quitItem = this.addAction(_('Quit'), () => this._quitFromTaskbar())
@@ -1928,31 +1933,34 @@ export class TaskbarSecondaryMenu extends AppMenu.AppMenu {
]) ])
} }
updateQuitText() { updateQuitItems() {
let count = this.sourceActor.window let ungrouped = !!this.sourceActor.window
? 1 let quitText = _('Quit')
: getInterestingWindows(this._app, this.sourceActor.dtpPanel.monitor) let count = getInterestingWindows(
.length this._app,
this.sourceActor.dtpPanel.monitor,
).length
let quitMultipleText = ngettext(
'Quit %d Window',
'Quit %d Windows',
count,
).format(count)
if (count > 0) { if (ungrouped) {
let quitFromTaskbarMenuText = '' this._quitAllItem.label.set_text(quitMultipleText)
if (count == 1) quitFromTaskbarMenuText = _('Quit') this._quitAllItem.visible = count > 1
else } else quitText = quitMultipleText
quitFromTaskbarMenuText = ngettext(
'Quit %d Window',
'Quit %d Windows',
count,
).format(count)
this._quitItem.label.set_text(quitFromTaskbarMenuText) this._quitItem.visible = count > 0
} this._quitItem.label.set_text(quitText)
} }
_quitFromTaskbar() { _quitFromTaskbar(all) {
let time = global.get_current_time() let time = global.get_current_time()
let windows = this.sourceActor.window // ungrouped applications let windows =
? [this.sourceActor.window] !all && this.sourceActor.window // ungrouped applications
: getInterestingWindows(this._app, this.sourceActor.dtpPanel.monitor) ? [this.sourceActor.window]
: getInterestingWindows(this._app, this.sourceActor.dtpPanel.monitor)
if (windows.length == this._app.get_windows().length) if (windows.length == this._app.get_windows().length)
this._app.request_quit() this._app.request_quit()