2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-05-20 11:18:46 -04:00
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
2011-05-15 12:55:23 -04:00
|
|
|
const GLib = imports.gi.GLib;
|
2010-05-20 11:18:46 -04:00
|
|
|
const Gtk = imports.gi.Gtk;
|
2011-05-15 12:55:23 -04:00
|
|
|
const Gio = imports.gi.Gio;
|
2010-05-20 11:18:46 -04:00
|
|
|
const Lang = imports.lang;
|
2010-07-22 08:34:02 -04:00
|
|
|
const Shell = imports.gi.Shell;
|
2010-05-20 11:18:46 -04:00
|
|
|
const Signals = imports.signals;
|
2010-07-22 08:34:02 -04:00
|
|
|
const St = imports.gi.St;
|
2012-02-27 11:31:10 -05:00
|
|
|
const Atk = imports.gi.Atk;
|
2010-05-20 11:18:46 -04:00
|
|
|
|
|
|
|
const BoxPointer = imports.ui.boxpointer;
|
2012-02-29 19:09:41 -05:00
|
|
|
const GrabHelper = imports.ui.grabHelper;
|
2010-07-03 19:47:31 -04:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
const Params = imports.misc.params;
|
2012-08-15 21:28:49 -04:00
|
|
|
const Separator = imports.ui.separator;
|
2011-07-12 16:12:28 -04:00
|
|
|
const Slider = imports.ui.slider;
|
2010-05-20 11:18:46 -04:00
|
|
|
const Tweener = imports.ui.tweener;
|
|
|
|
|
2013-04-19 20:57:38 -04:00
|
|
|
const Ornament = {
|
|
|
|
NONE: 0,
|
|
|
|
DOT: 1,
|
2013-04-19 21:13:37 -04:00
|
|
|
CHECK: 2,
|
2013-04-19 20:57:38 -04:00
|
|
|
};
|
|
|
|
|
2011-07-20 23:17:05 -04:00
|
|
|
function _ensureStyle(actor) {
|
|
|
|
if (actor.get_children) {
|
|
|
|
let children = actor.get_children();
|
|
|
|
for (let i = 0; i < children.length; i++)
|
|
|
|
_ensureStyle(children[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (actor instanceof St.Widget)
|
|
|
|
actor.ensure_style();
|
|
|
|
}
|
|
|
|
|
2013-08-28 10:50:07 -04:00
|
|
|
function isPopupMenuItemVisible(child) {
|
|
|
|
if (child._delegate instanceof PopupMenuSection)
|
|
|
|
if (child._delegate.isEmpty())
|
|
|
|
return false;
|
|
|
|
return child.visible;
|
|
|
|
}
|
|
|
|
|
2011-11-20 08:10:48 -05:00
|
|
|
const PopupBaseMenuItem = new Lang.Class({
|
|
|
|
Name: 'PopupBaseMenuItem',
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-07-03 19:47:31 -04:00
|
|
|
_init: function (params) {
|
|
|
|
params = Params.parse (params, { reactive: true,
|
|
|
|
activate: true,
|
2011-01-25 16:06:40 -05:00
|
|
|
hover: true,
|
2012-08-17 05:03:23 -04:00
|
|
|
style_class: null,
|
|
|
|
can_focus: true
|
2011-01-25 16:06:40 -05:00
|
|
|
});
|
2013-07-15 20:00:41 -04:00
|
|
|
|
|
|
|
this.actor = new St.BoxLayout({ style_class: 'popup-menu-item',
|
|
|
|
reactive: params.reactive,
|
|
|
|
track_hover: params.reactive,
|
|
|
|
can_focus: params.can_focus,
|
|
|
|
accessible_role: Atk.Role.MENU_ITEM });
|
2010-05-20 11:18:46 -04:00
|
|
|
this.actor._delegate = this;
|
2010-10-19 13:41:41 -04:00
|
|
|
|
2013-04-19 20:57:38 -04:00
|
|
|
this._ornament = Ornament.NONE;
|
2013-04-19 21:08:35 -04:00
|
|
|
this._ornamentLabel = new St.Label({ style_class: 'popup-menu-ornament' });
|
2013-07-15 20:00:41 -04:00
|
|
|
this.actor.add(this._ornamentLabel);
|
|
|
|
|
|
|
|
this._parent = null;
|
2010-05-20 11:18:46 -04:00
|
|
|
this.active = false;
|
2011-09-15 10:51:19 -04:00
|
|
|
this._activatable = params.reactive && params.activate;
|
2013-06-12 03:16:53 -04:00
|
|
|
this._sensitive = true;
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2012-09-11 08:00:22 -04:00
|
|
|
if (!this._activatable)
|
|
|
|
this.actor.add_style_class_name('popup-inactive-menu-item');
|
|
|
|
|
2011-01-25 16:06:40 -05:00
|
|
|
if (params.style_class)
|
|
|
|
this.actor.add_style_class_name(params.style_class);
|
|
|
|
|
2011-09-15 10:51:19 -04:00
|
|
|
if (this._activatable) {
|
2010-10-07 14:15:51 -04:00
|
|
|
this.actor.connect('button-release-event', Lang.bind(this, this._onButtonReleaseEvent));
|
|
|
|
this.actor.connect('key-press-event', Lang.bind(this, this._onKeyPressEvent));
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
2010-07-03 19:47:31 -04:00
|
|
|
if (params.reactive && params.hover)
|
2010-10-07 14:15:51 -04:00
|
|
|
this.actor.connect('notify::hover', Lang.bind(this, this._onHoverChanged));
|
2012-08-17 05:03:23 -04:00
|
|
|
|
|
|
|
this.actor.connect('key-focus-in', Lang.bind(this, this._onKeyFocusIn));
|
|
|
|
this.actor.connect('key-focus-out', Lang.bind(this, this._onKeyFocusOut));
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
2013-07-15 18:47:16 -04:00
|
|
|
_getTopMenu: function() {
|
|
|
|
if (this._parent)
|
|
|
|
return this._parent._getTopMenu();
|
|
|
|
else
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
_setParent: function(parent) {
|
|
|
|
this._parent = parent;
|
|
|
|
},
|
|
|
|
|
2010-10-07 14:15:51 -04:00
|
|
|
_onButtonReleaseEvent: function (actor, event) {
|
2010-11-01 11:03:28 -04:00
|
|
|
this.activate(event);
|
2010-10-07 14:15:51 -04:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onKeyPressEvent: function (actor, event) {
|
|
|
|
let symbol = event.get_key_symbol();
|
|
|
|
|
|
|
|
if (symbol == Clutter.KEY_space || symbol == Clutter.KEY_Return) {
|
2010-11-01 11:03:28 -04:00
|
|
|
this.activate(event);
|
2010-10-07 14:15:51 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onKeyFocusIn: function (actor) {
|
|
|
|
this.setActive(true);
|
|
|
|
},
|
|
|
|
|
2011-02-11 14:43:01 -05:00
|
|
|
_onKeyFocusOut: function (actor) {
|
|
|
|
this.setActive(false);
|
|
|
|
},
|
|
|
|
|
2010-10-07 14:15:51 -04:00
|
|
|
_onHoverChanged: function (actor) {
|
2010-05-20 11:18:46 -04:00
|
|
|
this.setActive(actor.hover);
|
|
|
|
},
|
|
|
|
|
|
|
|
activate: function (event) {
|
|
|
|
this.emit('activate', event);
|
|
|
|
},
|
|
|
|
|
2013-04-23 17:46:33 -04:00
|
|
|
setActive: function (active) {
|
2010-05-20 11:18:46 -04:00
|
|
|
let activeChanged = active != this.active;
|
|
|
|
if (activeChanged) {
|
|
|
|
this.active = active;
|
2010-10-07 14:15:51 -04:00
|
|
|
if (active) {
|
2010-05-20 11:18:46 -04:00
|
|
|
this.actor.add_style_pseudo_class('active');
|
2013-04-23 17:46:33 -04:00
|
|
|
this.actor.grab_key_focus();
|
|
|
|
} else {
|
2010-05-20 11:18:46 -04:00
|
|
|
this.actor.remove_style_pseudo_class('active');
|
2013-04-23 17:46:33 -04:00
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
this.emit('active-changed', active);
|
|
|
|
}
|
2010-07-03 19:47:31 -04:00
|
|
|
},
|
|
|
|
|
2013-06-12 03:16:53 -04:00
|
|
|
syncSensitive: function() {
|
|
|
|
let sensitive = this.getSensitive();
|
2011-09-15 10:51:19 -04:00
|
|
|
this.actor.reactive = sensitive;
|
2012-08-19 21:40:09 -04:00
|
|
|
this.actor.can_focus = sensitive;
|
2013-06-12 03:16:53 -04:00
|
|
|
this.emit('sensitive-changed');
|
|
|
|
return sensitive;
|
|
|
|
},
|
2011-09-15 10:51:19 -04:00
|
|
|
|
2013-06-12 03:16:53 -04:00
|
|
|
getSensitive: function() {
|
2013-07-15 18:54:15 -04:00
|
|
|
let parentSensitive = this._parent ? this._parent.getSensitive() : true;
|
|
|
|
return this._activatable && this._sensitive && parentSensitive;
|
2013-06-12 03:16:53 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
setSensitive: function(sensitive) {
|
|
|
|
if (this._sensitive == sensitive)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._sensitive = sensitive;
|
|
|
|
this.syncSensitive();
|
2011-09-15 10:51:19 -04:00
|
|
|
},
|
|
|
|
|
2010-07-03 19:47:31 -04:00
|
|
|
destroy: function() {
|
|
|
|
this.actor.destroy();
|
|
|
|
this.emit('destroy');
|
|
|
|
},
|
|
|
|
|
2013-04-19 20:57:38 -04:00
|
|
|
setOrnament: function(ornament) {
|
|
|
|
if (ornament == this._ornament)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._ornament = ornament;
|
2010-10-20 12:43:22 -04:00
|
|
|
|
2013-04-19 20:57:38 -04:00
|
|
|
if (ornament == Ornament.DOT) {
|
2013-04-19 21:08:35 -04:00
|
|
|
this._ornamentLabel.text = '\u2022';
|
|
|
|
this.actor.add_accessible_state(Atk.StateType.CHECKED);
|
2013-04-19 21:13:37 -04:00
|
|
|
} else if (ornament == Ornament.CHECK) {
|
|
|
|
this._ornamentLabel.text = '\u2713';
|
|
|
|
this.actor.add_accessible_state(Atk.StateType.CHECKED);
|
2013-04-19 21:08:35 -04:00
|
|
|
} else if (ornament == Ornament.NONE) {
|
|
|
|
this._ornamentLabel.text = '';
|
|
|
|
this.actor.remove_accessible_state(Atk.StateType.CHECKED);
|
2010-10-20 12:43:22 -04:00
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
2011-11-20 08:10:48 -05:00
|
|
|
});
|
2010-05-20 11:18:46 -04:00
|
|
|
Signals.addSignalMethods(PopupBaseMenuItem.prototype);
|
|
|
|
|
2011-11-20 08:10:48 -05:00
|
|
|
const PopupMenuItem = new Lang.Class({
|
|
|
|
Name: 'PopupMenuItem',
|
|
|
|
Extends: PopupBaseMenuItem,
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-11-16 09:22:38 -05:00
|
|
|
_init: function (text, params) {
|
2011-11-20 08:10:48 -05:00
|
|
|
this.parent(params);
|
2010-05-20 11:18:46 -04:00
|
|
|
|
|
|
|
this.label = new St.Label({ text: text });
|
2013-07-15 20:00:41 -04:00
|
|
|
this.actor.add_child(this.label);
|
2012-01-05 13:00:06 -05:00
|
|
|
this.actor.label_actor = this.label
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
2011-11-20 08:10:48 -05:00
|
|
|
});
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2011-11-20 08:10:48 -05:00
|
|
|
const PopupSeparatorMenuItem = new Lang.Class({
|
|
|
|
Name: 'PopupSeparatorMenuItem',
|
|
|
|
Extends: PopupBaseMenuItem,
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2013-04-24 16:21:57 -04:00
|
|
|
_init: function (text) {
|
2012-08-17 05:03:23 -04:00
|
|
|
this.parent({ reactive: false,
|
|
|
|
can_focus: false});
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2013-04-24 16:21:57 -04:00
|
|
|
this.label = new St.Label({ text: text || '' });
|
2013-07-15 20:00:41 -04:00
|
|
|
this.actor.add(this.label);
|
2013-04-24 16:21:57 -04:00
|
|
|
this.actor.label_actor = this.label;
|
|
|
|
|
2012-08-15 21:28:49 -04:00
|
|
|
this._separator = new Separator.HorizontalSeparator({ style_class: 'popup-separator-menu-item' });
|
2013-07-15 20:00:41 -04:00
|
|
|
this.actor.add(this._separator.actor, { expand: true });
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
2011-11-20 08:10:48 -05:00
|
|
|
});
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2011-11-20 08:10:48 -05:00
|
|
|
const Switch = new Lang.Class({
|
|
|
|
Name: 'Switch',
|
2010-07-22 08:34:02 -04:00
|
|
|
|
2011-02-08 14:19:04 -05:00
|
|
|
_init: function(state) {
|
2012-02-27 11:31:10 -05:00
|
|
|
this.actor = new St.Bin({ style_class: 'toggle-switch',
|
2012-08-19 21:40:09 -04:00
|
|
|
accessible_role: Atk.Role.CHECK_BOX,
|
|
|
|
can_focus: true });
|
2011-02-08 14:19:04 -05:00
|
|
|
// Translators: this MUST be either "toggle-switch-us"
|
|
|
|
// (for toggle switches containing the English words
|
|
|
|
// "ON" and "OFF") or "toggle-switch-intl" (for toggle
|
|
|
|
// switches containing "◯" and "|"). Other values will
|
|
|
|
// simply result in invisible toggle switches.
|
|
|
|
this.actor.add_style_class_name(_("toggle-switch-us"));
|
|
|
|
this.setToggleState(state);
|
|
|
|
},
|
|
|
|
|
|
|
|
setToggleState: function(state) {
|
|
|
|
if (state)
|
|
|
|
this.actor.add_style_pseudo_class('checked');
|
|
|
|
else
|
|
|
|
this.actor.remove_style_pseudo_class('checked');
|
|
|
|
this.state = state;
|
|
|
|
},
|
|
|
|
|
|
|
|
toggle: function() {
|
|
|
|
this.setToggleState(!this.state);
|
|
|
|
}
|
2011-11-20 08:10:48 -05:00
|
|
|
});
|
2010-06-17 08:17:01 -04:00
|
|
|
|
2011-11-20 08:10:48 -05:00
|
|
|
const PopupSwitchMenuItem = new Lang.Class({
|
|
|
|
Name: 'PopupSwitchMenuItem',
|
|
|
|
Extends: PopupBaseMenuItem,
|
2010-06-17 08:17:01 -04:00
|
|
|
|
2011-01-25 16:06:40 -05:00
|
|
|
_init: function(text, active, params) {
|
2011-11-20 08:10:48 -05:00
|
|
|
this.parent(params);
|
2010-06-17 08:17:01 -04:00
|
|
|
|
|
|
|
this.label = new St.Label({ text: text });
|
2010-10-13 14:10:38 -04:00
|
|
|
this._switch = new Switch(active);
|
2010-06-17 08:17:01 -04:00
|
|
|
|
2012-02-27 11:31:10 -05:00
|
|
|
this.actor.accessible_role = Atk.Role.CHECK_MENU_ITEM;
|
2012-01-20 12:10:45 -05:00
|
|
|
this.checkAccessibleState();
|
2012-02-27 11:31:10 -05:00
|
|
|
this.actor.label_actor = this.label;
|
|
|
|
|
2013-07-15 20:00:41 -04:00
|
|
|
this.actor.add_child(this.label);
|
2010-06-17 08:17:01 -04:00
|
|
|
|
2011-04-21 10:44:28 -04:00
|
|
|
this._statusBin = new St.Bin({ x_align: St.Align.END });
|
2013-07-15 20:00:41 -04:00
|
|
|
this.actor.add(this._statusBin, { expand: true, x_align: St.Align.END });
|
2011-04-21 10:44:28 -04:00
|
|
|
|
|
|
|
this._statusLabel = new St.Label({ text: '',
|
2012-09-11 08:00:22 -04:00
|
|
|
style_class: 'popup-status-menu-item'
|
2011-04-21 10:44:28 -04:00
|
|
|
});
|
|
|
|
this._statusBin.child = this._switch.actor;
|
|
|
|
},
|
|
|
|
|
|
|
|
setStatus: function(text) {
|
|
|
|
if (text != null) {
|
|
|
|
this._statusLabel.text = text;
|
|
|
|
this._statusBin.child = this._statusLabel;
|
|
|
|
this.actor.reactive = false;
|
2012-02-27 11:31:10 -05:00
|
|
|
this.actor.accessible_role = Atk.Role.MENU_ITEM;
|
2011-04-21 10:44:28 -04:00
|
|
|
} else {
|
|
|
|
this._statusBin.child = this._switch.actor;
|
|
|
|
this.actor.reactive = true;
|
2012-02-27 11:31:10 -05:00
|
|
|
this.actor.accessible_role = Atk.Role.CHECK_MENU_ITEM;
|
2011-04-21 10:44:28 -04:00
|
|
|
}
|
2012-01-20 12:10:45 -05:00
|
|
|
this.checkAccessibleState();
|
2011-04-21 10:44:28 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
activate: function(event) {
|
|
|
|
if (this._switch.actor.mapped) {
|
2010-06-17 08:17:01 -04:00
|
|
|
this.toggle();
|
2011-04-21 10:44:28 -04:00
|
|
|
}
|
|
|
|
|
2011-11-21 08:16:51 -05:00
|
|
|
// we allow pressing space to toggle the switch
|
|
|
|
// without closing the menu
|
|
|
|
if (event.type() == Clutter.EventType.KEY_PRESS &&
|
|
|
|
event.get_key_symbol() == Clutter.KEY_space)
|
|
|
|
return;
|
|
|
|
|
2011-11-20 12:56:27 -05:00
|
|
|
this.parent(event);
|
2010-06-17 08:17:01 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
toggle: function() {
|
|
|
|
this._switch.toggle();
|
|
|
|
this.emit('toggled', this._switch.state);
|
2012-01-20 12:10:45 -05:00
|
|
|
this.checkAccessibleState();
|
2010-06-17 08:17:01 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
get state() {
|
|
|
|
return this._switch.state;
|
|
|
|
},
|
|
|
|
|
|
|
|
setToggleState: function(state) {
|
|
|
|
this._switch.setToggleState(state);
|
2012-01-20 12:10:45 -05:00
|
|
|
this.checkAccessibleState();
|
|
|
|
},
|
|
|
|
|
|
|
|
checkAccessibleState: function() {
|
|
|
|
switch (this.actor.accessible_role) {
|
|
|
|
case Atk.Role.CHECK_MENU_ITEM:
|
|
|
|
if (this._switch.state)
|
|
|
|
this.actor.add_accessible_state (Atk.StateType.CHECKED);
|
|
|
|
else
|
|
|
|
this.actor.remove_accessible_state (Atk.StateType.CHECKED);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this.actor.remove_accessible_state (Atk.StateType.CHECKED);
|
|
|
|
}
|
2010-06-17 08:17:01 -04:00
|
|
|
}
|
2011-11-20 08:10:48 -05:00
|
|
|
});
|
2010-06-17 08:17:01 -04:00
|
|
|
|
2011-11-20 08:10:48 -05:00
|
|
|
const PopupImageMenuItem = new Lang.Class({
|
|
|
|
Name: 'PopupImageMenuItem',
|
|
|
|
Extends: PopupBaseMenuItem,
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2011-01-25 16:06:40 -05:00
|
|
|
_init: function (text, iconName, params) {
|
2011-11-20 08:10:48 -05:00
|
|
|
this.parent(params);
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-07-06 03:51:53 -04:00
|
|
|
this.label = new St.Label({ text: text });
|
2010-10-19 13:41:41 -04:00
|
|
|
this.addActor(this.label);
|
2010-11-02 18:33:22 -04:00
|
|
|
this._icon = new St.Icon({ style_class: 'popup-menu-icon' });
|
2010-11-17 14:10:12 -05:00
|
|
|
this.addActor(this._icon, { align: St.Align.END });
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-10-19 11:59:23 -04:00
|
|
|
this.setIcon(iconName);
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
2010-07-06 03:51:53 -04:00
|
|
|
setIcon: function(name) {
|
2010-11-02 18:33:22 -04:00
|
|
|
this._icon.icon_name = name;
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
2011-11-20 08:10:48 -05:00
|
|
|
});
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2011-11-20 08:10:48 -05:00
|
|
|
const PopupMenuBase = new Lang.Class({
|
|
|
|
Name: 'PopupMenuBase',
|
|
|
|
Abstract: true,
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
_init: function(sourceActor, styleClass) {
|
2010-05-20 11:18:46 -04:00
|
|
|
this.sourceActor = sourceActor;
|
2013-07-08 15:19:34 -04:00
|
|
|
this._parent = null;
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2011-01-25 16:06:40 -05:00
|
|
|
if (styleClass !== undefined) {
|
|
|
|
this.box = new St.BoxLayout({ style_class: styleClass,
|
|
|
|
vertical: true });
|
|
|
|
} else {
|
|
|
|
this.box = new St.BoxLayout({ vertical: true });
|
|
|
|
}
|
2011-03-28 15:27:03 -04:00
|
|
|
this.length = 0;
|
2010-10-07 14:15:51 -04:00
|
|
|
|
2010-05-20 11:18:46 -04:00
|
|
|
this.isOpen = false;
|
2011-03-22 10:29:32 -04:00
|
|
|
|
|
|
|
// If set, we don't send events (including crossing events) to the source actor
|
|
|
|
// for the menu which causes its prelight state to freeze
|
|
|
|
this.blockSourceEvents = false;
|
|
|
|
|
2010-05-20 11:18:46 -04:00
|
|
|
this._activeMenuItem = null;
|
2012-05-22 18:27:06 -04:00
|
|
|
this._settingsActions = { };
|
2012-09-01 08:42:53 -04:00
|
|
|
|
2013-06-12 03:16:53 -04:00
|
|
|
this._sensitive = true;
|
|
|
|
|
2012-09-01 08:42:53 -04:00
|
|
|
this._sessionUpdatedId = Main.sessionMode.connect('updated', Lang.bind(this, this._sessionUpdated));
|
|
|
|
},
|
|
|
|
|
2013-07-08 15:19:34 -04:00
|
|
|
_getTopMenu: function() {
|
|
|
|
if (this._parent)
|
|
|
|
return this._parent._getTopMenu();
|
|
|
|
else
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2013-07-15 18:47:16 -04:00
|
|
|
_setParent: function(parent) {
|
|
|
|
this._parent = parent;
|
|
|
|
},
|
|
|
|
|
2013-06-12 03:16:53 -04:00
|
|
|
getSensitive: function() {
|
2013-07-15 18:54:15 -04:00
|
|
|
let parentSensitive = this._parent ? this._parent.getSensitive() : true;
|
|
|
|
return this._sensitive && parentSensitive;
|
2013-06-12 03:16:53 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
setSensitive: function(sensitive) {
|
|
|
|
this._sensitive = sensitive;
|
|
|
|
this.emit('sensitive-changed');
|
|
|
|
},
|
|
|
|
|
2012-09-01 08:42:53 -04:00
|
|
|
_sessionUpdated: function() {
|
|
|
|
this._setSettingsVisibility(Main.sessionMode.allowSettings);
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
addAction: function(title, callback) {
|
2011-08-23 10:14:55 -04:00
|
|
|
let menuItem = new PopupMenuItem(title);
|
2010-05-20 11:18:46 -04:00
|
|
|
this.addMenuItem(menuItem);
|
|
|
|
menuItem.connect('activate', Lang.bind(this, function (menuItem, event) {
|
|
|
|
callback(event);
|
|
|
|
}));
|
2011-08-23 10:14:55 -04:00
|
|
|
|
|
|
|
return menuItem;
|
|
|
|
},
|
|
|
|
|
|
|
|
addSettingsAction: function(title, desktopFile) {
|
|
|
|
let menuItem = this.addAction(title, function() {
|
2013-01-24 14:32:27 -05:00
|
|
|
let app = Shell.AppSystem.get_default().lookup_app(desktopFile);
|
2011-08-23 10:14:55 -04:00
|
|
|
|
|
|
|
if (!app) {
|
|
|
|
log('Settings panel for desktop file ' + desktopFile + ' could not be loaded!');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Main.overview.hide();
|
|
|
|
app.activate();
|
|
|
|
});
|
2012-05-22 18:27:06 -04:00
|
|
|
|
2012-09-20 09:58:08 -04:00
|
|
|
menuItem.actor.visible = Main.sessionMode.allowSettings;
|
2012-05-22 18:27:06 -04:00
|
|
|
this._settingsActions[desktopFile] = menuItem;
|
|
|
|
|
2011-08-23 10:14:55 -04:00
|
|
|
return menuItem;
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
2012-09-01 08:42:53 -04:00
|
|
|
_setSettingsVisibility: function(visible) {
|
2012-05-22 18:27:06 -04:00
|
|
|
for (let id in this._settingsActions) {
|
|
|
|
let item = this._settingsActions[id];
|
|
|
|
item.actor.visible = visible;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-11-15 08:58:55 -05:00
|
|
|
isEmpty: function() {
|
2013-02-14 16:48:28 -05:00
|
|
|
let hasVisibleChildren = this.box.get_children().some(function(child) {
|
2013-07-15 14:16:30 -04:00
|
|
|
if (child._delegate instanceof PopupSeparatorMenuItem)
|
|
|
|
return false;
|
2013-08-28 10:50:07 -04:00
|
|
|
return isPopupMenuItemVisible(child);
|
2013-02-14 16:48:28 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
return !hasVisibleChildren;
|
2011-11-15 08:58:55 -05:00
|
|
|
},
|
|
|
|
|
2013-06-18 04:46:44 -04:00
|
|
|
itemActivated: function(animate) {
|
|
|
|
if (animate == undefined)
|
|
|
|
animate = BoxPointer.PopupAnimation.FULL;
|
|
|
|
|
|
|
|
this._getTopMenu().close(animate);
|
|
|
|
},
|
|
|
|
|
2013-06-11 19:18:06 -04:00
|
|
|
_subMenuActiveChanged: function(submenu, submenuItem) {
|
|
|
|
if (this._activeMenuItem && this._activeMenuItem != submenuItem)
|
|
|
|
this._activeMenuItem.setActive(false);
|
|
|
|
this._activeMenuItem = submenuItem;
|
|
|
|
this.emit('active-changed', submenuItem);
|
2011-01-25 16:04:57 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_connectItemSignals: function(menuItem) {
|
2010-05-20 11:18:46 -04:00
|
|
|
menuItem._activeChangeId = menuItem.connect('active-changed', Lang.bind(this, function (menuItem, active) {
|
|
|
|
if (active && this._activeMenuItem != menuItem) {
|
|
|
|
if (this._activeMenuItem)
|
|
|
|
this._activeMenuItem.setActive(false);
|
|
|
|
this._activeMenuItem = menuItem;
|
|
|
|
this.emit('active-changed', menuItem);
|
|
|
|
} else if (!active && this._activeMenuItem == menuItem) {
|
|
|
|
this._activeMenuItem = null;
|
|
|
|
this.emit('active-changed', null);
|
|
|
|
}
|
|
|
|
}));
|
2013-06-12 03:16:53 -04:00
|
|
|
menuItem._sensitiveChangeId = menuItem.connect('sensitive-changed', Lang.bind(this, function() {
|
|
|
|
let sensitive = menuItem.getSensitive();
|
2011-09-15 10:51:19 -04:00
|
|
|
if (!sensitive && this._activeMenuItem == menuItem) {
|
|
|
|
if (!this.actor.navigate_focus(menuItem.actor,
|
|
|
|
Gtk.DirectionType.TAB_FORWARD,
|
|
|
|
true))
|
|
|
|
this.actor.grab_key_focus();
|
|
|
|
} else if (sensitive && this._activeMenuItem == null) {
|
|
|
|
if (global.stage.get_key_focus() == this.actor)
|
|
|
|
menuItem.actor.grab_key_focus();
|
|
|
|
}
|
|
|
|
}));
|
2010-05-20 11:18:46 -04:00
|
|
|
menuItem._activateId = menuItem.connect('activate', Lang.bind(this, function (menuItem, event) {
|
|
|
|
this.emit('activate', menuItem);
|
2013-06-18 04:46:44 -04:00
|
|
|
this.itemActivated(BoxPointer.PopupAnimation.FULL);
|
2010-05-20 11:18:46 -04:00
|
|
|
}));
|
2013-06-12 03:16:53 -04:00
|
|
|
|
|
|
|
menuItem._parentSensitiveChangeId = this.connect('sensitive-changed', Lang.bind(this, function() {
|
|
|
|
menuItem.syncSensitive();
|
|
|
|
}));
|
|
|
|
|
2011-12-12 14:36:00 -05:00
|
|
|
// the weird name is to avoid a conflict with some random property
|
|
|
|
// the menuItem may have, called destroyId
|
|
|
|
// (FIXME: in the future it may make sense to have container objects
|
|
|
|
// like PopupMenuManager does)
|
|
|
|
menuItem._popupMenuDestroyId = menuItem.connect('destroy', Lang.bind(this, function(menuItem) {
|
|
|
|
menuItem.disconnect(menuItem._popupMenuDestroyId);
|
2010-07-03 19:47:31 -04:00
|
|
|
menuItem.disconnect(menuItem._activateId);
|
|
|
|
menuItem.disconnect(menuItem._activeChangeId);
|
2011-09-15 10:51:19 -04:00
|
|
|
menuItem.disconnect(menuItem._sensitiveChangeId);
|
2013-06-12 03:16:53 -04:00
|
|
|
this.disconnect(menuItem._parentSensitiveChangeId);
|
2010-07-03 19:47:31 -04:00
|
|
|
if (menuItem == this._activeMenuItem)
|
|
|
|
this._activeMenuItem = null;
|
|
|
|
}));
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
2011-08-19 14:42:20 -04:00
|
|
|
_updateSeparatorVisibility: function(menuItem) {
|
2013-04-24 16:21:57 -04:00
|
|
|
if (menuItem.label.text)
|
|
|
|
return;
|
|
|
|
|
2011-08-19 14:42:20 -04:00
|
|
|
let children = this.box.get_children();
|
|
|
|
|
|
|
|
let index = children.indexOf(menuItem.actor);
|
|
|
|
|
|
|
|
if (index < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let childBeforeIndex = index - 1;
|
|
|
|
|
2013-08-28 10:50:07 -04:00
|
|
|
while (childBeforeIndex >= 0 && !isPopupMenuItemVisible(children[childBeforeIndex]))
|
2011-08-19 14:42:20 -04:00
|
|
|
childBeforeIndex--;
|
|
|
|
|
|
|
|
if (childBeforeIndex < 0
|
|
|
|
|| children[childBeforeIndex]._delegate instanceof PopupSeparatorMenuItem) {
|
|
|
|
menuItem.actor.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let childAfterIndex = index + 1;
|
|
|
|
|
2013-08-28 10:50:07 -04:00
|
|
|
while (childAfterIndex < children.length && !isPopupMenuItemVisible(children[childAfterIndex]))
|
2011-08-19 14:42:20 -04:00
|
|
|
childAfterIndex++;
|
|
|
|
|
|
|
|
if (childAfterIndex >= children.length
|
|
|
|
|| children[childAfterIndex]._delegate instanceof PopupSeparatorMenuItem) {
|
|
|
|
menuItem.actor.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
menuItem.actor.show();
|
|
|
|
},
|
|
|
|
|
2011-01-25 16:04:57 -05:00
|
|
|
addMenuItem: function(menuItem, position) {
|
|
|
|
let before_item = null;
|
|
|
|
if (position == undefined) {
|
|
|
|
this.box.add(menuItem.actor);
|
|
|
|
} else {
|
|
|
|
let items = this._getMenuItems();
|
|
|
|
if (position < items.length) {
|
|
|
|
before_item = items[position].actor;
|
2012-02-13 15:27:16 -05:00
|
|
|
this.box.insert_child_below(menuItem.actor, before_item);
|
|
|
|
} else {
|
2011-01-25 16:04:57 -05:00
|
|
|
this.box.add(menuItem.actor);
|
2012-02-13 15:27:16 -05:00
|
|
|
}
|
2011-01-25 16:04:57 -05:00
|
|
|
}
|
2012-02-13 15:27:16 -05:00
|
|
|
|
2011-01-25 16:04:57 -05:00
|
|
|
if (menuItem instanceof PopupMenuSection) {
|
2013-06-11 19:18:06 -04:00
|
|
|
let activeChangeId = menuItem.connect('active-changed', Lang.bind(this, this._subMenuActiveChanged));
|
|
|
|
|
|
|
|
let parentOpenStateChangedId = this.connect('open-state-changed', function(self, open) {
|
|
|
|
if (open)
|
|
|
|
menuItem.open();
|
|
|
|
else
|
|
|
|
menuItem.close();
|
|
|
|
});
|
|
|
|
let parentClosingId = this.connect('menu-closed', function() {
|
2013-06-12 17:38:02 -04:00
|
|
|
menuItem.emit('menu-closed');
|
|
|
|
});
|
2013-06-12 03:16:53 -04:00
|
|
|
let subMenuSensitiveChangedId = this.connect('sensitive-changed', Lang.bind(this, function() {
|
|
|
|
menuItem.emit('sensitive-changed');
|
|
|
|
}));
|
2011-03-28 15:27:03 -04:00
|
|
|
|
2013-06-11 19:18:06 -04:00
|
|
|
menuItem.connect('destroy', Lang.bind(this, function() {
|
|
|
|
menuItem.disconnect(activeChangeId);
|
2013-06-12 03:16:53 -04:00
|
|
|
this.disconnect(subMenuSensitiveChangedId);
|
2013-06-11 19:18:06 -04:00
|
|
|
this.disconnect(parentOpenStateChangedId);
|
|
|
|
this.disconnect(parentClosingId);
|
2011-03-28 15:27:03 -04:00
|
|
|
this.length--;
|
2011-01-25 16:04:57 -05:00
|
|
|
}));
|
|
|
|
} else if (menuItem instanceof PopupSubMenuMenuItem) {
|
|
|
|
if (before_item == null)
|
|
|
|
this.box.add(menuItem.menu.actor);
|
|
|
|
else
|
2012-02-13 15:27:16 -05:00
|
|
|
this.box.insert_child_below(menuItem.menu.actor, before_item);
|
2013-06-11 19:18:06 -04:00
|
|
|
|
2011-01-25 16:04:57 -05:00
|
|
|
this._connectItemSignals(menuItem);
|
2013-06-11 19:18:06 -04:00
|
|
|
let subMenuActiveChangeId = menuItem.menu.connect('active-changed', Lang.bind(this, this._subMenuActiveChanged));
|
|
|
|
let closingId = this.connect('menu-closed', function() {
|
2013-06-12 17:38:02 -04:00
|
|
|
menuItem.menu.close(BoxPointer.PopupAnimation.NONE);
|
2011-01-25 16:04:57 -05:00
|
|
|
});
|
2013-06-11 19:18:06 -04:00
|
|
|
|
|
|
|
menuItem.connect('destroy', Lang.bind(this, function() {
|
|
|
|
menuItem.menu.disconnect(subMenuActiveChangeId);
|
|
|
|
this.disconnect(closingId);
|
|
|
|
}));
|
2011-08-19 14:42:20 -04:00
|
|
|
} else if (menuItem instanceof PopupSeparatorMenuItem) {
|
|
|
|
this._connectItemSignals(menuItem);
|
|
|
|
|
|
|
|
// updateSeparatorVisibility needs to get called any time the
|
|
|
|
// separator's adjacent siblings change visibility or position.
|
|
|
|
// open-state-changed isn't exactly that, but doing it in more
|
|
|
|
// precise ways would require a lot more bookkeeping.
|
2013-08-06 10:30:18 -04:00
|
|
|
let openStateChangeId = this.connect('open-state-changed', Lang.bind(this, function() { this._updateSeparatorVisibility(menuItem); }));
|
|
|
|
let destroyId = menuItem.connect('destroy', Lang.bind(this, function() {
|
|
|
|
this.disconnect(openStateChangeId);
|
|
|
|
menuItem.disconnect(destroyId);
|
|
|
|
}));
|
2011-01-25 16:04:57 -05:00
|
|
|
} else if (menuItem instanceof PopupBaseMenuItem)
|
|
|
|
this._connectItemSignals(menuItem);
|
|
|
|
else
|
|
|
|
throw TypeError("Invalid argument to PopupMenuBase.addMenuItem()");
|
2011-03-28 15:27:03 -04:00
|
|
|
|
2013-07-15 18:47:16 -04:00
|
|
|
menuItem._setParent(this);
|
2013-07-08 15:19:34 -04:00
|
|
|
|
2011-03-28 15:27:03 -04:00
|
|
|
this.length++;
|
2011-01-25 16:04:57 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_getMenuItems: function() {
|
|
|
|
return this.box.get_children().map(function (actor) {
|
|
|
|
return actor._delegate;
|
|
|
|
}).filter(function(item) {
|
|
|
|
return item instanceof PopupBaseMenuItem || item instanceof PopupMenuSection;
|
|
|
|
});
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
2011-06-27 11:45:24 -04:00
|
|
|
get firstMenuItem() {
|
|
|
|
let items = this._getMenuItems();
|
|
|
|
if (items.length)
|
|
|
|
return items[0];
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2011-07-20 23:17:05 -04:00
|
|
|
get numMenuItems() {
|
|
|
|
return this._getMenuItems().length;
|
|
|
|
},
|
|
|
|
|
2010-05-20 11:18:46 -04:00
|
|
|
removeAll: function() {
|
2011-01-25 16:04:57 -05:00
|
|
|
let children = this._getMenuItems();
|
2010-05-20 11:18:46 -04:00
|
|
|
for (let i = 0; i < children.length; i++) {
|
|
|
|
let item = children[i];
|
2010-07-03 19:47:31 -04:00
|
|
|
item.destroy();
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
toggle: function() {
|
2010-05-20 11:18:46 -04:00
|
|
|
if (this.isOpen)
|
2012-06-15 13:16:10 -04:00
|
|
|
this.close(BoxPointer.PopupAnimation.FULL);
|
2010-11-01 11:03:28 -04:00
|
|
|
else
|
2012-06-15 13:16:10 -04:00
|
|
|
this.open(BoxPointer.PopupAnimation.FULL);
|
2010-11-01 11:03:28 -04:00
|
|
|
},
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
destroy: function() {
|
2013-04-06 10:31:16 -04:00
|
|
|
this.close();
|
2010-11-01 11:03:28 -04:00
|
|
|
this.removeAll();
|
|
|
|
this.actor.destroy();
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
this.emit('destroy');
|
2012-09-01 08:42:53 -04:00
|
|
|
|
|
|
|
Main.sessionMode.disconnect(this._sessionUpdatedId);
|
|
|
|
this._sessionUpdatedId = 0;
|
2010-11-01 11:03:28 -04:00
|
|
|
}
|
2011-11-20 08:10:48 -05:00
|
|
|
});
|
2010-11-01 11:03:28 -04:00
|
|
|
Signals.addSignalMethods(PopupMenuBase.prototype);
|
2010-06-12 12:13:04 -04:00
|
|
|
|
2011-11-20 08:10:48 -05:00
|
|
|
const PopupMenu = new Lang.Class({
|
|
|
|
Name: 'PopupMenu',
|
|
|
|
Extends: PopupMenuBase,
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2011-09-14 18:14:03 -04:00
|
|
|
_init: function(sourceActor, arrowAlignment, arrowSide) {
|
2011-11-20 08:10:48 -05:00
|
|
|
this.parent(sourceActor, 'popup-menu-content');
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2011-09-14 18:14:03 -04:00
|
|
|
this._arrowAlignment = arrowAlignment;
|
2010-11-01 11:03:28 -04:00
|
|
|
this._arrowSide = arrowSide;
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
this._boxPointer = new BoxPointer.BoxPointer(arrowSide,
|
|
|
|
{ x_fill: true,
|
|
|
|
y_fill: true,
|
|
|
|
x_align: St.Align.START });
|
|
|
|
this.actor = this._boxPointer.actor;
|
|
|
|
this.actor._delegate = this;
|
|
|
|
this.actor.style_class = 'popup-menu-boxpointer';
|
2011-02-08 14:53:43 -05:00
|
|
|
|
2013-07-15 18:58:00 -04:00
|
|
|
this._boxPointer.bin.set_child(this.box);
|
2010-11-01 11:03:28 -04:00
|
|
|
this.actor.add_style_class_name('popup-menu');
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
global.focus_manager.add_group(this.actor);
|
2010-05-20 11:18:46 -04:00
|
|
|
this.actor.reactive = true;
|
2013-02-16 13:42:17 -05:00
|
|
|
|
2013-06-11 19:12:46 -04:00
|
|
|
this._openedSubMenu = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
_setOpenedSubMenu: function(submenu) {
|
|
|
|
if (this._openedSubMenu)
|
|
|
|
this._openedSubMenu.close(true);
|
|
|
|
|
|
|
|
this._openedSubMenu = submenu;
|
2010-11-01 11:03:28 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
setArrowOrigin: function(origin) {
|
|
|
|
this._boxPointer.setArrowOrigin(origin);
|
|
|
|
},
|
|
|
|
|
2011-09-14 18:14:03 -04:00
|
|
|
setSourceAlignment: function(alignment) {
|
|
|
|
this._boxPointer.setSourceAlignment(alignment);
|
|
|
|
},
|
|
|
|
|
2010-11-18 16:18:54 -05:00
|
|
|
open: function(animate) {
|
2010-11-01 11:03:28 -04:00
|
|
|
if (this.isOpen)
|
|
|
|
return;
|
|
|
|
|
2011-11-15 08:58:55 -05:00
|
|
|
if (this.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2010-05-20 11:18:46 -04:00
|
|
|
this.isOpen = true;
|
2010-11-01 11:03:28 -04:00
|
|
|
|
2011-09-14 18:14:03 -04:00
|
|
|
this._boxPointer.setPosition(this.sourceActor, this._arrowAlignment);
|
2010-11-18 16:18:54 -05:00
|
|
|
this._boxPointer.show(animate);
|
2010-11-01 11:03:28 -04:00
|
|
|
|
2011-08-29 12:04:17 -04:00
|
|
|
this.actor.raise_top();
|
|
|
|
|
2010-05-20 11:18:46 -04:00
|
|
|
this.emit('open-state-changed', true);
|
|
|
|
},
|
|
|
|
|
2010-11-18 16:18:54 -05:00
|
|
|
close: function(animate) {
|
2010-07-03 19:47:31 -04:00
|
|
|
if (this._activeMenuItem)
|
|
|
|
this._activeMenuItem.setActive(false);
|
2010-11-01 11:03:28 -04:00
|
|
|
|
2013-06-12 17:38:02 -04:00
|
|
|
if (this._boxPointer.actor.visible) {
|
|
|
|
this._boxPointer.hide(animate, Lang.bind(this, function() {
|
|
|
|
this.emit('menu-closed');
|
|
|
|
}));
|
|
|
|
}
|
2012-10-19 17:13:16 -04:00
|
|
|
|
|
|
|
if (!this.isOpen)
|
|
|
|
return;
|
2010-11-01 11:03:28 -04:00
|
|
|
|
2010-05-20 11:18:46 -04:00
|
|
|
this.isOpen = false;
|
|
|
|
this.emit('open-state-changed', false);
|
2010-11-01 11:03:28 -04:00
|
|
|
}
|
2011-11-20 08:10:48 -05:00
|
|
|
});
|
2010-11-01 11:03:28 -04:00
|
|
|
|
2012-12-04 14:52:34 -05:00
|
|
|
const PopupDummyMenu = new Lang.Class({
|
|
|
|
Name: 'PopupDummyMenu',
|
|
|
|
|
|
|
|
_init: function(sourceActor) {
|
|
|
|
this.sourceActor = sourceActor;
|
|
|
|
this.actor = sourceActor;
|
|
|
|
this.actor._delegate = this;
|
|
|
|
},
|
|
|
|
|
2013-06-12 03:16:53 -04:00
|
|
|
getSensitive: function() {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2012-12-04 14:52:34 -05:00
|
|
|
open: function() { this.emit('open-state-changed', true); },
|
|
|
|
close: function() { this.emit('open-state-changed', false); },
|
2012-12-10 03:42:53 -05:00
|
|
|
toggle: function() {},
|
2012-12-04 14:52:34 -05:00
|
|
|
destroy: function() {
|
|
|
|
this.emit('destroy');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
Signals.addSignalMethods(PopupDummyMenu.prototype);
|
|
|
|
|
2011-11-20 08:10:48 -05:00
|
|
|
const PopupSubMenu = new Lang.Class({
|
|
|
|
Name: 'PopupSubMenu',
|
|
|
|
Extends: PopupMenuBase,
|
2010-11-01 11:03:28 -04:00
|
|
|
|
|
|
|
_init: function(sourceActor, sourceArrow) {
|
2011-11-20 08:10:48 -05:00
|
|
|
this.parent(sourceActor);
|
2010-11-01 11:03:28 -04:00
|
|
|
|
|
|
|
this._arrow = sourceArrow;
|
|
|
|
|
2011-04-02 12:35:03 -04:00
|
|
|
// Since a function of a submenu might be to provide a "More.." expander
|
|
|
|
// with long content, we make it scrollable - the scrollbar will only take
|
|
|
|
// effect if a CSS max-height is set on the top menu.
|
2011-04-04 08:55:15 -04:00
|
|
|
this.actor = new St.ScrollView({ style_class: 'popup-sub-menu',
|
|
|
|
hscrollbar_policy: Gtk.PolicyType.NEVER,
|
2011-04-02 12:35:03 -04:00
|
|
|
vscrollbar_policy: Gtk.PolicyType.NEVER });
|
|
|
|
|
|
|
|
this.actor.add_actor(this.box);
|
2010-11-01 11:03:28 -04:00
|
|
|
this.actor._delegate = this;
|
|
|
|
this.actor.clip_to_allocation = true;
|
|
|
|
this.actor.connect('key-press-event', Lang.bind(this, this._onKeyPressEvent));
|
|
|
|
this.actor.hide();
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
2011-04-02 12:35:03 -04:00
|
|
|
_needsScrollbar: function() {
|
|
|
|
let topMenu = this._getTopMenu();
|
|
|
|
let [topMinHeight, topNaturalHeight] = topMenu.actor.get_preferred_height(-1);
|
|
|
|
let topThemeNode = topMenu.actor.get_theme_node();
|
|
|
|
|
|
|
|
let topMaxHeight = topThemeNode.get_max_height();
|
|
|
|
return topMaxHeight >= 0 && topNaturalHeight >= topMaxHeight;
|
|
|
|
},
|
|
|
|
|
2013-06-12 03:16:53 -04:00
|
|
|
getSensitive: function() {
|
2013-07-15 12:57:51 -04:00
|
|
|
return this._sensitive && this.sourceActor._delegate.getSensitive();
|
2013-06-12 03:16:53 -04:00
|
|
|
},
|
|
|
|
|
2010-11-18 16:18:54 -05:00
|
|
|
open: function(animate) {
|
2010-05-20 11:18:46 -04:00
|
|
|
if (this.isOpen)
|
2010-11-01 11:03:28 -04:00
|
|
|
return;
|
|
|
|
|
2011-11-15 08:58:55 -05:00
|
|
|
if (this.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
this.isOpen = true;
|
2013-06-11 18:29:36 -04:00
|
|
|
this.emit('open-state-changed', true);
|
2010-11-01 11:03:28 -04:00
|
|
|
|
2011-03-31 15:51:38 -04:00
|
|
|
this.actor.show();
|
2011-04-02 12:35:03 -04:00
|
|
|
|
|
|
|
let needsScrollbar = this._needsScrollbar();
|
|
|
|
|
|
|
|
// St.ScrollView always requests space horizontally for a possible vertical
|
|
|
|
// scrollbar if in AUTOMATIC mode. Doing better would require implementation
|
|
|
|
// of width-for-height in St.BoxLayout and St.ScrollView. This looks bad
|
|
|
|
// when we *don't* need it, so turn off the scrollbar when that's true.
|
|
|
|
// Dynamic changes in whether we need it aren't handled properly.
|
|
|
|
this.actor.vscrollbar_policy =
|
|
|
|
needsScrollbar ? Gtk.PolicyType.AUTOMATIC : Gtk.PolicyType.NEVER;
|
|
|
|
|
2012-09-06 05:41:23 -04:00
|
|
|
if (needsScrollbar)
|
|
|
|
this.actor.add_style_pseudo_class('scrolled');
|
|
|
|
else
|
|
|
|
this.actor.remove_style_pseudo_class('scrolled');
|
|
|
|
|
2011-04-02 12:35:03 -04:00
|
|
|
// It looks funny if we animate with a scrollbar (at what point is
|
|
|
|
// the scrollbar added?) so just skip that case
|
|
|
|
if (animate && needsScrollbar)
|
|
|
|
animate = false;
|
|
|
|
|
|
|
|
if (animate) {
|
|
|
|
let [minHeight, naturalHeight] = this.actor.get_preferred_height(-1);
|
|
|
|
this.actor.height = 0;
|
|
|
|
this.actor._arrow_rotation = this._arrow.rotation_angle_z;
|
|
|
|
Tweener.addTween(this.actor,
|
|
|
|
{ _arrow_rotation: 90,
|
|
|
|
height: naturalHeight,
|
|
|
|
time: 0.25,
|
|
|
|
onUpdateScope: this,
|
|
|
|
onUpdate: function() {
|
|
|
|
this._arrow.rotation_angle_z = this.actor._arrow_rotation;
|
|
|
|
},
|
|
|
|
onCompleteScope: this,
|
|
|
|
onComplete: function() {
|
|
|
|
this.actor.set_height(-1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this._arrow.rotation_angle_z = 90;
|
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
2010-11-18 16:18:54 -05:00
|
|
|
close: function(animate) {
|
2010-11-01 11:03:28 -04:00
|
|
|
if (!this.isOpen)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.isOpen = false;
|
2013-06-11 18:29:36 -04:00
|
|
|
this.emit('open-state-changed', false);
|
2010-11-01 11:03:28 -04:00
|
|
|
|
|
|
|
if (this._activeMenuItem)
|
2010-10-07 14:15:51 -04:00
|
|
|
this._activeMenuItem.setActive(false);
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2011-04-02 12:35:03 -04:00
|
|
|
if (animate && this._needsScrollbar())
|
|
|
|
animate = false;
|
|
|
|
|
2010-11-18 16:18:54 -05:00
|
|
|
if (animate) {
|
|
|
|
this.actor._arrow_rotation = this._arrow.rotation_angle_z;
|
|
|
|
Tweener.addTween(this.actor,
|
|
|
|
{ _arrow_rotation: 0,
|
|
|
|
height: 0,
|
|
|
|
time: 0.25,
|
2013-08-22 14:07:32 -04:00
|
|
|
onUpdateScope: this,
|
|
|
|
onUpdate: function() {
|
|
|
|
this._arrow.rotation_angle_z = this.actor._arrow_rotation;
|
|
|
|
},
|
2010-11-18 16:18:54 -05:00
|
|
|
onCompleteScope: this,
|
|
|
|
onComplete: function() {
|
|
|
|
this.actor.hide();
|
|
|
|
this.actor.set_height(-1);
|
|
|
|
},
|
|
|
|
});
|
2013-08-22 14:07:32 -04:00
|
|
|
} else {
|
|
|
|
this._arrow.rotation_angle_z = 0;
|
|
|
|
this.actor.hide();
|
|
|
|
}
|
2010-07-03 19:47:31 -04:00
|
|
|
},
|
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
_onKeyPressEvent: function(actor, event) {
|
|
|
|
// Move focus back to parent menu if the user types Left.
|
2010-07-03 19:47:31 -04:00
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
if (this.isOpen && event.get_key_symbol() == Clutter.KEY_Left) {
|
2012-06-15 13:16:10 -04:00
|
|
|
this.close(BoxPointer.PopupAnimation.FULL);
|
2010-11-01 11:03:28 -04:00
|
|
|
this.sourceActor._delegate.setActive(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
2011-11-20 08:10:48 -05:00
|
|
|
});
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2011-01-25 16:04:57 -05:00
|
|
|
/**
|
|
|
|
* PopupMenuSection:
|
|
|
|
*
|
|
|
|
* A section of a PopupMenu which is handled like a submenu
|
|
|
|
* (you can add and remove items, you can destroy it, you
|
|
|
|
* can add it to another menu), but is completely transparent
|
|
|
|
* to the user
|
|
|
|
*/
|
2011-11-20 08:10:48 -05:00
|
|
|
const PopupMenuSection = new Lang.Class({
|
|
|
|
Name: 'PopupMenuSection',
|
|
|
|
Extends: PopupMenuBase,
|
2011-01-25 16:04:57 -05:00
|
|
|
|
|
|
|
_init: function() {
|
2011-11-20 08:10:48 -05:00
|
|
|
this.parent();
|
2011-01-25 16:04:57 -05:00
|
|
|
|
|
|
|
this.actor = this.box;
|
|
|
|
this.actor._delegate = this;
|
|
|
|
this.isOpen = true;
|
|
|
|
},
|
|
|
|
|
2011-10-07 14:17:44 -04:00
|
|
|
// deliberately ignore any attempt to open() or close(), but emit the
|
|
|
|
// corresponding signal so children can still pick it up
|
2013-09-09 15:54:17 -04:00
|
|
|
open: function() { this.emit('open-state-changed', true); },
|
|
|
|
close: function() { this.emit('open-state-changed', false); },
|
2011-11-20 08:10:48 -05:00
|
|
|
});
|
2010-07-03 19:47:31 -04:00
|
|
|
|
2011-11-20 08:10:48 -05:00
|
|
|
const PopupSubMenuMenuItem = new Lang.Class({
|
|
|
|
Name: 'PopupSubMenuMenuItem',
|
|
|
|
Extends: PopupBaseMenuItem,
|
2010-07-03 19:47:31 -04:00
|
|
|
|
2013-06-06 14:17:41 -04:00
|
|
|
_init: function(text, wantIcon) {
|
2011-11-20 08:10:48 -05:00
|
|
|
this.parent();
|
2010-11-01 11:03:28 -04:00
|
|
|
|
|
|
|
this.actor.add_style_class_name('popup-submenu-menu-item');
|
2010-07-03 19:47:31 -04:00
|
|
|
|
2013-06-06 14:17:41 -04:00
|
|
|
if (wantIcon) {
|
|
|
|
this.icon = new St.Icon({ style_class: 'popup-menu-icon' });
|
2013-07-15 20:00:41 -04:00
|
|
|
this.actor.add_child(this.icon);
|
2013-06-06 14:17:41 -04:00
|
|
|
}
|
|
|
|
|
2013-09-18 17:36:09 -04:00
|
|
|
this.label = new St.Label({ text: text,
|
|
|
|
y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER });
|
2013-07-15 20:00:41 -04:00
|
|
|
this.actor.add_child(this.label);
|
2012-01-05 13:00:06 -05:00
|
|
|
this.actor.label_actor = this.label;
|
2013-06-06 14:17:41 -04:00
|
|
|
|
2013-07-15 20:00:41 -04:00
|
|
|
let expander = new St.Bin({ style_class: 'popup-menu-item-expander' });
|
|
|
|
this.actor.add(expander, { expand: true });
|
|
|
|
|
2013-09-18 17:36:09 -04:00
|
|
|
this.status = new St.Label({ style_class: 'popup-status-menu-item',
|
|
|
|
y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER });
|
2013-07-15 20:00:41 -04:00
|
|
|
this.actor.add_child(this.status);
|
2013-06-06 14:17:41 -04:00
|
|
|
|
2013-07-16 16:26:39 -04:00
|
|
|
this._triangle = new St.Label({ text: '\u25B8',
|
|
|
|
style_class: 'popup-submenu-menu-item-triangle' });
|
|
|
|
this._triangle.pivot_point = new Clutter.Point({ x: 0.5, y: 0.6 });
|
|
|
|
|
|
|
|
this._triangleBin = new St.Widget({ y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER });
|
|
|
|
this._triangleBin.add_child(this._triangle);
|
2013-08-19 10:02:22 -04:00
|
|
|
if (this._triangleBin.get_text_direction() == Clutter.TextDirection.RTL)
|
|
|
|
this._triangleBin.set_scale(-1.0, 1.0);
|
|
|
|
|
2013-07-16 16:26:39 -04:00
|
|
|
this.actor.add_child(this._triangleBin);
|
2013-09-13 19:29:21 -04:00
|
|
|
this.actor.add_accessible_state (Atk.StateType.EXPANDABLE);
|
2010-07-03 19:47:31 -04:00
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
this.menu = new PopupSubMenu(this.actor, this._triangle);
|
|
|
|
this.menu.connect('open-state-changed', Lang.bind(this, this._subMenuOpenStateChanged));
|
2010-07-03 19:47:31 -04:00
|
|
|
},
|
|
|
|
|
2013-07-15 18:47:16 -04:00
|
|
|
_setParent: function(parent) {
|
|
|
|
this.parent(parent);
|
|
|
|
this.menu._setParent(parent);
|
|
|
|
},
|
|
|
|
|
2013-06-12 03:35:28 -04:00
|
|
|
syncSensitive: function() {
|
|
|
|
let sensitive = this.parent();
|
|
|
|
this._triangle.visible = sensitive;
|
|
|
|
if (!sensitive)
|
|
|
|
this.menu.close(false);
|
|
|
|
},
|
|
|
|
|
2010-07-03 19:47:31 -04:00
|
|
|
_subMenuOpenStateChanged: function(menu, open) {
|
2013-07-15 19:38:05 -04:00
|
|
|
if (open) {
|
2010-11-01 11:03:28 -04:00
|
|
|
this.actor.add_style_pseudo_class('open');
|
2013-07-15 19:38:05 -04:00
|
|
|
this._getTopMenu()._setOpenedSubMenu(this.menu);
|
2013-09-13 19:29:21 -04:00
|
|
|
this.actor.add_accessible_state (Atk.StateType.EXPANDED);
|
2013-07-15 19:38:05 -04:00
|
|
|
} else {
|
2010-11-01 11:03:28 -04:00
|
|
|
this.actor.remove_style_pseudo_class('open');
|
2013-07-15 19:38:05 -04:00
|
|
|
this._getTopMenu()._setOpenedSubMenu(null);
|
2013-09-13 19:29:21 -04:00
|
|
|
this.actor.remove_accessible_state (Atk.StateType.EXPANDED);
|
2013-07-15 19:38:05 -04:00
|
|
|
}
|
2010-07-03 19:47:31 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
2010-11-01 11:03:28 -04:00
|
|
|
this.menu.destroy();
|
2011-11-20 08:10:48 -05:00
|
|
|
|
|
|
|
this.parent();
|
2010-07-03 19:47:31 -04:00
|
|
|
},
|
|
|
|
|
2013-05-10 14:32:58 -04:00
|
|
|
setSubmenuShown: function(open) {
|
|
|
|
if (open)
|
|
|
|
this.menu.open(BoxPointer.PopupAnimation.FULL);
|
|
|
|
else
|
|
|
|
this.menu.close(BoxPointer.PopupAnimation.FULL);
|
|
|
|
},
|
|
|
|
|
|
|
|
_setOpenState: function(open) {
|
2013-05-14 13:58:10 -04:00
|
|
|
this.setSubmenuShown(open);
|
2013-05-10 14:32:58 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_getOpenState: function() {
|
|
|
|
return this.menu.isOpen;
|
|
|
|
},
|
|
|
|
|
2010-10-07 14:15:51 -04:00
|
|
|
_onKeyPressEvent: function(actor, event) {
|
2011-02-08 14:53:43 -05:00
|
|
|
let symbol = event.get_key_symbol();
|
|
|
|
|
|
|
|
if (symbol == Clutter.KEY_Right) {
|
2013-05-10 14:32:58 -04:00
|
|
|
this._setOpenState(true);
|
2011-02-08 14:53:43 -05:00
|
|
|
this.menu.actor.navigate_focus(null, Gtk.DirectionType.DOWN, false);
|
|
|
|
return true;
|
2013-05-10 14:32:58 -04:00
|
|
|
} else if (symbol == Clutter.KEY_Left && this._getOpenState()) {
|
|
|
|
this._setOpenState(false);
|
2010-07-03 19:47:31 -04:00
|
|
|
return true;
|
|
|
|
}
|
2011-02-08 14:53:43 -05:00
|
|
|
|
2011-11-20 08:10:48 -05:00
|
|
|
return this.parent(actor, event);
|
2010-07-03 19:47:31 -04:00
|
|
|
},
|
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
activate: function(event) {
|
2013-05-10 14:32:58 -04:00
|
|
|
this._setOpenState(true);
|
2010-07-03 19:47:31 -04:00
|
|
|
},
|
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
_onButtonReleaseEvent: function(actor) {
|
2013-05-10 14:32:58 -04:00
|
|
|
this._setOpenState(!this._getOpenState());
|
2010-07-03 19:47:31 -04:00
|
|
|
}
|
2011-11-20 08:10:48 -05:00
|
|
|
});
|
2011-07-20 23:17:05 -04:00
|
|
|
|
2010-05-20 11:18:46 -04:00
|
|
|
/* Basic implementation of a menu manager.
|
|
|
|
* Call addMenu to add menus
|
|
|
|
*/
|
2011-11-20 08:10:48 -05:00
|
|
|
const PopupMenuManager = new Lang.Class({
|
|
|
|
Name: 'PopupMenuManager',
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2013-04-26 09:46:49 -04:00
|
|
|
_init: function(owner, grabParams) {
|
2010-05-20 11:18:46 -04:00
|
|
|
this._owner = owner;
|
2013-04-26 09:46:49 -04:00
|
|
|
this._grabHelper = new GrabHelper.GrabHelper(owner.actor, grabParams);
|
2010-05-20 11:18:46 -04:00
|
|
|
this._menus = [];
|
|
|
|
},
|
|
|
|
|
2010-10-07 14:15:51 -04:00
|
|
|
addMenu: function(menu, position) {
|
2012-09-01 08:42:53 -04:00
|
|
|
if (this._findMenu(menu) > -1)
|
|
|
|
return;
|
|
|
|
|
2010-06-25 08:55:03 -04:00
|
|
|
let menudata = {
|
|
|
|
menu: menu,
|
|
|
|
openStateChangeId: menu.connect('open-state-changed', Lang.bind(this, this._onMenuOpenState)),
|
2010-09-29 12:12:38 -04:00
|
|
|
destroyId: menu.connect('destroy', Lang.bind(this, this._onMenuDestroy)),
|
2010-06-25 08:55:03 -04:00
|
|
|
enterId: 0,
|
2011-02-08 14:53:43 -05:00
|
|
|
focusInId: 0
|
2010-06-25 08:55:03 -04:00
|
|
|
};
|
2010-05-20 11:18:46 -04:00
|
|
|
|
|
|
|
let source = menu.sourceActor;
|
|
|
|
if (source) {
|
2012-02-29 19:09:41 -05:00
|
|
|
if (!menu.blockSourceEvents)
|
|
|
|
this._grabHelper.addActor(source);
|
2010-10-07 14:15:51 -04:00
|
|
|
menudata.enterId = source.connect('enter-event', Lang.bind(this, function() { this._onMenuSourceEnter(menu); }));
|
2010-11-03 13:30:08 -04:00
|
|
|
menudata.focusInId = source.connect('key-focus-in', Lang.bind(this, function() { this._onMenuSourceEnter(menu); }));
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
2010-06-25 08:55:03 -04:00
|
|
|
|
|
|
|
if (position == undefined)
|
|
|
|
this._menus.push(menudata);
|
|
|
|
else
|
|
|
|
this._menus.splice(position, 0, menudata);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeMenu: function(menu) {
|
2013-03-14 11:48:19 -04:00
|
|
|
if (menu == this.activeMenu)
|
2012-02-29 19:09:41 -05:00
|
|
|
this._closeMenu(menu);
|
2010-07-03 19:47:31 -04:00
|
|
|
|
2010-06-25 08:55:03 -04:00
|
|
|
let position = this._findMenu(menu);
|
|
|
|
if (position == -1) // not a menu we manage
|
|
|
|
return;
|
|
|
|
|
|
|
|
let menudata = this._menus[position];
|
|
|
|
menu.disconnect(menudata.openStateChangeId);
|
2010-07-03 19:47:31 -04:00
|
|
|
menu.disconnect(menudata.destroyId);
|
2010-06-25 08:55:03 -04:00
|
|
|
|
|
|
|
if (menudata.enterId)
|
|
|
|
menu.sourceActor.disconnect(menudata.enterId);
|
2010-11-03 13:30:08 -04:00
|
|
|
if (menudata.focusInId)
|
|
|
|
menu.sourceActor.disconnect(menudata.focusInId);
|
2010-06-25 08:55:03 -04:00
|
|
|
|
2012-02-29 19:09:41 -05:00
|
|
|
if (menu.sourceActor)
|
|
|
|
this._grabHelper.removeActor(menu.sourceActor);
|
2010-06-25 08:55:03 -04:00
|
|
|
this._menus.splice(position, 1);
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
2012-02-29 19:09:41 -05:00
|
|
|
get activeMenu() {
|
2013-03-14 11:51:10 -04:00
|
|
|
let firstGrab = this._grabHelper.grabStack[0];
|
|
|
|
if (firstGrab)
|
|
|
|
return firstGrab.actor._delegate;
|
2012-02-29 19:09:41 -05:00
|
|
|
else
|
|
|
|
return null;
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
2012-02-29 19:09:41 -05:00
|
|
|
ignoreRelease: function() {
|
|
|
|
return this._grabHelper.ignoreRelease();
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_onMenuOpenState: function(menu, open) {
|
2011-07-12 15:47:37 -04:00
|
|
|
if (open) {
|
2013-04-23 17:46:33 -04:00
|
|
|
if (this.activeMenu)
|
2013-04-26 11:06:22 -04:00
|
|
|
this.activeMenu.close(BoxPointer.PopupAnimation.FADE);
|
2013-05-23 17:20:30 -04:00
|
|
|
this._grabHelper.grab({ actor: menu.actor, focus: menu.sourceActor,
|
2012-02-29 19:09:41 -05:00
|
|
|
onUngrab: Lang.bind(this, this._closeMenu, menu) });
|
2011-07-12 15:47:37 -04:00
|
|
|
} else {
|
2012-02-29 19:09:41 -05:00
|
|
|
this._grabHelper.ungrab({ actor: menu.actor });
|
2010-11-03 13:30:08 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_changeMenu: function(newMenu) {
|
2013-04-26 11:06:22 -04:00
|
|
|
newMenu.open(this.activeMenu ? BoxPointer.PopupAnimation.FADE
|
|
|
|
: BoxPointer.PopupAnimation.FULL);
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
2010-10-07 14:15:51 -04:00
|
|
|
_onMenuSourceEnter: function(menu) {
|
2012-02-29 19:09:41 -05:00
|
|
|
if (!this._grabHelper.grabbed)
|
2010-05-20 11:18:46 -04:00
|
|
|
return false;
|
|
|
|
|
2012-02-29 19:09:41 -05:00
|
|
|
if (this._grabHelper.isActorGrabbed(menu.actor))
|
2011-07-12 15:47:37 -04:00
|
|
|
return false;
|
|
|
|
|
2010-11-03 13:30:08 -04:00
|
|
|
this._changeMenu(menu);
|
2010-05-20 11:18:46 -04:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2010-07-03 19:47:31 -04:00
|
|
|
_onMenuDestroy: function(menu) {
|
|
|
|
this.removeMenu(menu);
|
|
|
|
},
|
|
|
|
|
2010-06-25 08:55:03 -04:00
|
|
|
_findMenu: function(item) {
|
|
|
|
for (let i = 0; i < this._menus.length; i++) {
|
|
|
|
let menudata = this._menus[i];
|
|
|
|
if (item == menudata.menu)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
},
|
|
|
|
|
2012-12-10 03:55:14 -05:00
|
|
|
_closeMenu: function(isUser, menu) {
|
|
|
|
// If this isn't a user action, we called close()
|
|
|
|
// on the BoxPointer ourselves, so we shouldn't
|
|
|
|
// reanimate.
|
|
|
|
if (isUser)
|
|
|
|
menu.close(BoxPointer.PopupAnimation.FULL);
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
2011-11-20 08:10:48 -05:00
|
|
|
});
|