From 13bf64a53df35482441d0193956ff6f2138c1273 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Tue, 23 Aug 2011 10:14:55 -0400 Subject: [PATCH] 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. https://bugzilla.gnome.org/show_bug.cgi?id=657082 --- js/ui/dateMenu.js | 20 +++++++------------- js/ui/popupMenu.js | 19 ++++++++++++++++++- 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, 35 insertions(+), 55 deletions(-) diff --git a/js/ui/dateMenu.js b/js/ui/dateMenu.js index edad21e65..4a4b10323 100644 --- a/js/ui/dateMenu.js +++ b/js/ui/dateMenu.js @@ -84,13 +84,14 @@ 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 = this.menu.addSettingsAction(_("Date and Time Settings"), 'gnome-datetime-panel.desktop'); + + 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; - vbox.add(item.actor); + item.actor.reparent(vbox); // Add vertical separator @@ -201,13 +202,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 228fc76e2..fc4956e25 100644 --- a/js/ui/popupMenu.js +++ b/js/ui/popupMenu.js @@ -803,11 +803,28 @@ PopupMenuBase.prototype = { }, addAction: function(title, callback) { - var menuItem = new PopupMenuItem(title); + let menuItem = new PopupMenuItem(title); this.addMenuItem(menuItem); menuItem.connect('activate', Lang.bind(this, function (menuItem, event) { callback(event); })); + + return menuItem; + }, + + addSettingsAction: function(title, desktopFile) { + let menuItem = this.addAction(title, function() { + let app = Shell.AppSystem.get_default().lookup_setting(desktopFile); + + if (!app) { + log('Settings panel for desktop file ' + desktopFile + ' could not be loaded!'); + return; + } + + Main.overview.hide(); + app.activate(); + }); + return menuItem; }, /** diff --git a/js/ui/status/accessibility.js b/js/ui/status/accessibility.js index 7792ed4ab..dac4ef047 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 2970b2c08..77be89daf 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 7b425a434..5a12df17a 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'); }, _adjust_group_names: function(names) { diff --git a/js/ui/status/network.js b/js/ui/status/network.js index 447efffcf..c4c42a533 100644 --- a/js/ui/status/network.js +++ b/js/ui/status/network.js @@ -1609,12 +1609,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 9b88ac371..baf0697ea 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 406ac6641..76726a83c 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();