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:
parent
3075f3cfe4
commit
af063dc2f2
@ -393,12 +393,19 @@ const PopupSeparatorMenuItem = new Lang.Class({
|
|||||||
Name: 'PopupSeparatorMenuItem',
|
Name: 'PopupSeparatorMenuItem',
|
||||||
Extends: PopupBaseMenuItem,
|
Extends: PopupBaseMenuItem,
|
||||||
|
|
||||||
_init: function () {
|
_init: function (text) {
|
||||||
this.parent({ reactive: false,
|
this.parent({ reactive: false,
|
||||||
can_focus: false});
|
can_focus: false});
|
||||||
|
|
||||||
|
this._box = new St.BoxLayout();
|
||||||
|
this.addActor(this._box, { span: -1, expand: true });
|
||||||
|
|
||||||
|
this.label = new St.Label({ text: text || '' });
|
||||||
|
this._box.add(this.label);
|
||||||
|
this.actor.label_actor = this.label;
|
||||||
|
|
||||||
this._separator = new Separator.HorizontalSeparator({ style_class: 'popup-separator-menu-item' });
|
this._separator = new Separator.HorizontalSeparator({ style_class: 'popup-separator-menu-item' });
|
||||||
this.addActor(this._separator.actor, { span: -1, expand: true });
|
this._box.add(this._separator.actor, { expand: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -983,6 +990,9 @@ const PopupMenuBase = new Lang.Class({
|
|||||||
},
|
},
|
||||||
|
|
||||||
_updateSeparatorVisibility: function(menuItem) {
|
_updateSeparatorVisibility: function(menuItem) {
|
||||||
|
if (menuItem.label.text)
|
||||||
|
return;
|
||||||
|
|
||||||
let children = this.box.get_children();
|
let children = this.box.get_children();
|
||||||
|
|
||||||
let index = children.indexOf(menuItem.actor);
|
let index = children.indexOf(menuItem.actor);
|
||||||
|
@ -11,6 +11,33 @@ const St = imports.gi.St;
|
|||||||
|
|
||||||
const PopupMenu = imports.ui.popupMenu;
|
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({
|
const RemoteMenuItemMapper = new Lang.Class({
|
||||||
Name: 'RemoteMenuItemMapper',
|
Name: 'RemoteMenuItemMapper',
|
||||||
|
|
||||||
@ -43,10 +70,7 @@ const RemoteMenuItemMapper = new Lang.Class({
|
|||||||
},
|
},
|
||||||
|
|
||||||
_updateLabel: function() {
|
_updateLabel: function() {
|
||||||
let label = this._trackerItem.label;
|
this._label.text = stripMnemonics(this._trackerItem.label);
|
||||||
// remove all underscores that are not followed by another underscore
|
|
||||||
label = label.replace(/_([^_])/, '$1');
|
|
||||||
this._label.text = label;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_updateSensitivity: function() {
|
_updateSensitivity: function() {
|
||||||
@ -103,7 +127,8 @@ const RemoteMenu = new Lang.Class({
|
|||||||
let item;
|
let item;
|
||||||
|
|
||||||
if (trackerItem.get_is_separator()) {
|
if (trackerItem.get_is_separator()) {
|
||||||
item = new PopupMenu.PopupSeparatorMenuItem();
|
let mapper = new RemoteMenuSeparatorItemMapper(trackerItem);
|
||||||
|
item = mapper.menuItem;
|
||||||
} else {
|
} else {
|
||||||
let mapper = new RemoteMenuItemMapper(trackerItem);
|
let mapper = new RemoteMenuItemMapper(trackerItem);
|
||||||
item = mapper.menuItem;
|
item = mapper.menuItem;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user