[gnome-shell/wip/gtkmenutrackeritem: 8/9] remoteMenu: Allow separator items to have labels
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/gtkmenutrackeritem: 8/9] remoteMenu: Allow separator items to have labels
- Date: Thu, 9 May 2013 21:52:02 +0000 (UTC)
commit 078d8ea7b3323e45478538e50b5eb840725937f3
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.
js/ui/popupMenu.js | 14 ++++++++++++--
js/ui/remoteMenu.js | 31 ++++++++++++++++++++++++++-----
2 files changed, 38 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 f144cf6..13b6e4a 100644
--- a/js/ui/remoteMenu.js
+++ b/js/ui/remoteMenu.js
@@ -11,6 +11,29 @@ 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();
+ },
+
+ _updateLabel: function() {
+ this.menuItem.label.text = stripMnemonics(this._trackerItem.label);
+ },
+});
+
const RemoteMenuItemMapper = new Lang.Class({
Name: 'RemoteMenuItemMapper',
@@ -39,10 +62,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 +123,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]