From 30861d480036b867c0272816ae7a7aaeaee32a08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 17 Apr 2019 18:36:01 -0500 Subject: [PATCH] popupMenu: Make sensitive a Menu and MenuItem property Use 'sensitive' as native gobject property for PopupBaseMenuItem, while simulate it for PopupMenuBase. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/499 --- js/ui/popupMenu.js | 51 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js index 8e58b016f..83a1d1ced 100644 --- a/js/ui/popupMenu.js +++ b/js/ui/popupMenu.js @@ -57,10 +57,13 @@ var PopupBaseMenuItem = GObject.registerClass({ GObject.ParamFlags.READWRITE, GObject.TYPE_BOOLEAN, false), + 'sensitive': GObject.ParamSpec.boolean('sensitive', 'sensitive', 'sensitive', + GObject.ParamFlags.READWRITE, + GObject.TYPE_BOOLEAN, + true), }, Signals: { 'activate': { param_types: [Clutter.Event.$gtype] }, - 'sensitive-changed': {}, } }, class PopupBaseMenuItem extends St.BoxLayout { _init(params) { @@ -204,15 +207,15 @@ var PopupBaseMenuItem = GObject.registerClass({ } syncSensitive() { - let sensitive = this.getSensitive(); + let sensitive = this.sensitive; this.reactive = sensitive; this.can_focus = sensitive; - this.emit('sensitive-changed'); + this.notify('sensitive'); return sensitive; } getSensitive() { - let parentSensitive = this._parent ? this._parent.getSensitive() : true; + let parentSensitive = this._parent ? this._parent.sensitive : true; return this._activatable && this._sensitive && parentSensitive; } @@ -224,6 +227,14 @@ var PopupBaseMenuItem = GObject.registerClass({ this.syncSensitive(); } + get sensitive() { + return this.getSensitive(); + } + + set sensitive(sensitive) { + this.setSensitive(sensitive); + } + setOrnament(ornament) { if (ornament == this._ornament) return; @@ -449,13 +460,21 @@ var PopupMenuBase = class { } getSensitive() { - let parentSensitive = this._parent ? this._parent.getSensitive() : true; + let parentSensitive = this._parent ? this._parent.sensitive : true; return this._sensitive && parentSensitive; } setSensitive(sensitive) { this._sensitive = sensitive; - this.emit('sensitive-changed'); + this.emit('notify::sensitive'); + } + + get sensitive() { + return this.getSensitive(); + } + + set sensitive(sensitive) { + this.setSensitive(sensitive); } _sessionUpdated() { @@ -541,8 +560,8 @@ var PopupMenuBase = class { this.emit('active-changed', null); } }); - menuItem._sensitiveChangeId = menuItem.connect('sensitive-changed', () => { - let sensitive = menuItem.getSensitive(); + menuItem._sensitiveChangeId = menuItem.connect('notify::sensitive', () => { + let sensitive = menuItem.sensitive; if (!sensitive && this._activeMenuItem == menuItem) { if (!this.actor.navigate_focus(menuItem.actor, St.DirectionType.TAB_FORWARD, @@ -558,7 +577,7 @@ var PopupMenuBase = class { this.itemActivated(BoxPointer.PopupAnimation.FULL); }); - menuItem._parentSensitiveChangeId = this.connect('sensitive-changed', () => { + menuItem._parentSensitiveChangeId = this.connect('notify::sensitive', () => { menuItem.syncSensitive(); }); @@ -657,8 +676,8 @@ var PopupMenuBase = class { let parentClosingId = this.connect('menu-closed', () => { menuItem.emit('menu-closed'); }); - let subMenuSensitiveChangedId = this.connect('sensitive-changed', () => { - menuItem.emit('sensitive-changed'); + let subMenuSensitiveChangedId = this.connect('notify::sensitive', () => { + menuItem.emit('notify::sensitive'); }); menuItem.connect('destroy', () => { @@ -897,6 +916,10 @@ var PopupDummyMenu = class { return true; } + get sensitive() { + return this.getSensitive(); + } + open() { this.emit('open-state-changed', true); } close() { this.emit('open-state-changed', false); } toggle() {} @@ -936,7 +959,11 @@ var PopupSubMenu = class extends PopupMenuBase { } getSensitive() { - return this._sensitive && this.sourceActor._delegate.getSensitive(); + return this._sensitive && this.sourceActor.sensitive; + } + + get sensitive() { + return this.getSensitive(); } open(animate) {