PopupMenu: enhance PopupSwitchMenuItem to show status labels
Moves and converts NMDeviceTitleMenuItem from network.js into PopupSwitchMenuItem, so that it can show both a switch and a greyed-out status label. This will be soon used by the Bluetooth menu. https://bugzilla.gnome.org/show_bug.cgi?id=648048
This commit is contained in:
parent
4132ccae33
commit
c8670819dc
@ -187,6 +187,7 @@ StTooltip StLabel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.popup-inactive-menu-item {
|
.popup-inactive-menu-item {
|
||||||
|
font-weight: normal;
|
||||||
color: #999;
|
color: #999;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -704,11 +704,36 @@ PopupSwitchMenuItem.prototype = {
|
|||||||
this._switch = new Switch(active);
|
this._switch = new Switch(active);
|
||||||
|
|
||||||
this.addActor(this.label);
|
this.addActor(this.label);
|
||||||
this.addActor(this._switch.actor, { align: St.Align.END });
|
|
||||||
|
|
||||||
this.connect('activate', Lang.bind(this,function(from) {
|
this._statusBin = new St.Bin({ x_align: St.Align.END });
|
||||||
|
this.addActor(this._statusBin, { align: St.Align.END });
|
||||||
|
|
||||||
|
this._statusLabel = new St.Label({ text: '',
|
||||||
|
style_class: 'popup-inactive-menu-item'
|
||||||
|
});
|
||||||
|
this._switch = new Switch(false);
|
||||||
|
this._statusBin.child = this._switch.actor;
|
||||||
|
},
|
||||||
|
|
||||||
|
setStatus: function(text) {
|
||||||
|
if (text != null) {
|
||||||
|
this._statusLabel.text = text;
|
||||||
|
this._statusBin.child = this._statusLabel;
|
||||||
|
this.actor.reactive = false;
|
||||||
|
this.actor.can_focus = false;
|
||||||
|
} else {
|
||||||
|
this._statusBin.child = this._switch.actor;
|
||||||
|
this.actor.reactive = true;
|
||||||
|
this.actor.can_focus = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
activate: function(event) {
|
||||||
|
if (this._switch.actor.mapped) {
|
||||||
this.toggle();
|
this.toggle();
|
||||||
}));
|
}
|
||||||
|
|
||||||
|
PopupBaseMenuItem.prototype.activate.call(this, event);
|
||||||
},
|
},
|
||||||
|
|
||||||
toggle: function() {
|
toggle: function() {
|
||||||
|
@ -196,68 +196,18 @@ NMNetworkMenuItem.prototype = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function NMDeviceTitleMenuItem() {
|
|
||||||
this._init.apply(this, arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
NMDeviceTitleMenuItem.prototype = {
|
|
||||||
__proto__: PopupMenu.PopupBaseMenuItem.prototype,
|
|
||||||
|
|
||||||
_init: function(description, params) {
|
|
||||||
PopupMenu.PopupBaseMenuItem.prototype._init.call(this, params);
|
|
||||||
|
|
||||||
this._descriptionLabel = new St.Label({ text: description,
|
|
||||||
style_class: 'popup-subtitle-menu-item'
|
|
||||||
});
|
|
||||||
this.addActor(this._descriptionLabel);
|
|
||||||
|
|
||||||
this._statusBin = new St.Bin({ x_align: St.Align.END });
|
|
||||||
this.addActor(this._statusBin, { align: St.Align.END });
|
|
||||||
|
|
||||||
this._statusLabel = new St.Label({ text: '',
|
|
||||||
style_class: 'popup-inactive-menu-item'
|
|
||||||
});
|
|
||||||
this._switch = new PopupMenu.Switch(false);
|
|
||||||
this._statusBin.child = this._switch.actor;
|
|
||||||
},
|
|
||||||
|
|
||||||
setStatus: function(text) {
|
|
||||||
if (text != null) {
|
|
||||||
this._statusLabel.text = text;
|
|
||||||
this._statusBin.child = this._statusLabel;
|
|
||||||
this.actor.reactive = false;
|
|
||||||
this.actor.can_focus = false;
|
|
||||||
} else {
|
|
||||||
this._statusBin.child = this._switch.actor;
|
|
||||||
this.actor.reactive = true;
|
|
||||||
this.actor.can_focus = true;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
activate: function(event) {
|
|
||||||
if (this._switch.actor.mapped) {
|
|
||||||
this._switch.toggle();
|
|
||||||
this.emit('toggled', this._switch.state);
|
|
||||||
}
|
|
||||||
|
|
||||||
PopupMenu.PopupBaseMenuItem.prototype.activate.call(this, event);
|
|
||||||
},
|
|
||||||
|
|
||||||
get state() {
|
|
||||||
return this._switch.state;
|
|
||||||
},
|
|
||||||
|
|
||||||
setToggleState: function(newval) {
|
|
||||||
this._switch.setToggleState(newval);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function NMWiredSectionTitleMenuItem() {
|
function NMWiredSectionTitleMenuItem() {
|
||||||
this._init.apply(this, arguments);
|
this._init.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
NMWiredSectionTitleMenuItem.prototype = {
|
NMWiredSectionTitleMenuItem.prototype = {
|
||||||
__proto__: NMDeviceTitleMenuItem.prototype,
|
__proto__: PopupMenu.PopupSwitchMenuItem.prototype,
|
||||||
|
|
||||||
|
_init: function(label, params) {
|
||||||
|
params = params || { };
|
||||||
|
params.style_class = 'popup-subtitle-menu-item';
|
||||||
|
PopupMenu.PopupSwitchMenuItem.prototype._init.call(this, label, false, params);
|
||||||
|
},
|
||||||
|
|
||||||
updateForDevice: function(device) {
|
updateForDevice: function(device) {
|
||||||
if (device) {
|
if (device) {
|
||||||
@ -269,7 +219,7 @@ NMWiredSectionTitleMenuItem.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
activate: function(event) {
|
activate: function(event) {
|
||||||
NMDeviceTitleMenuItem.prototype.activate.call(this, event);
|
PopupMenu.PopupSwitchMenuItem.prototype.activate.call(this, event);
|
||||||
|
|
||||||
if (!this._device) {
|
if (!this._device) {
|
||||||
log('Section title activated when there is more than one device, should be non reactive');
|
log('Section title activated when there is more than one device, should be non reactive');
|
||||||
@ -295,10 +245,12 @@ function NMWirelessSectionTitleMenuItem() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
NMWirelessSectionTitleMenuItem.prototype = {
|
NMWirelessSectionTitleMenuItem.prototype = {
|
||||||
__proto__: NMDeviceTitleMenuItem.prototype,
|
__proto__: PopupMenu.PopupSwitchMenuItem.prototype,
|
||||||
|
|
||||||
_init: function(client, property, title, params) {
|
_init: function(client, property, title, params) {
|
||||||
NMDeviceTitleMenuItem.prototype._init.call(this, title, params);
|
params = params || { };
|
||||||
|
params.style_class = 'popup-subtitle-menu-item';
|
||||||
|
PopupMenu.PopupSwitchMenuItem.prototype._init.call(this, title, false, params);
|
||||||
|
|
||||||
this._client = client;
|
this._client = client;
|
||||||
this._property = property + '_enabled';
|
this._property = property + '_enabled';
|
||||||
@ -324,7 +276,7 @@ NMWirelessSectionTitleMenuItem.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
activate: function(event) {
|
activate: function(event) {
|
||||||
NMDeviceTitleMenuItem.prototype.activate.call(this, event);
|
PopupMenu.PopupSwitchMenuItem.prototype.activate.call(this, event);
|
||||||
|
|
||||||
this._client[this._setEnabledFunc](this._switch.state);
|
this._client[this._setEnabledFunc](this._switch.state);
|
||||||
},
|
},
|
||||||
@ -380,7 +332,7 @@ NMDevice.prototype = {
|
|||||||
this._overflowItem = null;
|
this._overflowItem = null;
|
||||||
|
|
||||||
if (this.device) {
|
if (this.device) {
|
||||||
this.statusItem = new NMDeviceTitleMenuItem(this._getDescription());
|
this.statusItem = new PopupMenu.PopupSwitchMenuItem(this._getDescription(), this.connected, { style_class: 'popup-subtitle-menu-item' });
|
||||||
this._statusChanged = this.statusItem.connect('toggled', Lang.bind(this, function(item, state) {
|
this._statusChanged = this.statusItem.connect('toggled', Lang.bind(this, function(item, state) {
|
||||||
if (state)
|
if (state)
|
||||||
this.activate();
|
this.activate();
|
||||||
|
Loading…
Reference in New Issue
Block a user