status/network: Make NMSection a GObject

Instead of subclassing PopupMenuSection, it is now a plain GObject
that has a `menu` JS property.

That brings it a tad bit closer to QuickMenuToggle, which is another
GObject with a `menu` property.

We are on the final stretch now. Over the next couple of commits,
we'll add some (fake) properties so we can hook everything up,
and then it's finally time for the big switch.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2408>
This commit is contained in:
Florian Müllner 2022-08-03 02:14:52 +02:00 committed by Marge Bot
parent 864606ae9d
commit 16b63af441

View File

@ -1274,17 +1274,24 @@ const NMVpnConnectionItem = GObject.registerClass({
}
});
class NMSection extends PopupMenu.PopupMenuSection {
const NMSection = GObject.registerClass({
Signals: {
'activation-failed': {},
'icon-changed': {},
},
}, class NMSection extends GObject.Object {
constructor() {
super();
this.menu = new PopupMenu.PopupMenuSection();
this._items = new Map();
this._itemSorter = new ItemSorter({trackMru: true});
this._itemsSection = new PopupMenu.PopupMenuSection();
this.addMenuItem(this._itemsSection);
this.menu.addMenuItem(this._itemsSection);
this.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
}
setClient(client) {
@ -1303,7 +1310,7 @@ class NMSection extends PopupMenu.PopupMenuSection {
}
set visible(visible) {
this.actor.visible = visible;
this.menu.actor.visible = visible;
}
_loadInitialItems() {
@ -1351,13 +1358,14 @@ class NMSection extends PopupMenu.PopupMenuSection {
this.visible = this._items.size > 0;
this._updateItemsVisibility();
}
}
});
const NMVpnSection = GObject.registerClass(
class NMVpnSection extends NMSection {
constructor() {
super();
this.addSettingsAction(_('VPN Settings'),
this.menu.addSettingsAction(_('VPN Settings'),
'gnome-network-panel.desktop');
}
@ -1449,8 +1457,9 @@ class NMVpnSection extends NMSection {
}
return '';
}
}
});
const NMDeviceSection = GObject.registerClass(
class NMDeviceSection extends NMSection {
constructor(deviceType) {
super();
@ -1577,55 +1586,59 @@ class NMDeviceSection extends NMSection {
const nItems = this._items.size;
this._items.forEach(item => (item.singleDeviceMode = nItems === 1));
}
}
});
const NMWirelessSection = GObject.registerClass(
class NMWirelessSection extends NMDeviceSection {
constructor() {
super(NM.DeviceType.WIFI);
this.addSettingsAction(_('All Networks'),
this.menu.addSettingsAction(_('All Networks'),
'gnome-wifi-panel.desktop');
}
_createDeviceMenuItem(device) {
return new NMWirelessDeviceItem(this._client, device);
}
}
});
const NMWiredSection = GObject.registerClass(
class NMWiredSection extends NMDeviceSection {
constructor() {
super(NM.DeviceType.ETHERNET);
this.addSettingsAction(_('Wired Settings'),
this.menu.addSettingsAction(_('Wired Settings'),
'gnome-network-panel.desktop');
}
_createDeviceMenuItem(device) {
return new NMWiredDeviceItem(this._client, device);
}
}
});
const NMBluetoothSection = GObject.registerClass(
class NMBluetoothSection extends NMDeviceSection {
constructor() {
super(NM.DeviceType.BT);
this.addSettingsAction(_('Bluetooth Settings'),
this.menu.addSettingsAction(_('Bluetooth Settings'),
'gnome-network-panel.desktop');
}
_createDeviceMenuItem(device) {
return new NMBluetoothDeviceItem(this._client, device);
}
}
});
const NMModemSection = GObject.registerClass(
class NMModemSection extends NMDeviceSection {
constructor() {
super(NM.DeviceType.MODEM);
const settingsLabel = _('Mobile Broadband Settings');
this._wwanSettings = this.addSettingsAction(settingsLabel,
this._wwanSettings = this.menu.addSettingsAction(settingsLabel,
'gnome-wwan-panel.desktop');
this._legacySettings = this.addSettingsAction(settingsLabel,
this._legacySettings = this.menu.addSettingsAction(settingsLabel,
'gnome-network-panel.desktop');
}
@ -1641,7 +1654,7 @@ class NMModemSection extends NMDeviceSection {
this._wwanSettings.visible = useWwanPanel;
this._legacySettings.visible = !useWwanPanel;
}
}
});
var NMApplet = GObject.registerClass(
class Indicator extends PanelMenu.SystemIndicator {
@ -1679,7 +1692,7 @@ class Indicator extends PanelMenu.SystemIndicator {
'activation-failed', () => this._onActivationFailed(),
'icon-changed', () => this._updateIcon(),
this);
this.menu.addMenuItem(section);
this.menu.addMenuItem(section.menu);
});
this._getClient().catch(logError);