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
This commit is contained in:
parent
f96b2ee858
commit
13bf64a53d
@ -84,13 +84,14 @@ DateMenuButton.prototype = {
|
|||||||
}));
|
}));
|
||||||
vbox.add(this._calendar.actor);
|
vbox.add(this._calendar.actor);
|
||||||
|
|
||||||
item = new PopupMenu.PopupSeparatorMenuItem();
|
item = this.menu.addSettingsAction(_("Date and Time Settings"), 'gnome-datetime-panel.desktop');
|
||||||
item.setColumnWidths(1);
|
|
||||||
vbox.add(item.actor, {y_align: St.Align.END, expand: true, y_fill: false});
|
let separator = new PopupMenu.PopupSeparatorMenuItem();
|
||||||
item = new PopupMenu.PopupMenuItem(_("Date and Time Settings"));
|
separator.setColumnWidths(1);
|
||||||
item.connect('activate', Lang.bind(this, this._onPreferencesActivate));
|
vbox.add(separator.actor, {y_align: St.Align.END, expand: true, y_fill: false});
|
||||||
|
|
||||||
item.actor.can_focus = false;
|
item.actor.can_focus = false;
|
||||||
vbox.add(item.actor);
|
item.actor.reparent(vbox);
|
||||||
|
|
||||||
// Add vertical separator
|
// Add vertical separator
|
||||||
|
|
||||||
@ -201,13 +202,6 @@ DateMenuButton.prototype = {
|
|||||||
return false;
|
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() {
|
_onOpenCalendarActivate: function() {
|
||||||
this.menu.close();
|
this.menu.close();
|
||||||
let calendarSettings = new Gio.Settings({ schema: 'org.gnome.desktop.default-applications.office.calendar' });
|
let calendarSettings = new Gio.Settings({ schema: 'org.gnome.desktop.default-applications.office.calendar' });
|
||||||
|
@ -803,11 +803,28 @@ PopupMenuBase.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
addAction: function(title, callback) {
|
addAction: function(title, callback) {
|
||||||
var menuItem = new PopupMenuItem(title);
|
let menuItem = new PopupMenuItem(title);
|
||||||
this.addMenuItem(menuItem);
|
this.addMenuItem(menuItem);
|
||||||
menuItem.connect('activate', Lang.bind(this, function (menuItem, event) {
|
menuItem.connect('activate', Lang.bind(this, function (menuItem, event) {
|
||||||
callback(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;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,11 +88,7 @@ ATIndicator.prototype = {
|
|||||||
this.menu.addMenuItem(mouseKeys);
|
this.menu.addMenuItem(mouseKeys);
|
||||||
|
|
||||||
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
||||||
this.menu.addAction(_("Universal Access Settings"), function() {
|
this.menu.addSettingsAction(_("Universal Access Settings"), 'gnome-universal-access-panel.desktop');
|
||||||
Main.overview.hide();
|
|
||||||
let app = Shell.AppSystem.get_default().lookup_setting('gnome-universal-access-panel.desktop');
|
|
||||||
app.activate();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_buildItemExtended: function(string, initial_value, writable, on_set) {
|
_buildItemExtended: function(string, initial_value, writable, on_set) {
|
||||||
|
@ -88,11 +88,7 @@ Indicator.prototype = {
|
|||||||
this._applet.connect('notify::show-full-menu', Lang.bind(this, this._updateFullMenu));
|
this._applet.connect('notify::show-full-menu', Lang.bind(this, this._updateFullMenu));
|
||||||
this._updateFullMenu();
|
this._updateFullMenu();
|
||||||
|
|
||||||
this.menu.addAction(_("Bluetooth Settings"), function() {
|
this.menu.addSettingsAction(_("Bluetooth Settings"), 'bluetooth-properties.desktop');
|
||||||
Main.overview.hide()
|
|
||||||
let app = Shell.AppSystem.get_default().lookup_setting('bluetooth-properties.desktop');
|
|
||||||
app.activate();
|
|
||||||
});
|
|
||||||
|
|
||||||
this._applet.connect('pincode-request', Lang.bind(this, this._pinRequest));
|
this._applet.connect('pincode-request', Lang.bind(this, this._pinRequest));
|
||||||
this._applet.connect('confirm-request', Lang.bind(this, this._confirmRequest));
|
this._applet.connect('confirm-request', Lang.bind(this, this._confirmRequest));
|
||||||
@ -272,21 +268,15 @@ Indicator.prototype = {
|
|||||||
|
|
||||||
switch (device.type) {
|
switch (device.type) {
|
||||||
case GnomeBluetoothApplet.Type.KEYBOARD:
|
case GnomeBluetoothApplet.Type.KEYBOARD:
|
||||||
item.menu.addAction(_("Keyboard Settings"), function() {
|
item.menu.addSettingsAction(_("Keyboard Settings"), 'gnome-keyboard-panel.desktop');
|
||||||
GLib.spawn_command_line_async('gnome-control-center keyboard');
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case GnomeBluetoothApplet.Type.MOUSE:
|
case GnomeBluetoothApplet.Type.MOUSE:
|
||||||
item.menu.addAction(_("Mouse Settings"), function() {
|
item.menu.addSettingsAction(_("Mouse Settings"), 'gnome-mouse-panel.desktop');
|
||||||
GLib.spawn_command_line_async('gnome-control-center mouse');
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case GnomeBluetoothApplet.Type.HEADSET:
|
case GnomeBluetoothApplet.Type.HEADSET:
|
||||||
case GnomeBluetoothApplet.Type.HEADPHONES:
|
case GnomeBluetoothApplet.Type.HEADPHONES:
|
||||||
case GnomeBluetoothApplet.Type.OTHER_AUDIO:
|
case GnomeBluetoothApplet.Type.OTHER_AUDIO:
|
||||||
item.menu.addAction(_("Sound Settings"), function() {
|
item.menu.addSettingsAction(_("Sound Settings"), 'gnome-sound-panel.desktop');
|
||||||
GLib.spawn_command_line_async('gnome-control-center sound');
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -72,11 +72,7 @@ XKBIndicator.prototype = {
|
|||||||
Main.overview.hide();
|
Main.overview.hide();
|
||||||
Util.spawn(['gkbd-keyboard-display', '-g', String(this._config.get_current_group() + 1)]);
|
Util.spawn(['gkbd-keyboard-display', '-g', String(this._config.get_current_group() + 1)]);
|
||||||
}));
|
}));
|
||||||
this.menu.addAction(_("Region and Language Settings"), function() {
|
this.menu.addSettingsAction(_("Region and Language Settings"), 'gnome-region-panel.desktop');
|
||||||
Main.overview.hide();
|
|
||||||
let app = Shell.AppSystem.get_default().lookup_setting('gnome-region-panel.desktop');
|
|
||||||
app.activate();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_adjust_group_names: function(names) {
|
_adjust_group_names: function(names) {
|
||||||
|
@ -1609,12 +1609,7 @@ NMApplet.prototype = {
|
|||||||
this._devices.vpn.section.actor.hide();
|
this._devices.vpn.section.actor.hide();
|
||||||
this.menu.addMenuItem(this._devices.vpn.section);
|
this.menu.addMenuItem(this._devices.vpn.section);
|
||||||
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
||||||
|
this.menu.addSettingsAction(_("Network Settings"), 'gnome-network-panel.desktop');
|
||||||
this.menu.addAction(_("Network Settings"), function() {
|
|
||||||
Main.overview.hide();
|
|
||||||
let app = Shell.AppSystem.get_default().lookup_setting('gnome-network-panel.desktop');
|
|
||||||
app.activate();
|
|
||||||
});
|
|
||||||
|
|
||||||
this._activeConnections = [ ];
|
this._activeConnections = [ ];
|
||||||
this._connections = [ ];
|
this._connections = [ ];
|
||||||
|
@ -77,13 +77,9 @@ Indicator.prototype = {
|
|||||||
|
|
||||||
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
||||||
this._otherDevicePosition = 2;
|
this._otherDevicePosition = 2;
|
||||||
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
|
||||||
|
|
||||||
this.menu.addAction(_("Power Settings"),function() {
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
||||||
Main.overview.hide();
|
this.menu.addSettingsAction(_("Power Settings"), 'gnome-power-panel.desktop');
|
||||||
let app = Shell.AppSystem.get_default().lookup_setting('gnome-power-panel.desktop');
|
|
||||||
app.activate();
|
|
||||||
});
|
|
||||||
|
|
||||||
this._proxy.connect('Changed', Lang.bind(this, this._devicesChanged));
|
this._proxy.connect('Changed', Lang.bind(this, this._devicesChanged));
|
||||||
this._devicesChanged();
|
this._devicesChanged();
|
||||||
|
@ -60,11 +60,7 @@ Indicator.prototype = {
|
|||||||
this.menu.addMenuItem(this._inputSlider);
|
this.menu.addMenuItem(this._inputSlider);
|
||||||
|
|
||||||
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
||||||
this.menu.addAction(_("Sound Settings"), function() {
|
this.menu.addSettingsAction(_("Sound Settings"), 'gnome-sound-panel.desktop');
|
||||||
Main.overview.hide();
|
|
||||||
let app = Shell.AppSystem.get_default().lookup_setting('gnome-sound-panel.desktop');
|
|
||||||
app.activate();
|
|
||||||
});
|
|
||||||
|
|
||||||
this.actor.connect('scroll-event', Lang.bind(this, this._onScrollEvent));
|
this.actor.connect('scroll-event', Lang.bind(this, this._onScrollEvent));
|
||||||
this._control.open();
|
this._control.open();
|
||||||
|
Loading…
Reference in New Issue
Block a user