[gnome-shell] remoteMenu: Allow separator items to have labels
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] remoteMenu: Allow separator items to have labels
- Date: Mon, 13 May 2013 22:35:01 +0000 (UTC)
commit af063dc2f2ec23129d8157ebc869c6b987daacbd
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Wed Apr 24 16:21:57 2013 -0400
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
js/ui/popupMenu.js | 14 ++++++++++++--
js/ui/remoteMenu.js | 35 ++++++++++++++++++++++++++++++-----
2 files changed, 42 insertions(+), 7 deletions(-)
---
diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js
index 8a2b06e..bfb950f 100644
--- a/js/ui/popupMenu.js
+++ b/js/ui/popupMenu.js
@@ -393,12 +393,19 @@ const PopupSeparatorMenuItem = new Lang.Class({
Name: 'PopupSeparatorMenuItem',
Extends: PopupBaseMenuItem,
- _init: function () {
+ _init: function (text) {
this.parent({ reactive: 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.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) {
+ if (menuItem.label.text)
+ return;
+
let children = this.box.get_children();
let index = children.indexOf(menuItem.actor);
diff --git a/js/ui/remoteMenu.js b/js/ui/remoteMenu.js
index d03ed63..758d79a 100644
--- a/js/ui/remoteMenu.js
+++ b/js/ui/remoteMenu.js
@@ -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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]