remoteMenu: Allow separator items to have labels

This fixes a regression with remote menus where sections have
labels, like gnome-documents.

https://bugzilla.gnome.org/show_bug.cgi?id=700257
This commit is contained in:
Jasper St. Pierre
2013-04-24 16:21:57 -04:00
parent 3075f3cfe4
commit af063dc2f2
2 changed files with 42 additions and 7 deletions

View File

@ -11,6 +11,33 @@ const St = imports.gi.St;
const PopupMenu = imports.ui.popupMenu;
function stripMnemonics(label) {
if (!label)
return '';
// remove all underscores that are not followed by another underscore
return label.replace(/_([^_])/, '$1');
}
const RemoteMenuSeparatorItemMapper = new Lang.Class({
Name: 'RemoteMenuSeparatorItemMapper',
_init: function(trackerItem) {
this._trackerItem = trackerItem;
this.menuItem = new PopupMenu.PopupSeparatorMenuItem();
this._trackerItem.connect('notify::label', Lang.bind(this, this._updateLabel));
this._updateLabel();
this.menuItem.connect('destroy', function() {
trackerItem.run_dispose();
});
},
_updateLabel: function() {
this.menuItem.label.text = stripMnemonics(this._trackerItem.label);
},
});
const RemoteMenuItemMapper = new Lang.Class({
Name: 'RemoteMenuItemMapper',
@ -43,10 +70,7 @@ const RemoteMenuItemMapper = new Lang.Class({
},
_updateLabel: function() {
let label = this._trackerItem.label;
// remove all underscores that are not followed by another underscore
label = label.replace(/_([^_])/, '$1');
this._label.text = label;
this._label.text = stripMnemonics(this._trackerItem.label);
},
_updateSensitivity: function() {
@ -103,7 +127,8 @@ const RemoteMenu = new Lang.Class({
let item;
if (trackerItem.get_is_separator()) {
item = new PopupMenu.PopupSeparatorMenuItem();
let mapper = new RemoteMenuSeparatorItemMapper(trackerItem);
item = mapper.menuItem;
} else {
let mapper = new RemoteMenuItemMapper(trackerItem);
item = mapper.menuItem;