2019-07-16 05:24:13 -04:00
|
|
|
/* exported MessageListSection */
|
2019-02-20 14:54:29 -05:00
|
|
|
const { Atk, Clutter, Gio, GLib,
|
|
|
|
GObject, Graphene, Meta, Pango, St } = imports.gi;
|
2016-02-15 06:02:31 -05:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
const MessageTray = imports.ui.messageTray;
|
|
|
|
|
|
|
|
const Util = imports.misc.util;
|
|
|
|
|
2019-08-01 19:13:10 -04:00
|
|
|
var MESSAGE_ANIMATION_TIME = 100;
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var DEFAULT_EXPAND_LINES = 6;
|
2016-02-15 06:02:31 -05:00
|
|
|
|
|
|
|
function _fixMarkup(text, allowMarkup) {
|
|
|
|
if (allowMarkup) {
|
|
|
|
// Support &, ", ', < and >, escape all other
|
|
|
|
// occurrences of '&'.
|
|
|
|
let _text = text.replace(/&(?!amp;|quot;|apos;|lt;|gt;)/g, '&');
|
|
|
|
|
|
|
|
// Support <b>, <i>, and <u>, escape anything else
|
|
|
|
// so it displays as raw markup.
|
2018-05-21 15:07:09 -04:00
|
|
|
// Ref: https://developer.gnome.org/notification-spec/#markup
|
2016-02-15 06:02:31 -05:00
|
|
|
_text = _text.replace(/<(?!\/?[biu]>)/g, '<');
|
|
|
|
|
|
|
|
try {
|
|
|
|
Pango.parse_markup(_text, -1, '');
|
|
|
|
return _text;
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
// !allowMarkup, or invalid markup
|
|
|
|
return GLib.markup_escape_text(text, -1);
|
|
|
|
}
|
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
var URLHighlighter = GObject.registerClass(
|
|
|
|
class URLHighlighter extends St.Label {
|
|
|
|
_init(text = '', lineWrap, allowMarkup) {
|
|
|
|
super._init({
|
|
|
|
reactive: true,
|
|
|
|
style_class: 'url-highlighter',
|
|
|
|
x_expand: true,
|
2019-08-20 17:43:54 -04:00
|
|
|
x_align: Clutter.ActorAlign.START,
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|
2016-02-15 06:02:31 -05:00
|
|
|
this._linkColor = '#ccccff';
|
2019-07-16 05:24:13 -04:00
|
|
|
this.connect('style-changed', () => {
|
|
|
|
let [hasColor, color] = this.get_theme_node().lookup_color('link-color', false);
|
2016-02-15 06:02:31 -05:00
|
|
|
if (hasColor) {
|
|
|
|
let linkColor = color.to_string().substr(0, 7);
|
|
|
|
if (linkColor != this._linkColor) {
|
|
|
|
this._linkColor = linkColor;
|
|
|
|
this._highlightUrls();
|
|
|
|
}
|
|
|
|
}
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2019-07-16 05:24:13 -04:00
|
|
|
this.clutter_text.line_wrap = lineWrap;
|
|
|
|
this.clutter_text.line_wrap_mode = Pango.WrapMode.WORD_CHAR;
|
2016-02-15 06:02:31 -05:00
|
|
|
|
|
|
|
this.setMarkup(text, allowMarkup);
|
2019-09-10 01:42:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
vfunc_button_press_event(buttonEvent) {
|
|
|
|
// Don't try to URL highlight when invisible.
|
|
|
|
// The MessageTray doesn't actually hide us, so
|
|
|
|
// we need to check for paint opacities as well.
|
|
|
|
if (!this.visible || this.get_paint_opacity() == 0)
|
2016-02-15 06:02:31 -05:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2019-09-10 01:42:48 -04:00
|
|
|
|
|
|
|
// Keep Notification from seeing this and taking
|
|
|
|
// a pointer grab, which would block our button-release-event
|
|
|
|
// handler, if an URL is clicked
|
|
|
|
return this._findUrlAtPos(buttonEvent) != -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vfunc_button_release_event(buttonEvent) {
|
|
|
|
if (!this.visible || this.get_paint_opacity() == 0)
|
2016-02-15 06:02:31 -05:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
2019-09-10 01:42:48 -04:00
|
|
|
let urlId = this._findUrlAtPos(buttonEvent);
|
|
|
|
if (urlId != -1) {
|
|
|
|
let url = this._urls[urlId].url;
|
|
|
|
if (!url.includes(':'))
|
2020-02-14 10:10:34 -05:00
|
|
|
url = 'http://%s'.format(url);
|
2019-09-10 01:42:48 -04:00
|
|
|
|
|
|
|
Gio.app_info_launch_default_for_uri(
|
|
|
|
url, global.create_app_launch_context(0, -1));
|
|
|
|
return Clutter.EVENT_STOP;
|
|
|
|
}
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
vfunc_motion_event(motionEvent) {
|
|
|
|
if (!this.visible || this.get_paint_opacity() == 0)
|
2016-02-15 06:02:31 -05:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2019-09-10 01:42:48 -04:00
|
|
|
|
|
|
|
let urlId = this._findUrlAtPos(motionEvent);
|
|
|
|
if (urlId != -1 && !this._cursorChanged) {
|
|
|
|
global.display.set_cursor(Meta.Cursor.POINTING_HAND);
|
|
|
|
this._cursorChanged = true;
|
|
|
|
} else if (urlId == -1) {
|
|
|
|
global.display.set_cursor(Meta.Cursor.DEFAULT);
|
|
|
|
this._cursorChanged = false;
|
|
|
|
}
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
vfunc_leave_event(crossingEvent) {
|
|
|
|
if (!this.visible || this.get_paint_opacity() == 0)
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
if (this._cursorChanged) {
|
|
|
|
this._cursorChanged = false;
|
|
|
|
global.display.set_cursor(Meta.Cursor.DEFAULT);
|
|
|
|
}
|
|
|
|
return super.vfunc_leave_event(crossingEvent);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setMarkup(text, allowMarkup) {
|
2016-02-15 06:02:31 -05:00
|
|
|
text = text ? _fixMarkup(text, allowMarkup) : '';
|
|
|
|
this._text = text;
|
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
this.clutter_text.set_markup(text);
|
2016-02-15 06:02:31 -05:00
|
|
|
/* clutter_text.text contain text without markup */
|
2019-07-16 05:24:13 -04:00
|
|
|
this._urls = Util.findUrls(this.clutter_text.text);
|
2016-02-15 06:02:31 -05:00
|
|
|
this._highlightUrls();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_highlightUrls() {
|
2016-02-15 06:02:31 -05:00
|
|
|
// text here contain markup
|
|
|
|
let urls = Util.findUrls(this._text);
|
|
|
|
let markup = '';
|
|
|
|
let pos = 0;
|
|
|
|
for (let i = 0; i < urls.length; i++) {
|
|
|
|
let url = urls[i];
|
|
|
|
let str = this._text.substr(pos, url.pos - pos);
|
2020-02-14 10:10:34 -05:00
|
|
|
markup += '%s<span foreground="%s"><u>%s</u></span>'.format(str, this._linkColor, url.url);
|
2016-02-15 06:02:31 -05:00
|
|
|
pos = url.pos + url.url.length;
|
|
|
|
}
|
|
|
|
markup += this._text.substr(pos);
|
2019-07-16 05:24:13 -04:00
|
|
|
this.clutter_text.set_markup(markup);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_findUrlAtPos(event) {
|
2019-09-10 01:42:48 -04:00
|
|
|
let { x, y } = event;
|
2019-07-16 05:24:13 -04:00
|
|
|
[, x, y] = this.transform_stage_point(x, y);
|
2019-01-31 08:43:52 -05:00
|
|
|
let findPos = -1;
|
2019-07-16 05:24:13 -04:00
|
|
|
for (let i = 0; i < this.clutter_text.text.length; i++) {
|
|
|
|
let [, px, py, lineHeight] = this.clutter_text.position_to_coords(i);
|
2019-01-31 08:43:52 -05:00
|
|
|
if (py > y || py + lineHeight < y || x < px)
|
2016-02-15 06:02:31 -05:00
|
|
|
continue;
|
2019-01-31 08:43:52 -05:00
|
|
|
findPos = i;
|
2016-02-15 06:02:31 -05:00
|
|
|
}
|
2019-01-31 08:43:52 -05:00
|
|
|
if (findPos != -1) {
|
2019-08-19 20:51:42 -04:00
|
|
|
for (let i = 0; i < this._urls.length; i++) {
|
2019-01-29 14:36:54 -05:00
|
|
|
if (findPos >= this._urls[i].pos &&
|
|
|
|
this._urls[i].pos + this._urls[i].url.length > findPos)
|
|
|
|
return i;
|
2019-08-19 20:51:42 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2019-01-31 14:38:24 -05:00
|
|
|
var ScaleLayout = GObject.registerClass(
|
2017-10-30 21:23:39 -04:00
|
|
|
class ScaleLayout extends Clutter.BinLayout {
|
2017-10-30 20:03:21 -04:00
|
|
|
_init(params) {
|
2017-06-12 22:24:12 -04:00
|
|
|
this._container = null;
|
2017-10-30 21:23:39 -04:00
|
|
|
super._init(params);
|
|
|
|
}
|
2017-06-12 22:24:12 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_connectContainer(container) {
|
2016-02-15 06:02:31 -05:00
|
|
|
if (this._container == container)
|
|
|
|
return;
|
|
|
|
|
2019-08-19 20:51:42 -04:00
|
|
|
if (this._container) {
|
2016-02-15 06:02:31 -05:00
|
|
|
for (let id of this._signals)
|
|
|
|
this._container.disconnect(id);
|
2019-08-19 20:51:42 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
|
|
|
this._container = container;
|
|
|
|
this._signals = [];
|
|
|
|
|
2019-08-19 20:51:42 -04:00
|
|
|
if (this._container) {
|
2016-02-15 06:02:31 -05:00
|
|
|
for (let signal of ['notify::scale-x', 'notify::scale-y']) {
|
2017-10-30 20:38:18 -04:00
|
|
|
let id = this._container.connect(signal, () => {
|
|
|
|
this.layout_changed();
|
|
|
|
});
|
2016-02-15 06:02:31 -05:00
|
|
|
this._signals.push(id);
|
|
|
|
}
|
2019-08-19 20:51:42 -04:00
|
|
|
}
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
vfunc_get_preferred_width(container, forHeight) {
|
2016-02-15 06:02:31 -05:00
|
|
|
this._connectContainer(container);
|
|
|
|
|
2017-10-30 21:23:39 -04:00
|
|
|
let [min, nat] = super.vfunc_get_preferred_width(container, forHeight);
|
2016-02-15 06:02:31 -05:00
|
|
|
return [Math.floor(min * container.scale_x),
|
|
|
|
Math.floor(nat * container.scale_x)];
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
vfunc_get_preferred_height(container, forWidth) {
|
2016-02-15 06:02:31 -05:00
|
|
|
this._connectContainer(container);
|
|
|
|
|
2017-10-30 21:23:39 -04:00
|
|
|
let [min, nat] = super.vfunc_get_preferred_height(container, forWidth);
|
2016-02-15 06:02:31 -05:00
|
|
|
return [Math.floor(min * container.scale_y),
|
|
|
|
Math.floor(nat * container.scale_y)];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-10-30 21:23:39 -04:00
|
|
|
var LabelExpanderLayout = GObject.registerClass({
|
2019-01-29 13:15:23 -05:00
|
|
|
Properties: {
|
|
|
|
'expansion': GObject.ParamSpec.double('expansion',
|
|
|
|
'Expansion',
|
|
|
|
'Expansion of the layout, between 0 (collapsed) ' +
|
|
|
|
'and 1 (fully expanded',
|
|
|
|
GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
|
2019-08-20 17:43:54 -04:00
|
|
|
0, 1, 0),
|
2019-01-29 13:15:23 -05:00
|
|
|
},
|
2017-10-30 21:23:39 -04:00
|
|
|
}, class LabelExpanderLayout extends Clutter.LayoutManager {
|
2017-10-30 20:03:21 -04:00
|
|
|
_init(params) {
|
2016-02-15 06:02:31 -05:00
|
|
|
this._expansion = 0;
|
|
|
|
this._expandLines = DEFAULT_EXPAND_LINES;
|
|
|
|
|
2017-10-30 21:23:39 -04:00
|
|
|
super._init(params);
|
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
|
|
|
get expansion() {
|
|
|
|
return this._expansion;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
|
|
|
set expansion(v) {
|
|
|
|
if (v == this._expansion)
|
|
|
|
return;
|
|
|
|
this._expansion = v;
|
|
|
|
this.notify('expansion');
|
|
|
|
|
|
|
|
let visibleIndex = this._expansion > 0 ? 1 : 0;
|
|
|
|
for (let i = 0; this._container && i < this._container.get_n_children(); i++)
|
2019-08-19 15:38:51 -04:00
|
|
|
this._container.get_child_at_index(i).visible = i == visibleIndex;
|
2016-02-15 06:02:31 -05:00
|
|
|
|
|
|
|
this.layout_changed();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
|
|
|
set expandLines(v) {
|
|
|
|
if (v == this._expandLines)
|
|
|
|
return;
|
|
|
|
this._expandLines = v;
|
|
|
|
if (this._expansion > 0)
|
|
|
|
this.layout_changed();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
vfunc_set_container(container) {
|
2016-02-15 06:02:31 -05:00
|
|
|
this._container = container;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
vfunc_get_preferred_width(container, forHeight) {
|
2016-02-15 06:02:31 -05:00
|
|
|
let [min, nat] = [0, 0];
|
|
|
|
|
|
|
|
for (let i = 0; i < container.get_n_children(); i++) {
|
|
|
|
if (i > 1)
|
|
|
|
break; // we support one unexpanded + one expanded child
|
|
|
|
|
|
|
|
let child = container.get_child_at_index(i);
|
|
|
|
let [childMin, childNat] = child.get_preferred_width(forHeight);
|
|
|
|
[min, nat] = [Math.max(min, childMin), Math.max(nat, childNat)];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [min, nat];
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
vfunc_get_preferred_height(container, forWidth) {
|
2016-02-15 06:02:31 -05:00
|
|
|
let [min, nat] = [0, 0];
|
|
|
|
|
|
|
|
let children = container.get_children();
|
|
|
|
if (children[0])
|
|
|
|
[min, nat] = children[0].get_preferred_height(forWidth);
|
|
|
|
|
|
|
|
if (children[1]) {
|
|
|
|
let [min2, nat2] = children[1].get_preferred_height(forWidth);
|
|
|
|
let [expMin, expNat] = [Math.min(min2, min * this._expandLines),
|
|
|
|
Math.min(nat2, nat * this._expandLines)];
|
|
|
|
[min, nat] = [min + this._expansion * (expMin - min),
|
|
|
|
nat + this._expansion * (expNat - nat)];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [min, nat];
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2020-05-09 15:30:26 -04:00
|
|
|
vfunc_allocate(container, box) {
|
2016-02-15 06:02:31 -05:00
|
|
|
for (let i = 0; i < container.get_n_children(); i++) {
|
|
|
|
let child = container.get_child_at_index(i);
|
|
|
|
|
|
|
|
if (child.visible)
|
2020-05-09 15:30:26 -04:00
|
|
|
child.allocate(box);
|
2016-02-15 06:02:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
var Message = GObject.registerClass({
|
|
|
|
Signals: {
|
|
|
|
'close': {},
|
|
|
|
'expanded': {},
|
|
|
|
'unexpanded': {},
|
2019-08-20 17:43:54 -04:00
|
|
|
},
|
2019-07-16 05:24:13 -04:00
|
|
|
}, class Message extends St.Button {
|
|
|
|
_init(title, body) {
|
|
|
|
super._init({
|
|
|
|
style_class: 'message',
|
|
|
|
accessible_role: Atk.Role.NOTIFICATION,
|
|
|
|
can_focus: true,
|
|
|
|
x_expand: true,
|
2019-10-17 17:40:24 -04:00
|
|
|
y_expand: true,
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
this.expanded = false;
|
2017-06-12 22:24:12 -04:00
|
|
|
this._useBodyMarkup = false;
|
|
|
|
|
2019-10-17 17:40:24 -04:00
|
|
|
let vbox = new St.BoxLayout({
|
|
|
|
vertical: true,
|
|
|
|
x_expand: true,
|
|
|
|
});
|
2019-07-16 05:24:13 -04:00
|
|
|
this.set_child(vbox);
|
2016-02-15 06:02:31 -05:00
|
|
|
|
|
|
|
let hbox = new St.BoxLayout();
|
|
|
|
vbox.add_actor(hbox);
|
|
|
|
|
|
|
|
this._actionBin = new St.Widget({ layout_manager: new ScaleLayout(),
|
|
|
|
visible: false });
|
|
|
|
vbox.add_actor(this._actionBin);
|
|
|
|
|
|
|
|
this._iconBin = new St.Bin({ style_class: 'message-icon-bin',
|
|
|
|
y_expand: true,
|
2019-10-17 17:40:24 -04:00
|
|
|
y_align: Clutter.ActorAlign.START,
|
2016-02-15 06:02:31 -05:00
|
|
|
visible: false });
|
|
|
|
hbox.add_actor(this._iconBin);
|
|
|
|
|
|
|
|
let contentBox = new St.BoxLayout({ style_class: 'message-content',
|
|
|
|
vertical: true, x_expand: true });
|
|
|
|
hbox.add_actor(contentBox);
|
|
|
|
|
2016-02-15 06:13:22 -05:00
|
|
|
this._mediaControls = new St.BoxLayout();
|
|
|
|
hbox.add_actor(this._mediaControls);
|
|
|
|
|
2016-02-15 06:02:31 -05:00
|
|
|
let titleBox = new St.BoxLayout();
|
|
|
|
contentBox.add_actor(titleBox);
|
|
|
|
|
2017-02-25 21:33:26 -05:00
|
|
|
this.titleLabel = new St.Label({ style_class: 'message-title' });
|
2016-02-15 06:02:31 -05:00
|
|
|
this.setTitle(title);
|
|
|
|
titleBox.add_actor(this.titleLabel);
|
|
|
|
|
2019-08-20 17:43:54 -04:00
|
|
|
this._secondaryBin = new St.Bin({
|
|
|
|
style_class: 'message-secondary-bin',
|
|
|
|
x_expand: true, y_expand: true,
|
|
|
|
});
|
2016-02-15 06:02:31 -05:00
|
|
|
titleBox.add_actor(this._secondaryBin);
|
|
|
|
|
|
|
|
let closeIcon = new St.Icon({ icon_name: 'window-close-symbolic',
|
|
|
|
icon_size: 16 });
|
2019-11-19 12:40:09 -05:00
|
|
|
this._closeButton = new St.Button({
|
|
|
|
style_class: 'message-close-button',
|
|
|
|
child: closeIcon, opacity: 0,
|
|
|
|
});
|
2016-02-15 06:02:31 -05:00
|
|
|
titleBox.add_actor(this._closeButton);
|
|
|
|
|
|
|
|
this._bodyStack = new St.Widget({ x_expand: true });
|
|
|
|
this._bodyStack.layout_manager = new LabelExpanderLayout();
|
|
|
|
contentBox.add_actor(this._bodyStack);
|
|
|
|
|
|
|
|
this.bodyLabel = new URLHighlighter('', false, this._useBodyMarkup);
|
2019-07-16 05:24:13 -04:00
|
|
|
this.bodyLabel.add_style_class_name('message-body');
|
|
|
|
this._bodyStack.add_actor(this.bodyLabel);
|
2016-02-15 06:02:31 -05:00
|
|
|
this.setBody(body);
|
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
this._closeButton.connect('clicked', this.close.bind(this));
|
2019-07-16 05:24:13 -04:00
|
|
|
let actorHoverId = this.connect('notify::hover', this._sync.bind(this));
|
|
|
|
this._closeButton.connect('destroy', this.disconnect.bind(this, actorHoverId));
|
|
|
|
this.connect('destroy', this._onDestroy.bind(this));
|
2016-02-15 06:02:31 -05:00
|
|
|
this._sync();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
close() {
|
2016-02-15 06:02:31 -05:00
|
|
|
this.emit('close');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setIcon(actor) {
|
2016-02-15 06:02:31 -05:00
|
|
|
this._iconBin.child = actor;
|
2019-08-19 15:38:51 -04:00
|
|
|
this._iconBin.visible = actor != null;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setSecondaryActor(actor) {
|
2016-02-15 06:02:31 -05:00
|
|
|
this._secondaryBin.child = actor;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setTitle(text) {
|
2016-02-15 06:02:31 -05:00
|
|
|
let title = text ? _fixMarkup(text.replace(/\n/g, ' '), false) : '';
|
|
|
|
this.titleLabel.clutter_text.set_markup(title);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setBody(text) {
|
2016-02-15 06:02:31 -05:00
|
|
|
this._bodyText = text;
|
|
|
|
this.bodyLabel.setMarkup(text ? text.replace(/\n/g, ' ') : '',
|
|
|
|
this._useBodyMarkup);
|
|
|
|
if (this._expandedLabel)
|
|
|
|
this._expandedLabel.setMarkup(text, this._useBodyMarkup);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setUseBodyMarkup(enable) {
|
2016-02-15 06:02:31 -05:00
|
|
|
if (this._useBodyMarkup === enable)
|
|
|
|
return;
|
|
|
|
this._useBodyMarkup = enable;
|
|
|
|
if (this.bodyLabel)
|
|
|
|
this.setBody(this._bodyText);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setActionArea(actor) {
|
2016-02-15 06:02:31 -05:00
|
|
|
if (actor == null) {
|
|
|
|
if (this._actionBin.get_n_children() > 0)
|
|
|
|
this._actionBin.get_child_at_index(0).destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._actionBin.get_n_children() > 0)
|
|
|
|
throw new Error('Message already has an action area');
|
|
|
|
|
|
|
|
this._actionBin.add_actor(actor);
|
|
|
|
this._actionBin.visible = this.expanded;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
addMediaControl(iconName, callback) {
|
2016-02-15 06:13:22 -05:00
|
|
|
let icon = new St.Icon({ icon_name: iconName, icon_size: 16 });
|
|
|
|
let button = new St.Button({ style_class: 'message-media-control',
|
|
|
|
child: icon });
|
|
|
|
button.connect('clicked', callback);
|
|
|
|
this._mediaControls.add_actor(button);
|
|
|
|
return button;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:13:22 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setExpandedBody(actor) {
|
2016-02-15 06:02:31 -05:00
|
|
|
if (actor == null) {
|
|
|
|
if (this._bodyStack.get_n_children() > 1)
|
|
|
|
this._bodyStack.get_child_at_index(1).destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._bodyStack.get_n_children() > 1)
|
|
|
|
throw new Error('Message already has an expanded body actor');
|
|
|
|
|
|
|
|
this._bodyStack.insert_child_at_index(actor, 1);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setExpandedLines(nLines) {
|
2016-02-15 06:02:31 -05:00
|
|
|
this._bodyStack.layout_manager.expandLines = nLines;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
expand(animate) {
|
2016-02-15 06:02:31 -05:00
|
|
|
this.expanded = true;
|
|
|
|
|
2019-08-19 15:38:51 -04:00
|
|
|
this._actionBin.visible = this._actionBin.get_n_children() > 0;
|
2016-02-15 06:02:31 -05:00
|
|
|
|
|
|
|
if (this._bodyStack.get_n_children() < 2) {
|
|
|
|
this._expandedLabel = new URLHighlighter(this._bodyText,
|
|
|
|
true, this._useBodyMarkup);
|
2019-07-16 05:24:13 -04:00
|
|
|
this.setExpandedBody(this._expandedLabel);
|
2016-02-15 06:02:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (animate) {
|
2019-07-24 20:06:05 -04:00
|
|
|
this._bodyStack.ease_property('@layout.expansion', 1, {
|
|
|
|
progress_mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
|
|
|
duration: MessageTray.ANIMATION_TIME,
|
|
|
|
});
|
|
|
|
|
2016-02-15 06:02:31 -05:00
|
|
|
this._actionBin.scale_y = 0;
|
2018-07-20 15:46:19 -04:00
|
|
|
this._actionBin.ease({
|
|
|
|
scale_y: 1,
|
|
|
|
duration: MessageTray.ANIMATION_TIME,
|
2019-08-20 17:43:54 -04:00
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
2018-07-20 15:46:19 -04:00
|
|
|
});
|
2016-02-15 06:02:31 -05:00
|
|
|
} else {
|
|
|
|
this._bodyStack.layout_manager.expansion = 1;
|
|
|
|
this._actionBin.scale_y = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.emit('expanded');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
unexpand(animate) {
|
2016-02-15 06:02:31 -05:00
|
|
|
if (animate) {
|
2019-07-24 20:06:05 -04:00
|
|
|
this._bodyStack.ease_property('@layout.expansion', 0, {
|
|
|
|
progress_mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
|
|
|
duration: MessageTray.ANIMATION_TIME,
|
|
|
|
});
|
|
|
|
|
2018-07-20 15:46:19 -04:00
|
|
|
this._actionBin.ease({
|
|
|
|
scale_y: 0,
|
|
|
|
duration: MessageTray.ANIMATION_TIME,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
|
|
|
onComplete: () => {
|
|
|
|
this._actionBin.hide();
|
|
|
|
this.expanded = false;
|
2019-08-20 17:43:54 -04:00
|
|
|
},
|
2018-07-20 15:46:19 -04:00
|
|
|
});
|
2016-02-15 06:02:31 -05:00
|
|
|
} else {
|
|
|
|
this._bodyStack.layout_manager.expansion = 0;
|
|
|
|
this._actionBin.scale_y = 0;
|
|
|
|
this.expanded = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.emit('unexpanded');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
canClose() {
|
2018-12-17 12:36:03 -05:00
|
|
|
return false;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sync() {
|
2019-07-16 05:24:13 -04:00
|
|
|
let visible = this.hover && this.canClose();
|
2017-02-25 21:33:26 -05:00
|
|
|
this._closeButton.opacity = visible ? 255 : 0;
|
2018-02-23 04:27:07 -05:00
|
|
|
this._closeButton.reactive = visible;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onDestroy() {
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2019-09-10 01:42:48 -04:00
|
|
|
vfunc_key_press_event(keyEvent) {
|
|
|
|
let keysym = keyEvent.keyval;
|
2016-02-15 06:02:31 -05:00
|
|
|
|
|
|
|
if (keysym == Clutter.KEY_Delete ||
|
|
|
|
keysym == Clutter.KEY_KP_Delete) {
|
|
|
|
this.close();
|
|
|
|
return Clutter.EVENT_STOP;
|
|
|
|
}
|
2020-03-26 18:40:38 -04:00
|
|
|
return super.vfunc_key_press_event(keyEvent);
|
2016-02-15 06:02:31 -05:00
|
|
|
}
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
var MessageListSection = GObject.registerClass({
|
|
|
|
Properties: {
|
|
|
|
'can-clear': GObject.ParamSpec.boolean(
|
|
|
|
'can-clear', 'can-clear', 'can-clear',
|
|
|
|
GObject.ParamFlags.READABLE,
|
|
|
|
false),
|
|
|
|
'empty': GObject.ParamSpec.boolean(
|
|
|
|
'empty', 'empty', 'empty',
|
|
|
|
GObject.ParamFlags.READABLE,
|
|
|
|
true),
|
|
|
|
},
|
|
|
|
Signals: {
|
|
|
|
'can-clear-changed': {},
|
|
|
|
'empty-changed': {},
|
|
|
|
'message-focused': { param_types: [Message.$gtype] },
|
2019-08-20 17:43:54 -04:00
|
|
|
},
|
2019-07-16 05:24:13 -04:00
|
|
|
}, class MessageListSection extends St.BoxLayout {
|
|
|
|
_init() {
|
|
|
|
super._init({
|
|
|
|
style_class: 'message-list-section',
|
|
|
|
clip_to_allocation: true,
|
|
|
|
vertical: true,
|
2019-08-20 17:43:54 -04:00
|
|
|
x_expand: true,
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|
2016-02-15 06:02:31 -05:00
|
|
|
|
|
|
|
this._list = new St.BoxLayout({ style_class: 'message-list-section-list',
|
|
|
|
vertical: true });
|
2019-07-16 05:24:13 -04:00
|
|
|
this.add_actor(this._list);
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
this._list.connect('actor-added', this._sync.bind(this));
|
|
|
|
this._list.connect('actor-removed', this._sync.bind(this));
|
2016-02-15 06:02:31 -05:00
|
|
|
|
|
|
|
let id = Main.sessionMode.connect('updated',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._sync.bind(this));
|
2019-07-16 05:24:13 -04:00
|
|
|
this.connect('destroy', () => {
|
2016-02-15 06:02:31 -05:00
|
|
|
Main.sessionMode.disconnect(id);
|
|
|
|
});
|
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
this._empty = true;
|
|
|
|
this._canClear = false;
|
2016-02-15 06:02:31 -05:00
|
|
|
this._sync();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
get empty() {
|
|
|
|
return this._empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
get canClear() {
|
|
|
|
return this._canClear;
|
|
|
|
}
|
|
|
|
|
2019-05-13 14:02:26 -04:00
|
|
|
get _messages() {
|
|
|
|
return this._list.get_children().map(i => i.child);
|
|
|
|
}
|
|
|
|
|
2019-08-28 16:06:14 -04:00
|
|
|
_onKeyFocusIn(messageActor) {
|
|
|
|
this.emit('message-focused', messageActor);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
|
|
|
get allowed() {
|
|
|
|
return true;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
addMessage(message, animate) {
|
2016-02-15 06:02:31 -05:00
|
|
|
this.addMessageAtIndex(message, -1, animate);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
addMessageAtIndex(message, index, animate) {
|
2019-05-13 14:02:26 -04:00
|
|
|
if (this._messages.includes(message))
|
|
|
|
throw new Error('Message was already added previously');
|
|
|
|
|
|
|
|
let listItem = new St.Bin({
|
|
|
|
child: message,
|
|
|
|
layout_manager: new ScaleLayout(),
|
|
|
|
pivot_point: new Graphene.Point({ x: .5, y: .5 }),
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2019-05-13 14:02:26 -04:00
|
|
|
listItem._connectionsIds = [];
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2019-05-13 14:02:26 -04:00
|
|
|
listItem._connectionsIds.push(message.connect('key-focus-in',
|
|
|
|
this._onKeyFocusIn.bind(this)));
|
|
|
|
listItem._connectionsIds.push(message.connect('close', () => {
|
|
|
|
this.removeMessage(message, true);
|
|
|
|
}));
|
|
|
|
listItem._connectionsIds.push(message.connect('destroy', () => {
|
|
|
|
listItem._connectionsIds.forEach(id => message.disconnect(id));
|
|
|
|
listItem.destroy();
|
|
|
|
}));
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2019-05-13 14:02:26 -04:00
|
|
|
this._list.insert_child_at_index(listItem, index);
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2019-05-13 14:02:26 -04:00
|
|
|
if (animate) {
|
|
|
|
listItem.set({ scale_x: 0, scale_y: 0 });
|
|
|
|
listItem.ease({
|
2018-07-20 15:46:19 -04:00
|
|
|
scale_x: 1,
|
|
|
|
scale_y: 1,
|
|
|
|
duration: MESSAGE_ANIMATION_TIME,
|
2019-08-20 17:43:54 -04:00
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
2018-07-20 15:46:19 -04:00
|
|
|
});
|
2019-05-13 14:02:26 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
moveMessage(message, index, animate) {
|
2019-05-13 14:02:26 -04:00
|
|
|
if (!this._messages.includes(message))
|
2019-11-17 08:35:42 -05:00
|
|
|
throw new Error(`Impossible to move untracked message`);
|
2019-05-13 14:02:26 -04:00
|
|
|
|
|
|
|
let listItem = message.get_parent();
|
2016-02-15 06:02:31 -05:00
|
|
|
|
|
|
|
if (!animate) {
|
2019-05-13 14:02:26 -04:00
|
|
|
this._list.set_child_at_index(listItem, index);
|
2016-02-15 06:02:31 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
let onComplete = () => {
|
2019-05-13 14:02:26 -04:00
|
|
|
this._list.set_child_at_index(listItem, index);
|
|
|
|
listItem.ease({
|
2018-07-20 15:46:19 -04:00
|
|
|
scale_x: 1,
|
|
|
|
scale_y: 1,
|
|
|
|
duration: MESSAGE_ANIMATION_TIME,
|
2019-08-20 17:43:54 -04:00
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
2018-07-20 15:46:19 -04:00
|
|
|
});
|
2017-10-30 20:38:18 -04:00
|
|
|
};
|
2019-05-13 14:02:26 -04:00
|
|
|
listItem.ease({
|
2018-07-20 15:46:19 -04:00
|
|
|
scale_x: 0,
|
|
|
|
scale_y: 0,
|
|
|
|
duration: MESSAGE_ANIMATION_TIME,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
2019-08-20 17:43:54 -04:00
|
|
|
onComplete,
|
2018-07-20 15:46:19 -04:00
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
removeMessage(message, animate) {
|
2021-11-28 19:19:35 -05:00
|
|
|
const messages = this._messages;
|
|
|
|
|
|
|
|
if (!messages.includes(message))
|
2019-11-17 08:35:42 -05:00
|
|
|
throw new Error(`Impossible to remove untracked message`);
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2019-05-13 14:02:26 -04:00
|
|
|
let listItem = message.get_parent();
|
|
|
|
listItem._connectionsIds.forEach(id => message.disconnect(id));
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2021-11-28 19:19:35 -05:00
|
|
|
let nextMessage = null;
|
|
|
|
|
|
|
|
if (message.has_key_focus()) {
|
|
|
|
const index = messages.indexOf(message);
|
|
|
|
nextMessage =
|
|
|
|
messages[index + 1] ||
|
|
|
|
messages[index - 1] ||
|
|
|
|
this._list;
|
|
|
|
}
|
|
|
|
|
2016-02-15 06:02:31 -05:00
|
|
|
if (animate) {
|
2019-05-13 14:02:26 -04:00
|
|
|
listItem.ease({
|
2018-07-20 15:46:19 -04:00
|
|
|
scale_x: 0,
|
|
|
|
scale_y: 0,
|
|
|
|
duration: MESSAGE_ANIMATION_TIME,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
|
|
|
onComplete: () => {
|
2019-05-13 14:02:26 -04:00
|
|
|
listItem.destroy();
|
2021-11-28 19:19:35 -05:00
|
|
|
nextMessage?.grab_key_focus();
|
2019-08-20 17:43:54 -04:00
|
|
|
},
|
2018-07-20 15:46:19 -04:00
|
|
|
});
|
2016-02-15 06:02:31 -05:00
|
|
|
} else {
|
2019-05-13 14:02:26 -04:00
|
|
|
listItem.destroy();
|
2021-11-28 19:19:35 -05:00
|
|
|
nextMessage?.grab_key_focus();
|
2016-02-15 06:02:31 -05:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
clear() {
|
2019-05-13 14:02:26 -04:00
|
|
|
let messages = this._messages.filter(msg => msg.canClose());
|
2016-02-15 06:02:31 -05:00
|
|
|
|
|
|
|
// If there are few messages, letting them all zoom out looks OK
|
|
|
|
if (messages.length < 2) {
|
2017-10-30 20:38:18 -04:00
|
|
|
messages.forEach(message => {
|
2016-02-15 06:02:31 -05:00
|
|
|
message.close();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Otherwise we slide them out one by one, and then zoom them
|
|
|
|
// out "off-screen" in the end to smoothly shrink the parent
|
|
|
|
let delay = MESSAGE_ANIMATION_TIME / Math.max(messages.length, 5);
|
|
|
|
for (let i = 0; i < messages.length; i++) {
|
|
|
|
let message = messages[i];
|
2019-05-13 14:02:26 -04:00
|
|
|
message.get_parent().ease({
|
|
|
|
translation_x: this._list.width,
|
2018-07-20 15:46:19 -04:00
|
|
|
opacity: 0,
|
|
|
|
duration: MESSAGE_ANIMATION_TIME,
|
|
|
|
delay: i * delay,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
2019-08-20 17:43:54 -04:00
|
|
|
onComplete: () => message.close(),
|
2018-07-20 15:46:19 -04:00
|
|
|
});
|
2016-02-15 06:02:31 -05:00
|
|
|
}
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_shouldShow() {
|
2016-02-15 06:02:31 -05:00
|
|
|
return !this.empty;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sync() {
|
2019-05-13 14:02:26 -04:00
|
|
|
let messages = this._messages;
|
|
|
|
let empty = messages.length == 0;
|
2016-02-15 06:02:31 -05:00
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
if (this._empty != empty) {
|
|
|
|
this._empty = empty;
|
|
|
|
this.notify('empty');
|
|
|
|
}
|
2017-02-26 16:23:11 -05:00
|
|
|
|
2019-05-13 14:02:26 -04:00
|
|
|
let canClear = messages.some(m => m.canClose());
|
2019-07-16 05:24:13 -04:00
|
|
|
if (this._canClear != canClear) {
|
|
|
|
this._canClear = canClear;
|
|
|
|
this.notify('can-clear');
|
|
|
|
}
|
2017-02-26 16:23:11 -05:00
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
this.visible = this.allowed && this._shouldShow();
|
2016-02-15 06:02:31 -05:00
|
|
|
}
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|