js/status: Use menu items as actors

All menu items are actors now, so remove all the actor property usages.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/499
This commit is contained in:
Marco Trevisan (Treviño) 2019-04-12 16:00:49 -05:00 committed by Florian Müllner
parent bdf66d7b62
commit 41dd744b74
11 changed files with 59 additions and 58 deletions

View File

@ -118,9 +118,9 @@ var Indicator = class extends PanelMenu.SystemIndicator {
// Remember if there were setup devices and show the menu // Remember if there were setup devices and show the menu
// if we've seen setup devices and we're not hard blocked // if we've seen setup devices and we're not hard blocked
if (nDevices > 0) if (nDevices > 0)
this._item.actor.visible = !this._proxy.BluetoothHardwareAirplaneMode; this._item.visible = !this._proxy.BluetoothHardwareAirplaneMode;
else else
this._item.actor.visible = this._proxy.BluetoothHasAirplaneMode && !this._proxy.BluetoothAirplaneMode; this._item.visible = this._proxy.BluetoothHasAirplaneMode && !this._proxy.BluetoothAirplaneMode;
if (nConnectedDevices > 0) if (nConnectedDevices > 0)
/* Translators: this is the number of connected bluetooth devices */ /* Translators: this is the number of connected bluetooth devices */

View File

@ -37,12 +37,12 @@ var Indicator = class extends PanelMenu.SystemIndicator {
let icon = new St.Icon({ icon_name: 'display-brightness-symbolic', let icon = new St.Icon({ icon_name: 'display-brightness-symbolic',
style_class: 'popup-menu-icon' }); style_class: 'popup-menu-icon' });
this._item.actor.add(icon); this._item.add(icon);
this._item.actor.add(this._slider.actor, { expand: true }); this._item.add(this._slider.actor, { expand: true });
this._item.actor.connect('button-press-event', (actor, event) => { this._item.connect('button-press-event', (actor, event) => {
return this._slider.startDragging(event); return this._slider.startDragging(event);
}); });
this._item.actor.connect('key-press-event', (actor, event) => { this._item.connect('key-press-event', (actor, event) => {
return this._slider.onKeyPressEvent(actor, event); return this._slider.onKeyPressEvent(actor, event);
}); });
@ -55,7 +55,7 @@ var Indicator = class extends PanelMenu.SystemIndicator {
_sync() { _sync() {
let visible = this._proxy.Brightness >= 0; let visible = this._proxy.Brightness >= 0;
this._item.actor.visible = visible; this._item.visible = visible;
if (visible) if (visible)
this._slider.setValue(this._proxy.Brightness / 100.0); this._slider.setValue(this._proxy.Brightness / 100.0);
} }

View File

@ -15,17 +15,18 @@ const Util = imports.misc.util;
const INPUT_SOURCE_TYPE_XKB = 'xkb'; const INPUT_SOURCE_TYPE_XKB = 'xkb';
const INPUT_SOURCE_TYPE_IBUS = 'ibus'; const INPUT_SOURCE_TYPE_IBUS = 'ibus';
var LayoutMenuItem = class extends PopupMenu.PopupBaseMenuItem { var LayoutMenuItem = GObject.registerClass(
constructor(displayName, shortName) { class LayoutMenuItem extends PopupMenu.PopupBaseMenuItem {
super(); _init(displayName, shortName) {
super._init();
this.label = new St.Label({ text: displayName }); this.label = new St.Label({ text: displayName });
this.indicator = new St.Label({ text: shortName }); this.indicator = new St.Label({ text: shortName });
this.actor.add(this.label, { expand: true }); this.add(this.label, { expand: true });
this.actor.add(this.indicator); this.add(this.indicator);
this.actor.label_actor = this.label; this.label_actor = this.label;
} }
}; });
var InputSource = class { var InputSource = class {
constructor(type, id, displayName, shortName, index) { constructor(type, id, displayName, shortName, index) {
@ -857,7 +858,7 @@ class InputSourceIndicator extends PanelMenu.Button {
// but at least for now it is used as "allow popping up windows // but at least for now it is used as "allow popping up windows
// from shell menus"; we can always add a separate sessionMode // from shell menus"; we can always add a separate sessionMode
// option if need arises. // option if need arises.
this._showLayoutItem.actor.visible = Main.sessionMode.allowSettings; this._showLayoutItem.visible = Main.sessionMode.allowSettings;
} }
_sourcesChanged() { _sourcesChanged() {

View File

@ -101,12 +101,12 @@ var Indicator = class extends PanelMenu.SystemIndicator {
_syncIndicator() { _syncIndicator() {
if (this._managerProxy == null) { if (this._managerProxy == null) {
this._indicator.visible = false; this._indicator.visible = false;
this._item.actor.visible = false; this._item.visible = false;
return; return;
} }
this._indicator.visible = this._managerProxy.InUse; this._indicator.visible = this._managerProxy.InUse;
this._item.actor.visible = this._indicator.visible; this._item.visible = this._indicator.visible;
this._updateMenuLabels(); this._updateMenuLabels();
} }

View File

@ -389,8 +389,8 @@ var NMConnectionDevice = class NMConnectionDevice extends NMConnectionSection {
_sync() { _sync() {
let nItems = this._connectionItems.size; let nItems = this._connectionItems.size;
this._autoConnectItem.actor.visible = (nItems == 0); this._autoConnectItem.visible = (nItems == 0);
this._deactivateItem.actor.visible = this._device.state > NM.DeviceState.DISCONNECTED; this._deactivateItem.visible = this._device.state > NM.DeviceState.DISCONNECTED;
if (this._activeConnection == null) { if (this._activeConnection == null) {
let activeConnection = this._device.active_connection; let activeConnection = this._device.active_connection;
@ -477,7 +477,7 @@ var NMDeviceWired = class extends NMConnectionDevice {
} }
_sync() { _sync() {
this.item.actor.visible = this._hasCarrier(); this.item.visible = this._hasCarrier();
super._sync(); super._sync();
} }
@ -1076,7 +1076,7 @@ var NMWirelessDialog = class extends ModalDialog.ModalDialog {
let newPos = Util.insertSorted(this._networks, network, this._networkSortFunction); let newPos = Util.insertSorted(this._networks, network, this._networkSortFunction);
this._createNetworkItem(network); this._createNetworkItem(network);
this._itemBox.insert_child_at_index(network.item.actor, newPos); this._itemBox.insert_child_at_index(network.item, newPos);
} }
this._syncView(); this._syncView();
@ -1094,7 +1094,7 @@ var NMWirelessDialog = class extends ModalDialog.ModalDialog {
network.accessPoints.splice(res.ap, 1); network.accessPoints.splice(res.ap, 1);
if (network.accessPoints.length == 0) { if (network.accessPoints.length == 0) {
network.item.actor.destroy(); network.item.destroy();
this._networks.splice(res.network, 1); this._networks.splice(res.network, 1);
} else { } else {
network.item.updateBestAP(network.accessPoints[0]); network.item.updateBestAP(network.accessPoints[0]);
@ -1110,7 +1110,7 @@ var NMWirelessDialog = class extends ModalDialog.ModalDialog {
this._itemBox.remove_all_children(); this._itemBox.remove_all_children();
this._networks.forEach(network => { this._networks.forEach(network => {
this._itemBox.add_child(network.item.actor); this._itemBox.add_child(network.item);
}); });
adjustment.value = scrollValue; adjustment.value = scrollValue;
@ -1118,25 +1118,25 @@ var NMWirelessDialog = class extends ModalDialog.ModalDialog {
_selectNetwork(network) { _selectNetwork(network) {
if (this._selectedNetwork) if (this._selectedNetwork)
this._selectedNetwork.item.actor.remove_style_pseudo_class('selected'); this._selectedNetwork.item.remove_style_pseudo_class('selected');
this._selectedNetwork = network; this._selectedNetwork = network;
this._updateSensitivity(); this._updateSensitivity();
if (this._selectedNetwork) if (this._selectedNetwork)
this._selectedNetwork.item.actor.add_style_pseudo_class('selected'); this._selectedNetwork.item.add_style_pseudo_class('selected');
} }
_createNetworkItem(network) { _createNetworkItem(network) {
network.item = new NMWirelessDialogItem(network); network.item = new NMWirelessDialogItem(network);
network.item.setActive(network == this._selectedNetwork); network.item.setActive(network == this._selectedNetwork);
network.item.connect('selected', () => { network.item.connect('selected', () => {
Util.ensureActorVisibleInScrollView(this._scrollView, network.item.actor); Util.ensureActorVisibleInScrollView(this._scrollView, network.item);
this._selectNetwork(network); this._selectNetwork(network);
}); });
network.item.actor.connect('destroy', () => { network.item.connect('destroy', () => {
let keyFocus = global.stage.key_focus; let keyFocus = global.stage.key_focus;
if (keyFocus && keyFocus.contains(network.item.actor)) if (keyFocus && keyFocus.contains(network.item))
this._itemBox.grab_key_focus(); this._itemBox.grab_key_focus();
}); });
} }
@ -1262,7 +1262,7 @@ var NMDeviceWireless = class {
_sync() { _sync() {
this._toggleItem.label.text = this._client.wireless_enabled ? _("Turn Off") : _("Turn On"); this._toggleItem.label.text = this._client.wireless_enabled ? _("Turn Off") : _("Turn On");
this._toggleItem.actor.visible = this._client.wireless_hardware_enabled; this._toggleItem.visible = this._client.wireless_hardware_enabled;
this.item.icon.icon_name = this._getMenuIcon(); this.item.icon.icon_name = this._getMenuIcon();
this.item.label.text = this._getStatus(); this.item.label.text = this._getStatus();
@ -1452,7 +1452,7 @@ var NMVpnSection = class extends NMConnectionSection {
_sync() { _sync() {
let nItems = this._connectionItems.size; let nItems = this._connectionItems.size;
this.item.actor.visible = (nItems > 0); this.item.visible = (nItems > 0);
super._sync(); super._sync();
} }
@ -1535,7 +1535,7 @@ var DeviceCategory = class extends PopupMenu.PopupMenuSection {
this._summaryItem.menu.addSettingsAction(_('Network Settings'), this._summaryItem.menu.addSettingsAction(_('Network Settings'),
'gnome-network-panel.desktop'); 'gnome-network-panel.desktop');
this._summaryItem.actor.hide(); this._summaryItem.hide();
} }
@ -1544,7 +1544,7 @@ var DeviceCategory = class extends PopupMenu.PopupMenuSection {
(prev, child) => prev + (child.visible ? 1 : 0), 0); (prev, child) => prev + (child.visible ? 1 : 0), 0);
this._summaryItem.label.text = this._getSummaryLabel(nDevices); this._summaryItem.label.text = this._getSummaryLabel(nDevices);
let shouldSummarize = nDevices > MAX_DEVICE_ITEMS; let shouldSummarize = nDevices > MAX_DEVICE_ITEMS;
this._summaryItem.actor.visible = shouldSummarize; this._summaryItem.visible = shouldSummarize;
this.section.actor.visible = !shouldSummarize; this.section.actor.visible = !shouldSummarize;
} }

View File

@ -61,6 +61,6 @@ var Indicator = class extends PanelMenu.SystemIndicator {
: _("Night Light On"); : _("Night Light On");
this._disableItem.label.text = disabled ? _("Resume") this._disableItem.label.text = disabled ? _("Resume")
: _("Disable Until Tomorrow"); : _("Disable Until Tomorrow");
this._item.actor.visible = this._indicator.visible = visible; this._item.visible = this._indicator.visible = visible;
} }
}; };

View File

@ -96,11 +96,11 @@ var Indicator = class extends PanelMenu.SystemIndicator {
// Do we have batteries or a UPS? // Do we have batteries or a UPS?
let visible = this._proxy.IsPresent; let visible = this._proxy.IsPresent;
if (visible) { if (visible) {
this._item.actor.show(); this._item.show();
this._percentageLabel.visible = this._desktopSettings.get_boolean(SHOW_BATTERY_PERCENTAGE); this._percentageLabel.visible = this._desktopSettings.get_boolean(SHOW_BATTERY_PERCENTAGE);
} else { } else {
// If there's no battery, then we use the power icon. // If there's no battery, then we use the power icon.
this._item.actor.hide(); this._item.hide();
this._indicator.icon_name = 'system-shutdown-symbolic'; this._indicator.icon_name = 'system-shutdown-symbolic';
this._percentageLabel.hide(); this._percentageLabel.hide();
return; return;

View File

@ -53,10 +53,10 @@ var RemoteAccessApplet = class extends PanelMenu.SystemIndicator {
_sync() { _sync() {
if (this._handles.size == 0) { if (this._handles.size == 0) {
this._indicator.visible = false; this._indicator.visible = false;
this._item.actor.visible = false; this._item.visible = false;
} else { } else {
this._indicator.visible = true; this._indicator.visible = true;
this._item.actor.visible = true; this._item.visible = true;
} }
} }

View File

@ -97,7 +97,7 @@ var Indicator = class extends PanelMenu.SystemIndicator {
let showAirplaneMode = this._manager.shouldShowAirplaneMode; let showAirplaneMode = this._manager.shouldShowAirplaneMode;
this._indicator.visible = (airplaneMode && showAirplaneMode); this._indicator.visible = (airplaneMode && showAirplaneMode);
this._item.actor.visible = (airplaneMode && showAirplaneMode); this._item.visible = (airplaneMode && showAirplaneMode);
this._offItem.setSensitive(!hwAirplaneMode); this._offItem.setSensitive(!hwAirplaneMode);
if (hwAirplaneMode) if (hwAirplaneMode)

View File

@ -116,10 +116,10 @@ var Indicator = class extends PanelMenu.SystemIndicator {
this._createSubMenu(); this._createSubMenu();
this._loginScreenItem.actor.connect('notify::visible', this._loginScreenItem.connect('notify::visible',
() => { this._updateMultiUser(); }); () => { this._updateMultiUser(); });
this._logoutItem.actor.connect('notify::visible', this._logoutItem.connect('notify::visible',
() => { this._updateMultiUser(); }); () => { this._updateMultiUser(); });
// Whether shutdown is available or not depends on both lockdown // Whether shutdown is available or not depends on both lockdown
// settings (disable-log-out) and Polkit policy - the latter doesn't // settings (disable-log-out) and Polkit policy - the latter doesn't
// notify, so we update the menu item each time the menu opens or // notify, so we update the menu item each time the menu opens or
@ -142,7 +142,7 @@ var Indicator = class extends PanelMenu.SystemIndicator {
this._lockScreenAction.visible || this._lockScreenAction.visible ||
this._altSwitcher.actor.visible); this._altSwitcher.actor.visible);
this._actionsItem.actor.visible = visible; this._actionsItem.visible = visible;
} }
_sessionUpdated() { _sessionUpdated() {
@ -150,10 +150,10 @@ var Indicator = class extends PanelMenu.SystemIndicator {
} }
_updateMultiUser() { _updateMultiUser() {
let hasSwitchUser = this._loginScreenItem.actor.visible; let hasSwitchUser = this._loginScreenItem.visible;
let hasLogout = this._logoutItem.actor.visible; let hasLogout = this._logoutItem.visible;
this._switchUserSubMenu.actor.visible = hasSwitchUser || hasLogout; this._switchUserSubMenu.visible = hasSwitchUser || hasLogout;
} }
_updateSwitchUserSubMenu() { _updateSwitchUserSubMenu() {
@ -208,7 +208,7 @@ var Indicator = class extends PanelMenu.SystemIndicator {
this._switchUserSubMenu.menu.addMenuItem(item); this._switchUserSubMenu.menu.addMenuItem(item);
this._loginScreenItem = item; this._loginScreenItem = item;
this._systemActions.bind_property('can-switch-user', this._systemActions.bind_property('can-switch-user',
this._loginScreenItem.actor, this._loginScreenItem,
'visible', 'visible',
bindFlags); bindFlags);
@ -220,7 +220,7 @@ var Indicator = class extends PanelMenu.SystemIndicator {
this._switchUserSubMenu.menu.addMenuItem(item); this._switchUserSubMenu.menu.addMenuItem(item);
this._logoutItem = item; this._logoutItem = item;
this._systemActions.bind_property('can-logout', this._systemActions.bind_property('can-logout',
this._logoutItem.actor, this._logoutItem,
'visible', 'visible',
bindFlags); bindFlags);
@ -236,7 +236,7 @@ var Indicator = class extends PanelMenu.SystemIndicator {
item = new PopupMenu.PopupBaseMenuItem({ reactive: false, item = new PopupMenu.PopupBaseMenuItem({ reactive: false,
can_focus: false }); can_focus: false });
this.buttonGroup = item.actor; this.buttonGroup = item;
let app = this._settingsApp = Shell.AppSystem.get_default().lookup_app( let app = this._settingsApp = Shell.AppSystem.get_default().lookup_app(
'gnome-control-center.desktop' 'gnome-control-center.desktop'
@ -251,14 +251,14 @@ var Indicator = class extends PanelMenu.SystemIndicator {
log('Missing required core component Settings, expect trouble…'); log('Missing required core component Settings, expect trouble…');
this._settingsAction = new St.Widget(); this._settingsAction = new St.Widget();
} }
item.actor.add(this._settingsAction, { expand: true, x_fill: false }); item.add(this._settingsAction, { expand: true, x_fill: false });
this._orientationLockAction = this._createActionButton('', _("Orientation Lock")); this._orientationLockAction = this._createActionButton('', _("Orientation Lock"));
this._orientationLockAction.connect('clicked', () => { this._orientationLockAction.connect('clicked', () => {
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE), this.menu.itemActivated(BoxPointer.PopupAnimation.NONE),
this._systemActions.activateLockOrientation(); this._systemActions.activateLockOrientation();
}); });
item.actor.add(this._orientationLockAction, { expand: true, x_fill: false }); item.add(this._orientationLockAction, { expand: true, x_fill: false });
this._systemActions.bind_property('can-lock-orientation', this._systemActions.bind_property('can-lock-orientation',
this._orientationLockAction, this._orientationLockAction,
'visible', 'visible',
@ -273,7 +273,7 @@ var Indicator = class extends PanelMenu.SystemIndicator {
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE); this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
this._systemActions.activateLockScreen(); this._systemActions.activateLockScreen();
}); });
item.actor.add(this._lockScreenAction, { expand: true, x_fill: false }); item.add(this._lockScreenAction, { expand: true, x_fill: false });
this._systemActions.bind_property('can-lock-screen', this._systemActions.bind_property('can-lock-screen',
this._lockScreenAction, this._lockScreenAction,
'visible', 'visible',
@ -300,7 +300,7 @@ var Indicator = class extends PanelMenu.SystemIndicator {
bindFlags); bindFlags);
this._altSwitcher = new AltSwitcher(this._powerOffAction, this._suspendAction); this._altSwitcher = new AltSwitcher(this._powerOffAction, this._suspendAction);
item.actor.add(this._altSwitcher.actor, { expand: true, x_fill: false }); item.add(this._altSwitcher.actor, { expand: true, x_fill: false });
this._actionsItem = item; this._actionsItem = item;
this.menu.addMenuItem(item); this.menu.addMenuItem(item);

View File

@ -41,12 +41,12 @@ var StreamSlider = class {
this._slider.connect('drag-end', this._notifyVolumeChange.bind(this)); this._slider.connect('drag-end', this._notifyVolumeChange.bind(this));
this._icon = new St.Icon({ style_class: 'popup-menu-icon' }); this._icon = new St.Icon({ style_class: 'popup-menu-icon' });
this.item.actor.add(this._icon); this.item.add(this._icon);
this.item.actor.add(this._slider.actor, { expand: true }); this.item.add(this._slider.actor, { expand: true });
this.item.actor.connect('button-press-event', (actor, event) => { this.item.connect('button-press-event', (actor, event) => {
return this._slider.startDragging(event); return this._slider.startDragging(event);
}); });
this.item.actor.connect('key-press-event', (actor, event) => { this.item.connect('key-press-event', (actor, event) => {
return this._slider.onKeyPressEvent(actor, event); return this._slider.onKeyPressEvent(actor, event);
}); });
@ -93,7 +93,7 @@ var StreamSlider = class {
_updateVisibility() { _updateVisibility() {
let visible = this._shouldBeVisible(); let visible = this._shouldBeVisible();
this.item.actor.visible = visible; this.item.visible = visible;
} }
scroll(event) { scroll(event) {