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:
@ -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;
|
||||
|
Reference in New Issue
Block a user