cleanup: Use inheritance for Actor classes instead of composition
Remove the `this.actor = ...` and `this.actor._delegate = this` patterns in most of classes, by inheriting all the actor container classes. Uses interfaces when needed for making sure that multiple classes will implement some required methods or to avoid redefining the same code multiple times. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/559
This commit is contained in:

committed by
Florian Müllner

parent
f67b409fc1
commit
c4c5c4fd5c
@ -102,7 +102,7 @@ class ATIndicator extends PanelMenu.Button {
|
||||
_buildItemExtended(string, initialValue, writable, onSet) {
|
||||
let widget = new PopupMenu.PopupSwitchMenuItem(string, initialValue);
|
||||
if (!writable)
|
||||
widget.actor.reactive = false;
|
||||
widget.reactive = false;
|
||||
else
|
||||
widget.connect('toggled', item => {
|
||||
onSet(item.state);
|
||||
|
@ -1,7 +1,7 @@
|
||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||
/* exported Indicator */
|
||||
|
||||
const { Gio, GnomeBluetooth } = imports.gi;
|
||||
const { Gio, GnomeBluetooth, GObject } = imports.gi;
|
||||
|
||||
const Main = imports.ui.main;
|
||||
const PanelMenu = imports.ui.panelMenu;
|
||||
@ -17,9 +17,11 @@ const RfkillManagerProxy = Gio.DBusProxy.makeProxyWrapper(RfkillManagerInterface
|
||||
|
||||
const HAD_BLUETOOTH_DEVICES_SETUP = 'had-bluetooth-devices-setup';
|
||||
|
||||
var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
constructor() {
|
||||
super();
|
||||
var Indicator = GObject.registerClass({
|
||||
GTypeName: 'Bluetooth_Indicator'
|
||||
}, class Indicator extends PanelMenu.SystemIndicator {
|
||||
_init() {
|
||||
super._init();
|
||||
|
||||
this._indicator = this._addIndicator();
|
||||
this._indicator.icon_name = 'bluetooth-active-symbolic';
|
||||
@ -133,4 +135,4 @@ var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
|
||||
this._toggleItem.label.text = this._proxy.BluetoothAirplaneMode ? _("Turn On") : _("Turn Off");
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -15,9 +15,11 @@ const OBJECT_PATH = '/org/gnome/SettingsDaemon/Power';
|
||||
const BrightnessInterface = loadInterfaceXML('org.gnome.SettingsDaemon.Power.Screen');
|
||||
const BrightnessProxy = Gio.DBusProxy.makeProxyWrapper(BrightnessInterface);
|
||||
|
||||
var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
constructor() {
|
||||
super('display-brightness-symbolic');
|
||||
var Indicator = GObject.registerClass({
|
||||
GTypeName: 'Brightness_Indicator'
|
||||
}, class Indicator extends PanelMenu.SystemIndicator {
|
||||
_init() {
|
||||
super._init();
|
||||
this._proxy = new BrightnessProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH,
|
||||
(proxy, error) => {
|
||||
if (error) {
|
||||
@ -67,4 +69,4 @@ var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
if (visible)
|
||||
this._changeSlider(this._proxy.Brightness / 100.0);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -923,7 +923,7 @@ class InputSourceIndicator extends PanelMenu.Button {
|
||||
}
|
||||
|
||||
_buildPropSection(properties) {
|
||||
this._propSeparator.actor.hide();
|
||||
this._propSeparator.hide();
|
||||
this._propSection.actor.hide();
|
||||
this._propSection.removeAll();
|
||||
|
||||
@ -931,7 +931,7 @@ class InputSourceIndicator extends PanelMenu.Button {
|
||||
|
||||
if (!this._propSection.isEmpty()) {
|
||||
this._propSection.actor.show();
|
||||
this._propSeparator.actor.show();
|
||||
this._propSeparator.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,9 +42,11 @@ const GeoclueManager = Gio.DBusProxy.makeProxyWrapper(GeoclueIface);
|
||||
|
||||
var AgentIface = loadInterfaceXML('org.freedesktop.GeoClue2.Agent');
|
||||
|
||||
var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
constructor() {
|
||||
super();
|
||||
var Indicator = GObject.registerClass({
|
||||
GTypeName: 'Location_Indicator'
|
||||
}, class Indicator extends PanelMenu.SystemIndicator {
|
||||
_init() {
|
||||
super._init();
|
||||
|
||||
this._settings = new Gio.Settings({ schema_id: LOCATION_SCHEMA });
|
||||
this._settings.connect(`changed::${ENABLED}`,
|
||||
@ -222,7 +224,7 @@ var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
|
||||
this._permStoreProxy = proxy;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
function clamp(value, min, max) {
|
||||
return Math.max(min, Math.min(max, value));
|
||||
|
@ -860,7 +860,7 @@ class NMWirelessDialog extends ModalDialog.ModalDialog {
|
||||
y_align: Clutter.ActorAlign.CENTER });
|
||||
|
||||
this._noNetworksSpinner = new Animation.Spinner(16);
|
||||
this._noNetworksBox.add_actor(this._noNetworksSpinner.actor);
|
||||
this._noNetworksBox.add_actor(this._noNetworksSpinner);
|
||||
this._noNetworksBox.add_actor(new St.Label({ style_class: 'no-networks-label',
|
||||
text: _("No Networks") }));
|
||||
this._stack.add_child(this._noNetworksBox);
|
||||
@ -1588,9 +1588,11 @@ var DeviceCategory = class extends PopupMenu.PopupMenuSection {
|
||||
}
|
||||
};
|
||||
|
||||
var NMApplet = class extends PanelMenu.SystemIndicator {
|
||||
constructor() {
|
||||
super();
|
||||
var NMApplet = GObject.registerClass({
|
||||
GTypeName: 'Network_Indicator'
|
||||
}, class Indicator extends PanelMenu.SystemIndicator {
|
||||
_init() {
|
||||
super._init();
|
||||
|
||||
this._primaryIndicator = this._addIndicator();
|
||||
this._vpnIndicator = this._addIndicator();
|
||||
@ -1939,7 +1941,7 @@ var NMApplet = class extends PanelMenu.SystemIndicator {
|
||||
}
|
||||
|
||||
_syncNMState() {
|
||||
this.indicators.visible = this._client.nm_running;
|
||||
this.visible = this._client.nm_running;
|
||||
this.menu.actor.visible = this._client.networking_enabled;
|
||||
|
||||
this._updateIcon();
|
||||
@ -2058,4 +2060,4 @@ var NMApplet = class extends PanelMenu.SystemIndicator {
|
||||
this._vpnIndicator.icon_name = this._vpnSection.getIndicatorIcon();
|
||||
this._vpnIndicator.visible = (this._vpnIndicator.icon_name != '');
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||
/* exported Indicator */
|
||||
|
||||
const Gio = imports.gi.Gio;
|
||||
const { Gio, GObject } = imports.gi;
|
||||
|
||||
const Main = imports.ui.main;
|
||||
const PanelMenu = imports.ui.panelMenu;
|
||||
@ -15,9 +15,11 @@ const OBJECT_PATH = '/org/gnome/SettingsDaemon/Color';
|
||||
const ColorInterface = loadInterfaceXML('org.gnome.SettingsDaemon.Color');
|
||||
const ColorProxy = Gio.DBusProxy.makeProxyWrapper(ColorInterface);
|
||||
|
||||
var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
constructor() {
|
||||
super();
|
||||
var Indicator = GObject.registerClass({
|
||||
GTypeName: 'NightLight_Indicator'
|
||||
}, class Indicator extends PanelMenu.SystemIndicator {
|
||||
_init() {
|
||||
super._init();
|
||||
|
||||
this._indicator = this._addIndicator();
|
||||
this._indicator.icon_name = 'night-light-symbolic';
|
||||
@ -66,4 +68,4 @@ var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
: _("Disable Until Tomorrow");
|
||||
this._item.visible = this._indicator.visible = visible;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||
/* exported Indicator */
|
||||
|
||||
const { Clutter, Gio, St, UPowerGlib: UPower } = imports.gi;
|
||||
const { Clutter, Gio, GObject, St, UPowerGlib: UPower } = imports.gi;
|
||||
|
||||
const Main = imports.ui.main;
|
||||
const PanelMenu = imports.ui.panelMenu;
|
||||
@ -17,9 +17,11 @@ const PowerManagerProxy = Gio.DBusProxy.makeProxyWrapper(DisplayDeviceInterface)
|
||||
|
||||
const SHOW_BATTERY_PERCENTAGE = 'show-battery-percentage';
|
||||
|
||||
var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
constructor() {
|
||||
super();
|
||||
var Indicator = GObject.registerClass({
|
||||
GTypeName: 'Power_Indicator'
|
||||
}, class Indicator extends PanelMenu.SystemIndicator {
|
||||
_init() {
|
||||
super._init();
|
||||
|
||||
this._desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
|
||||
this._desktopSettings.connect(`changed::${SHOW_BATTERY_PERCENTAGE}`,
|
||||
@ -28,8 +30,8 @@ var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
this._indicator = this._addIndicator();
|
||||
this._percentageLabel = new St.Label({ y_expand: true,
|
||||
y_align: Clutter.ActorAlign.CENTER });
|
||||
this.indicators.add(this._percentageLabel, { expand: true, y_fill: true });
|
||||
this.indicators.add_style_class_name('power-status');
|
||||
this.add(this._percentageLabel, { expand: true, y_fill: true });
|
||||
this.add_style_class_name('power-status');
|
||||
|
||||
this._proxy = new PowerManagerProxy(Gio.DBus.system, BUS_NAME, OBJECT_PATH,
|
||||
(proxy, error) => {
|
||||
@ -140,4 +142,4 @@ var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
// The status label
|
||||
this._item.label.text = this._getStatus();
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -1,14 +1,16 @@
|
||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||
/* exported RemoteAccessApplet */
|
||||
|
||||
const Meta = imports.gi.Meta;
|
||||
const { GObject, Meta } = imports.gi;
|
||||
|
||||
const PanelMenu = imports.ui.panelMenu;
|
||||
const PopupMenu = imports.ui.popupMenu;
|
||||
|
||||
var RemoteAccessApplet = class extends PanelMenu.SystemIndicator {
|
||||
constructor() {
|
||||
super();
|
||||
var RemoteAccessApplet = GObject.registerClass({
|
||||
GTypeName: 'RemoteAccess_Indicator'
|
||||
}, class RemoteAccessApplet extends PanelMenu.SystemIndicator {
|
||||
_init() {
|
||||
super._init();
|
||||
|
||||
let backend = Meta.get_backend();
|
||||
let controller = backend.get_remote_access_controller();
|
||||
@ -75,4 +77,4 @@ var RemoteAccessApplet = class extends PanelMenu.SystemIndicator {
|
||||
this._sync();
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||
/* exported Indicator */
|
||||
|
||||
const Gio = imports.gi.Gio;
|
||||
const { Gio, GObject } = imports.gi;
|
||||
const Signals = imports.signals;
|
||||
|
||||
const Main = imports.ui.main;
|
||||
@ -61,9 +61,11 @@ function getRfkillManager() {
|
||||
return _manager;
|
||||
}
|
||||
|
||||
var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
constructor() {
|
||||
super();
|
||||
var Indicator = GObject.registerClass({
|
||||
GTypeName: 'Rfkill_Indicator'
|
||||
}, class Indicator extends PanelMenu.SystemIndicator {
|
||||
_init() {
|
||||
super._init();
|
||||
|
||||
this._manager = getRfkillManager();
|
||||
this._manager.connect('airplane-mode-changed', this._sync.bind(this));
|
||||
@ -106,4 +108,4 @@ var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
else
|
||||
this._offItem.label.text = _("Turn Off");
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -1,12 +1,16 @@
|
||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||
/* exported Indicator */
|
||||
|
||||
const GObject = imports.gi.GObject;
|
||||
|
||||
const Main = imports.ui.main;
|
||||
const PanelMenu = imports.ui.panelMenu;
|
||||
|
||||
var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
constructor() {
|
||||
super();
|
||||
var Indicator = GObject.registerClass({
|
||||
GTypeName: 'Screencast_Indicator'
|
||||
}, class Indicator extends PanelMenu.SystemIndicator {
|
||||
_init() {
|
||||
super._init();
|
||||
|
||||
this._indicator = this._addIndicator();
|
||||
this._indicator.icon_name = 'media-record-symbolic';
|
||||
@ -19,4 +23,4 @@ var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
_sync() {
|
||||
this._indicator.visible = Main.screencastService.isRecording;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -10,8 +10,10 @@ const PanelMenu = imports.ui.panelMenu;
|
||||
const PopupMenu = imports.ui.popupMenu;
|
||||
|
||||
|
||||
var AltSwitcher = class {
|
||||
constructor(standard, alternate) {
|
||||
var AltSwitcher = GObject.registerClass(
|
||||
class AltSwitcher extends St.Bin {
|
||||
_init(standard, alternate) {
|
||||
super._init();
|
||||
this._standard = standard;
|
||||
this._standard.connect('notify::visible', this._sync.bind(this));
|
||||
if (this._standard instanceof St.Button)
|
||||
@ -31,9 +33,8 @@ var AltSwitcher = class {
|
||||
this._clickAction = new Clutter.ClickAction();
|
||||
this._clickAction.connect('long-press', this._onLongPress.bind(this));
|
||||
|
||||
this.actor = new St.Bin();
|
||||
this.actor.connect('destroy', this._onDestroy.bind(this));
|
||||
this.actor.connect('notify::mapped', () => (this._flipped = false));
|
||||
this.connect('destroy', this._onDestroy.bind(this));
|
||||
this.connect('notify::mapped', () => (this._flipped = false));
|
||||
}
|
||||
|
||||
_sync() {
|
||||
@ -51,11 +52,11 @@ var AltSwitcher = class {
|
||||
} else if (this._alternate.visible) {
|
||||
childToShow = this._alternate;
|
||||
} else {
|
||||
this.actor.hide();
|
||||
this.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
let childShown = this.actor.get_child();
|
||||
let childShown = this.get_child();
|
||||
if (childShown != childToShow) {
|
||||
if (childShown) {
|
||||
if (childShown.fake_release)
|
||||
@ -64,8 +65,8 @@ var AltSwitcher = class {
|
||||
}
|
||||
childToShow.add_action(this._clickAction);
|
||||
|
||||
let hasFocus = this.actor.contains(global.stage.get_key_focus());
|
||||
this.actor.set_child(childToShow);
|
||||
let hasFocus = this.contains(global.stage.get_key_focus());
|
||||
this.set_child(childToShow);
|
||||
if (hasFocus)
|
||||
childToShow.grab_key_focus();
|
||||
|
||||
@ -74,7 +75,7 @@ var AltSwitcher = class {
|
||||
global.sync_pointer();
|
||||
}
|
||||
|
||||
this.actor.show();
|
||||
this.show();
|
||||
}
|
||||
|
||||
_onDestroy() {
|
||||
@ -104,11 +105,13 @@ var AltSwitcher = class {
|
||||
this._sync();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
constructor() {
|
||||
super();
|
||||
var Indicator = GObject.registerClass({
|
||||
GTypeName: 'System_Indicator'
|
||||
}, class Indicator extends PanelMenu.SystemIndicator {
|
||||
_init() {
|
||||
super._init();
|
||||
|
||||
let userManager = AccountsService.UserManager.get_default();
|
||||
this._user = userManager.get_user(GLib.get_user_name());
|
||||
@ -289,7 +292,7 @@ var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
bindFlags);
|
||||
|
||||
this._altSwitcher = new AltSwitcher(this._powerOffAction, this._suspendAction);
|
||||
item.add(this._altSwitcher.actor, { expand: true, x_fill: false });
|
||||
item.add(this._altSwitcher, { expand: true, x_fill: false });
|
||||
|
||||
this.menu.addMenuItem(item);
|
||||
|
||||
@ -297,7 +300,7 @@ var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
this._settingsAction,
|
||||
this._orientationLockAction,
|
||||
this._lockScreenAction,
|
||||
this._altSwitcher.actor,
|
||||
this._altSwitcher,
|
||||
];
|
||||
|
||||
for (let actor of visibilityGroup) {
|
||||
@ -312,4 +315,4 @@ var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
Main.overview.hide();
|
||||
this._settingsApp.activate();
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
// the following is a modified version of bolt/contrib/js/client.js
|
||||
|
||||
const { Gio, GLib, Polkit, Shell } = imports.gi;
|
||||
const { Gio, GLib, GObject, Polkit, Shell } = imports.gi;
|
||||
const Signals = imports.signals;
|
||||
|
||||
const Main = imports.ui.main;
|
||||
@ -221,9 +221,11 @@ Signals.addSignalMethods(AuthRobot.prototype);
|
||||
|
||||
/* eof client.js */
|
||||
|
||||
var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
constructor() {
|
||||
super();
|
||||
var Indicator = GObject.registerClass({
|
||||
GTypeName: 'Thunderbolt_Indicator'
|
||||
}, class Indicator extends PanelMenu.SystemIndicator {
|
||||
_init() {
|
||||
super._init();
|
||||
|
||||
this._indicator = this._addIndicator();
|
||||
this._indicator.icon_name = 'thunderbolt-symbolic';
|
||||
@ -334,4 +336,4 @@ var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
const body = _("Could not authorize the Thunderbolt device: %s").format(error.message);
|
||||
this._notify(title, body);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -347,9 +347,11 @@ var VolumeMenu = class extends PopupMenu.PopupMenuSection {
|
||||
}
|
||||
};
|
||||
|
||||
var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
constructor() {
|
||||
super();
|
||||
var Indicator = GObject.registerClass({
|
||||
GTypeName: 'Volume_Indicator'
|
||||
}, class Indicator extends PanelMenu.SystemIndicator {
|
||||
_init() {
|
||||
super._init();
|
||||
|
||||
this._primaryIndicator = this._addIndicator();
|
||||
this._inputIndicator = this._addIndicator();
|
||||
@ -374,7 +376,7 @@ var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
|
||||
this.menu.addMenuItem(this._volumeMenu);
|
||||
|
||||
this.indicators.connect('scroll-event', this._onScrollEvent.bind(this));
|
||||
this.connect('scroll-event', this._onScrollEvent.bind(this));
|
||||
}
|
||||
|
||||
_onScrollEvent(actor, event) {
|
||||
@ -388,4 +390,4 @@ var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
Main.osdWindowManager.show(-1, gicon, null, level, maxLevel);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
Reference in New Issue
Block a user