[gnome-shell/wip/gdm-shell: 4/16] popupMenu: Use new convenience method for settings



commit 60d87e457bc692471d223cce02906c0acc34ee0f
Author: Ray Strode <rstrode redhat com>
Date:   Tue Aug 23 10:14:55 2011 -0400

    popupMenu: Use new convenience method for settings
    
    All the system status menus in the panel offer a
    menu item to jump to a relevant part of the
    control-center.
    
    This means each status icon has the same, or nearly the
    same bit of code to:
    
    - Add a new "action" menu item and listen for its activation.
    - Hide the overview if it's showing when the menu item is activated
    - Find the relevant control-center panel from its desktop file
    - Launch the control-center to the relevant panel
    
    This commit consolidates all those details in a new method,
    addSettingsAction.  This refactoring reduces code duplication and
    slight inconsistencies in the code resulting from that duplication.
    It will also make it easier in subsequent commits to hide settings menu
    items when the shell is used in the login screen.

 js/ui/dateMenu.js             |   24 ++++++++++--------------
 js/ui/popupMenu.js            |   16 ++++++++++++++++
 js/ui/status/accessibility.js |    6 +-----
 js/ui/status/bluetooth.js     |   18 ++++--------------
 js/ui/status/keyboard.js      |    6 +-----
 js/ui/status/network.js       |    7 +------
 js/ui/status/power.js         |    8 ++------
 js/ui/status/volume.js        |    6 +-----
 8 files changed, 36 insertions(+), 55 deletions(-)
---
diff --git a/js/ui/dateMenu.js b/js/ui/dateMenu.js
index edad21e..7926861 100644
--- a/js/ui/dateMenu.js
+++ b/js/ui/dateMenu.js
@@ -84,13 +84,16 @@ DateMenuButton.prototype = {
                                }));
         vbox.add(this._calendar.actor);
 
-        item = new PopupMenu.PopupSeparatorMenuItem();
-        item.setColumnWidths(1);
-        vbox.add(item.actor, {y_align: St.Align.END, expand: true, y_fill: false});
-        item = new PopupMenu.PopupMenuItem(_("Date and Time Settings"));
-        item.connect('activate', Lang.bind(this, this._onPreferencesActivate));
-        item.actor.can_focus = false;
-        vbox.add(item.actor);
+        item = this.menu.addSettingsAction(_("Date and Time Settings"), 'gnome-datetime-panel.desktop');
+
+        if (item) {
+            let separator = new PopupMenu.PopupSeparatorMenuItem();
+            separator.setColumnWidths(1);
+            vbox.add(separator.actor, {y_align: St.Align.END, expand: true, y_fill: false});
+
+            item.actor.can_focus = false;
+            item.actor.reparent(vbox);
+        }
 
         // Add vertical separator
 
@@ -201,13 +204,6 @@ DateMenuButton.prototype = {
         return false;
     },
 
-    _onPreferencesActivate: function() {
-        this.menu.close();
-        Main.overview.hide();
-        let app = Shell.AppSystem.get_default().lookup_setting('gnome-datetime-panel.desktop');
-        app.activate();
-    },
-
     _onOpenCalendarActivate: function() {
         this.menu.close();
         let calendarSettings = new Gio.Settings({ schema: 'org.gnome.desktop.default-applications.office.calendar' });
diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js
index fbf1fc6..d06220b 100644
--- a/js/ui/popupMenu.js
+++ b/js/ui/popupMenu.js
@@ -808,6 +808,22 @@ PopupMenuBase.prototype = {
         menuItem.connect('activate', Lang.bind(this, function (menuItem, event) {
             callback(event);
         }));
+
+        return menuItem;
+    },
+
+    addSettingsAction: function(title, desktopFile) {
+        let app = Shell.AppSystem.get_default().lookup_setting(desktopFile);
+
+        if (app) {
+            let menuItem = this.addAction(title, function() {
+                               Main.overview.hide();
+                               app.activate();
+                           });
+            return menuItem;
+        }
+
+        return null;
     },
 
     /**
diff --git a/js/ui/status/accessibility.js b/js/ui/status/accessibility.js
index 7792ed4..dac4ef0 100644
--- a/js/ui/status/accessibility.js
+++ b/js/ui/status/accessibility.js
@@ -88,11 +88,7 @@ ATIndicator.prototype = {
         this.menu.addMenuItem(mouseKeys);
 
         this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
-        this.menu.addAction(_("Universal Access Settings"), function() {
-            Main.overview.hide();
-            let app = Shell.AppSystem.get_default().lookup_setting('gnome-universal-access-panel.desktop');
-            app.activate();
-        });
+        this.menu.addSettingsAction(_("Universal Access Settings"), 'gnome-universal-access-panel.desktop');
     },
 
     _buildItemExtended: function(string, initial_value, writable, on_set) {
diff --git a/js/ui/status/bluetooth.js b/js/ui/status/bluetooth.js
index 2970b2c..77be89d 100644
--- a/js/ui/status/bluetooth.js
+++ b/js/ui/status/bluetooth.js
@@ -88,11 +88,7 @@ Indicator.prototype = {
         this._applet.connect('notify::show-full-menu', Lang.bind(this, this._updateFullMenu));
         this._updateFullMenu();
 
-        this.menu.addAction(_("Bluetooth Settings"), function() {
-            Main.overview.hide()
-            let app = Shell.AppSystem.get_default().lookup_setting('bluetooth-properties.desktop');
-            app.activate();
-        });
+        this.menu.addSettingsAction(_("Bluetooth Settings"), 'bluetooth-properties.desktop');
 
         this._applet.connect('pincode-request', Lang.bind(this, this._pinRequest));
         this._applet.connect('confirm-request', Lang.bind(this, this._confirmRequest));
@@ -272,21 +268,15 @@ Indicator.prototype = {
 
         switch (device.type) {
         case GnomeBluetoothApplet.Type.KEYBOARD:
-            item.menu.addAction(_("Keyboard Settings"), function() {
-                GLib.spawn_command_line_async('gnome-control-center keyboard');
-            });
+            item.menu.addSettingsAction(_("Keyboard Settings"), 'gnome-keyboard-panel.desktop');
             break;
         case GnomeBluetoothApplet.Type.MOUSE:
-            item.menu.addAction(_("Mouse Settings"), function() {
-                GLib.spawn_command_line_async('gnome-control-center mouse');
-            });
+            item.menu.addSettingsAction(_("Mouse Settings"), 'gnome-mouse-panel.desktop');
             break;
         case GnomeBluetoothApplet.Type.HEADSET:
         case GnomeBluetoothApplet.Type.HEADPHONES:
         case GnomeBluetoothApplet.Type.OTHER_AUDIO:
-            item.menu.addAction(_("Sound Settings"), function() {
-                GLib.spawn_command_line_async('gnome-control-center sound');
-            });
+            item.menu.addSettingsAction(_("Sound Settings"), 'gnome-sound-panel.desktop');
             break;
         default:
             break;
diff --git a/js/ui/status/keyboard.js b/js/ui/status/keyboard.js
index 1db0d82..ab7244f 100644
--- a/js/ui/status/keyboard.js
+++ b/js/ui/status/keyboard.js
@@ -72,11 +72,7 @@ XKBIndicator.prototype = {
             Main.overview.hide();
             Util.spawn(['gkbd-keyboard-display', '-g', String(this._config.get_current_group() + 1)]);
         }));
-        this.menu.addAction(_("Region and Language Settings"), function() {
-            Main.overview.hide();
-            let app = Shell.AppSystem.get_default().lookup_setting('gnome-region-panel.desktop');
-            app.activate();
-        });
+        this.menu.addSettingsAction(_("Region and Language Settings"), 'gnome-region-panel.desktop');
     },
 
     _sync_config: function() {
diff --git a/js/ui/status/network.js b/js/ui/status/network.js
index 4e988ad..d6223d1 100644
--- a/js/ui/status/network.js
+++ b/js/ui/status/network.js
@@ -1605,12 +1605,7 @@ NMApplet.prototype = {
         this._devices.vpn.section.actor.hide();
         this.menu.addMenuItem(this._devices.vpn.section);
         this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
-
-        this.menu.addAction(_("Network Settings"), function() {
-            Main.overview.hide();
-            let app = Shell.AppSystem.get_default().lookup_setting('gnome-network-panel.desktop');
-            app.activate();
-        });
+        this.menu.addSettingsAction(_("Network Settings"), 'gnome-network-panel.desktop');
 
         this._activeConnections = [ ];
         this._connections = [ ];
diff --git a/js/ui/status/power.js b/js/ui/status/power.js
index 9b88ac3..baf0697 100644
--- a/js/ui/status/power.js
+++ b/js/ui/status/power.js
@@ -77,13 +77,9 @@ Indicator.prototype = {
 
         this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
         this._otherDevicePosition = 2;
-        this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
 
-        this.menu.addAction(_("Power Settings"),function() {
-            Main.overview.hide();
-            let app = Shell.AppSystem.get_default().lookup_setting('gnome-power-panel.desktop');
-            app.activate();
-        });
+        this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
+        this.menu.addSettingsAction(_("Power Settings"), 'gnome-power-panel.desktop');
 
         this._proxy.connect('Changed', Lang.bind(this, this._devicesChanged));
         this._devicesChanged();
diff --git a/js/ui/status/volume.js b/js/ui/status/volume.js
index 3e3e8c9..28ffdb1 100644
--- a/js/ui/status/volume.js
+++ b/js/ui/status/volume.js
@@ -60,11 +60,7 @@ Indicator.prototype = {
         this.menu.addMenuItem(this._inputSlider);
 
         this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
-        this.menu.addAction(_("Sound Settings"), function() {
-            Main.overview.hide();
-            let app = Shell.AppSystem.get_default().lookup_setting('gnome-sound-panel.desktop');
-            app.activate();
-        });
+        this.menu.addSettingsAction(_("Sound Settings"), 'gnome-sound-panel.desktop');
 
         this.actor.connect('scroll-event', Lang.bind(this, this._onScrollEvent));
         this._control.open();



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