2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2023-07-10 05:53:00 -04:00
|
|
|
|
|
|
|
import Atk from 'gi://Atk';
|
|
|
|
import Clutter from 'gi://Clutter';
|
|
|
|
import Gio from 'gi://Gio';
|
|
|
|
import GObject from 'gi://GObject';
|
|
|
|
import Graphene from 'gi://Graphene';
|
|
|
|
import Shell from 'gi://Shell';
|
|
|
|
import St from 'gi://St';
|
|
|
|
import * as Signals from '../misc/signals.js';
|
|
|
|
|
|
|
|
import * as BoxPointer from './boxpointer.js';
|
|
|
|
import * as Main from './main.js';
|
|
|
|
import * as Params from '../misc/params.js';
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2023-07-30 08:56:59 -04:00
|
|
|
/** @enum {number} */
|
2023-07-10 05:53:00 -04:00
|
|
|
export const Ornament = {
|
2013-04-19 20:57:38 -04:00
|
|
|
NONE: 0,
|
|
|
|
DOT: 1,
|
2013-04-19 21:13:37 -04:00
|
|
|
CHECK: 2,
|
2019-09-13 11:59:16 -04:00
|
|
|
HIDDEN: 3,
|
2013-04-19 20:57:38 -04:00
|
|
|
};
|
|
|
|
|
2013-08-28 10:50:07 -04:00
|
|
|
function isPopupMenuItemVisible(child) {
|
2019-08-19 20:51:42 -04:00
|
|
|
if (child._delegate instanceof PopupMenuSection) {
|
2013-08-28 10:50:07 -04:00
|
|
|
if (child._delegate.isEmpty())
|
|
|
|
return false;
|
2019-08-19 20:51:42 -04:00
|
|
|
}
|
2013-08-28 10:50:07 -04:00
|
|
|
return child.visible;
|
|
|
|
}
|
|
|
|
|
2013-10-07 10:01:07 -04:00
|
|
|
/**
|
2019-10-17 12:41:52 -04:00
|
|
|
* arrowIcon
|
2023-07-10 05:53:00 -04:00
|
|
|
*
|
2019-10-17 12:41:52 -04:00
|
|
|
* @param {St.Side} side - Side to which the arrow points.
|
|
|
|
* @returns {St.Icon} a new arrow icon
|
2013-10-07 10:01:07 -04:00
|
|
|
*/
|
2023-07-10 05:53:00 -04:00
|
|
|
export function arrowIcon(side) {
|
2014-06-24 13:43:35 -04:00
|
|
|
let iconName;
|
2013-10-07 10:01:07 -04:00
|
|
|
switch (side) {
|
2019-02-01 07:21:00 -05:00
|
|
|
case St.Side.TOP:
|
|
|
|
iconName = 'pan-up-symbolic';
|
|
|
|
break;
|
|
|
|
case St.Side.RIGHT:
|
|
|
|
iconName = 'pan-end-symbolic';
|
|
|
|
break;
|
|
|
|
case St.Side.BOTTOM:
|
|
|
|
iconName = 'pan-down-symbolic';
|
|
|
|
break;
|
|
|
|
case St.Side.LEFT:
|
|
|
|
iconName = 'pan-start-symbolic';
|
|
|
|
break;
|
2013-10-07 10:01:07 -04:00
|
|
|
}
|
|
|
|
|
2020-03-29 17:51:13 -04:00
|
|
|
const arrow = new St.Icon({
|
|
|
|
style_class: 'popup-menu-arrow',
|
|
|
|
icon_name: iconName,
|
|
|
|
accessible_role: Atk.Role.ARROW,
|
|
|
|
y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
|
|
|
});
|
2014-02-18 07:45:26 -05:00
|
|
|
|
|
|
|
return arrow;
|
2013-10-07 10:01:07 -04:00
|
|
|
}
|
|
|
|
|
2023-07-10 05:53:00 -04:00
|
|
|
export const PopupBaseMenuItem = GObject.registerClass({
|
2019-04-17 19:15:56 -04:00
|
|
|
Properties: {
|
|
|
|
'active': GObject.ParamSpec.boolean('active', 'active', 'active',
|
|
|
|
GObject.ParamFlags.READWRITE,
|
|
|
|
false),
|
2019-04-17 19:36:01 -04:00
|
|
|
'sensitive': GObject.ParamSpec.boolean('sensitive', 'sensitive', 'sensitive',
|
|
|
|
GObject.ParamFlags.READWRITE,
|
|
|
|
true),
|
2019-04-17 19:15:56 -04:00
|
|
|
},
|
2019-04-11 20:19:31 -04:00
|
|
|
Signals: {
|
|
|
|
'activate': { param_types: [Clutter.Event.$gtype] },
|
2019-08-20 17:43:54 -04:00
|
|
|
},
|
2019-04-11 20:19:31 -04:00
|
|
|
}, class PopupBaseMenuItem extends St.BoxLayout {
|
|
|
|
_init(params) {
|
2019-08-19 13:55:49 -04:00
|
|
|
params = Params.parse(params, {
|
2019-02-12 09:02:09 -05:00
|
|
|
reactive: true,
|
|
|
|
activate: true,
|
|
|
|
hover: true,
|
|
|
|
style_class: null,
|
|
|
|
can_focus: true,
|
|
|
|
});
|
2020-03-29 17:51:13 -04:00
|
|
|
super._init({
|
|
|
|
style_class: 'popup-menu-item',
|
|
|
|
reactive: params.reactive,
|
|
|
|
track_hover: params.reactive,
|
|
|
|
can_focus: params.can_focus,
|
|
|
|
accessible_role: Atk.Role.MENU_ITEM,
|
|
|
|
});
|
2019-04-11 20:19:31 -04:00
|
|
|
this._delegate = this;
|
2010-10-19 13:41:41 -04:00
|
|
|
|
2023-05-16 19:33:19 -04:00
|
|
|
this._ornamentIcon = new St.Icon({style_class: 'popup-menu-ornament'});
|
|
|
|
this.add(this._ornamentIcon);
|
2023-07-13 13:04:20 -04:00
|
|
|
this.setOrnament(Ornament.HIDDEN);
|
2013-07-15 20:00:41 -04:00
|
|
|
|
|
|
|
this._parent = null;
|
2019-04-17 19:15:56 -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
|
|
|
|
2023-04-19 08:11:09 -04:00
|
|
|
this._clickAction = new Clutter.ClickAction({
|
|
|
|
enabled: this._activatable,
|
|
|
|
});
|
|
|
|
this._clickAction.connect('clicked',
|
|
|
|
() => this.activate(Clutter.get_current_event()));
|
|
|
|
this._clickAction.connect('notify::pressed', () => {
|
|
|
|
if (this._clickAction.pressed)
|
|
|
|
this.add_style_pseudo_class('active');
|
|
|
|
else
|
|
|
|
this.remove_style_pseudo_class('active');
|
|
|
|
});
|
|
|
|
this.add_action(this._clickAction);
|
|
|
|
|
2012-09-11 08:00:22 -04:00
|
|
|
if (!this._activatable)
|
2019-04-11 20:19:31 -04:00
|
|
|
this.add_style_class_name('popup-inactive-menu-item');
|
2012-09-11 08:00:22 -04:00
|
|
|
|
2011-01-25 16:06:40 -05:00
|
|
|
if (params.style_class)
|
2019-04-11 20:19:31 -04:00
|
|
|
this.add_style_class_name(params.style_class);
|
2011-01-25 16:06:40 -05:00
|
|
|
|
2010-07-03 19:47:31 -04:00
|
|
|
if (params.reactive && params.hover)
|
2019-04-17 19:15:56 -04:00
|
|
|
this.bind_property('hover', this, 'active', GObject.BindingFlags.SYNC_CREATE);
|
2019-04-11 20:19:31 -04:00
|
|
|
}
|
2012-08-17 05:03:23 -04:00
|
|
|
|
2019-04-11 20:19:31 -04:00
|
|
|
get actor() {
|
|
|
|
/* This is kept for compatibility with current implementation, and we
|
|
|
|
don't want to warn here yet since PopupMenu depends on this */
|
|
|
|
return this;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getTopMenu() {
|
2013-07-15 18:47:16 -04:00
|
|
|
if (this._parent)
|
|
|
|
return this._parent._getTopMenu();
|
|
|
|
else
|
|
|
|
return this;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-07-15 18:47:16 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_setParent(parent) {
|
2013-07-15 18:47:16 -04:00
|
|
|
this._parent = parent;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-07-15 18:47:16 -04:00
|
|
|
|
2019-09-10 01:42:48 -04:00
|
|
|
vfunc_key_press_event(keyEvent) {
|
2022-02-01 08:33:03 -05:00
|
|
|
if (global.focus_manager.navigate_from_event(Clutter.get_current_event()))
|
|
|
|
return Clutter.EVENT_STOP;
|
|
|
|
|
2019-09-10 01:42:48 -04:00
|
|
|
if (!this._activatable)
|
|
|
|
return super.vfunc_key_press_event(keyEvent);
|
|
|
|
|
|
|
|
let state = keyEvent.modifier_state;
|
2018-06-21 12:40:43 -04:00
|
|
|
|
2018-09-12 16:13:04 -04:00
|
|
|
// if user has a modifier down (except capslock and numlock)
|
2018-06-21 12:40:43 -04:00
|
|
|
// then don't handle the key press here
|
|
|
|
state &= ~Clutter.ModifierType.LOCK_MASK;
|
2018-09-12 16:13:04 -04:00
|
|
|
state &= ~Clutter.ModifierType.MOD2_MASK;
|
2018-06-21 12:40:43 -04:00
|
|
|
state &= Clutter.ModifierType.MODIFIER_MASK;
|
2010-10-07 14:15:51 -04:00
|
|
|
|
2018-06-21 12:40:43 -04:00
|
|
|
if (state)
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
2019-09-10 01:42:48 -04:00
|
|
|
let symbol = keyEvent.keyval;
|
2010-10-07 14:15:51 -04:00
|
|
|
if (symbol == Clutter.KEY_space || symbol == Clutter.KEY_Return) {
|
2019-09-10 01:42:48 -04:00
|
|
|
this.activate(Clutter.get_current_event());
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_STOP;
|
2010-10-07 14:15:51 -04:00
|
|
|
}
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-10-07 14:15:51 -04:00
|
|
|
|
2019-04-12 16:46:10 -04:00
|
|
|
vfunc_key_focus_in() {
|
|
|
|
super.vfunc_key_focus_in();
|
2019-04-17 19:15:56 -04:00
|
|
|
this.active = true;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-10-07 14:15:51 -04:00
|
|
|
|
2019-04-12 16:46:10 -04:00
|
|
|
vfunc_key_focus_out() {
|
|
|
|
super.vfunc_key_focus_out();
|
2019-04-17 19:15:56 -04:00
|
|
|
this.active = false;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
activate(event) {
|
2010-05-20 11:18:46 -04:00
|
|
|
this.emit('activate', event);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2019-04-17 19:15:56 -04:00
|
|
|
get active() {
|
|
|
|
return this._active;
|
|
|
|
}
|
|
|
|
|
|
|
|
set active(active) {
|
2010-05-20 11:18:46 -04:00
|
|
|
let activeChanged = active != this.active;
|
|
|
|
if (activeChanged) {
|
2019-04-17 19:15:56 -04:00
|
|
|
this._active = active;
|
2010-10-07 14:15:51 -04:00
|
|
|
if (active) {
|
2019-04-11 20:19:31 -04:00
|
|
|
this.add_style_class_name('selected');
|
|
|
|
if (this.can_focus)
|
|
|
|
this.grab_key_focus();
|
2013-04-23 17:46:33 -04:00
|
|
|
} else {
|
2019-04-11 20:19:31 -04:00
|
|
|
this.remove_style_class_name('selected');
|
2015-02-18 11:07:59 -05: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
|
2020-08-19 05:26:11 -04:00
|
|
|
// active state as well, but button-press-event is not triggered,
|
2015-02-18 11:07:59 -05:00
|
|
|
// so we should track it in our own, which would involve some work
|
|
|
|
// in the container
|
2019-04-11 20:19:31 -04:00
|
|
|
this.remove_style_pseudo_class('active');
|
2013-04-23 17:46:33 -04:00
|
|
|
}
|
2019-04-17 19:15:56 -04:00
|
|
|
this.notify('active');
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-07-03 19:47:31 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
syncSensitive() {
|
2019-04-17 19:36:01 -04:00
|
|
|
let sensitive = this.sensitive;
|
2019-04-11 20:19:31 -04:00
|
|
|
this.reactive = sensitive;
|
|
|
|
this.can_focus = sensitive;
|
2019-04-17 19:36:01 -04:00
|
|
|
this.notify('sensitive');
|
2013-06-12 03:16:53 -04:00
|
|
|
return sensitive;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-09-15 10:51:19 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getSensitive() {
|
2020-08-12 14:59:01 -04:00
|
|
|
const parentSensitive = this._parent?.sensitive ?? true;
|
2013-07-15 18:54:15 -04:00
|
|
|
return this._activatable && this._sensitive && parentSensitive;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-06-12 03:16:53 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setSensitive(sensitive) {
|
2013-06-12 03:16:53 -04:00
|
|
|
if (this._sensitive == sensitive)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._sensitive = sensitive;
|
|
|
|
this.syncSensitive();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-09-15 10:51:19 -04:00
|
|
|
|
2019-04-17 19:36:01 -04:00
|
|
|
get sensitive() {
|
|
|
|
return this.getSensitive();
|
|
|
|
}
|
|
|
|
|
|
|
|
set sensitive(sensitive) {
|
|
|
|
this.setSensitive(sensitive);
|
|
|
|
}
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setOrnament(ornament) {
|
2023-06-08 00:53:07 -04:00
|
|
|
if (ornament === this._ornament)
|
2013-04-19 20:57:38 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
this._ornament = ornament;
|
2010-10-20 12:43:22 -04:00
|
|
|
|
2013-04-19 20:57:38 -04:00
|
|
|
if (ornament == Ornament.DOT) {
|
2023-05-16 19:33:19 -04:00
|
|
|
this._ornamentIcon.icon_name = 'ornament-dot-symbolic';
|
2019-04-11 20:19:31 -04:00
|
|
|
this.add_accessible_state(Atk.StateType.CHECKED);
|
2013-04-19 21:13:37 -04:00
|
|
|
} else if (ornament == Ornament.CHECK) {
|
2023-05-16 19:33:19 -04:00
|
|
|
this._ornamentIcon.icon_name = 'ornament-check-symbolic';
|
2019-04-11 20:19:31 -04:00
|
|
|
this.add_accessible_state(Atk.StateType.CHECKED);
|
2019-09-13 11:59:16 -04:00
|
|
|
} else if (ornament == Ornament.NONE || ornament == Ornament.HIDDEN) {
|
2023-05-16 19:33:19 -04:00
|
|
|
this._ornamentIcon.icon_name = '';
|
2019-04-11 20:19:31 -04:00
|
|
|
this.remove_accessible_state(Atk.StateType.CHECKED);
|
2010-10-20 12:43:22 -04:00
|
|
|
}
|
2019-09-13 11:59:16 -04:00
|
|
|
|
2023-05-16 19:33:19 -04:00
|
|
|
this._ornamentIcon.visible = ornament !== Ornament.HIDDEN;
|
2023-05-17 16:49:34 -04:00
|
|
|
this._updateOrnamentStyle();
|
|
|
|
}
|
|
|
|
|
|
|
|
_updateOrnamentStyle() {
|
|
|
|
if (this._ornament !== Ornament.HIDDEN)
|
|
|
|
this.add_style_class_name('popup-ornamented-menu-item');
|
|
|
|
else
|
|
|
|
this.remove_style_class_name('popup-ornamented-menu-item');
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
2019-04-11 20:19:31 -04:00
|
|
|
});
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2023-07-10 05:53:00 -04:00
|
|
|
export const PopupMenuItem = GObject.registerClass(
|
2019-04-11 20:19:31 -04:00
|
|
|
class PopupMenuItem extends PopupBaseMenuItem {
|
|
|
|
_init(text, params) {
|
|
|
|
super._init(params);
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2022-01-18 02:47:25 -05:00
|
|
|
this.label = new St.Label({
|
|
|
|
text,
|
|
|
|
y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
|
|
|
});
|
2019-04-11 20:19:31 -04:00
|
|
|
this.add_child(this.label);
|
2019-01-28 20:18:52 -05:00
|
|
|
this.label_actor = this.label;
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
2019-04-11 20:19:31 -04:00
|
|
|
});
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2019-04-11 20:19:31 -04:00
|
|
|
|
2023-07-10 05:53:00 -04:00
|
|
|
export const PopupSeparatorMenuItem = GObject.registerClass(
|
2019-04-11 20:19:31 -04:00
|
|
|
class PopupSeparatorMenuItem extends PopupBaseMenuItem {
|
|
|
|
_init(text) {
|
2020-02-14 07:36:04 -05:00
|
|
|
super._init({
|
|
|
|
style_class: 'popup-separator-menu-item',
|
|
|
|
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 || '' });
|
2019-04-11 20:19:31 -04:00
|
|
|
this.add(this.label);
|
|
|
|
this.label_actor = this.label;
|
2013-04-24 16:21:57 -04:00
|
|
|
|
2014-05-25 10:38:05 -04:00
|
|
|
this.label.connect('notify::text',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._syncVisibility.bind(this));
|
2014-05-25 10:38:05 -04:00
|
|
|
this._syncVisibility();
|
|
|
|
|
2020-02-14 07:36:04 -05:00
|
|
|
this._separator = new St.Widget({
|
|
|
|
style_class: 'popup-separator-menu-item-separator',
|
|
|
|
x_expand: true,
|
|
|
|
y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
|
|
|
});
|
2019-10-21 14:44:00 -04:00
|
|
|
this.add_child(this._separator);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-05-25 10:38:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_syncVisibility() {
|
2014-05-25 10:38:05 -04:00
|
|
|
this.label.visible = this.label.text != '';
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
2019-04-11 20:19:31 -04:00
|
|
|
});
|
2010-07-22 08:34:02 -04:00
|
|
|
|
2023-07-10 05:53:00 -04:00
|
|
|
export const Switch = GObject.registerClass({
|
2020-01-21 08:52:15 -05:00
|
|
|
Properties: {
|
|
|
|
'state': GObject.ParamSpec.boolean(
|
|
|
|
'state', 'state', 'state',
|
|
|
|
GObject.ParamFlags.READWRITE,
|
|
|
|
false),
|
|
|
|
},
|
|
|
|
}, class Switch extends St.Bin {
|
2019-04-12 17:04:16 -04:00
|
|
|
_init(state) {
|
2020-01-21 08:52:15 -05:00
|
|
|
this._state = false;
|
|
|
|
|
|
|
|
super._init({
|
|
|
|
style_class: 'toggle-switch',
|
|
|
|
accessible_role: Atk.Role.CHECK_BOX,
|
|
|
|
state,
|
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-02-08 14:19:04 -05:00
|
|
|
|
2020-01-21 08:52:15 -05:00
|
|
|
get state() {
|
|
|
|
return this._state;
|
|
|
|
}
|
|
|
|
|
|
|
|
set state(state) {
|
|
|
|
if (this._state === state)
|
|
|
|
return;
|
|
|
|
|
2011-02-08 14:19:04 -05:00
|
|
|
if (state)
|
2019-04-12 17:04:16 -04:00
|
|
|
this.add_style_pseudo_class('checked');
|
2011-02-08 14:19:04 -05:00
|
|
|
else
|
2019-04-12 17:04:16 -04:00
|
|
|
this.remove_style_pseudo_class('checked');
|
2020-01-21 08:52:15 -05:00
|
|
|
|
|
|
|
this._state = state;
|
|
|
|
this.notify('state');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-02-08 14:19:04 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
toggle() {
|
2020-01-21 08:52:15 -05:00
|
|
|
this.state = !this.state;
|
2011-02-08 14:19:04 -05:00
|
|
|
}
|
2019-04-12 17:04:16 -04:00
|
|
|
});
|
2010-06-17 08:17:01 -04:00
|
|
|
|
2023-07-10 05:53:00 -04:00
|
|
|
export const PopupSwitchMenuItem = GObject.registerClass({
|
2019-08-20 17:43:54 -04:00
|
|
|
Signals: { 'toggled': { param_types: [GObject.TYPE_BOOLEAN] } },
|
2019-06-29 09:04:13 -04:00
|
|
|
}, class PopupSwitchMenuItem extends PopupBaseMenuItem {
|
2019-04-11 20:19:31 -04:00
|
|
|
_init(text, active, params) {
|
|
|
|
super._init(params);
|
2010-06-17 08:17:01 -04:00
|
|
|
|
2022-01-18 02:47:25 -05:00
|
|
|
this.label = new St.Label({
|
|
|
|
text,
|
|
|
|
y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
|
|
|
});
|
2010-10-13 14:10:38 -04:00
|
|
|
this._switch = new Switch(active);
|
2010-06-17 08:17:01 -04:00
|
|
|
|
2019-04-11 20:19:31 -04:00
|
|
|
this.accessible_role = Atk.Role.CHECK_MENU_ITEM;
|
2012-01-20 12:10:45 -05:00
|
|
|
this.checkAccessibleState();
|
2019-04-11 20:19:31 -04:00
|
|
|
this.label_actor = this.label;
|
2012-02-27 11:31:10 -05:00
|
|
|
|
2019-04-11 20:19:31 -04:00
|
|
|
this.add_child(this.label);
|
2010-06-17 08:17:01 -04:00
|
|
|
|
2019-10-21 14:44:00 -04:00
|
|
|
this._statusBin = new St.Bin({
|
2019-10-17 17:27:27 -04:00
|
|
|
x_align: Clutter.ActorAlign.END,
|
2019-10-21 14:44:00 -04:00
|
|
|
x_expand: true,
|
|
|
|
});
|
|
|
|
this.add_child(this._statusBin);
|
2011-04-21 10:44:28 -04:00
|
|
|
|
2019-02-12 09:02:09 -05:00
|
|
|
this._statusLabel = new St.Label({
|
|
|
|
text: '',
|
|
|
|
style_class: 'popup-status-menu-item',
|
2022-01-18 02:47:25 -05:00
|
|
|
y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
2019-02-12 09:02:09 -05:00
|
|
|
});
|
2019-04-12 17:04:16 -04:00
|
|
|
this._statusBin.child = this._switch;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-04-21 10:44:28 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setStatus(text) {
|
2011-04-21 10:44:28 -04:00
|
|
|
if (text != null) {
|
|
|
|
this._statusLabel.text = text;
|
|
|
|
this._statusBin.child = this._statusLabel;
|
2019-04-11 20:19:31 -04:00
|
|
|
this.reactive = false;
|
|
|
|
this.accessible_role = Atk.Role.MENU_ITEM;
|
2011-04-21 10:44:28 -04:00
|
|
|
} else {
|
2019-04-12 17:04:16 -04:00
|
|
|
this._statusBin.child = this._switch;
|
2019-04-11 20:19:31 -04:00
|
|
|
this.reactive = true;
|
|
|
|
this.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();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-04-21 10:44:28 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
activate(event) {
|
2019-04-12 17:04:16 -04:00
|
|
|
if (this._switch.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;
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
super.activate(event);
|
|
|
|
}
|
2010-06-17 08:17:01 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
toggle() {
|
2010-06-17 08:17:01 -04:00
|
|
|
this._switch.toggle();
|
|
|
|
this.emit('toggled', this._switch.state);
|
2012-01-20 12:10:45 -05:00
|
|
|
this.checkAccessibleState();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-06-17 08:17:01 -04:00
|
|
|
|
|
|
|
get state() {
|
|
|
|
return this._switch.state;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-06-17 08:17:01 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setToggleState(state) {
|
2020-01-21 08:52:15 -05:00
|
|
|
this._switch.state = state;
|
2012-01-20 12:10:45 -05:00
|
|
|
this.checkAccessibleState();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-01-20 12:10:45 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
checkAccessibleState() {
|
2019-04-11 20:19:31 -04:00
|
|
|
switch (this.accessible_role) {
|
2012-01-20 12:10:45 -05:00
|
|
|
case Atk.Role.CHECK_MENU_ITEM:
|
|
|
|
if (this._switch.state)
|
2019-04-11 20:19:31 -04:00
|
|
|
this.add_accessible_state(Atk.StateType.CHECKED);
|
2012-01-20 12:10:45 -05:00
|
|
|
else
|
2019-04-11 20:19:31 -04:00
|
|
|
this.remove_accessible_state(Atk.StateType.CHECKED);
|
2012-01-20 12:10:45 -05:00
|
|
|
break;
|
|
|
|
default:
|
2019-04-11 20:19:31 -04:00
|
|
|
this.remove_accessible_state(Atk.StateType.CHECKED);
|
2012-01-20 12:10:45 -05:00
|
|
|
}
|
2010-06-17 08:17:01 -04:00
|
|
|
}
|
2019-04-11 20:19:31 -04:00
|
|
|
});
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2023-07-10 05:53:00 -04:00
|
|
|
export const PopupImageMenuItem = GObject.registerClass(
|
2019-04-11 20:19:31 -04:00
|
|
|
class PopupImageMenuItem extends PopupBaseMenuItem {
|
|
|
|
_init(text, icon, params) {
|
|
|
|
super._init(params);
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2020-03-29 17:51:13 -04:00
|
|
|
this._icon = new St.Icon({
|
|
|
|
style_class: 'popup-menu-icon',
|
|
|
|
x_align: Clutter.ActorAlign.END,
|
|
|
|
});
|
2019-04-11 20:19:31 -04:00
|
|
|
this.add_child(this._icon);
|
2022-01-18 02:47:25 -05:00
|
|
|
this.label = new St.Label({
|
|
|
|
text,
|
|
|
|
y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
|
|
|
});
|
2019-04-11 20:19:31 -04:00
|
|
|
this.add_child(this.label);
|
|
|
|
this.label_actor = this.label;
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2023-05-16 19:33:19 -04:00
|
|
|
this.set_child_above_sibling(this._ornamentIcon, this.label);
|
2022-07-23 11:04:57 -04:00
|
|
|
|
2017-05-08 06:36:35 -04:00
|
|
|
this.setIcon(icon);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setIcon(icon) {
|
2017-05-08 06:36:35 -04:00
|
|
|
// The 'icon' parameter can be either a Gio.Icon or a string.
|
2017-10-15 18:09:52 -04:00
|
|
|
if (icon instanceof GObject.Object && GObject.type_is_a(icon, Gio.Icon))
|
2017-05-08 06:36:35 -04:00
|
|
|
this._icon.gicon = icon;
|
|
|
|
else
|
|
|
|
this._icon.icon_name = icon;
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
2023-08-01 12:13:10 -04:00
|
|
|
|
|
|
|
_updateOrnamentStyle() {
|
|
|
|
// we move the ornament after the label, so we don't need
|
|
|
|
// additional padding regardless of ornament visibility
|
|
|
|
}
|
2019-04-11 20:19:31 -04:00
|
|
|
});
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2023-07-10 05:53:00 -04:00
|
|
|
export class PopupMenuBase extends Signals.EventEmitter {
|
2017-10-30 21:19:44 -04:00
|
|
|
constructor(sourceActor, styleClass) {
|
2022-07-04 18:30:44 -04:00
|
|
|
super();
|
|
|
|
|
2019-04-18 16:55:34 -04:00
|
|
|
if (this.constructor === PopupMenuBase)
|
2022-02-07 09:14:06 -05:00
|
|
|
throw new TypeError(`Cannot instantiate abstract class ${this.constructor.name}`);
|
2010-05-20 11:18:46 -04:00
|
|
|
|
|
|
|
this.sourceActor = sourceActor;
|
2019-09-12 23:15:41 -04:00
|
|
|
this.focusActor = sourceActor;
|
2013-07-08 15:19:34 -04:00
|
|
|
this._parent = null;
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2019-10-17 17:40:24 -04:00
|
|
|
this.box = new St.BoxLayout({
|
|
|
|
vertical: true,
|
|
|
|
x_expand: true,
|
|
|
|
y_expand: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (styleClass !== undefined)
|
|
|
|
this.box.style_class = styleClass;
|
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
|
|
|
|
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;
|
|
|
|
|
2021-08-15 18:36:59 -04:00
|
|
|
Main.sessionMode.connectObject('updated', () => this._sessionUpdated(), this);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-09-01 08:42:53 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getTopMenu() {
|
2013-07-08 15:19:34 -04:00
|
|
|
if (this._parent)
|
|
|
|
return this._parent._getTopMenu();
|
|
|
|
else
|
|
|
|
return this;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-07-08 15:19:34 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_setParent(parent) {
|
2013-07-15 18:47:16 -04:00
|
|
|
this._parent = parent;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-07-15 18:47:16 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getSensitive() {
|
2020-08-12 14:59:01 -04:00
|
|
|
const parentSensitive = this._parent?.sensitive ?? true;
|
2013-07-15 18:54:15 -04:00
|
|
|
return this._sensitive && parentSensitive;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-06-12 03:16:53 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setSensitive(sensitive) {
|
2013-06-12 03:16:53 -04:00
|
|
|
this._sensitive = sensitive;
|
2019-04-17 19:36:01 -04:00
|
|
|
this.emit('notify::sensitive');
|
|
|
|
}
|
|
|
|
|
|
|
|
get sensitive() {
|
|
|
|
return this.getSensitive();
|
|
|
|
}
|
|
|
|
|
|
|
|
set sensitive(sensitive) {
|
|
|
|
this.setSensitive(sensitive);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-06-12 03:16:53 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sessionUpdated() {
|
2012-09-01 08:42:53 -04:00
|
|
|
this._setSettingsVisibility(Main.sessionMode.allowSettings);
|
2017-09-14 11:12:12 -04:00
|
|
|
this.close();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
addAction(title, callback, icon) {
|
2017-05-08 06:38:16 -04:00
|
|
|
let menuItem;
|
|
|
|
if (icon != undefined)
|
|
|
|
menuItem = new PopupImageMenuItem(title, icon);
|
|
|
|
else
|
|
|
|
menuItem = new PopupMenuItem(title);
|
|
|
|
|
2010-05-20 11:18:46 -04:00
|
|
|
this.addMenuItem(menuItem);
|
2019-08-19 20:20:08 -04:00
|
|
|
menuItem.connect('activate', (o, event) => {
|
2010-05-20 11:18:46 -04:00
|
|
|
callback(event);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2011-08-23 10:14:55 -04:00
|
|
|
|
|
|
|
return menuItem;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-08-23 10:14:55 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
addSettingsAction(title, desktopFile) {
|
2017-10-30 20:38:18 -04:00
|
|
|
let menuItem = this.addAction(title, () => {
|
|
|
|
let app = Shell.AppSystem.get_default().lookup_app(desktopFile);
|
2011-08-23 10:14:55 -04:00
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
if (!app) {
|
2022-02-07 09:14:06 -05:00
|
|
|
log(`Settings panel for desktop file ${desktopFile} could not be loaded!`);
|
2017-10-30 20:38:18 -04:00
|
|
|
return;
|
|
|
|
}
|
2011-08-23 10:14:55 -04:00
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
Main.overview.hide();
|
2022-07-29 20:24:40 -04:00
|
|
|
Main.panel.closeQuickSettings();
|
2017-10-30 20:38:18 -04:00
|
|
|
app.activate();
|
|
|
|
});
|
2012-05-22 18:27:06 -04:00
|
|
|
|
2019-04-11 20:19:31 -04:00
|
|
|
menuItem.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;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_setSettingsVisibility(visible) {
|
2012-05-22 18:27:06 -04:00
|
|
|
for (let id in this._settingsActions) {
|
|
|
|
let item = this._settingsActions[id];
|
2019-04-11 20:19:31 -04:00
|
|
|
item.visible = visible;
|
2012-05-22 18:27:06 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-05-22 18:27:06 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
isEmpty() {
|
2017-10-30 20:38:18 -04:00
|
|
|
let hasVisibleChildren = this.box.get_children().some(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;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-11-15 08:58:55 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
itemActivated(animate) {
|
2013-06-18 04:46:44 -04:00
|
|
|
if (animate == undefined)
|
|
|
|
animate = BoxPointer.PopupAnimation.FULL;
|
|
|
|
|
|
|
|
this._getTopMenu().close(animate);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-06-18 04:46:44 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_subMenuActiveChanged(submenu, submenuItem) {
|
2013-06-11 19:18:06 -04:00
|
|
|
if (this._activeMenuItem && this._activeMenuItem != submenuItem)
|
2019-04-17 19:15:56 -04:00
|
|
|
this._activeMenuItem.active = false;
|
2013-06-11 19:18:06 -04:00
|
|
|
this._activeMenuItem = submenuItem;
|
|
|
|
this.emit('active-changed', submenuItem);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-25 16:04:57 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_connectItemSignals(menuItem) {
|
2021-08-15 18:36:59 -04:00
|
|
|
menuItem.connectObject(
|
|
|
|
'notify::active', () => {
|
|
|
|
const { active } = menuItem;
|
|
|
|
if (active && this._activeMenuItem !== menuItem) {
|
|
|
|
if (this._activeMenuItem)
|
|
|
|
this._activeMenuItem.active = false;
|
|
|
|
this._activeMenuItem = menuItem;
|
|
|
|
this.emit('active-changed', menuItem);
|
|
|
|
} else if (!active && this._activeMenuItem === menuItem) {
|
|
|
|
this._activeMenuItem = null;
|
|
|
|
this.emit('active-changed', null);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'notify::sensitive', () => {
|
|
|
|
const { sensitive } = menuItem;
|
|
|
|
if (!sensitive && this._activeMenuItem === menuItem) {
|
|
|
|
if (!this.actor.navigate_focus(menuItem.actor,
|
|
|
|
St.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();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'activate', () => {
|
|
|
|
this.emit('activate', menuItem);
|
|
|
|
this.itemActivated(BoxPointer.PopupAnimation.FULL);
|
|
|
|
}, GObject.ConnectFlags.AFTER,
|
|
|
|
'destroy', () => {
|
|
|
|
if (menuItem === this._activeMenuItem)
|
|
|
|
this._activeMenuItem = null;
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.connectObject('notify::sensitive',
|
|
|
|
() => menuItem.syncSensitive(), menuItem);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateSeparatorVisibility(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--;
|
|
|
|
|
2019-08-19 15:33:15 -04:00
|
|
|
if (childBeforeIndex < 0 ||
|
|
|
|
children[childBeforeIndex]._delegate instanceof PopupSeparatorMenuItem) {
|
2011-08-19 14:42:20 -04:00
|
|
|
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++;
|
|
|
|
|
2019-08-19 15:33:15 -04:00
|
|
|
if (childAfterIndex >= children.length ||
|
|
|
|
children[childAfterIndex]._delegate instanceof PopupSeparatorMenuItem) {
|
2011-08-19 14:42:20 -04:00
|
|
|
menuItem.actor.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-11 20:19:31 -04:00
|
|
|
menuItem.show();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-08-19 14:42:20 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
moveMenuItem(menuItem, position) {
|
2017-02-13 10:02:02 -05:00
|
|
|
let items = this._getMenuItems();
|
|
|
|
let i = 0;
|
|
|
|
|
|
|
|
while (i < items.length && position > 0) {
|
2019-01-29 14:36:54 -05:00
|
|
|
if (items[i] != menuItem)
|
|
|
|
position--;
|
|
|
|
i++;
|
2017-02-13 10:02:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i < items.length) {
|
2019-01-29 14:36:54 -05:00
|
|
|
if (items[i] != menuItem)
|
|
|
|
this.box.set_child_below_sibling(menuItem.actor, items[i].actor);
|
2017-02-13 10:02:02 -05:00
|
|
|
} else {
|
2019-01-29 14:36:54 -05:00
|
|
|
this.box.set_child_above_sibling(menuItem.actor, null);
|
2017-02-13 10:02:02 -05:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2017-02-13 10:02:02 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
addMenuItem(menuItem, position) {
|
2019-01-31 08:43:52 -05:00
|
|
|
let beforeItem = null;
|
2011-01-25 16:04:57 -05:00
|
|
|
if (position == undefined) {
|
|
|
|
this.box.add(menuItem.actor);
|
|
|
|
} else {
|
|
|
|
let items = this._getMenuItems();
|
|
|
|
if (position < items.length) {
|
2019-01-31 08:43:52 -05:00
|
|
|
beforeItem = items[position].actor;
|
|
|
|
this.box.insert_child_below(menuItem.actor, beforeItem);
|
2012-02-13 15:27:16 -05:00
|
|
|
} 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) {
|
2021-08-15 18:36:59 -04:00
|
|
|
menuItem.connectObject(
|
|
|
|
'active-changed', this._subMenuActiveChanged.bind(this),
|
|
|
|
'destroy', () => this.length--, this);
|
|
|
|
|
|
|
|
this.connectObject(
|
|
|
|
'open-state-changed', (self, open) => {
|
|
|
|
if (open)
|
|
|
|
menuItem.open();
|
|
|
|
else
|
|
|
|
menuItem.close();
|
|
|
|
},
|
|
|
|
'menu-closed', () => menuItem.emit('menu-closed'),
|
|
|
|
'notify::sensitive', () => menuItem.emit('notify::sensitive'),
|
|
|
|
menuItem);
|
2011-01-25 16:04:57 -05:00
|
|
|
} else if (menuItem instanceof PopupSubMenuMenuItem) {
|
2019-01-31 08:43:52 -05:00
|
|
|
if (beforeItem == null)
|
2011-01-25 16:04:57 -05:00
|
|
|
this.box.add(menuItem.menu.actor);
|
|
|
|
else
|
2019-01-31 08:43:52 -05:00
|
|
|
this.box.insert_child_below(menuItem.menu.actor, beforeItem);
|
2013-06-11 19:18:06 -04:00
|
|
|
|
2011-01-25 16:04:57 -05:00
|
|
|
this._connectItemSignals(menuItem);
|
2021-08-15 18:36:59 -04:00
|
|
|
menuItem.menu.connectObject('active-changed',
|
|
|
|
this._subMenuActiveChanged.bind(this), this);
|
|
|
|
this.connectObject('menu-closed', () => {
|
2013-06-12 17:38:02 -04:00
|
|
|
menuItem.menu.close(BoxPointer.PopupAnimation.NONE);
|
2021-08-15 18:36:59 -04:00
|
|
|
}, menuItem);
|
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.
|
2021-08-15 18:36:59 -04:00
|
|
|
this.connectObject('open-state-changed', () => {
|
2017-10-30 20:38:18 -04:00
|
|
|
this._updateSeparatorVisibility(menuItem);
|
2021-08-15 18:36:59 -04:00
|
|
|
}, menuItem);
|
2019-08-19 20:51:42 -04:00
|
|
|
} else if (menuItem instanceof PopupBaseMenuItem) {
|
2011-01-25 16:04:57 -05:00
|
|
|
this._connectItemSignals(menuItem);
|
2019-08-19 20:51:42 -04:00
|
|
|
} else {
|
2011-01-25 16:04:57 -05:00
|
|
|
throw TypeError("Invalid argument to PopupMenuBase.addMenuItem()");
|
2019-08-19 20:51:42 -04:00
|
|
|
}
|
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++;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-25 16:04:57 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getMenuItems() {
|
2017-10-30 20:38:18 -04:00
|
|
|
return this.box.get_children().map(a => a._delegate).filter(item => {
|
2011-01-25 16:04:57 -05:00
|
|
|
return item instanceof PopupBaseMenuItem || item instanceof PopupMenuSection;
|
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
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;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-06-27 11:45:24 -04:00
|
|
|
|
2011-07-20 23:17:05 -04:00
|
|
|
get numMenuItems() {
|
|
|
|
return this._getMenuItems().length;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-07-20 23:17:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
removeAll() {
|
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
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
toggle() {
|
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);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
destroy() {
|
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
|
|
|
|
2021-08-15 18:36:59 -04:00
|
|
|
Main.sessionMode.disconnectObject(this);
|
2010-11-01 11:03:28 -04:00
|
|
|
}
|
2023-07-10 05:53:00 -04:00
|
|
|
}
|
2010-06-12 12:13:04 -04:00
|
|
|
|
2023-07-10 05:53:00 -04:00
|
|
|
export class PopupMenu extends PopupMenuBase {
|
2017-10-30 21:19:44 -04:00
|
|
|
constructor(sourceActor, arrowAlignment, arrowSide) {
|
|
|
|
super(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
|
|
|
|
2019-10-17 17:40:24 -04:00
|
|
|
this._boxPointer = new BoxPointer.BoxPointer(arrowSide);
|
2018-08-21 06:38:23 -04:00
|
|
|
this.actor = this._boxPointer;
|
2010-11-01 11:03:28 -04:00
|
|
|
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
|
|
|
|
2019-08-19 20:51:42 -04:00
|
|
|
if (this.sourceActor) {
|
2021-08-15 18:36:59 -04:00
|
|
|
this.sourceActor.connectObject(
|
|
|
|
'key-press-event', this._onKeyPress.bind(this),
|
|
|
|
'notify::mapped', () => {
|
2019-12-16 19:01:13 -05:00
|
|
|
if (!this.sourceActor.mapped)
|
|
|
|
this.close();
|
2021-08-15 18:36:59 -04:00
|
|
|
}, this);
|
2019-08-19 20:51:42 -04:00
|
|
|
}
|
2014-08-28 11:04:23 -04:00
|
|
|
|
2019-12-06 12:07:35 -05:00
|
|
|
this._systemModalOpenedId = 0;
|
2013-06-11 19:12:46 -04:00
|
|
|
this._openedSubMenu = null;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-06-11 19:12:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_setOpenedSubMenu(submenu) {
|
2013-06-11 19:12:46 -04:00
|
|
|
if (this._openedSubMenu)
|
|
|
|
this._openedSubMenu.close(true);
|
|
|
|
|
|
|
|
this._openedSubMenu = submenu;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-11-01 11:03:28 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onKeyPress(actor, event) {
|
2017-03-24 22:26:06 -04:00
|
|
|
// Disable toggling the menu by keyboard
|
|
|
|
// when it cannot be toggled by pointer
|
|
|
|
if (!actor.reactive)
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
2014-08-28 11:27:00 -04:00
|
|
|
let navKey;
|
|
|
|
switch (this._boxPointer.arrowSide) {
|
2019-02-01 07:21:00 -05:00
|
|
|
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;
|
2014-08-28 11:27:00 -04:00
|
|
|
}
|
|
|
|
|
2016-10-26 10:46:21 -04:00
|
|
|
let state = event.get_state();
|
|
|
|
|
2020-07-21 10:33:04 -04:00
|
|
|
// if user has a modifier down (except capslock and numlock)
|
2016-10-26 10:46:21 -04:00
|
|
|
// then don't handle the key press here
|
|
|
|
state &= ~Clutter.ModifierType.LOCK_MASK;
|
2020-07-21 10:33:04 -04:00
|
|
|
state &= ~Clutter.ModifierType.MOD2_MASK;
|
2016-10-26 10:46:21 -04:00
|
|
|
state &= Clutter.ModifierType.MODIFIER_MASK;
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
2014-08-28 11:04:23 -04:00
|
|
|
let symbol = event.get_key_symbol();
|
2021-11-17 19:22:33 -05:00
|
|
|
|
2014-08-28 11:04:23 -04:00
|
|
|
if (symbol == Clutter.KEY_space || symbol == Clutter.KEY_Return) {
|
|
|
|
this.toggle();
|
|
|
|
return Clutter.EVENT_STOP;
|
2014-08-28 11:27:00 -04:00
|
|
|
} else if (symbol == navKey) {
|
2014-08-28 11:04:23 -04:00
|
|
|
if (!this.isOpen)
|
|
|
|
this.toggle();
|
2018-11-27 07:58:25 -05:00
|
|
|
this.actor.navigate_focus(null, St.DirectionType.TAB_FORWARD, false);
|
2014-08-28 11:04:23 -04:00
|
|
|
return Clutter.EVENT_STOP;
|
2019-01-29 16:02:57 -05:00
|
|
|
} else {
|
2014-08-28 11:04:23 -04:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2019-01-29 16:02:57 -05:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-08-28 11:04:23 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setArrowOrigin(origin) {
|
2010-11-01 11:03:28 -04:00
|
|
|
this._boxPointer.setArrowOrigin(origin);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-11-01 11:03:28 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setSourceAlignment(alignment) {
|
2011-09-14 18:14:03 -04:00
|
|
|
this._boxPointer.setSourceAlignment(alignment);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-09-14 18:14:03 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
open(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;
|
|
|
|
|
2019-12-06 12:07:35 -05:00
|
|
|
if (!this._systemModalOpenedId) {
|
|
|
|
this._systemModalOpenedId =
|
|
|
|
Main.layoutManager.connect('system-modal-opened', () => this.close());
|
|
|
|
}
|
|
|
|
|
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);
|
2018-08-21 06:29:44 -04:00
|
|
|
this._boxPointer.open(animate);
|
2010-11-01 11:03:28 -04:00
|
|
|
|
2019-11-05 14:17:19 -05:00
|
|
|
this.actor.get_parent().set_child_above_sibling(this.actor, null);
|
2011-08-29 12:04:17 -04:00
|
|
|
|
2010-05-20 11:18:46 -04:00
|
|
|
this.emit('open-state-changed', true);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
close(animate) {
|
2010-07-03 19:47:31 -04:00
|
|
|
if (this._activeMenuItem)
|
2019-04-17 19:15:56 -04:00
|
|
|
this._activeMenuItem.active = false;
|
2010-11-01 11:03:28 -04:00
|
|
|
|
2019-04-09 16:21:15 -04:00
|
|
|
if (this._boxPointer.visible) {
|
2018-08-21 06:29:44 -04:00
|
|
|
this._boxPointer.close(animate, () => {
|
2013-06-12 17:38:02 -04:00
|
|
|
this.emit('menu-closed');
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2013-06-12 17:38:02 -04:00
|
|
|
}
|
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);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-08-28 11:04:23 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
destroy() {
|
2021-08-15 18:36:59 -04:00
|
|
|
this.sourceActor?.disconnectObject(this);
|
2019-12-16 19:01:13 -05:00
|
|
|
|
2019-12-06 12:07:35 -05:00
|
|
|
if (this._systemModalOpenedId)
|
|
|
|
Main.layoutManager.disconnect(this._systemModalOpenedId);
|
|
|
|
this._systemModalOpenedId = 0;
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
super.destroy();
|
2010-11-01 11:03:28 -04:00
|
|
|
}
|
2023-07-10 05:53:00 -04:00
|
|
|
}
|
2012-12-04 14:52:34 -05:00
|
|
|
|
2023-07-10 05:53:00 -04:00
|
|
|
export class PopupDummyMenu extends Signals.EventEmitter {
|
2017-10-30 21:19:44 -04:00
|
|
|
constructor(sourceActor) {
|
2022-07-04 18:30:44 -04:00
|
|
|
super();
|
|
|
|
|
2012-12-04 14:52:34 -05:00
|
|
|
this.sourceActor = sourceActor;
|
|
|
|
this.actor = sourceActor;
|
|
|
|
this.actor._delegate = this;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-12-04 14:52:34 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getSensitive() {
|
2013-06-12 03:16:53 -04:00
|
|
|
return true;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-06-12 03:16:53 -04:00
|
|
|
|
2019-04-17 19:36:01 -04:00
|
|
|
get sensitive() {
|
|
|
|
return this.getSensitive();
|
|
|
|
}
|
|
|
|
|
2019-06-29 11:47:33 -04:00
|
|
|
open() {
|
2022-02-13 08:05:41 -05:00
|
|
|
if (this.isOpen)
|
|
|
|
return;
|
|
|
|
this.isOpen = true;
|
2019-06-29 11:47:33 -04:00
|
|
|
this.emit('open-state-changed', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
close() {
|
2022-02-13 08:05:41 -05:00
|
|
|
if (!this.isOpen)
|
|
|
|
return;
|
|
|
|
this.isOpen = false;
|
2019-06-29 11:47:33 -04:00
|
|
|
this.emit('open-state-changed', false);
|
|
|
|
}
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
toggle() {}
|
2019-06-29 11:47:33 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
destroy() {
|
2012-12-04 14:52:34 -05:00
|
|
|
this.emit('destroy');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2023-07-10 05:53:00 -04:00
|
|
|
}
|
2012-12-04 14:52:34 -05:00
|
|
|
|
2023-07-10 05:53:00 -04:00
|
|
|
export class PopupSubMenu extends PopupMenuBase {
|
2017-10-30 21:19:44 -04:00
|
|
|
constructor(sourceActor, sourceArrow) {
|
|
|
|
super(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.
|
2020-03-29 17:51:13 -04:00
|
|
|
this.actor = new St.ScrollView({
|
|
|
|
style_class: 'popup-sub-menu',
|
|
|
|
hscrollbar_policy: St.PolicyType.NEVER,
|
|
|
|
vscrollbar_policy: St.PolicyType.NEVER,
|
|
|
|
});
|
2011-04-02 12:35:03 -04:00
|
|
|
|
|
|
|
this.actor.add_actor(this.box);
|
2010-11-01 11:03:28 -04:00
|
|
|
this.actor._delegate = this;
|
|
|
|
this.actor.clip_to_allocation = true;
|
2017-12-01 19:27:35 -05:00
|
|
|
this.actor.connect('key-press-event', this._onKeyPressEvent.bind(this));
|
2010-11-01 11:03:28 -04:00
|
|
|
this.actor.hide();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_needsScrollbar() {
|
2011-04-02 12:35:03 -04:00
|
|
|
let topMenu = this._getTopMenu();
|
2019-02-01 08:41:55 -05:00
|
|
|
let [, topNaturalHeight] = topMenu.actor.get_preferred_height(-1);
|
2011-04-02 12:35:03 -04:00
|
|
|
let topThemeNode = topMenu.actor.get_theme_node();
|
|
|
|
|
|
|
|
let topMaxHeight = topThemeNode.get_max_height();
|
|
|
|
return topMaxHeight >= 0 && topNaturalHeight >= topMaxHeight;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-04-02 12:35:03 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getSensitive() {
|
2019-04-17 19:36:01 -04:00
|
|
|
return this._sensitive && this.sourceActor.sensitive;
|
|
|
|
}
|
|
|
|
|
|
|
|
get sensitive() {
|
|
|
|
return this.getSensitive();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-06-12 03:16:53 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
open(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 =
|
2018-11-27 07:45:36 -05:00
|
|
|
needsScrollbar ? St.PolicyType.AUTOMATIC : St.PolicyType.NEVER;
|
2011-04-02 12:35:03 -04:00
|
|
|
|
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;
|
|
|
|
|
2014-09-09 13:00:13 -04:00
|
|
|
let targetAngle = this.actor.text_direction == Clutter.TextDirection.RTL ? -90 : 90;
|
|
|
|
|
2011-04-02 12:35:03 -04:00
|
|
|
if (animate) {
|
2019-02-01 08:41:55 -05:00
|
|
|
let [, naturalHeight] = this.actor.get_preferred_height(-1);
|
2011-04-02 12:35:03 -04:00
|
|
|
this.actor.height = 0;
|
2018-07-20 15:46:19 -04:00
|
|
|
this.actor.ease({
|
|
|
|
height: naturalHeight,
|
|
|
|
duration: 250,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_EXPO,
|
2019-08-20 17:43:54 -04:00
|
|
|
onComplete: () => this.actor.set_height(-1),
|
2018-07-20 15:46:19 -04:00
|
|
|
});
|
|
|
|
this._arrow.ease({
|
|
|
|
rotation_angle_z: targetAngle,
|
|
|
|
duration: 250,
|
2019-08-20 17:43:54 -04:00
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_EXPO,
|
2018-07-20 15:46:19 -04:00
|
|
|
});
|
2011-04-02 12:35:03 -04:00
|
|
|
} else {
|
2014-09-09 13:00:13 -04:00
|
|
|
this._arrow.rotation_angle_z = targetAngle;
|
2011-04-02 12:35:03 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
close(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)
|
2019-04-17 19:15:56 -04:00
|
|
|
this._activeMenuItem.active = 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) {
|
2018-07-20 15:46:19 -04:00
|
|
|
this.actor.ease({
|
|
|
|
height: 0,
|
|
|
|
duration: 250,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_EXPO,
|
|
|
|
onComplete: () => {
|
|
|
|
this.actor.hide();
|
|
|
|
this.actor.set_height(-1);
|
2019-08-20 17:43:54 -04:00
|
|
|
},
|
2018-07-20 15:46:19 -04:00
|
|
|
});
|
|
|
|
this._arrow.ease({
|
|
|
|
rotation_angle_z: 0,
|
|
|
|
duration: 250,
|
2019-08-20 17:43:54 -04:00
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_EXPO,
|
2018-07-20 15:46:19 -04:00
|
|
|
});
|
2013-08-22 14:07:32 -04:00
|
|
|
} else {
|
2014-09-09 13:00:13 -04:00
|
|
|
this._arrow.rotation_angle_z = 0;
|
2013-08-22 14:07:32 -04:00
|
|
|
this.actor.hide();
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-07-03 19:47:31 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onKeyPressEvent(actor, event) {
|
2010-11-01 11:03:28 -04:00
|
|
|
// 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);
|
2019-04-17 19:15:56 -04:00
|
|
|
this.sourceActor._delegate.active = true;
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_STOP;
|
2010-11-01 11:03:28 -04:00
|
|
|
}
|
|
|
|
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
2023-07-10 05:53:00 -04: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
|
|
|
|
*/
|
2023-07-10 05:53:00 -04:00
|
|
|
export class PopupMenuSection extends PopupMenuBase {
|
2017-10-30 21:19:44 -04:00
|
|
|
constructor() {
|
|
|
|
super();
|
2011-01-25 16:04:57 -05:00
|
|
|
|
|
|
|
this.actor = this.box;
|
|
|
|
this.actor._delegate = this;
|
|
|
|
this.isOpen = true;
|
2022-01-25 09:47:23 -05:00
|
|
|
|
|
|
|
this.actor.add_style_class_name('popup-menu-section');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-25 16:04:57 -05:00
|
|
|
|
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
|
2019-06-29 11:47:33 -04:00
|
|
|
open() {
|
|
|
|
this.emit('open-state-changed', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
close() {
|
|
|
|
this.emit('open-state-changed', false);
|
|
|
|
}
|
2023-07-10 05:53:00 -04:00
|
|
|
}
|
2010-07-03 19:47:31 -04:00
|
|
|
|
2023-07-10 05:53:00 -04:00
|
|
|
export const PopupSubMenuMenuItem = GObject.registerClass(
|
2019-04-11 20:19:31 -04:00
|
|
|
class PopupSubMenuMenuItem extends PopupBaseMenuItem {
|
|
|
|
_init(text, wantIcon) {
|
|
|
|
super._init();
|
2010-11-01 11:03:28 -04:00
|
|
|
|
2019-04-11 20:19:31 -04:00
|
|
|
this.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' });
|
2019-04-11 20:19:31 -04:00
|
|
|
this.add_child(this.icon);
|
2013-06-06 14:17:41 -04:00
|
|
|
}
|
|
|
|
|
2020-03-29 17:51:13 -04:00
|
|
|
this.label = new St.Label({
|
|
|
|
text,
|
|
|
|
y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
|
|
|
});
|
2019-04-11 20:19:31 -04:00
|
|
|
this.add_child(this.label);
|
|
|
|
this.label_actor = this.label;
|
2013-06-06 14:17:41 -04:00
|
|
|
|
2019-10-21 14:44:00 -04:00
|
|
|
let expander = new St.Bin({
|
|
|
|
style_class: 'popup-menu-item-expander',
|
|
|
|
x_expand: true,
|
|
|
|
});
|
|
|
|
this.add_child(expander);
|
2013-07-15 20:00:41 -04:00
|
|
|
|
2014-02-18 07:45:26 -05:00
|
|
|
this._triangle = arrowIcon(St.Side.RIGHT);
|
2019-02-20 14:54:29 -05:00
|
|
|
this._triangle.pivot_point = new Graphene.Point({ x: 0.5, y: 0.6 });
|
2013-07-16 16:26:39 -04:00
|
|
|
|
2020-03-29 17:51:13 -04:00
|
|
|
this._triangleBin = new St.Widget({
|
|
|
|
y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
|
|
|
});
|
2013-07-16 16:26:39 -04:00
|
|
|
this._triangleBin.add_child(this._triangle);
|
2013-08-19 10:02:22 -04:00
|
|
|
|
2019-04-11 20:19:31 -04:00
|
|
|
this.add_child(this._triangleBin);
|
|
|
|
this.add_accessible_state(Atk.StateType.EXPANDABLE);
|
2010-07-03 19:47:31 -04:00
|
|
|
|
2019-04-11 20:19:31 -04:00
|
|
|
this.menu = new PopupSubMenu(this, this._triangle);
|
2017-12-01 19:27:35 -05:00
|
|
|
this.menu.connect('open-state-changed', this._subMenuOpenStateChanged.bind(this));
|
2019-01-27 19:42:00 -05:00
|
|
|
this.connect('destroy', () => this.menu.destroy());
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-07-03 19:47:31 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_setParent(parent) {
|
2017-10-30 21:19:44 -04:00
|
|
|
super._setParent(parent);
|
2013-07-15 18:47:16 -04:00
|
|
|
this.menu._setParent(parent);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-07-15 18:47:16 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
syncSensitive() {
|
2017-10-30 21:19:44 -04:00
|
|
|
let sensitive = super.syncSensitive();
|
2013-06-12 03:35:28 -04:00
|
|
|
this._triangle.visible = sensitive;
|
|
|
|
if (!sensitive)
|
|
|
|
this.menu.close(false);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-06-12 03:35:28 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_subMenuOpenStateChanged(menu, open) {
|
2013-07-15 19:38:05 -04:00
|
|
|
if (open) {
|
2019-04-11 20:19:31 -04:00
|
|
|
this.add_style_pseudo_class('open');
|
2013-07-15 19:38:05 -04:00
|
|
|
this._getTopMenu()._setOpenedSubMenu(this.menu);
|
2019-04-11 20:19:31 -04:00
|
|
|
this.add_accessible_state(Atk.StateType.EXPANDED);
|
|
|
|
this.add_style_pseudo_class('checked');
|
2013-07-15 19:38:05 -04:00
|
|
|
} else {
|
2019-04-11 20:19:31 -04:00
|
|
|
this.remove_style_pseudo_class('open');
|
2013-07-15 19:38:05 -04:00
|
|
|
this._getTopMenu()._setOpenedSubMenu(null);
|
2019-08-19 13:55:49 -04:00
|
|
|
this.remove_accessible_state(Atk.StateType.EXPANDED);
|
2019-04-11 20:19:31 -04:00
|
|
|
this.remove_style_pseudo_class('checked');
|
2013-07-15 19:38:05 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-07-03 19:47:31 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setSubmenuShown(open) {
|
2013-05-10 14:32:58 -04:00
|
|
|
if (open)
|
|
|
|
this.menu.open(BoxPointer.PopupAnimation.FULL);
|
|
|
|
else
|
|
|
|
this.menu.close(BoxPointer.PopupAnimation.FULL);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-05-10 14:32:58 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_setOpenState(open) {
|
2013-05-14 13:58:10 -04:00
|
|
|
this.setSubmenuShown(open);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-05-10 14:32:58 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getOpenState() {
|
2013-05-10 14:32:58 -04:00
|
|
|
return this.menu.isOpen;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-05-10 14:32:58 -04:00
|
|
|
|
2019-09-10 01:42:48 -04:00
|
|
|
vfunc_key_press_event(keyPressEvent) {
|
|
|
|
let symbol = keyPressEvent.keyval;
|
2011-02-08 14:53:43 -05:00
|
|
|
|
|
|
|
if (symbol == Clutter.KEY_Right) {
|
2013-05-10 14:32:58 -04:00
|
|
|
this._setOpenState(true);
|
2018-11-27 07:58:25 -05:00
|
|
|
this.menu.actor.navigate_focus(null, St.DirectionType.DOWN, false);
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_STOP;
|
2013-05-10 14:32:58 -04:00
|
|
|
} else if (symbol == Clutter.KEY_Left && this._getOpenState()) {
|
|
|
|
this._setOpenState(false);
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_STOP;
|
2010-07-03 19:47:31 -04:00
|
|
|
}
|
2011-02-08 14:53:43 -05:00
|
|
|
|
2019-09-10 01:42:48 -04:00
|
|
|
return super.vfunc_key_press_event(keyPressEvent);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-07-03 19:47:31 -04:00
|
|
|
|
2019-02-04 06:30:53 -05:00
|
|
|
activate(_event) {
|
2013-05-10 14:32:58 -04:00
|
|
|
this._setOpenState(!this._getOpenState());
|
2010-07-03 19:47:31 -04:00
|
|
|
}
|
2019-04-11 20:19:31 -04: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
|
|
|
|
*/
|
2023-07-10 05:53:00 -04:00
|
|
|
export class PopupMenuManager {
|
2017-10-30 21:19:44 -04:00
|
|
|
constructor(owner, grabParams) {
|
2021-11-17 19:22:33 -05:00
|
|
|
this._grabParams = Params.parse(grabParams,
|
|
|
|
{ actionMode: Shell.ActionMode.POPUP });
|
|
|
|
global.stage.connect('notify::key-focus', () => {
|
|
|
|
if (!this.activeMenu)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let actor = global.stage.get_key_focus();
|
|
|
|
let newMenu = this._findMenuForSource(actor);
|
|
|
|
|
|
|
|
if (newMenu)
|
|
|
|
this._changeMenu(newMenu);
|
|
|
|
});
|
2010-05-20 11:18:46 -04:00
|
|
|
this._menus = [];
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
addMenu(menu, position) {
|
2021-08-15 18:36:59 -04:00
|
|
|
if (this._menus.includes(menu))
|
2012-09-01 08:42:53 -04:00
|
|
|
return;
|
|
|
|
|
2021-08-15 18:36:59 -04:00
|
|
|
menu.connectObject(
|
|
|
|
'open-state-changed', this._onMenuOpenState.bind(this),
|
|
|
|
'destroy', () => this.removeMenu(menu), this);
|
|
|
|
menu.actor.connectObject('captured-event',
|
|
|
|
this._onCapturedEvent.bind(this), this);
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-06-25 08:55:03 -04:00
|
|
|
if (position == undefined)
|
2021-08-15 18:36:59 -04:00
|
|
|
this._menus.push(menu);
|
2010-06-25 08:55:03 -04:00
|
|
|
else
|
2021-08-15 18:36:59 -04:00
|
|
|
this._menus.splice(position, 0, menu);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-06-25 08:55:03 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
removeMenu(menu) {
|
2021-11-25 04:49:42 -05:00
|
|
|
if (menu === this.activeMenu) {
|
|
|
|
Main.popModal(this._grab);
|
|
|
|
this._grab = null;
|
|
|
|
}
|
2010-07-03 19:47:31 -04:00
|
|
|
|
2021-08-15 18:36:59 -04:00
|
|
|
const position = this._menus.indexOf(menu);
|
2010-06-25 08:55:03 -04:00
|
|
|
if (position == -1) // not a menu we manage
|
|
|
|
return;
|
|
|
|
|
2021-08-15 18:36:59 -04:00
|
|
|
menu.disconnectObject(this);
|
|
|
|
menu.actor.disconnectObject(this);
|
2010-06-25 08:55:03 -04:00
|
|
|
|
|
|
|
this._menus.splice(position, 1);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
ignoreRelease() {
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onMenuOpenState(menu, open) {
|
2021-11-17 19:22:33 -05:00
|
|
|
if (open && this.activeMenu === menu)
|
|
|
|
return;
|
|
|
|
|
2011-07-12 15:47:37 -04:00
|
|
|
if (open) {
|
2022-02-09 09:32:56 -05:00
|
|
|
const oldMenu = this.activeMenu;
|
|
|
|
const oldGrab = this._grab;
|
2021-11-25 04:49:42 -05:00
|
|
|
this._grab = Main.pushModal(menu.actor, this._grabParams);
|
2021-11-17 19:22:33 -05:00
|
|
|
this.activeMenu = menu;
|
2022-02-09 09:32:56 -05:00
|
|
|
oldMenu?.close(BoxPointer.PopupAnimation.FADE);
|
|
|
|
if (oldGrab)
|
|
|
|
Main.popModal(oldGrab);
|
|
|
|
} else if (this.activeMenu === menu) {
|
|
|
|
this.activeMenu = null;
|
2021-11-25 04:49:42 -05:00
|
|
|
Main.popModal(this._grab);
|
|
|
|
this._grab = null;
|
2010-11-03 13:30:08 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-11-03 13:30:08 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_changeMenu(newMenu) {
|
2019-08-19 15:33:15 -04:00
|
|
|
newMenu.open(this.activeMenu
|
|
|
|
? BoxPointer.PopupAnimation.FADE
|
|
|
|
: BoxPointer.PopupAnimation.FULL);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2021-11-17 19:22:33 -05:00
|
|
|
_onCapturedEvent(actor, event) {
|
|
|
|
let menu = actor._delegate;
|
2022-02-25 07:09:33 -05:00
|
|
|
const targetActor = global.stage.get_event_actor(event);
|
|
|
|
|
2021-11-17 19:22:33 -05:00
|
|
|
if (event.type() === Clutter.EventType.KEY_PRESS) {
|
|
|
|
let symbol = event.get_key_symbol();
|
|
|
|
if (symbol === Clutter.KEY_Down &&
|
|
|
|
global.stage.get_key_focus() === menu.actor) {
|
|
|
|
actor.navigate_focus(null, St.DirectionType.TAB_FORWARD, false);
|
|
|
|
return Clutter.EVENT_STOP;
|
|
|
|
} else if (symbol === Clutter.KEY_Escape && menu.isOpen) {
|
|
|
|
menu.close(BoxPointer.PopupAnimation.FULL);
|
|
|
|
return Clutter.EVENT_STOP;
|
|
|
|
}
|
|
|
|
} else if (event.type() === Clutter.EventType.ENTER &&
|
2022-03-07 06:11:06 -05:00
|
|
|
(event.get_flags() & Clutter.EventFlags.FLAG_GRAB_NOTIFY) === 0) {
|
2022-02-25 07:09:33 -05:00
|
|
|
let hoveredMenu = this._findMenuForSource(targetActor);
|
2021-11-17 19:22:33 -05:00
|
|
|
|
|
|
|
if (hoveredMenu && hoveredMenu !== menu)
|
|
|
|
this._changeMenu(hoveredMenu);
|
|
|
|
} else if ((event.type() === Clutter.EventType.BUTTON_PRESS ||
|
|
|
|
event.type() === Clutter.EventType.TOUCH_BEGIN) &&
|
2022-02-25 07:09:33 -05:00
|
|
|
!actor.contains(targetActor)) {
|
2021-11-17 19:22:33 -05:00
|
|
|
menu.close(BoxPointer.PopupAnimation.FULL);
|
|
|
|
}
|
2011-07-12 15:47:37 -04:00
|
|
|
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2021-11-17 19:22:33 -05:00
|
|
|
_findMenuForSource(source) {
|
|
|
|
while (source) {
|
|
|
|
let actor = source;
|
2021-08-15 18:36:59 -04:00
|
|
|
const menu = this._menus.find(m => m.sourceActor === actor);
|
2021-11-17 19:22:33 -05:00
|
|
|
if (menu)
|
|
|
|
return menu;
|
|
|
|
source = source.get_parent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_closeMenu(isUser, menu) {
|
2012-12-10 03:55:14 -05: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 11:18:46 -04:00
|
|
|
}
|
2023-07-10 05:53:00 -04:00
|
|
|
}
|