[gnome-shell] status/network: Use submenus when necessary



commit c2139b27dadb60ea1e312c250f42af089bf45f51
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Aug 3 01:23:29 2022 +0200

    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>

 js/ui/status/network.js | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/js/ui/status/network.js b/js/ui/status/network.js
index 8f5cf20669..5405c7aa07 100644
--- a/js/ui/status/network.js
+++ b/js/ui/status/network.js
@@ -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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]