2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-05-20 15:18:46 +00:00
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Gtk = imports.gi.Gtk;
|
2017-05-08 10:36:35 +00:00
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GObject = imports.gi.GObject;
|
2010-05-20 15:18:46 +00:00
|
|
|
const Lang = imports.lang;
|
2010-07-22 12:34:02 +00:00
|
|
|
const Shell = imports.gi.Shell;
|
2010-05-20 15:18:46 +00:00
|
|
|
const Signals = imports.signals;
|
2010-07-22 12:34:02 +00:00
|
|
|
const St = imports.gi.St;
|
2012-02-27 16:31:10 +00:00
|
|
|
const Atk = imports.gi.Atk;
|
2010-05-20 15:18:46 +00:00
|
|
|
|
|
|
|
const BoxPointer = imports.ui.boxpointer;
|
2012-03-01 00:09:41 +00:00
|
|
|
const GrabHelper = imports.ui.grabHelper;
|
2010-07-03 23:47:31 +00:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
const Params = imports.misc.params;
|
2010-05-20 15:18:46 +00:00
|
|
|
const Tweener = imports.ui.tweener;
|
|
|
|
|
2017-07-18 17:47:27 +00:00
|
|
|
var Ornament = {
|
2013-04-20 00:57:38 +00:00
|
|
|
NONE: 0,
|
|
|
|
DOT: 1,
|
2013-04-20 01:13:37 +00:00
|
|
|
CHECK: 2,
|
2013-04-20 00:57:38 +00:00
|
|
|
};
|
|
|
|
|
2013-08-28 14:50:07 +00:00
|
|
|
function isPopupMenuItemVisible(child) {
|
|
|
|
if (child._delegate instanceof PopupMenuSection)
|
|
|
|
if (child._delegate.isEmpty())
|
|
|
|
return false;
|
|
|
|
return child.visible;
|
|
|
|
}
|
|
|
|
|
2013-10-07 14:01:07 +00:00
|
|
|
/**
|
|
|
|
* @side Side to which the arrow points.
|
|
|
|
*/
|
2014-02-18 12:45:26 +00:00
|
|
|
function arrowIcon(side) {
|
2014-06-24 17:43:35 +00:00
|
|
|
let iconName;
|
2013-10-07 14:01:07 +00:00
|
|
|
switch (side) {
|
|
|
|
case St.Side.TOP:
|
2014-06-24 17:43:35 +00:00
|
|
|
iconName = 'pan-up-symbolic';
|
2013-10-07 14:01:07 +00:00
|
|
|
break;
|
|
|
|
case St.Side.RIGHT:
|
2014-06-24 17:43:35 +00:00
|
|
|
iconName = 'pan-end-symbolic';
|
2013-10-07 14:01:07 +00:00
|
|
|
break;
|
|
|
|
case St.Side.BOTTOM:
|
2014-06-24 17:43:35 +00:00
|
|
|
iconName = 'pan-down-symbolic';
|
2013-10-07 14:01:07 +00:00
|
|
|
break;
|
|
|
|
case St.Side.LEFT:
|
2014-06-24 17:43:35 +00:00
|
|
|
iconName = 'pan-start-symbolic';
|
2013-10-07 14:01:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-02-18 12:45:26 +00:00
|
|
|
let arrow = new St.Icon({ style_class: 'popup-menu-arrow',
|
2014-06-24 18:36:59 +00:00
|
|
|
icon_name: iconName,
|
2014-02-18 12:45:26 +00:00
|
|
|
accessible_role: Atk.Role.ARROW,
|
|
|
|
y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER });
|
|
|
|
|
|
|
|
return arrow;
|
2013-10-07 14:01:07 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 17:41:25 +00:00
|
|
|
var PopupBaseMenuItem = new Lang.Class({
|
2011-11-20 13:10:48 +00:00
|
|
|
Name: 'PopupBaseMenuItem',
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(params) {
|
2010-07-03 23:47:31 +00:00
|
|
|
params = Params.parse (params, { reactive: true,
|
|
|
|
activate: true,
|
2011-01-25 21:06:40 +00:00
|
|
|
hover: true,
|
2012-08-17 09:03:23 +00:00
|
|
|
style_class: null,
|
|
|
|
can_focus: true
|
2011-01-25 21:06:40 +00:00
|
|
|
});
|
2013-07-16 00:00:41 +00: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 15:18:46 +00:00
|
|
|
this.actor._delegate = this;
|
2010-10-19 17:41:41 +00:00
|
|
|
|
2013-04-20 00:57:38 +00:00
|
|
|
this._ornament = Ornament.NONE;
|
2013-04-20 01:08:35 +00:00
|
|
|
this._ornamentLabel = new St.Label({ style_class: 'popup-menu-ornament' });
|
2013-07-16 00:00:41 +00:00
|
|
|
this.actor.add(this._ornamentLabel);
|
|
|
|
|
|
|
|
this._parent = null;
|
2010-05-20 15:18:46 +00:00
|
|
|
this.active = false;
|
2011-09-15 14:51:19 +00:00
|
|
|
this._activatable = params.reactive && params.activate;
|
2013-06-12 07:16:53 +00:00
|
|
|
this._sensitive = true;
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2012-09-11 12:00:22 +00:00
|
|
|
if (!this._activatable)
|
|
|
|
this.actor.add_style_class_name('popup-inactive-menu-item');
|
|
|
|
|
2011-01-25 21:06:40 +00:00
|
|
|
if (params.style_class)
|
|
|
|
this.actor.add_style_class_name(params.style_class);
|
|
|
|
|
2011-09-15 14:51:19 +00:00
|
|
|
if (this._activatable) {
|
2017-12-02 00:27:35 +00:00
|
|
|
this.actor.connect('button-press-event', this._onButtonPressEvent.bind(this));
|
|
|
|
this.actor.connect('button-release-event', this._onButtonReleaseEvent.bind(this));
|
|
|
|
this.actor.connect('touch-event', this._onTouchEvent.bind(this));
|
|
|
|
this.actor.connect('key-press-event', this._onKeyPressEvent.bind(this));
|
2010-05-20 15:18:46 +00:00
|
|
|
}
|
2010-07-03 23:47:31 +00:00
|
|
|
if (params.reactive && params.hover)
|
2017-12-02 00:27:35 +00:00
|
|
|
this.actor.connect('notify::hover', this._onHoverChanged.bind(this));
|
2012-08-17 09:03:23 +00:00
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
this.actor.connect('key-focus-in', this._onKeyFocusIn.bind(this));
|
|
|
|
this.actor.connect('key-focus-out', this._onKeyFocusOut.bind(this));
|
|
|
|
this.actor.connect('destroy', this._onDestroy.bind(this));
|
2010-05-20 15:18:46 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getTopMenu() {
|
2013-07-15 22:47:16 +00:00
|
|
|
if (this._parent)
|
|
|
|
return this._parent._getTopMenu();
|
|
|
|
else
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_setParent(parent) {
|
2013-07-15 22:47:16 +00:00
|
|
|
this._parent = parent;
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onButtonPressEvent(actor, event) {
|
2015-02-18 16:07:59 +00:00
|
|
|
// This is the CSS active state
|
|
|
|
this.actor.add_style_pseudo_class ('active');
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onButtonReleaseEvent(actor, event) {
|
2015-02-18 16:07:59 +00:00
|
|
|
this.actor.remove_style_pseudo_class ('active');
|
2010-11-01 15:03:28 +00:00
|
|
|
this.activate(event);
|
2013-11-29 18:17:34 +00:00
|
|
|
return Clutter.EVENT_STOP;
|
2010-10-07 18:15:51 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onTouchEvent(actor, event) {
|
2014-07-22 10:27:05 +00:00
|
|
|
if (event.type() == Clutter.EventType.TOUCH_END) {
|
2015-02-18 16:07:59 +00:00
|
|
|
this.actor.remove_style_pseudo_class ('active');
|
2014-07-22 10:27:05 +00:00
|
|
|
this.activate(event);
|
|
|
|
return Clutter.EVENT_STOP;
|
2015-02-18 16:07:59 +00:00
|
|
|
} else if (event.type() == Clutter.EventType.TOUCH_BEGIN) {
|
|
|
|
// This is the CSS active state
|
|
|
|
this.actor.add_style_pseudo_class ('active');
|
2014-07-22 10:27:05 +00:00
|
|
|
}
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onKeyPressEvent(actor, event) {
|
2010-10-07 18:15:51 +00:00
|
|
|
let symbol = event.get_key_symbol();
|
|
|
|
|
|
|
|
if (symbol == Clutter.KEY_space || symbol == Clutter.KEY_Return) {
|
2010-11-01 15:03:28 +00:00
|
|
|
this.activate(event);
|
2013-11-29 18:17:34 +00:00
|
|
|
return Clutter.EVENT_STOP;
|
2010-10-07 18:15:51 +00:00
|
|
|
}
|
2013-11-29 18:17:34 +00:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2010-10-07 18:15:51 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onKeyFocusIn(actor) {
|
2010-10-07 18:15:51 +00:00
|
|
|
this.setActive(true);
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onKeyFocusOut(actor) {
|
2011-02-11 19:43:01 +00:00
|
|
|
this.setActive(false);
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onHoverChanged(actor) {
|
2010-05-20 15:18:46 +00:00
|
|
|
this.setActive(actor.hover);
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
activate(event) {
|
2010-05-20 15:18:46 +00:00
|
|
|
this.emit('activate', event);
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setActive(active) {
|
2010-05-20 15:18:46 +00:00
|
|
|
let activeChanged = active != this.active;
|
|
|
|
if (activeChanged) {
|
|
|
|
this.active = active;
|
2010-10-07 18:15:51 +00:00
|
|
|
if (active) {
|
2015-03-16 15:52:53 +00:00
|
|
|
this.actor.add_style_class_name('selected');
|
2013-04-23 21:46:33 +00:00
|
|
|
this.actor.grab_key_focus();
|
|
|
|
} else {
|
2015-03-16 15:52:53 +00:00
|
|
|
this.actor.remove_style_class_name('selected');
|
2015-02-18 16:07:59 +00:00
|
|
|
// Remove the CSS active state if the user press the button and
|
|
|
|
// while holding moves to another menu item, so we don't paint all items.
|
|
|
|
// The correct behaviour would be to set the new item with the CSS
|
|
|
|
// active state as well, but button-press-event is not trigered,
|
|
|
|
// so we should track it in our own, which would involve some work
|
|
|
|
// in the container
|
|
|
|
this.actor.remove_style_pseudo_class ('active');
|
2013-04-23 21:46:33 +00:00
|
|
|
}
|
2010-05-20 15:18:46 +00:00
|
|
|
this.emit('active-changed', active);
|
|
|
|
}
|
2010-07-03 23:47:31 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
syncSensitive() {
|
2013-06-12 07:16:53 +00:00
|
|
|
let sensitive = this.getSensitive();
|
2011-09-15 14:51:19 +00:00
|
|
|
this.actor.reactive = sensitive;
|
2012-08-20 01:40:09 +00:00
|
|
|
this.actor.can_focus = sensitive;
|
2013-06-12 07:16:53 +00:00
|
|
|
this.emit('sensitive-changed');
|
|
|
|
return sensitive;
|
|
|
|
},
|
2011-09-15 14:51:19 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
getSensitive() {
|
2013-07-15 22:54:15 +00:00
|
|
|
let parentSensitive = this._parent ? this._parent.getSensitive() : true;
|
|
|
|
return this._activatable && this._sensitive && parentSensitive;
|
2013-06-12 07:16:53 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setSensitive(sensitive) {
|
2013-06-12 07:16:53 +00:00
|
|
|
if (this._sensitive == sensitive)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._sensitive = sensitive;
|
|
|
|
this.syncSensitive();
|
2011-09-15 14:51:19 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
destroy() {
|
2010-07-03 23:47:31 +00:00
|
|
|
this.actor.destroy();
|
2014-02-14 23:32:45 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onDestroy() {
|
2010-07-03 23:47:31 +00:00
|
|
|
this.emit('destroy');
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setOrnament(ornament) {
|
2013-04-20 00:57:38 +00:00
|
|
|
if (ornament == this._ornament)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._ornament = ornament;
|
2010-10-20 16:43:22 +00:00
|
|
|
|
2013-04-20 00:57:38 +00:00
|
|
|
if (ornament == Ornament.DOT) {
|
2013-04-20 01:08:35 +00:00
|
|
|
this._ornamentLabel.text = '\u2022';
|
|
|
|
this.actor.add_accessible_state(Atk.StateType.CHECKED);
|
2013-04-20 01:13:37 +00:00
|
|
|
} else if (ornament == Ornament.CHECK) {
|
|
|
|
this._ornamentLabel.text = '\u2713';
|
|
|
|
this.actor.add_accessible_state(Atk.StateType.CHECKED);
|
2013-04-20 01:08:35 +00:00
|
|
|
} else if (ornament == Ornament.NONE) {
|
|
|
|
this._ornamentLabel.text = '';
|
|
|
|
this.actor.remove_accessible_state(Atk.StateType.CHECKED);
|
2010-10-20 16:43:22 +00:00
|
|
|
}
|
2010-05-20 15:18:46 +00:00
|
|
|
}
|
2011-11-20 13:10:48 +00:00
|
|
|
});
|
2010-05-20 15:18:46 +00:00
|
|
|
Signals.addSignalMethods(PopupBaseMenuItem.prototype);
|
|
|
|
|
2017-07-18 17:41:25 +00:00
|
|
|
var PopupMenuItem = new Lang.Class({
|
2011-11-20 13:10:48 +00:00
|
|
|
Name: 'PopupMenuItem',
|
|
|
|
Extends: PopupBaseMenuItem,
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(text, params) {
|
2011-11-20 13:10:48 +00:00
|
|
|
this.parent(params);
|
2010-05-20 15:18:46 +00:00
|
|
|
|
|
|
|
this.label = new St.Label({ text: text });
|
2013-07-16 00:00:41 +00:00
|
|
|
this.actor.add_child(this.label);
|
2012-01-05 18:00:06 +00:00
|
|
|
this.actor.label_actor = this.label
|
2010-05-20 15:18:46 +00:00
|
|
|
}
|
2011-11-20 13:10:48 +00:00
|
|
|
});
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2017-07-18 17:41:25 +00:00
|
|
|
var PopupSeparatorMenuItem = new Lang.Class({
|
2011-11-20 13:10:48 +00:00
|
|
|
Name: 'PopupSeparatorMenuItem',
|
|
|
|
Extends: PopupBaseMenuItem,
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(text) {
|
2012-08-17 09:03:23 +00:00
|
|
|
this.parent({ reactive: false,
|
|
|
|
can_focus: false});
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2013-04-24 20:21:57 +00:00
|
|
|
this.label = new St.Label({ text: text || '' });
|
2013-07-16 00:00:41 +00:00
|
|
|
this.actor.add(this.label);
|
2013-04-24 20:21:57 +00:00
|
|
|
this.actor.label_actor = this.label;
|
|
|
|
|
2014-05-25 14:38:05 +00:00
|
|
|
this.label.connect('notify::text',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._syncVisibility.bind(this));
|
2014-05-25 14:38:05 +00:00
|
|
|
this._syncVisibility();
|
|
|
|
|
2015-03-06 17:57:19 +00:00
|
|
|
this._separator = new St.Widget({ style_class: 'popup-separator-menu-item',
|
|
|
|
y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER });
|
2015-02-20 09:35:30 +00:00
|
|
|
this.actor.add(this._separator, { expand: true });
|
2014-05-25 14:38:05 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_syncVisibility() {
|
2014-05-25 14:38:05 +00:00
|
|
|
this.label.visible = this.label.text != '';
|
2010-05-20 15:18:46 +00:00
|
|
|
}
|
2011-11-20 13:10:48 +00:00
|
|
|
});
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2017-07-18 17:41:25 +00:00
|
|
|
var Switch = new Lang.Class({
|
2011-11-20 13:10:48 +00:00
|
|
|
Name: 'Switch',
|
2010-07-22 12:34:02 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(state) {
|
2012-02-27 16:31:10 +00:00
|
|
|
this.actor = new St.Bin({ style_class: 'toggle-switch',
|
2012-08-20 01:40:09 +00:00
|
|
|
accessible_role: Atk.Role.CHECK_BOX,
|
|
|
|
can_focus: true });
|
2011-02-08 19:19:04 +00: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);
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setToggleState(state) {
|
2011-02-08 19:19:04 +00:00
|
|
|
if (state)
|
|
|
|
this.actor.add_style_pseudo_class('checked');
|
|
|
|
else
|
|
|
|
this.actor.remove_style_pseudo_class('checked');
|
|
|
|
this.state = state;
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
toggle() {
|
2011-02-08 19:19:04 +00:00
|
|
|
this.setToggleState(!this.state);
|
|
|
|
}
|
2011-11-20 13:10:48 +00:00
|
|
|
});
|
2010-06-17 12:17:01 +00:00
|
|
|
|
2017-07-18 17:41:25 +00:00
|
|
|
var PopupSwitchMenuItem = new Lang.Class({
|
2011-11-20 13:10:48 +00:00
|
|
|
Name: 'PopupSwitchMenuItem',
|
|
|
|
Extends: PopupBaseMenuItem,
|
2010-06-17 12:17:01 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(text, active, params) {
|
2011-11-20 13:10:48 +00:00
|
|
|
this.parent(params);
|
2010-06-17 12:17:01 +00:00
|
|
|
|
|
|
|
this.label = new St.Label({ text: text });
|
2010-10-13 18:10:38 +00:00
|
|
|
this._switch = new Switch(active);
|
2010-06-17 12:17:01 +00:00
|
|
|
|
2012-02-27 16:31:10 +00:00
|
|
|
this.actor.accessible_role = Atk.Role.CHECK_MENU_ITEM;
|
2012-01-20 17:10:45 +00:00
|
|
|
this.checkAccessibleState();
|
2012-02-27 16:31:10 +00:00
|
|
|
this.actor.label_actor = this.label;
|
|
|
|
|
2013-07-16 00:00:41 +00:00
|
|
|
this.actor.add_child(this.label);
|
2010-06-17 12:17:01 +00:00
|
|
|
|
2011-04-21 14:44:28 +00:00
|
|
|
this._statusBin = new St.Bin({ x_align: St.Align.END });
|
2013-07-16 00:00:41 +00:00
|
|
|
this.actor.add(this._statusBin, { expand: true, x_align: St.Align.END });
|
2011-04-21 14:44:28 +00:00
|
|
|
|
|
|
|
this._statusLabel = new St.Label({ text: '',
|
2012-09-11 12:00:22 +00:00
|
|
|
style_class: 'popup-status-menu-item'
|
2011-04-21 14:44:28 +00:00
|
|
|
});
|
|
|
|
this._statusBin.child = this._switch.actor;
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setStatus(text) {
|
2011-04-21 14:44:28 +00:00
|
|
|
if (text != null) {
|
|
|
|
this._statusLabel.text = text;
|
|
|
|
this._statusBin.child = this._statusLabel;
|
|
|
|
this.actor.reactive = false;
|
2012-02-27 16:31:10 +00:00
|
|
|
this.actor.accessible_role = Atk.Role.MENU_ITEM;
|
2011-04-21 14:44:28 +00:00
|
|
|
} else {
|
|
|
|
this._statusBin.child = this._switch.actor;
|
|
|
|
this.actor.reactive = true;
|
2012-02-27 16:31:10 +00:00
|
|
|
this.actor.accessible_role = Atk.Role.CHECK_MENU_ITEM;
|
2011-04-21 14:44:28 +00:00
|
|
|
}
|
2012-01-20 17:10:45 +00:00
|
|
|
this.checkAccessibleState();
|
2011-04-21 14:44:28 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
activate(event) {
|
2011-04-21 14:44:28 +00:00
|
|
|
if (this._switch.actor.mapped) {
|
2010-06-17 12:17:01 +00:00
|
|
|
this.toggle();
|
2011-04-21 14:44:28 +00:00
|
|
|
}
|
|
|
|
|
2011-11-21 13:16:51 +00: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 17:56:27 +00:00
|
|
|
this.parent(event);
|
2010-06-17 12:17:01 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
toggle() {
|
2010-06-17 12:17:01 +00:00
|
|
|
this._switch.toggle();
|
|
|
|
this.emit('toggled', this._switch.state);
|
2012-01-20 17:10:45 +00:00
|
|
|
this.checkAccessibleState();
|
2010-06-17 12:17:01 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get state() {
|
|
|
|
return this._switch.state;
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setToggleState(state) {
|
2010-06-17 12:17:01 +00:00
|
|
|
this._switch.setToggleState(state);
|
2012-01-20 17:10:45 +00:00
|
|
|
this.checkAccessibleState();
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
checkAccessibleState() {
|
2012-01-20 17:10:45 +00:00
|
|
|
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 12:17:01 +00:00
|
|
|
}
|
2011-11-20 13:10:48 +00:00
|
|
|
});
|
2010-06-17 12:17:01 +00:00
|
|
|
|
2017-07-18 17:41:25 +00:00
|
|
|
var PopupImageMenuItem = new Lang.Class({
|
2011-11-20 13:10:48 +00:00
|
|
|
Name: 'PopupImageMenuItem',
|
|
|
|
Extends: PopupBaseMenuItem,
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(text, icon, params) {
|
2011-11-20 13:10:48 +00:00
|
|
|
this.parent(params);
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2010-11-02 22:33:22 +00:00
|
|
|
this._icon = new St.Icon({ style_class: 'popup-menu-icon' });
|
2014-07-23 08:24:18 +00:00
|
|
|
this.actor.add_child(this._icon, { align: St.Align.END });
|
2017-05-04 17:09:39 +00:00
|
|
|
this.label = new St.Label({ text: text });
|
|
|
|
this.actor.add_child(this.label);
|
2015-09-23 12:16:31 +00:00
|
|
|
this.actor.label_actor = this.label;
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2017-05-08 10:36:35 +00:00
|
|
|
this.setIcon(icon);
|
2010-05-20 15:18:46 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setIcon(icon) {
|
2017-05-08 10:36:35 +00:00
|
|
|
// The 'icon' parameter can be either a Gio.Icon or a string.
|
2017-10-15 22:09:52 +00:00
|
|
|
if (icon instanceof GObject.Object && GObject.type_is_a(icon, Gio.Icon))
|
2017-05-08 10:36:35 +00:00
|
|
|
this._icon.gicon = icon;
|
|
|
|
else
|
|
|
|
this._icon.icon_name = icon;
|
2010-05-20 15:18:46 +00:00
|
|
|
}
|
2011-11-20 13:10:48 +00:00
|
|
|
});
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2017-07-18 17:41:25 +00:00
|
|
|
var PopupMenuBase = new Lang.Class({
|
2011-11-20 13:10:48 +00:00
|
|
|
Name: 'PopupMenuBase',
|
|
|
|
Abstract: true,
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(sourceActor, styleClass) {
|
2010-05-20 15:18:46 +00:00
|
|
|
this.sourceActor = sourceActor;
|
2013-07-08 19:19:34 +00:00
|
|
|
this._parent = null;
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2011-01-25 21:06:40 +00: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 19:27:03 +00:00
|
|
|
this.length = 0;
|
2010-10-07 18:15:51 +00:00
|
|
|
|
2010-05-20 15:18:46 +00:00
|
|
|
this.isOpen = false;
|
2011-03-22 14:29:32 +00: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 15:18:46 +00:00
|
|
|
this._activeMenuItem = null;
|
2012-05-22 22:27:06 +00:00
|
|
|
this._settingsActions = { };
|
2012-09-01 12:42:53 +00:00
|
|
|
|
2013-06-12 07:16:53 +00:00
|
|
|
this._sensitive = true;
|
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
this._sessionUpdatedId = Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
|
2012-09-01 12:42:53 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getTopMenu() {
|
2013-07-08 19:19:34 +00:00
|
|
|
if (this._parent)
|
|
|
|
return this._parent._getTopMenu();
|
|
|
|
else
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_setParent(parent) {
|
2013-07-15 22:47:16 +00:00
|
|
|
this._parent = parent;
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
getSensitive() {
|
2013-07-15 22:54:15 +00:00
|
|
|
let parentSensitive = this._parent ? this._parent.getSensitive() : true;
|
|
|
|
return this._sensitive && parentSensitive;
|
2013-06-12 07:16:53 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setSensitive(sensitive) {
|
2013-06-12 07:16:53 +00:00
|
|
|
this._sensitive = sensitive;
|
|
|
|
this.emit('sensitive-changed');
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sessionUpdated() {
|
2012-09-01 12:42:53 +00:00
|
|
|
this._setSettingsVisibility(Main.sessionMode.allowSettings);
|
2017-09-14 15:12:12 +00:00
|
|
|
this.close();
|
2010-05-20 15:18:46 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
addAction(title, callback, icon) {
|
2017-05-08 10:38:16 +00:00
|
|
|
let menuItem;
|
|
|
|
if (icon != undefined)
|
|
|
|
menuItem = new PopupImageMenuItem(title, icon);
|
|
|
|
else
|
|
|
|
menuItem = new PopupMenuItem(title);
|
|
|
|
|
2010-05-20 15:18:46 +00:00
|
|
|
this.addMenuItem(menuItem);
|
2017-10-31 00:38:18 +00:00
|
|
|
menuItem.connect('activate', (menuItem, event) => {
|
2010-05-20 15:18:46 +00:00
|
|
|
callback(event);
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2011-08-23 14:14:55 +00:00
|
|
|
|
|
|
|
return menuItem;
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
addSettingsAction(title, desktopFile) {
|
2017-10-31 00:38:18 +00:00
|
|
|
let menuItem = this.addAction(title, () => {
|
|
|
|
let app = Shell.AppSystem.get_default().lookup_app(desktopFile);
|
2011-08-23 14:14:55 +00:00
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
if (!app) {
|
|
|
|
log('Settings panel for desktop file ' + desktopFile + ' could not be loaded!');
|
|
|
|
return;
|
|
|
|
}
|
2011-08-23 14:14:55 +00:00
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
Main.overview.hide();
|
|
|
|
app.activate();
|
|
|
|
});
|
2012-05-22 22:27:06 +00:00
|
|
|
|
2012-09-20 13:58:08 +00:00
|
|
|
menuItem.actor.visible = Main.sessionMode.allowSettings;
|
2012-05-22 22:27:06 +00:00
|
|
|
this._settingsActions[desktopFile] = menuItem;
|
|
|
|
|
2011-08-23 14:14:55 +00:00
|
|
|
return menuItem;
|
2010-05-20 15:18:46 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_setSettingsVisibility(visible) {
|
2012-05-22 22:27:06 +00:00
|
|
|
for (let id in this._settingsActions) {
|
|
|
|
let item = this._settingsActions[id];
|
|
|
|
item.actor.visible = visible;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
isEmpty() {
|
2017-10-31 00:38:18 +00:00
|
|
|
let hasVisibleChildren = this.box.get_children().some(child => {
|
2013-07-15 18:16:30 +00:00
|
|
|
if (child._delegate instanceof PopupSeparatorMenuItem)
|
|
|
|
return false;
|
2013-08-28 14:50:07 +00:00
|
|
|
return isPopupMenuItemVisible(child);
|
2013-02-14 21:48:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return !hasVisibleChildren;
|
2011-11-15 13:58:55 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
itemActivated(animate) {
|
2013-06-18 08:46:44 +00:00
|
|
|
if (animate == undefined)
|
|
|
|
animate = BoxPointer.PopupAnimation.FULL;
|
|
|
|
|
|
|
|
this._getTopMenu().close(animate);
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_subMenuActiveChanged(submenu, submenuItem) {
|
2013-06-11 23:18:06 +00:00
|
|
|
if (this._activeMenuItem && this._activeMenuItem != submenuItem)
|
|
|
|
this._activeMenuItem.setActive(false);
|
|
|
|
this._activeMenuItem = submenuItem;
|
|
|
|
this.emit('active-changed', submenuItem);
|
2011-01-25 21:04:57 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_connectItemSignals(menuItem) {
|
2017-10-31 00:38:18 +00:00
|
|
|
menuItem._activeChangeId = menuItem.connect('active-changed', (menuItem, active) => {
|
2010-05-20 15:18:46 +00:00
|
|
|
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);
|
|
|
|
}
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
|
|
|
menuItem._sensitiveChangeId = menuItem.connect('sensitive-changed', () => {
|
2013-06-12 07:16:53 +00:00
|
|
|
let sensitive = menuItem.getSensitive();
|
2011-09-15 14:51:19 +00: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();
|
|
|
|
}
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
|
|
|
menuItem._activateId = menuItem.connect('activate', (menuItem, event) => {
|
2010-05-20 15:18:46 +00:00
|
|
|
this.emit('activate', menuItem);
|
2013-06-18 08:46:44 +00:00
|
|
|
this.itemActivated(BoxPointer.PopupAnimation.FULL);
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2013-06-12 07:16:53 +00:00
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
menuItem._parentSensitiveChangeId = this.connect('sensitive-changed', () => {
|
2013-06-12 07:16:53 +00:00
|
|
|
menuItem.syncSensitive();
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2013-06-12 07:16:53 +00:00
|
|
|
|
2011-12-12 19:36:00 +00: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)
|
2017-10-31 00:38:18 +00:00
|
|
|
menuItem._popupMenuDestroyId = menuItem.connect('destroy', menuItem => {
|
2011-12-12 19:36:00 +00:00
|
|
|
menuItem.disconnect(menuItem._popupMenuDestroyId);
|
2010-07-03 23:47:31 +00:00
|
|
|
menuItem.disconnect(menuItem._activateId);
|
|
|
|
menuItem.disconnect(menuItem._activeChangeId);
|
2011-09-15 14:51:19 +00:00
|
|
|
menuItem.disconnect(menuItem._sensitiveChangeId);
|
2013-06-12 07:16:53 +00:00
|
|
|
this.disconnect(menuItem._parentSensitiveChangeId);
|
2010-07-03 23:47:31 +00:00
|
|
|
if (menuItem == this._activeMenuItem)
|
|
|
|
this._activeMenuItem = null;
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2010-05-20 15:18:46 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateSeparatorVisibility(menuItem) {
|
2013-04-24 20:21:57 +00:00
|
|
|
if (menuItem.label.text)
|
|
|
|
return;
|
|
|
|
|
2011-08-19 18:42:20 +00:00
|
|
|
let children = this.box.get_children();
|
|
|
|
|
|
|
|
let index = children.indexOf(menuItem.actor);
|
|
|
|
|
|
|
|
if (index < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let childBeforeIndex = index - 1;
|
|
|
|
|
2013-08-28 14:50:07 +00:00
|
|
|
while (childBeforeIndex >= 0 && !isPopupMenuItemVisible(children[childBeforeIndex]))
|
2011-08-19 18:42:20 +00:00
|
|
|
childBeforeIndex--;
|
|
|
|
|
|
|
|
if (childBeforeIndex < 0
|
|
|
|
|| children[childBeforeIndex]._delegate instanceof PopupSeparatorMenuItem) {
|
|
|
|
menuItem.actor.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let childAfterIndex = index + 1;
|
|
|
|
|
2013-08-28 14:50:07 +00:00
|
|
|
while (childAfterIndex < children.length && !isPopupMenuItemVisible(children[childAfterIndex]))
|
2011-08-19 18:42:20 +00:00
|
|
|
childAfterIndex++;
|
|
|
|
|
|
|
|
if (childAfterIndex >= children.length
|
|
|
|
|| children[childAfterIndex]._delegate instanceof PopupSeparatorMenuItem) {
|
|
|
|
menuItem.actor.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
menuItem.actor.show();
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
moveMenuItem(menuItem, position) {
|
2017-02-13 15:02:02 +00:00
|
|
|
let items = this._getMenuItems();
|
|
|
|
let i = 0;
|
|
|
|
|
|
|
|
while (i < items.length && position > 0) {
|
|
|
|
if (items[i] != menuItem)
|
|
|
|
position--;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i < items.length) {
|
|
|
|
if (items[i] != menuItem)
|
|
|
|
this.box.set_child_below_sibling(menuItem.actor, items[i].actor);
|
|
|
|
} else {
|
|
|
|
this.box.set_child_above_sibling(menuItem.actor, null);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
addMenuItem(menuItem, position) {
|
2011-01-25 21:04:57 +00:00
|
|
|
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 20:27:16 +00:00
|
|
|
this.box.insert_child_below(menuItem.actor, before_item);
|
|
|
|
} else {
|
2011-01-25 21:04:57 +00:00
|
|
|
this.box.add(menuItem.actor);
|
2012-02-13 20:27:16 +00:00
|
|
|
}
|
2011-01-25 21:04:57 +00:00
|
|
|
}
|
2012-02-13 20:27:16 +00:00
|
|
|
|
2011-01-25 21:04:57 +00:00
|
|
|
if (menuItem instanceof PopupMenuSection) {
|
2017-12-02 00:27:35 +00:00
|
|
|
let activeChangeId = menuItem.connect('active-changed', this._subMenuActiveChanged.bind(this));
|
2013-06-11 23:18:06 +00:00
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
let parentOpenStateChangedId = this.connect('open-state-changed', (self, open) => {
|
2013-06-11 23:18:06 +00:00
|
|
|
if (open)
|
|
|
|
menuItem.open();
|
|
|
|
else
|
|
|
|
menuItem.close();
|
|
|
|
});
|
2017-10-31 00:38:18 +00:00
|
|
|
let parentClosingId = this.connect('menu-closed', () => {
|
2013-06-12 21:38:02 +00:00
|
|
|
menuItem.emit('menu-closed');
|
|
|
|
});
|
2017-10-31 00:38:18 +00:00
|
|
|
let subMenuSensitiveChangedId = this.connect('sensitive-changed', () => {
|
2013-06-12 07:16:53 +00:00
|
|
|
menuItem.emit('sensitive-changed');
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2011-03-28 19:27:03 +00:00
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
menuItem.connect('destroy', () => {
|
2013-06-11 23:18:06 +00:00
|
|
|
menuItem.disconnect(activeChangeId);
|
2013-06-12 07:16:53 +00:00
|
|
|
this.disconnect(subMenuSensitiveChangedId);
|
2013-06-11 23:18:06 +00:00
|
|
|
this.disconnect(parentOpenStateChangedId);
|
|
|
|
this.disconnect(parentClosingId);
|
2011-03-28 19:27:03 +00:00
|
|
|
this.length--;
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2011-01-25 21:04:57 +00:00
|
|
|
} else if (menuItem instanceof PopupSubMenuMenuItem) {
|
|
|
|
if (before_item == null)
|
|
|
|
this.box.add(menuItem.menu.actor);
|
|
|
|
else
|
2012-02-13 20:27:16 +00:00
|
|
|
this.box.insert_child_below(menuItem.menu.actor, before_item);
|
2013-06-11 23:18:06 +00:00
|
|
|
|
2011-01-25 21:04:57 +00:00
|
|
|
this._connectItemSignals(menuItem);
|
2017-12-02 00:27:35 +00:00
|
|
|
let subMenuActiveChangeId = menuItem.menu.connect('active-changed', this._subMenuActiveChanged.bind(this));
|
2017-10-31 00:38:18 +00:00
|
|
|
let closingId = this.connect('menu-closed', () => {
|
2013-06-12 21:38:02 +00:00
|
|
|
menuItem.menu.close(BoxPointer.PopupAnimation.NONE);
|
2011-01-25 21:04:57 +00:00
|
|
|
});
|
2013-06-11 23:18:06 +00:00
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
menuItem.connect('destroy', () => {
|
2013-06-11 23:18:06 +00:00
|
|
|
menuItem.menu.disconnect(subMenuActiveChangeId);
|
|
|
|
this.disconnect(closingId);
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2011-08-19 18:42:20 +00: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.
|
2017-10-31 00:38:18 +00:00
|
|
|
let openStateChangeId = this.connect('open-state-changed', () => {
|
|
|
|
this._updateSeparatorVisibility(menuItem);
|
|
|
|
});
|
|
|
|
let destroyId = menuItem.connect('destroy', () => {
|
2013-08-06 14:30:18 +00:00
|
|
|
this.disconnect(openStateChangeId);
|
|
|
|
menuItem.disconnect(destroyId);
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2011-01-25 21:04:57 +00:00
|
|
|
} else if (menuItem instanceof PopupBaseMenuItem)
|
|
|
|
this._connectItemSignals(menuItem);
|
|
|
|
else
|
|
|
|
throw TypeError("Invalid argument to PopupMenuBase.addMenuItem()");
|
2011-03-28 19:27:03 +00:00
|
|
|
|
2013-07-15 22:47:16 +00:00
|
|
|
menuItem._setParent(this);
|
2013-07-08 19:19:34 +00:00
|
|
|
|
2011-03-28 19:27:03 +00:00
|
|
|
this.length++;
|
2011-01-25 21:04:57 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getMenuItems() {
|
2017-10-31 00:38:18 +00:00
|
|
|
return this.box.get_children().map(a => a._delegate).filter(item => {
|
2011-01-25 21:04:57 +00:00
|
|
|
return item instanceof PopupBaseMenuItem || item instanceof PopupMenuSection;
|
|
|
|
});
|
2010-05-20 15:18:46 +00:00
|
|
|
},
|
|
|
|
|
2011-06-27 15:45:24 +00:00
|
|
|
get firstMenuItem() {
|
|
|
|
let items = this._getMenuItems();
|
|
|
|
if (items.length)
|
|
|
|
return items[0];
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2011-07-21 03:17:05 +00:00
|
|
|
get numMenuItems() {
|
|
|
|
return this._getMenuItems().length;
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
removeAll() {
|
2011-01-25 21:04:57 +00:00
|
|
|
let children = this._getMenuItems();
|
2010-05-20 15:18:46 +00:00
|
|
|
for (let i = 0; i < children.length; i++) {
|
|
|
|
let item = children[i];
|
2010-07-03 23:47:31 +00:00
|
|
|
item.destroy();
|
2010-05-20 15:18:46 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
toggle() {
|
2010-05-20 15:18:46 +00:00
|
|
|
if (this.isOpen)
|
2012-06-15 17:16:10 +00:00
|
|
|
this.close(BoxPointer.PopupAnimation.FULL);
|
2010-11-01 15:03:28 +00:00
|
|
|
else
|
2012-06-15 17:16:10 +00:00
|
|
|
this.open(BoxPointer.PopupAnimation.FULL);
|
2010-11-01 15:03:28 +00:00
|
|
|
},
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
destroy() {
|
2013-04-06 14:31:16 +00:00
|
|
|
this.close();
|
2010-11-01 15:03:28 +00:00
|
|
|
this.removeAll();
|
|
|
|
this.actor.destroy();
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2010-11-01 15:03:28 +00:00
|
|
|
this.emit('destroy');
|
2012-09-01 12:42:53 +00:00
|
|
|
|
|
|
|
Main.sessionMode.disconnect(this._sessionUpdatedId);
|
|
|
|
this._sessionUpdatedId = 0;
|
2010-11-01 15:03:28 +00:00
|
|
|
}
|
2011-11-20 13:10:48 +00:00
|
|
|
});
|
2010-11-01 15:03:28 +00:00
|
|
|
Signals.addSignalMethods(PopupMenuBase.prototype);
|
2010-06-12 16:13:04 +00:00
|
|
|
|
2017-07-18 17:41:25 +00:00
|
|
|
var PopupMenu = new Lang.Class({
|
2011-11-20 13:10:48 +00:00
|
|
|
Name: 'PopupMenu',
|
|
|
|
Extends: PopupMenuBase,
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(sourceActor, arrowAlignment, arrowSide) {
|
2011-11-20 13:10:48 +00:00
|
|
|
this.parent(sourceActor, 'popup-menu-content');
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2011-09-14 22:14:03 +00:00
|
|
|
this._arrowAlignment = arrowAlignment;
|
2010-11-01 15:03:28 +00:00
|
|
|
this._arrowSide = arrowSide;
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2010-11-01 15:03:28 +00: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 19:53:43 +00:00
|
|
|
|
2013-07-15 22:58:00 +00:00
|
|
|
this._boxPointer.bin.set_child(this.box);
|
2010-11-01 15:03:28 +00:00
|
|
|
this.actor.add_style_class_name('popup-menu');
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2010-11-01 15:03:28 +00:00
|
|
|
global.focus_manager.add_group(this.actor);
|
2010-05-20 15:18:46 +00:00
|
|
|
this.actor.reactive = true;
|
2013-02-16 18:42:17 +00:00
|
|
|
|
2014-08-28 15:04:23 +00:00
|
|
|
if (this.sourceActor)
|
|
|
|
this._keyPressId = this.sourceActor.connect('key-press-event',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._onKeyPress.bind(this));
|
2014-08-28 15:04:23 +00:00
|
|
|
|
2013-06-11 23:12:46 +00:00
|
|
|
this._openedSubMenu = null;
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_setOpenedSubMenu(submenu) {
|
2013-06-11 23:12:46 +00:00
|
|
|
if (this._openedSubMenu)
|
|
|
|
this._openedSubMenu.close(true);
|
|
|
|
|
|
|
|
this._openedSubMenu = submenu;
|
2010-11-01 15:03:28 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onKeyPress(actor, event) {
|
2017-03-25 02:26:06 +00:00
|
|
|
// Disable toggling the menu by keyboard
|
|
|
|
// when it cannot be toggled by pointer
|
|
|
|
if (!actor.reactive)
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
2014-08-28 15:27:00 +00:00
|
|
|
let navKey;
|
|
|
|
switch (this._boxPointer.arrowSide) {
|
|
|
|
case St.Side.TOP:
|
|
|
|
navKey = Clutter.KEY_Down;
|
|
|
|
break;
|
|
|
|
case St.Side.BOTTOM:
|
|
|
|
navKey = Clutter.KEY_Up;
|
|
|
|
break;
|
|
|
|
case St.Side.LEFT:
|
|
|
|
navKey = Clutter.KEY_Right;
|
|
|
|
break;
|
|
|
|
case St.Side.RIGHT:
|
|
|
|
navKey = Clutter.KEY_Left;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-10-26 14:46:21 +00:00
|
|
|
let state = event.get_state();
|
|
|
|
|
|
|
|
// if user has a modifier down (except capslock)
|
|
|
|
// then don't handle the key press here
|
|
|
|
state &= ~Clutter.ModifierType.LOCK_MASK;
|
|
|
|
state &= Clutter.ModifierType.MODIFIER_MASK;
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
2014-08-28 15:04:23 +00:00
|
|
|
let symbol = event.get_key_symbol();
|
|
|
|
if (symbol == Clutter.KEY_space || symbol == Clutter.KEY_Return) {
|
|
|
|
this.toggle();
|
|
|
|
return Clutter.EVENT_STOP;
|
|
|
|
} else if (symbol == Clutter.KEY_Escape && this.isOpen) {
|
|
|
|
this.close();
|
|
|
|
return Clutter.EVENT_STOP;
|
2014-08-28 15:27:00 +00:00
|
|
|
} else if (symbol == navKey) {
|
2014-08-28 15:04:23 +00:00
|
|
|
if (!this.isOpen)
|
|
|
|
this.toggle();
|
2014-08-28 15:27:00 +00:00
|
|
|
this.actor.navigate_focus(null, Gtk.DirectionType.TAB_FORWARD, false);
|
2014-08-28 15:04:23 +00:00
|
|
|
return Clutter.EVENT_STOP;
|
|
|
|
} else
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setArrowOrigin(origin) {
|
2010-11-01 15:03:28 +00:00
|
|
|
this._boxPointer.setArrowOrigin(origin);
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setSourceAlignment(alignment) {
|
2011-09-14 22:14:03 +00:00
|
|
|
this._boxPointer.setSourceAlignment(alignment);
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
open(animate) {
|
2010-11-01 15:03:28 +00:00
|
|
|
if (this.isOpen)
|
|
|
|
return;
|
|
|
|
|
2011-11-15 13:58:55 +00:00
|
|
|
if (this.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2010-05-20 15:18:46 +00:00
|
|
|
this.isOpen = true;
|
2010-11-01 15:03:28 +00:00
|
|
|
|
2011-09-14 22:14:03 +00:00
|
|
|
this._boxPointer.setPosition(this.sourceActor, this._arrowAlignment);
|
2010-11-18 21:18:54 +00:00
|
|
|
this._boxPointer.show(animate);
|
2010-11-01 15:03:28 +00:00
|
|
|
|
2011-08-29 16:04:17 +00:00
|
|
|
this.actor.raise_top();
|
|
|
|
|
2010-05-20 15:18:46 +00:00
|
|
|
this.emit('open-state-changed', true);
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
close(animate) {
|
2010-07-03 23:47:31 +00:00
|
|
|
if (this._activeMenuItem)
|
|
|
|
this._activeMenuItem.setActive(false);
|
2010-11-01 15:03:28 +00:00
|
|
|
|
2013-06-12 21:38:02 +00:00
|
|
|
if (this._boxPointer.actor.visible) {
|
2017-10-31 00:38:18 +00:00
|
|
|
this._boxPointer.hide(animate, () => {
|
2013-06-12 21:38:02 +00:00
|
|
|
this.emit('menu-closed');
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2013-06-12 21:38:02 +00:00
|
|
|
}
|
2012-10-19 21:13:16 +00:00
|
|
|
|
|
|
|
if (!this.isOpen)
|
|
|
|
return;
|
2010-11-01 15:03:28 +00:00
|
|
|
|
2010-05-20 15:18:46 +00:00
|
|
|
this.isOpen = false;
|
|
|
|
this.emit('open-state-changed', false);
|
2014-08-28 15:04:23 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
destroy() {
|
2014-08-28 15:04:23 +00:00
|
|
|
if (this._keyPressId)
|
|
|
|
this.sourceActor.disconnect(this._keyPressId);
|
|
|
|
this.parent();
|
2010-11-01 15:03:28 +00:00
|
|
|
}
|
2011-11-20 13:10:48 +00:00
|
|
|
});
|
2010-11-01 15:03:28 +00:00
|
|
|
|
2017-07-18 17:41:25 +00:00
|
|
|
var PopupDummyMenu = new Lang.Class({
|
2012-12-04 19:52:34 +00:00
|
|
|
Name: 'PopupDummyMenu',
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(sourceActor) {
|
2012-12-04 19:52:34 +00:00
|
|
|
this.sourceActor = sourceActor;
|
|
|
|
this.actor = sourceActor;
|
|
|
|
this.actor._delegate = this;
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
getSensitive() {
|
2013-06-12 07:16:53 +00:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
open() { this.emit('open-state-changed', true); },
|
|
|
|
close() { this.emit('open-state-changed', false); },
|
|
|
|
toggle() {},
|
|
|
|
destroy() {
|
2012-12-04 19:52:34 +00:00
|
|
|
this.emit('destroy');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
Signals.addSignalMethods(PopupDummyMenu.prototype);
|
|
|
|
|
2017-07-18 17:41:25 +00:00
|
|
|
var PopupSubMenu = new Lang.Class({
|
2011-11-20 13:10:48 +00:00
|
|
|
Name: 'PopupSubMenu',
|
|
|
|
Extends: PopupMenuBase,
|
2010-11-01 15:03:28 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(sourceActor, sourceArrow) {
|
2011-11-20 13:10:48 +00:00
|
|
|
this.parent(sourceActor);
|
2010-11-01 15:03:28 +00:00
|
|
|
|
|
|
|
this._arrow = sourceArrow;
|
|
|
|
|
2011-04-02 16:35:03 +00: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 12:55:15 +00:00
|
|
|
this.actor = new St.ScrollView({ style_class: 'popup-sub-menu',
|
|
|
|
hscrollbar_policy: Gtk.PolicyType.NEVER,
|
2011-04-02 16:35:03 +00:00
|
|
|
vscrollbar_policy: Gtk.PolicyType.NEVER });
|
|
|
|
|
|
|
|
this.actor.add_actor(this.box);
|
2010-11-01 15:03:28 +00:00
|
|
|
this.actor._delegate = this;
|
|
|
|
this.actor.clip_to_allocation = true;
|
2017-12-02 00:27:35 +00:00
|
|
|
this.actor.connect('key-press-event', this._onKeyPressEvent.bind(this));
|
2010-11-01 15:03:28 +00:00
|
|
|
this.actor.hide();
|
2010-05-20 15:18:46 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_needsScrollbar() {
|
2011-04-02 16:35:03 +00:00
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
getSensitive() {
|
2013-07-15 16:57:51 +00:00
|
|
|
return this._sensitive && this.sourceActor._delegate.getSensitive();
|
2013-06-12 07:16:53 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
open(animate) {
|
2010-05-20 15:18:46 +00:00
|
|
|
if (this.isOpen)
|
2010-11-01 15:03:28 +00:00
|
|
|
return;
|
|
|
|
|
2011-11-15 13:58:55 +00:00
|
|
|
if (this.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2010-11-01 15:03:28 +00:00
|
|
|
this.isOpen = true;
|
2013-06-11 22:29:36 +00:00
|
|
|
this.emit('open-state-changed', true);
|
2010-11-01 15:03:28 +00:00
|
|
|
|
2011-03-31 19:51:38 +00:00
|
|
|
this.actor.show();
|
2011-04-02 16:35:03 +00: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 09:41:23 +00:00
|
|
|
if (needsScrollbar)
|
|
|
|
this.actor.add_style_pseudo_class('scrolled');
|
|
|
|
else
|
|
|
|
this.actor.remove_style_pseudo_class('scrolled');
|
|
|
|
|
2011-04-02 16:35:03 +00: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;
|
|
|
|
|
2014-09-09 17:00:13 +00:00
|
|
|
let targetAngle = this.actor.text_direction == Clutter.TextDirection.RTL ? -90 : 90;
|
|
|
|
|
2011-04-02 16:35:03 +00:00
|
|
|
if (animate) {
|
|
|
|
let [minHeight, naturalHeight] = this.actor.get_preferred_height(-1);
|
|
|
|
this.actor.height = 0;
|
2014-02-19 11:35:59 +00:00
|
|
|
this.actor._arrowRotation = this._arrow.rotation_angle_z;
|
2011-04-02 16:35:03 +00:00
|
|
|
Tweener.addTween(this.actor,
|
2014-09-09 17:00:13 +00:00
|
|
|
{ _arrowRotation: targetAngle,
|
2011-04-02 16:35:03 +00:00
|
|
|
height: naturalHeight,
|
|
|
|
time: 0.25,
|
|
|
|
onUpdateScope: this,
|
2017-10-31 00:03:21 +00:00
|
|
|
onUpdate() {
|
2014-02-19 11:35:59 +00:00
|
|
|
this._arrow.rotation_angle_z = this.actor._arrowRotation;
|
2011-04-02 16:35:03 +00:00
|
|
|
},
|
|
|
|
onCompleteScope: this,
|
2017-10-31 00:03:21 +00:00
|
|
|
onComplete() {
|
2011-04-02 16:35:03 +00:00
|
|
|
this.actor.set_height(-1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2014-09-09 17:00:13 +00:00
|
|
|
this._arrow.rotation_angle_z = targetAngle;
|
2011-04-02 16:35:03 +00:00
|
|
|
}
|
2010-05-20 15:18:46 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
close(animate) {
|
2010-11-01 15:03:28 +00:00
|
|
|
if (!this.isOpen)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.isOpen = false;
|
2013-06-11 22:29:36 +00:00
|
|
|
this.emit('open-state-changed', false);
|
2010-11-01 15:03:28 +00:00
|
|
|
|
|
|
|
if (this._activeMenuItem)
|
2010-10-07 18:15:51 +00:00
|
|
|
this._activeMenuItem.setActive(false);
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2011-04-02 16:35:03 +00:00
|
|
|
if (animate && this._needsScrollbar())
|
|
|
|
animate = false;
|
|
|
|
|
2010-11-18 21:18:54 +00:00
|
|
|
if (animate) {
|
2014-02-19 11:35:59 +00:00
|
|
|
this.actor._arrowRotation = this._arrow.rotation_angle_z;
|
2010-11-18 21:18:54 +00:00
|
|
|
Tweener.addTween(this.actor,
|
2014-09-09 17:00:13 +00:00
|
|
|
{ _arrowRotation: 0,
|
2010-11-18 21:18:54 +00:00
|
|
|
height: 0,
|
|
|
|
time: 0.25,
|
2013-08-22 18:07:32 +00:00
|
|
|
onUpdateScope: this,
|
2017-10-31 00:03:21 +00:00
|
|
|
onUpdate() {
|
2014-02-19 11:35:59 +00:00
|
|
|
this._arrow.rotation_angle_z = this.actor._arrowRotation;
|
2013-08-22 18:07:32 +00:00
|
|
|
},
|
2010-11-18 21:18:54 +00:00
|
|
|
onCompleteScope: this,
|
2017-10-31 00:03:21 +00:00
|
|
|
onComplete() {
|
2010-11-18 21:18:54 +00:00
|
|
|
this.actor.hide();
|
|
|
|
this.actor.set_height(-1);
|
|
|
|
},
|
|
|
|
});
|
2013-08-22 18:07:32 +00:00
|
|
|
} else {
|
2014-09-09 17:00:13 +00:00
|
|
|
this._arrow.rotation_angle_z = 0;
|
2013-08-22 18:07:32 +00:00
|
|
|
this.actor.hide();
|
|
|
|
}
|
2010-07-03 23:47:31 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onKeyPressEvent(actor, event) {
|
2010-11-01 15:03:28 +00:00
|
|
|
// Move focus back to parent menu if the user types Left.
|
2010-07-03 23:47:31 +00:00
|
|
|
|
2010-11-01 15:03:28 +00:00
|
|
|
if (this.isOpen && event.get_key_symbol() == Clutter.KEY_Left) {
|
2012-06-15 17:16:10 +00:00
|
|
|
this.close(BoxPointer.PopupAnimation.FULL);
|
2010-11-01 15:03:28 +00:00
|
|
|
this.sourceActor._delegate.setActive(true);
|
2013-11-29 18:17:34 +00:00
|
|
|
return Clutter.EVENT_STOP;
|
2010-11-01 15:03:28 +00:00
|
|
|
}
|
|
|
|
|
2013-11-29 18:17:34 +00:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2010-05-20 15:18:46 +00:00
|
|
|
}
|
2011-11-20 13:10:48 +00:00
|
|
|
});
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2011-01-25 21:04:57 +00: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
|
|
|
|
*/
|
2017-07-18 17:41:25 +00:00
|
|
|
var PopupMenuSection = new Lang.Class({
|
2011-11-20 13:10:48 +00:00
|
|
|
Name: 'PopupMenuSection',
|
|
|
|
Extends: PopupMenuBase,
|
2011-01-25 21:04:57 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_init() {
|
2011-11-20 13:10:48 +00:00
|
|
|
this.parent();
|
2011-01-25 21:04:57 +00:00
|
|
|
|
|
|
|
this.actor = this.box;
|
|
|
|
this.actor._delegate = this;
|
|
|
|
this.isOpen = true;
|
|
|
|
},
|
|
|
|
|
2011-10-07 18:17:44 +00:00
|
|
|
// deliberately ignore any attempt to open() or close(), but emit the
|
|
|
|
// corresponding signal so children can still pick it up
|
2017-10-31 00:03:21 +00:00
|
|
|
open() { this.emit('open-state-changed', true); },
|
|
|
|
close() { this.emit('open-state-changed', false); },
|
2011-11-20 13:10:48 +00:00
|
|
|
});
|
2010-07-03 23:47:31 +00:00
|
|
|
|
2017-07-18 17:41:25 +00:00
|
|
|
var PopupSubMenuMenuItem = new Lang.Class({
|
2011-11-20 13:10:48 +00:00
|
|
|
Name: 'PopupSubMenuMenuItem',
|
|
|
|
Extends: PopupBaseMenuItem,
|
2010-07-03 23:47:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(text, wantIcon) {
|
2011-11-20 13:10:48 +00:00
|
|
|
this.parent();
|
2010-11-01 15:03:28 +00:00
|
|
|
|
|
|
|
this.actor.add_style_class_name('popup-submenu-menu-item');
|
2010-07-03 23:47:31 +00:00
|
|
|
|
2013-06-06 18:17:41 +00:00
|
|
|
if (wantIcon) {
|
|
|
|
this.icon = new St.Icon({ style_class: 'popup-menu-icon' });
|
2013-07-16 00:00:41 +00:00
|
|
|
this.actor.add_child(this.icon);
|
2013-06-06 18:17:41 +00:00
|
|
|
}
|
|
|
|
|
2013-09-18 21:36:09 +00:00
|
|
|
this.label = new St.Label({ text: text,
|
|
|
|
y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER });
|
2013-07-16 00:00:41 +00:00
|
|
|
this.actor.add_child(this.label);
|
2012-01-05 18:00:06 +00:00
|
|
|
this.actor.label_actor = this.label;
|
2013-06-06 18:17:41 +00:00
|
|
|
|
2013-07-16 00:00:41 +00:00
|
|
|
let expander = new St.Bin({ style_class: 'popup-menu-item-expander' });
|
|
|
|
this.actor.add(expander, { expand: true });
|
|
|
|
|
2014-02-18 12:45:26 +00:00
|
|
|
this._triangle = arrowIcon(St.Side.RIGHT);
|
2013-07-16 20:26:39 +00:00
|
|
|
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 14:02:22 +00:00
|
|
|
|
2013-07-16 20:26:39 +00:00
|
|
|
this.actor.add_child(this._triangleBin);
|
2013-09-13 23:29:21 +00:00
|
|
|
this.actor.add_accessible_state (Atk.StateType.EXPANDABLE);
|
2010-07-03 23:47:31 +00:00
|
|
|
|
2010-11-01 15:03:28 +00:00
|
|
|
this.menu = new PopupSubMenu(this.actor, this._triangle);
|
2017-12-02 00:27:35 +00:00
|
|
|
this.menu.connect('open-state-changed', this._subMenuOpenStateChanged.bind(this));
|
2010-07-03 23:47:31 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_setParent(parent) {
|
2013-07-15 22:47:16 +00:00
|
|
|
this.parent(parent);
|
|
|
|
this.menu._setParent(parent);
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
syncSensitive() {
|
2013-06-12 07:35:28 +00:00
|
|
|
let sensitive = this.parent();
|
|
|
|
this._triangle.visible = sensitive;
|
|
|
|
if (!sensitive)
|
|
|
|
this.menu.close(false);
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_subMenuOpenStateChanged(menu, open) {
|
2013-07-15 23:38:05 +00:00
|
|
|
if (open) {
|
2010-11-01 15:03:28 +00:00
|
|
|
this.actor.add_style_pseudo_class('open');
|
2013-07-15 23:38:05 +00:00
|
|
|
this._getTopMenu()._setOpenedSubMenu(this.menu);
|
2013-09-13 23:29:21 +00:00
|
|
|
this.actor.add_accessible_state (Atk.StateType.EXPANDED);
|
2015-01-21 16:14:42 +00:00
|
|
|
this.actor.add_style_pseudo_class('checked');
|
2013-07-15 23:38:05 +00:00
|
|
|
} else {
|
2010-11-01 15:03:28 +00:00
|
|
|
this.actor.remove_style_pseudo_class('open');
|
2013-07-15 23:38:05 +00:00
|
|
|
this._getTopMenu()._setOpenedSubMenu(null);
|
2013-09-13 23:29:21 +00:00
|
|
|
this.actor.remove_accessible_state (Atk.StateType.EXPANDED);
|
2015-01-21 16:14:42 +00:00
|
|
|
this.actor.remove_style_pseudo_class('checked');
|
2013-07-15 23:38:05 +00:00
|
|
|
}
|
2010-07-03 23:47:31 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
destroy() {
|
2010-11-01 15:03:28 +00:00
|
|
|
this.menu.destroy();
|
2011-11-20 13:10:48 +00:00
|
|
|
|
|
|
|
this.parent();
|
2010-07-03 23:47:31 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setSubmenuShown(open) {
|
2013-05-10 18:32:58 +00:00
|
|
|
if (open)
|
|
|
|
this.menu.open(BoxPointer.PopupAnimation.FULL);
|
|
|
|
else
|
|
|
|
this.menu.close(BoxPointer.PopupAnimation.FULL);
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_setOpenState(open) {
|
2013-05-14 17:58:10 +00:00
|
|
|
this.setSubmenuShown(open);
|
2013-05-10 18:32:58 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getOpenState() {
|
2013-05-10 18:32:58 +00:00
|
|
|
return this.menu.isOpen;
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onKeyPressEvent(actor, event) {
|
2011-02-08 19:53:43 +00:00
|
|
|
let symbol = event.get_key_symbol();
|
|
|
|
|
|
|
|
if (symbol == Clutter.KEY_Right) {
|
2013-05-10 18:32:58 +00:00
|
|
|
this._setOpenState(true);
|
2011-02-08 19:53:43 +00:00
|
|
|
this.menu.actor.navigate_focus(null, Gtk.DirectionType.DOWN, false);
|
2013-11-29 18:17:34 +00:00
|
|
|
return Clutter.EVENT_STOP;
|
2013-05-10 18:32:58 +00:00
|
|
|
} else if (symbol == Clutter.KEY_Left && this._getOpenState()) {
|
|
|
|
this._setOpenState(false);
|
2013-11-29 18:17:34 +00:00
|
|
|
return Clutter.EVENT_STOP;
|
2010-07-03 23:47:31 +00:00
|
|
|
}
|
2011-02-08 19:53:43 +00:00
|
|
|
|
2011-11-20 13:10:48 +00:00
|
|
|
return this.parent(actor, event);
|
2010-07-03 23:47:31 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
activate(event) {
|
2013-05-10 18:32:58 +00:00
|
|
|
this._setOpenState(true);
|
2010-07-03 23:47:31 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onButtonReleaseEvent(actor) {
|
2015-02-18 16:07:59 +00:00
|
|
|
// Since we override the parent, we need to manage what the parent does
|
|
|
|
// with the active style class
|
|
|
|
this.actor.remove_style_pseudo_class ('active');
|
2013-05-10 18:32:58 +00:00
|
|
|
this._setOpenState(!this._getOpenState());
|
2013-11-29 18:17:34 +00:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2015-10-16 16:03:30 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onTouchEvent(actor, event) {
|
2015-10-16 16:03:30 +00:00
|
|
|
if (event.type() == Clutter.EventType.TOUCH_END) {
|
|
|
|
// Since we override the parent, we need to manage what the parent does
|
|
|
|
// with the active style class
|
|
|
|
this.actor.remove_style_pseudo_class ('active');
|
|
|
|
this._setOpenState(!this._getOpenState());
|
|
|
|
}
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2010-07-03 23:47:31 +00:00
|
|
|
}
|
2011-11-20 13:10:48 +00:00
|
|
|
});
|
2011-07-21 03:17:05 +00:00
|
|
|
|
2010-05-20 15:18:46 +00:00
|
|
|
/* Basic implementation of a menu manager.
|
|
|
|
* Call addMenu to add menus
|
|
|
|
*/
|
2017-07-18 17:41:25 +00:00
|
|
|
var PopupMenuManager = new Lang.Class({
|
2011-11-20 13:10:48 +00:00
|
|
|
Name: 'PopupMenuManager',
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(owner, grabParams) {
|
2015-02-23 19:07:04 +00:00
|
|
|
grabParams = Params.parse(grabParams,
|
|
|
|
{ actionMode: Shell.ActionMode.POPUP });
|
2010-05-20 15:18:46 +00:00
|
|
|
this._owner = owner;
|
2013-04-26 13:46:49 +00:00
|
|
|
this._grabHelper = new GrabHelper.GrabHelper(owner.actor, grabParams);
|
2010-05-20 15:18:46 +00:00
|
|
|
this._menus = [];
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
addMenu(menu, position) {
|
2012-09-01 12:42:53 +00:00
|
|
|
if (this._findMenu(menu) > -1)
|
|
|
|
return;
|
|
|
|
|
2010-06-25 12:55:03 +00:00
|
|
|
let menudata = {
|
|
|
|
menu: menu,
|
2017-12-02 00:27:35 +00:00
|
|
|
openStateChangeId: menu.connect('open-state-changed', this._onMenuOpenState.bind(this)),
|
|
|
|
destroyId: menu.connect('destroy', this._onMenuDestroy.bind(this)),
|
2010-06-25 12:55:03 +00:00
|
|
|
enterId: 0,
|
2011-02-08 19:53:43 +00:00
|
|
|
focusInId: 0
|
2010-06-25 12:55:03 +00:00
|
|
|
};
|
2010-05-20 15:18:46 +00:00
|
|
|
|
|
|
|
let source = menu.sourceActor;
|
|
|
|
if (source) {
|
2012-03-01 00:09:41 +00:00
|
|
|
if (!menu.blockSourceEvents)
|
|
|
|
this._grabHelper.addActor(source);
|
2017-10-31 00:38:18 +00:00
|
|
|
menudata.enterId = source.connect('enter-event',
|
|
|
|
() => this._onMenuSourceEnter(menu));
|
|
|
|
menudata.focusInId = source.connect('key-focus-in', () => {
|
|
|
|
this._onMenuSourceEnter(menu);
|
|
|
|
});
|
2010-05-20 15:18:46 +00:00
|
|
|
}
|
2010-06-25 12:55:03 +00:00
|
|
|
|
|
|
|
if (position == undefined)
|
|
|
|
this._menus.push(menudata);
|
|
|
|
else
|
|
|
|
this._menus.splice(position, 0, menudata);
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
removeMenu(menu) {
|
2013-03-14 15:48:19 +00:00
|
|
|
if (menu == this.activeMenu)
|
2013-11-06 22:40:22 +00:00
|
|
|
this._closeMenu(false, menu);
|
2010-07-03 23:47:31 +00:00
|
|
|
|
2010-06-25 12:55:03 +00: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 23:47:31 +00:00
|
|
|
menu.disconnect(menudata.destroyId);
|
2010-06-25 12:55:03 +00:00
|
|
|
|
|
|
|
if (menudata.enterId)
|
|
|
|
menu.sourceActor.disconnect(menudata.enterId);
|
2010-11-03 17:30:08 +00:00
|
|
|
if (menudata.focusInId)
|
|
|
|
menu.sourceActor.disconnect(menudata.focusInId);
|
2010-06-25 12:55:03 +00:00
|
|
|
|
2012-03-01 00:09:41 +00:00
|
|
|
if (menu.sourceActor)
|
|
|
|
this._grabHelper.removeActor(menu.sourceActor);
|
2010-06-25 12:55:03 +00:00
|
|
|
this._menus.splice(position, 1);
|
2010-05-20 15:18:46 +00:00
|
|
|
},
|
|
|
|
|
2012-03-01 00:09:41 +00:00
|
|
|
get activeMenu() {
|
2013-03-14 15:51:10 +00:00
|
|
|
let firstGrab = this._grabHelper.grabStack[0];
|
|
|
|
if (firstGrab)
|
|
|
|
return firstGrab.actor._delegate;
|
2012-03-01 00:09:41 +00:00
|
|
|
else
|
|
|
|
return null;
|
2010-05-20 15:18:46 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
ignoreRelease() {
|
2012-03-01 00:09:41 +00:00
|
|
|
return this._grabHelper.ignoreRelease();
|
2010-05-20 15:18:46 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onMenuOpenState(menu, open) {
|
2011-07-12 19:47:37 +00:00
|
|
|
if (open) {
|
2013-04-23 21:46:33 +00:00
|
|
|
if (this.activeMenu)
|
2013-04-26 15:06:22 +00:00
|
|
|
this.activeMenu.close(BoxPointer.PopupAnimation.FADE);
|
2013-05-23 21:20:30 +00:00
|
|
|
this._grabHelper.grab({ actor: menu.actor, focus: menu.sourceActor,
|
2017-12-02 00:27:35 +00:00
|
|
|
onUngrab: isUser => {
|
|
|
|
this._closeMenu(isUser, menu);
|
|
|
|
} });
|
2011-07-12 19:47:37 +00:00
|
|
|
} else {
|
2012-03-01 00:09:41 +00:00
|
|
|
this._grabHelper.ungrab({ actor: menu.actor });
|
2010-11-03 17:30:08 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_changeMenu(newMenu) {
|
2013-04-26 15:06:22 +00:00
|
|
|
newMenu.open(this.activeMenu ? BoxPointer.PopupAnimation.FADE
|
|
|
|
: BoxPointer.PopupAnimation.FULL);
|
2010-05-20 15:18:46 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onMenuSourceEnter(menu) {
|
2012-03-01 00:09:41 +00:00
|
|
|
if (!this._grabHelper.grabbed)
|
2013-11-29 18:17:34 +00:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2010-05-20 15:18:46 +00:00
|
|
|
|
2012-03-01 00:09:41 +00:00
|
|
|
if (this._grabHelper.isActorGrabbed(menu.actor))
|
2013-11-29 18:17:34 +00:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2011-07-12 19:47:37 +00:00
|
|
|
|
2010-11-03 17:30:08 +00:00
|
|
|
this._changeMenu(menu);
|
2013-11-29 18:17:34 +00:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2010-05-20 15:18:46 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onMenuDestroy(menu) {
|
2010-07-03 23:47:31 +00:00
|
|
|
this.removeMenu(menu);
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_findMenu(item) {
|
2010-06-25 12:55:03 +00:00
|
|
|
for (let i = 0; i < this._menus.length; i++) {
|
|
|
|
let menudata = this._menus[i];
|
|
|
|
if (item == menudata.menu)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_closeMenu(isUser, menu) {
|
2012-12-10 08:55:14 +00:00
|
|
|
// 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 15:18:46 +00:00
|
|
|
}
|
2011-11-20 13:10:48 +00:00
|
|
|
});
|