[gnome-shell/wip/message-tray-menu: 6/25] popupMenu: Allow separator items to have labels
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/message-tray-menu: 6/25] popupMenu: Allow separator items to have labels
- Date: Thu, 25 Apr 2013 19:04:49 +0000 (UTC)
commit ea92eb38ae539baa8ea2f1484ebff9f24819f74b
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Wed Apr 24 16:21:57 2013 -0400
popupMenu: Allow separator items to have labels
js/ui/popupMenu.js | 33 +++++++++++++++++++++++++++------
1 files changed, 27 insertions(+), 6 deletions(-)
---
diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js
index 53b075a..3391657 100644
--- a/js/ui/popupMenu.js
+++ b/js/ui/popupMenu.js
@@ -393,12 +393,23 @@ 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 });
+
+ if (text) {
+ this.label = new St.Label({ text: text });
+ this._box.add(this.label);
+ this.actor.label_actor = this.label;
+ } else {
+ this.label = null;
+ }
+
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 +994,9 @@ const PopupMenuBase = new Lang.Class({
},
_updateSeparatorVisibility: function(menuItem) {
+ if (menuItem.label !== null)
+ return;
+
let children = this.box.get_children();
let index = children.indexOf(menuItem.actor);
@@ -1881,11 +1895,16 @@ const RemoteMenu = new Lang.Class({
});
},
- _createMenuItem: function(model, index, action_namespace) {
+ _getLabel: function(model, index) {
let labelValue = model.get_item_attribute_value(index, Gio.MENU_ATTRIBUTE_LABEL, null);
let label = labelValue ? labelValue.deep_unpack() : '';
// remove all underscores that are not followed by another underscore
label = label.replace(/_([^_])/, '$1');
+ return label;
+ },
+
+ _createMenuItem: function(model, index, action_namespace) {
+ let label = this._getLabel(model, index);
let submenuModel = model.get_item_link(index, Gio.MENU_LINK_SUBMENU);
if (submenuModel) {
@@ -1960,10 +1979,12 @@ const RemoteMenu = new Lang.Class({
_insertItem: function(position, model, item_index, action_namespace, is_separator, target) {
let item;
- if (is_separator)
- item = new PopupSeparatorMenuItem();
- else
+ if (is_separator) {
+ let label = this._getLabel(model, item_index);
+ item = new PopupSeparatorMenuItem(label);
+ } else {
item = this._createMenuItem(model, item_index, action_namespace);
+ }
target.addMenuItem(item, position);
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]