PopupMenu: make parameters overridable in items
Make all subclasses of PopupMenuBase accept a params argument, which can be used to make the item non reactive, not responsive to hover and, as a new feature, with a different style class. https://bugzilla.gnome.org/show_bug.cgi?id=621707
This commit is contained in:
parent
3fd908d92c
commit
6e236546ea
@ -26,7 +26,9 @@ PopupBaseMenuItem.prototype = {
|
|||||||
_init: function (params) {
|
_init: function (params) {
|
||||||
params = Params.parse (params, { reactive: true,
|
params = Params.parse (params, { reactive: true,
|
||||||
activate: true,
|
activate: true,
|
||||||
hover: true });
|
hover: true,
|
||||||
|
style_class: null
|
||||||
|
});
|
||||||
this.actor = new Shell.GenericContainer({ style_class: 'popup-menu-item',
|
this.actor = new Shell.GenericContainer({ style_class: 'popup-menu-item',
|
||||||
reactive: params.reactive,
|
reactive: params.reactive,
|
||||||
track_hover: params.reactive,
|
track_hover: params.reactive,
|
||||||
@ -43,6 +45,9 @@ PopupBaseMenuItem.prototype = {
|
|||||||
this._spacing = 0;
|
this._spacing = 0;
|
||||||
this.active = false;
|
this.active = false;
|
||||||
|
|
||||||
|
if (params.style_class)
|
||||||
|
this.actor.add_style_class_name(params.style_class);
|
||||||
|
|
||||||
if (params.reactive && params.activate) {
|
if (params.reactive && params.activate) {
|
||||||
this.actor.connect('button-release-event', Lang.bind(this, this._onButtonReleaseEvent));
|
this.actor.connect('button-release-event', Lang.bind(this, this._onButtonReleaseEvent));
|
||||||
this.actor.connect('key-press-event', Lang.bind(this, this._onKeyPressEvent));
|
this.actor.connect('key-press-event', Lang.bind(this, this._onKeyPressEvent));
|
||||||
@ -527,8 +532,8 @@ function PopupSwitchMenuItem() {
|
|||||||
PopupSwitchMenuItem.prototype = {
|
PopupSwitchMenuItem.prototype = {
|
||||||
__proto__: PopupBaseMenuItem.prototype,
|
__proto__: PopupBaseMenuItem.prototype,
|
||||||
|
|
||||||
_init: function(text, active) {
|
_init: function(text, active, params) {
|
||||||
PopupBaseMenuItem.prototype._init.call(this);
|
PopupBaseMenuItem.prototype._init.call(this, params);
|
||||||
|
|
||||||
this.label = new St.Label({ text: text });
|
this.label = new St.Label({ text: text });
|
||||||
this._switch = new Switch(active);
|
this._switch = new Switch(active);
|
||||||
@ -555,15 +560,15 @@ PopupSwitchMenuItem.prototype = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function PopupImageMenuItem(text, iconName) {
|
function PopupImageMenuItem() {
|
||||||
this._init(text, iconName);
|
this._init.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
PopupImageMenuItem.prototype = {
|
PopupImageMenuItem.prototype = {
|
||||||
__proto__: PopupBaseMenuItem.prototype,
|
__proto__: PopupBaseMenuItem.prototype,
|
||||||
|
|
||||||
_init: function (text, iconName) {
|
_init: function (text, iconName, params) {
|
||||||
PopupBaseMenuItem.prototype._init.call(this);
|
PopupBaseMenuItem.prototype._init.call(this, params);
|
||||||
|
|
||||||
this.label = new St.Label({ text: text });
|
this.label = new St.Label({ text: text });
|
||||||
this.addActor(this.label);
|
this.addActor(this.label);
|
||||||
@ -608,8 +613,12 @@ PopupMenuBase.prototype = {
|
|||||||
_init: function(sourceActor, styleClass) {
|
_init: function(sourceActor, styleClass) {
|
||||||
this.sourceActor = sourceActor;
|
this.sourceActor = sourceActor;
|
||||||
|
|
||||||
|
if (styleClass !== undefined) {
|
||||||
this.box = new St.BoxLayout({ style_class: styleClass,
|
this.box = new St.BoxLayout({ style_class: styleClass,
|
||||||
vertical: true });
|
vertical: true });
|
||||||
|
} else {
|
||||||
|
this.box = new St.BoxLayout({ vertical: true });
|
||||||
|
}
|
||||||
|
|
||||||
this.isOpen = false;
|
this.isOpen = false;
|
||||||
this._activeMenuItem = null;
|
this._activeMenuItem = null;
|
||||||
|
@ -99,12 +99,12 @@ StatusMenuButton.prototype = {
|
|||||||
_createSubMenu: function() {
|
_createSubMenu: function() {
|
||||||
let item;
|
let item;
|
||||||
|
|
||||||
item = new PopupMenu.PopupImageMenuItem(_("Available"), 'user-available', true);
|
item = new PopupMenu.PopupImageMenuItem(_("Available"), 'user-available');
|
||||||
item.connect('activate', Lang.bind(this, this._setPresenceStatus, GnomeSession.PresenceStatus.AVAILABLE));
|
item.connect('activate', Lang.bind(this, this._setPresenceStatus, GnomeSession.PresenceStatus.AVAILABLE));
|
||||||
this.menu.addMenuItem(item);
|
this.menu.addMenuItem(item);
|
||||||
this._presenceItems[GnomeSession.PresenceStatus.AVAILABLE] = item;
|
this._presenceItems[GnomeSession.PresenceStatus.AVAILABLE] = item;
|
||||||
|
|
||||||
item = new PopupMenu.PopupImageMenuItem(_("Busy"), 'user-busy', true);
|
item = new PopupMenu.PopupImageMenuItem(_("Busy"), 'user-busy');
|
||||||
item.connect('activate', Lang.bind(this, this._setPresenceStatus, GnomeSession.PresenceStatus.BUSY));
|
item.connect('activate', Lang.bind(this, this._setPresenceStatus, GnomeSession.PresenceStatus.BUSY));
|
||||||
this.menu.addMenuItem(item);
|
this.menu.addMenuItem(item);
|
||||||
this._presenceItems[GnomeSession.PresenceStatus.BUSY] = item;
|
this._presenceItems[GnomeSession.PresenceStatus.BUSY] = item;
|
||||||
|
Loading…
Reference in New Issue
Block a user