[gnome-shell] [panel] split out a PanelBaseMenuItem class
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] [panel] split out a PanelBaseMenuItem class
- Date: Wed, 19 May 2010 17:17:35 +0000 (UTC)
commit 320adb316d6ea23d671d4e427b563520cfe15e14
Author: Dan Winship <danw gnome org>
Date: Tue May 18 13:14:38 2010 -0400
[panel] split out a PanelBaseMenuItem class
Make the existing PanelMenuItem, PanelSeparatorMenuItem,
PanelImageMenuItem inherit from it.
https://bugzilla.gnome.org/show_bug.cgi?id=619008
js/ui/panel.js | 75 +++++++++++++++++++++++++++++++++++--------------------
1 files changed, 48 insertions(+), 27 deletions(-)
---
diff --git a/js/ui/panel.js b/js/ui/panel.js
index 5047f60..05c58ef 100644
--- a/js/ui/panel.js
+++ b/js/ui/panel.js
@@ -126,40 +126,61 @@ TextShadower.prototype = {
}
};
-function PanelMenuItem(text) {
- this._init(text);
+function PanelBaseMenuItem(reactive) {
+ this._init(reactive);
}
-PanelMenuItem.prototype = {
- _init: function (text) {
+PanelBaseMenuItem.prototype = {
+ _init: function (reactive) {
this.actor = new St.Bin({ style_class: 'panel-menu-item',
- reactive: true,
- track_hover: true,
+ reactive: reactive,
+ track_hover: reactive,
x_fill: true,
y_fill: true,
x_align: St.Align.START });
- this.label = new St.Label({ text: text });
- this.actor.set_child(this.label);
- this.actor.connect('button-release-event', Lang.bind(this, function (actor, event) {
- this.emit('activate', event);
- }));
+
+ if (reactive) {
+ this.actor.connect('button-release-event', Lang.bind(this, function (actor, event) {
+ this.emit('activate', event);
+ }));
+ }
}
};
-Signals.addSignalMethods(PanelMenuItem.prototype);
+Signals.addSignalMethods(PanelBaseMenuItem.prototype);
-function PanelSeparatorMenuItem(text) {
+function PanelMenuItem(text) {
this._init(text);
}
-PanelSeparatorMenuItem.prototype = {
+PanelMenuItem.prototype = {
+ __proto__: PanelBaseMenuItem.prototype,
+
_init: function (text) {
- this.actor = new St.DrawingArea({ style_class: 'panel-separator-menu-item' });
- this.actor.connect('repaint', Lang.bind(this, this._onRepaint));
+ PanelBaseMenuItem.prototype._init.call(this, true);
+
+ this.label = new St.Label({ text: text });
+ this.actor.set_child(this.label);
+ },
+};
+
+function PanelSeparatorMenuItem() {
+ this._init();
+}
+
+PanelSeparatorMenuItem.prototype = {
+ __proto__: PanelBaseMenuItem.prototype,
+
+ _init: function () {
+ PanelBaseMenuItem.prototype._init.call(this, false);
+
+ this._drawingArea = new St.DrawingArea({ style_class: 'panel-separator-menu-item' });
+ this.actor.set_child(this._drawingArea);
+ this._drawingArea.connect('repaint', Lang.bind(this, this._onRepaint));
},
_onRepaint: function(area) {
let cr = area.get_context();
- let themeNode = this.actor.get_theme_node();
+ let themeNode = area.get_theme_node();
let [width, height] = area.get_surface_size();
let found, margin, gradientHeight;
[found, margin] = themeNode.get_length('-margin-horizontal', false);
@@ -180,7 +201,6 @@ PanelSeparatorMenuItem.prototype = {
cr.fill();
}
};
-Signals.addSignalMethods(PanelSeparatorMenuItem.prototype);
function PanelImageMenuItem(text, iconName, alwaysShowImage) {
this._init(text, iconName, alwaysShowImage);
@@ -191,25 +211,27 @@ function PanelImageMenuItem(text, iconName, alwaysShowImage) {
var _gtkImageMenuItemCreated = false;
PanelImageMenuItem.prototype = {
+ __proto__: PanelBaseMenuItem.prototype,
+
_init: function (text, iconName, alwaysShowImage) {
+ PanelBaseMenuItem.prototype._init.call(this, true);
if (!_gtkImageMenuItemCreated) {
let menuItem = new Gtk.ImageMenuItem();
menuItem.destroy();
_gtkImageMenuItemCreated = true;
}
+
this._alwaysShowImage = alwaysShowImage;
- this.actor = new St.BoxLayout({ style_class: 'panel-menu-item panel-image-menu-item',
- reactive: true,
- track_hover: true });
this._iconName = iconName;
this._size = 16;
+
+ let box = new St.BoxLayout({ style_class: 'panel-image-menu-item' });
+ this.actor.set_child(box);
this._imageBin = new St.Bin({ width: this._size, height: this._size });
- this.actor.add(this._imageBin, { y_fill: false });
- this.actor.add(new St.Label({ text: text }), { expand: true });
- this.actor.connect('button-release-event', Lang.bind(this, function (actor, event) {
- this.emit('activate', event);
- }));
+ box.add(this._imageBin, { y_fill: false });
+ box.add(new St.Label({ text: text }), { expand: true });
+
if (!alwaysShowImage) {
let settings = Gtk.Settings.get_default();
settings.connect('notify::gtk-menu-images', Lang.bind(this, this._onMenuImagesChanged));
@@ -234,7 +256,6 @@ PanelImageMenuItem.prototype = {
}
}
};
-Signals.addSignalMethods(PanelImageMenuItem.prototype);
function PanelMenu(sourceButton) {
this._init(sourceButton);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]