status/network: Use submenus when necessary

We currently stopped using submenus altogether, but that only works

 - if there is a single connection that represents
   the device as a whole

 - if there is just one device, so it is unambiguous
   what device items belong to

To implement that behavior, add a 'single-device-mode' property that
NMDeviceSection can set on its items, and have items update their
'use-submenu' property based on that.

For wireless devices it's a straight mapping, as its items represent
wireless networks that can appear and disappear by just walking around
(multiple wifi adapters also sounds rather fringey).

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2407>
This commit is contained in:
Florian Müllner 2022-08-03 01:23:29 +02:00 committed by Marge Bot
parent 03ded1dcf0
commit c2139b27da

View File

@ -379,8 +379,13 @@ const NMDeviceConnectionItem = GObject.registerClass({
}
});
const NMDeviceItem = GObject.registerClass(
class NMDeviceItem extends NMSectionItem {
const NMDeviceItem = GObject.registerClass({
Properties: {
'single-device-mode': GObject.ParamSpec.boolean('single-device-mode', '', '',
GObject.ParamFlags.READWRITE,
false),
},
}, class NMDeviceItem extends NMSectionItem {
constructor(client, device) {
super();
@ -419,6 +424,8 @@ class NMDeviceItem extends NMSectionItem {
'notify::active-connection', () => this._activeConnectionChanged(),
this);
this.connect('notify::single-device-mode', () => this._sync());
this._syncConnections();
this._activeConnectionChanged();
}
@ -526,6 +533,7 @@ class NMDeviceItem extends NMSectionItem {
_sync() {
const nItems = this._connectionItems.size;
this.radio_mode = nItems > 1;
this.useSubmenu = this.radioMode && !this.singleDeviceMode;
this._autoConnectItem.visible = nItems === 0;
this._deactivateItem.visible = this.radioMode && this.isActive;
}
@ -959,8 +967,13 @@ class NMWirelessNetworkItem extends PopupMenu.PopupBaseMenuItem {
}
});
const NMWirelessDeviceItem = GObject.registerClass(
class NMWirelessDeviceItem extends NMSectionItem {
const NMWirelessDeviceItem = GObject.registerClass({
Properties: {
'single-device-mode': GObject.ParamSpec.boolean('single-device-mode', '', '',
GObject.ParamFlags.READWRITE,
false),
},
}, class NMWirelessDeviceItem extends NMSectionItem {
constructor(client, device) {
super();
@ -996,6 +1009,10 @@ class NMWirelessDeviceItem extends NMSectionItem {
this._updateItemsVisibility();
}, this);
this.bind_property('single-device-mode',
this, 'use-submenu',
GObject.BindingFlags.INVERT_BOOLEAN);
Main.sessionMode.connectObject('updated',
() => this._updateItemsVisibility(),
this);
@ -1534,6 +1551,9 @@ class NMDeviceSection extends NMSection {
_sync() {
super._sync();
const nItems = this._items.size;
this._items.forEach(item => (item.singleDeviceMode = nItems === 1));
let nDevices = this._itemsSection.box.get_children().reduce(
(prev, child) => prev + (child.visible ? 1 : 0), 0);
this._summaryItem.label.text = this._getSummaryLabel(nDevices);