2017-01-19 18:49:52 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
import Clutter from 'gi://Clutter';
|
|
|
|
import GLib from 'gi://GLib';
|
|
|
|
import GObject from 'gi://GObject';
|
|
|
|
import Meta from 'gi://Meta';
|
|
|
|
import Pango from 'gi://Pango';
|
|
|
|
import St from 'gi://St';
|
2017-01-19 18:49:52 +00:00
|
|
|
|
2020-01-19 22:20:02 +00:00
|
|
|
function _setLabel(label, value) {
|
|
|
|
label.set({
|
|
|
|
text: value || '',
|
|
|
|
visible: value !== null,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
export const Dialog = GObject.registerClass(
|
2017-10-31 01:23:39 +00:00
|
|
|
class Dialog extends St.Widget {
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(parentActor, styleClass) {
|
2022-01-28 10:59:51 +00:00
|
|
|
super._init({
|
|
|
|
layout_manager: new Clutter.BinLayout(),
|
|
|
|
reactive: true,
|
|
|
|
});
|
2017-12-02 00:27:35 +00:00
|
|
|
this.connect('destroy', this._onDestroy.bind(this));
|
2017-01-19 18:49:52 +00:00
|
|
|
|
2017-09-28 10:38:33 +00:00
|
|
|
this._initialKeyFocus = null;
|
2017-01-19 18:49:52 +00:00
|
|
|
this._pressedKey = null;
|
|
|
|
this._buttonKeys = {};
|
|
|
|
this._createDialog();
|
|
|
|
this.add_child(this._dialog);
|
|
|
|
|
|
|
|
if (styleClass != null)
|
|
|
|
this._dialog.add_style_class_name(styleClass);
|
|
|
|
|
|
|
|
this._parentActor = parentActor;
|
|
|
|
this._parentActor.add_child(this);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-01-19 18:49:52 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_createDialog() {
|
2019-12-05 08:54:38 +00:00
|
|
|
this._dialog = new St.BoxLayout({
|
|
|
|
style_class: 'modal-dialog',
|
|
|
|
x_align: Clutter.ActorAlign.CENTER,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
|
|
|
vertical: true,
|
|
|
|
});
|
2017-01-19 18:49:52 +00:00
|
|
|
|
|
|
|
// modal dialogs are fixed width and grow vertically; set the request
|
|
|
|
// mode accordingly so wrapped labels are handled correctly during
|
|
|
|
// size requests.
|
|
|
|
this._dialog.request_mode = Clutter.RequestMode.HEIGHT_FOR_WIDTH;
|
2018-04-06 10:26:58 +00:00
|
|
|
this._dialog.set_offscreen_redirect(Clutter.OffscreenRedirect.ALWAYS);
|
2017-01-19 18:49:52 +00:00
|
|
|
|
2019-10-21 18:44:00 +00:00
|
|
|
this.contentLayout = new St.BoxLayout({
|
|
|
|
vertical: true,
|
|
|
|
style_class: 'modal-dialog-content-box',
|
|
|
|
y_expand: true,
|
|
|
|
});
|
|
|
|
this._dialog.add_child(this.contentLayout);
|
2017-01-19 18:49:52 +00:00
|
|
|
|
2019-12-05 08:54:38 +00:00
|
|
|
this.buttonLayout = new St.Widget({
|
2023-08-06 22:40:20 +00:00
|
|
|
layout_manager: new Clutter.BoxLayout({homogeneous: true}),
|
2019-12-05 08:54:38 +00:00
|
|
|
});
|
2019-10-21 18:44:00 +00:00
|
|
|
this._dialog.add_child(this.buttonLayout);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-01-19 18:49:52 +00:00
|
|
|
|
2020-02-19 21:54:42 +00:00
|
|
|
makeInactive() {
|
|
|
|
this.buttonLayout.get_children().forEach(c => c.set_reactive(false));
|
|
|
|
}
|
|
|
|
|
|
|
|
_onDestroy() {
|
|
|
|
this.makeInactive();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-01-19 18:49:52 +00:00
|
|
|
|
2022-01-28 10:59:51 +00:00
|
|
|
vfunc_event(event) {
|
2023-08-07 00:51:19 +00:00
|
|
|
if (event.type() === Clutter.EventType.KEY_PRESS) {
|
2017-01-19 18:49:52 +00:00
|
|
|
this._pressedKey = event.get_key_symbol();
|
2023-08-07 00:51:19 +00:00
|
|
|
} else if (event.type() === Clutter.EventType.KEY_RELEASE) {
|
2017-01-19 18:49:52 +00:00
|
|
|
let pressedKey = this._pressedKey;
|
|
|
|
this._pressedKey = null;
|
|
|
|
|
|
|
|
let symbol = event.get_key_symbol();
|
2023-08-07 00:51:19 +00:00
|
|
|
if (symbol !== pressedKey)
|
2017-01-19 18:49:52 +00:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
let buttonInfo = this._buttonKeys[symbol];
|
|
|
|
if (!buttonInfo)
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
2023-08-06 22:40:20 +00:00
|
|
|
let {button, action} = buttonInfo;
|
2017-01-19 18:49:52 +00:00
|
|
|
|
|
|
|
if (action && button.reactive) {
|
|
|
|
action();
|
|
|
|
return Clutter.EVENT_STOP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-01-19 18:49:52 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_setInitialKeyFocus(actor) {
|
2021-08-15 22:36:59 +00:00
|
|
|
this._initialKeyFocus?.disconnectObject(this);
|
2017-10-05 08:06:10 +00:00
|
|
|
|
|
|
|
this._initialKeyFocus = actor;
|
|
|
|
|
2021-08-15 22:36:59 +00:00
|
|
|
actor.connectObject('destroy',
|
|
|
|
() => (this._initialKeyFocus = null), this);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-10-05 08:06:10 +00:00
|
|
|
|
2017-09-28 10:38:33 +00:00
|
|
|
get initialKeyFocus() {
|
|
|
|
return this._initialKeyFocus || this;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-09-28 10:38:33 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
addButton(buttonInfo) {
|
2023-08-06 22:40:20 +00:00
|
|
|
let {label, action, key} = buttonInfo;
|
2017-01-19 18:49:52 +00:00
|
|
|
let isDefault = buttonInfo['default'];
|
|
|
|
let keys;
|
|
|
|
|
|
|
|
if (key)
|
|
|
|
keys = [key];
|
|
|
|
else if (isDefault)
|
|
|
|
keys = [Clutter.KEY_Return, Clutter.KEY_KP_Enter, Clutter.KEY_ISO_Enter];
|
|
|
|
else
|
|
|
|
keys = [];
|
|
|
|
|
2019-12-05 08:54:38 +00:00
|
|
|
let button = new St.Button({
|
|
|
|
style_class: 'modal-dialog-linked-button',
|
|
|
|
button_mask: St.ButtonMask.ONE | St.ButtonMask.THREE,
|
|
|
|
reactive: true,
|
|
|
|
can_focus: true,
|
|
|
|
x_expand: true,
|
|
|
|
y_expand: true,
|
|
|
|
label,
|
|
|
|
});
|
2021-04-19 16:37:58 +00:00
|
|
|
button.connect('clicked', () => action());
|
2017-01-19 18:49:52 +00:00
|
|
|
|
|
|
|
buttonInfo['button'] = button;
|
|
|
|
|
|
|
|
if (isDefault)
|
|
|
|
button.add_style_pseudo_class('default');
|
|
|
|
|
2017-09-28 10:38:33 +00:00
|
|
|
if (this._initialKeyFocus == null || isDefault)
|
2017-10-05 08:06:10 +00:00
|
|
|
this._setInitialKeyFocus(button);
|
2017-01-19 18:49:52 +00:00
|
|
|
|
|
|
|
for (let i in keys)
|
|
|
|
this._buttonKeys[keys[i]] = buttonInfo;
|
|
|
|
|
|
|
|
this.buttonLayout.add_actor(button);
|
|
|
|
|
|
|
|
return button;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-01-19 18:49:52 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
clearButtons() {
|
2017-01-19 18:49:52 +00:00
|
|
|
this.buttonLayout.destroy_all_children();
|
|
|
|
this._buttonKeys = {};
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-01-19 18:49:52 +00:00
|
|
|
});
|
2017-07-15 03:12:57 +00:00
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
export const MessageDialogContent = GObject.registerClass({
|
2017-07-15 03:12:57 +00:00
|
|
|
Properties: {
|
2019-12-05 08:54:38 +00:00
|
|
|
'title': GObject.ParamSpec.string(
|
|
|
|
'title', 'title', 'title',
|
|
|
|
GObject.ParamFlags.READWRITE |
|
|
|
|
GObject.ParamFlags.CONSTRUCT,
|
|
|
|
null),
|
2020-01-13 13:07:28 +00:00
|
|
|
'description': GObject.ParamSpec.string(
|
|
|
|
'description', 'description', 'description',
|
2019-12-05 08:54:38 +00:00
|
|
|
GObject.ParamFlags.READWRITE |
|
|
|
|
GObject.ParamFlags.CONSTRUCT,
|
|
|
|
null),
|
2019-08-20 21:43:54 +00:00
|
|
|
},
|
2017-10-31 01:23:39 +00:00
|
|
|
}, class MessageDialogContent extends St.BoxLayout {
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(params) {
|
2023-08-06 22:40:20 +00:00
|
|
|
this._title = new St.Label({style_class: 'message-dialog-title'});
|
|
|
|
this._description = new St.Label({style_class: 'message-dialog-description'});
|
2017-07-15 03:12:57 +00:00
|
|
|
|
2020-01-13 13:04:40 +00:00
|
|
|
this._description.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
|
|
|
|
this._description.clutter_text.line_wrap = true;
|
2017-07-15 03:12:57 +00:00
|
|
|
|
2019-12-05 09:55:00 +00:00
|
|
|
let defaultParams = {
|
2019-12-05 08:54:38 +00:00
|
|
|
style_class: 'message-dialog-content',
|
|
|
|
x_expand: true,
|
|
|
|
vertical: true,
|
2019-12-05 09:55:00 +00:00
|
|
|
};
|
|
|
|
super._init(Object.assign(defaultParams, params));
|
|
|
|
|
2020-02-17 18:59:31 +00:00
|
|
|
this.connect('notify::size', this._updateTitleStyle.bind(this));
|
|
|
|
this.connect('destroy', this._onDestroy.bind(this));
|
|
|
|
|
2019-12-05 09:55:00 +00:00
|
|
|
this.add_child(this._title);
|
2020-01-13 13:07:28 +00:00
|
|
|
this.add_child(this._description);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-07-15 03:12:57 +00:00
|
|
|
|
2020-02-17 18:59:31 +00:00
|
|
|
_onDestroy() {
|
|
|
|
if (this._updateTitleStyleLater) {
|
2022-09-07 18:23:38 +00:00
|
|
|
const laters = global.compositor.get_laters();
|
|
|
|
laters.remove(this._updateTitleStyleLater);
|
2020-02-17 18:59:31 +00:00
|
|
|
delete this._updateTitleStyleLater;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-15 03:12:57 +00:00
|
|
|
get title() {
|
|
|
|
return this._title.text;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-07-15 03:12:57 +00:00
|
|
|
|
2020-01-13 13:07:28 +00:00
|
|
|
get description() {
|
|
|
|
return this._description.text;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-07-15 03:12:57 +00:00
|
|
|
|
2020-02-17 18:59:31 +00:00
|
|
|
_updateTitleStyle() {
|
|
|
|
if (!this._title.mapped)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._title.ensure_style();
|
|
|
|
const [, titleNatWidth] = this._title.get_preferred_width(-1);
|
|
|
|
|
|
|
|
if (titleNatWidth > this.width) {
|
|
|
|
if (this._updateTitleStyleLater)
|
|
|
|
return;
|
|
|
|
|
2022-09-07 18:23:38 +00:00
|
|
|
const laters = global.compositor.get_laters();
|
|
|
|
this._updateTitleStyleLater = laters.add(Meta.LaterType.BEFORE_REDRAW, () => {
|
2020-02-17 18:59:31 +00:00
|
|
|
this._updateTitleStyleLater = 0;
|
2020-08-19 09:26:11 +00:00
|
|
|
this._title.add_style_class_name('lightweight');
|
2020-06-28 11:06:50 +00:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2020-02-17 18:59:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-15 03:12:57 +00:00
|
|
|
set title(title) {
|
2020-06-28 11:06:26 +00:00
|
|
|
if (this._title.text === title)
|
|
|
|
return;
|
|
|
|
|
2020-01-19 22:20:02 +00:00
|
|
|
_setLabel(this._title, title);
|
2020-02-17 18:59:31 +00:00
|
|
|
|
2020-08-19 09:26:11 +00:00
|
|
|
this._title.remove_style_class_name('lightweight');
|
2020-02-17 18:59:31 +00:00
|
|
|
this._updateTitleStyle();
|
|
|
|
|
2020-01-19 22:20:02 +00:00
|
|
|
this.notify('title');
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-07-15 03:12:57 +00:00
|
|
|
|
2020-01-13 13:07:28 +00:00
|
|
|
set description(description) {
|
2020-06-28 11:06:26 +00:00
|
|
|
if (this._description.text === description)
|
|
|
|
return;
|
|
|
|
|
2020-01-19 22:20:02 +00:00
|
|
|
_setLabel(this._description, description);
|
|
|
|
this.notify('description');
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-07-15 03:12:57 +00:00
|
|
|
});
|
2020-01-17 13:05:49 +00:00
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
export const ListSection = GObject.registerClass({
|
2020-01-17 13:05:49 +00:00
|
|
|
Properties: {
|
|
|
|
'title': GObject.ParamSpec.string(
|
|
|
|
'title', 'title', 'title',
|
|
|
|
GObject.ParamFlags.READWRITE |
|
|
|
|
GObject.ParamFlags.CONSTRUCT,
|
|
|
|
null),
|
|
|
|
},
|
|
|
|
}, class ListSection extends St.BoxLayout {
|
|
|
|
_init(params) {
|
2023-08-06 22:40:20 +00:00
|
|
|
this._title = new St.Label({style_class: 'dialog-list-title'});
|
2020-01-17 13:05:49 +00:00
|
|
|
|
|
|
|
this._listScrollView = new St.ScrollView({
|
|
|
|
style_class: 'dialog-list-scrollview',
|
|
|
|
hscrollbar_policy: St.PolicyType.NEVER,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.list = new St.BoxLayout({
|
|
|
|
style_class: 'dialog-list-box',
|
|
|
|
vertical: true,
|
|
|
|
});
|
|
|
|
this._listScrollView.add_actor(this.list);
|
|
|
|
|
|
|
|
let defaultParams = {
|
|
|
|
style_class: 'dialog-list',
|
|
|
|
x_expand: true,
|
|
|
|
vertical: true,
|
|
|
|
};
|
|
|
|
super._init(Object.assign(defaultParams, params));
|
|
|
|
|
|
|
|
this.label_actor = this._title;
|
|
|
|
this.add_child(this._title);
|
|
|
|
this.add_child(this._listScrollView);
|
|
|
|
}
|
|
|
|
|
|
|
|
get title() {
|
|
|
|
return this._title.text;
|
|
|
|
}
|
|
|
|
|
|
|
|
set title(title) {
|
|
|
|
_setLabel(this._title, title);
|
|
|
|
this.notify('title');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
export const ListSectionItem = GObject.registerClass({
|
2020-01-17 13:05:49 +00:00
|
|
|
Properties: {
|
|
|
|
'icon-actor': GObject.ParamSpec.object(
|
|
|
|
'icon-actor', 'icon-actor', 'Icon actor',
|
|
|
|
GObject.ParamFlags.READWRITE,
|
|
|
|
Clutter.Actor.$gtype),
|
|
|
|
'title': GObject.ParamSpec.string(
|
|
|
|
'title', 'title', 'title',
|
|
|
|
GObject.ParamFlags.READWRITE |
|
|
|
|
GObject.ParamFlags.CONSTRUCT,
|
|
|
|
null),
|
|
|
|
'description': GObject.ParamSpec.string(
|
|
|
|
'description', 'description', 'description',
|
|
|
|
GObject.ParamFlags.READWRITE |
|
|
|
|
GObject.ParamFlags.CONSTRUCT,
|
|
|
|
null),
|
|
|
|
},
|
|
|
|
}, class ListSectionItem extends St.BoxLayout {
|
|
|
|
_init(params) {
|
|
|
|
this._iconActorBin = new St.Bin();
|
|
|
|
|
|
|
|
let textLayout = new St.BoxLayout({
|
|
|
|
vertical: true,
|
|
|
|
y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
|
|
|
});
|
|
|
|
|
2023-08-06 22:40:20 +00:00
|
|
|
this._title = new St.Label({style_class: 'dialog-list-item-title'});
|
2020-01-17 13:05:49 +00:00
|
|
|
|
|
|
|
this._description = new St.Label({
|
|
|
|
style_class: 'dialog-list-item-title-description',
|
|
|
|
});
|
|
|
|
|
|
|
|
textLayout.add_child(this._title);
|
|
|
|
textLayout.add_child(this._description);
|
|
|
|
|
2023-08-06 22:40:20 +00:00
|
|
|
let defaultParams = {style_class: 'dialog-list-item'};
|
2020-01-17 13:05:49 +00:00
|
|
|
super._init(Object.assign(defaultParams, params));
|
|
|
|
|
|
|
|
this.label_actor = this._title;
|
|
|
|
this.add_child(this._iconActorBin);
|
|
|
|
this.add_child(textLayout);
|
|
|
|
}
|
|
|
|
|
2021-01-30 01:03:07 +00:00
|
|
|
get iconActor() {
|
2020-01-17 13:05:49 +00:00
|
|
|
return this._iconActorBin.get_child();
|
|
|
|
}
|
|
|
|
|
2021-01-30 01:03:07 +00:00
|
|
|
set iconActor(actor) {
|
2020-01-17 13:05:49 +00:00
|
|
|
this._iconActorBin.set_child(actor);
|
|
|
|
this.notify('icon-actor');
|
|
|
|
}
|
|
|
|
|
|
|
|
get title() {
|
|
|
|
return this._title.text;
|
|
|
|
}
|
|
|
|
|
|
|
|
set title(title) {
|
|
|
|
_setLabel(this._title, title);
|
|
|
|
this.notify('title');
|
|
|
|
}
|
|
|
|
|
|
|
|
get description() {
|
|
|
|
return this._description.text;
|
|
|
|
}
|
|
|
|
|
|
|
|
set description(description) {
|
|
|
|
_setLabel(this._description, description);
|
|
|
|
this.notify('description');
|
|
|
|
}
|
|
|
|
});
|