2019-02-09 03:21:36 +00:00
|
|
|
const { Atk, Clutter, Gio, GLib, GObject, Meta, Pango, St } = imports.gi;
|
2016-02-15 11:02:31 +00:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
const MessageTray = imports.ui.messageTray;
|
|
|
|
const Signals = imports.signals;
|
|
|
|
|
|
|
|
const Calendar = imports.ui.calendar;
|
|
|
|
const Tweener = imports.ui.tweener;
|
|
|
|
const Util = imports.misc.util;
|
|
|
|
|
2019-08-01 23:13:10 +00:00
|
|
|
var MESSAGE_ANIMATION_TIME = 100;
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-07-18 17:47:27 +00:00
|
|
|
var DEFAULT_EXPAND_LINES = 6;
|
2016-02-15 11:02:31 +00: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 19:07:09 +00:00
|
|
|
// Ref: https://developer.gnome.org/notification-spec/#markup
|
2016-02-15 11:02:31 +00: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);
|
|
|
|
}
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var URLHighlighter = class URLHighlighter {
|
2019-07-11 23:31:38 +00:00
|
|
|
constructor(text = '', lineWrap, allowMarkup) {
|
2016-02-15 11:02:31 +00:00
|
|
|
this.actor = new St.Label({ reactive: true, style_class: 'url-highlighter',
|
|
|
|
x_expand: true, x_align: Clutter.ActorAlign.START });
|
|
|
|
this._linkColor = '#ccccff';
|
2017-10-31 00:38:18 +00:00
|
|
|
this.actor.connect('style-changed', () => {
|
2016-02-15 11:02:31 +00:00
|
|
|
let [hasColor, color] = this.actor.get_theme_node().lookup_color('link-color', false);
|
|
|
|
if (hasColor) {
|
|
|
|
let linkColor = color.to_string().substr(0, 7);
|
|
|
|
if (linkColor != this._linkColor) {
|
|
|
|
this._linkColor = linkColor;
|
|
|
|
this._highlightUrls();
|
|
|
|
}
|
|
|
|
}
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2016-02-15 11:02:31 +00:00
|
|
|
this.actor.clutter_text.line_wrap = lineWrap;
|
|
|
|
this.actor.clutter_text.line_wrap_mode = Pango.WrapMode.WORD_CHAR;
|
|
|
|
|
|
|
|
this.setMarkup(text, allowMarkup);
|
2017-10-31 00:38:18 +00:00
|
|
|
this.actor.connect('button-press-event', (actor, event) => {
|
2016-02-15 11:02:31 +00:00
|
|
|
// 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 (!actor.visible || actor.get_paint_opacity() == 0)
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
// Keep Notification.actor from seeing this and taking
|
|
|
|
// a pointer grab, which would block our button-release-event
|
|
|
|
// handler, if an URL is clicked
|
|
|
|
return this._findUrlAtPos(event) != -1;
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
|
|
|
this.actor.connect('button-release-event', (actor, event) => {
|
2016-02-15 11:02:31 +00:00
|
|
|
if (!actor.visible || actor.get_paint_opacity() == 0)
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
let urlId = this._findUrlAtPos(event);
|
|
|
|
if (urlId != -1) {
|
|
|
|
let url = this._urls[urlId].url;
|
2018-07-14 20:56:22 +00:00
|
|
|
if (!url.includes(':'))
|
2016-02-15 11:02:31 +00:00
|
|
|
url = 'http://' + url;
|
|
|
|
|
|
|
|
Gio.app_info_launch_default_for_uri(url, global.create_app_launch_context(0, -1));
|
|
|
|
return Clutter.EVENT_STOP;
|
|
|
|
}
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
|
|
|
this.actor.connect('motion-event', (actor, event) => {
|
2016-02-15 11:02:31 +00:00
|
|
|
if (!actor.visible || actor.get_paint_opacity() == 0)
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
let urlId = this._findUrlAtPos(event);
|
|
|
|
if (urlId != -1 && !this._cursorChanged) {
|
2018-01-03 07:55:38 +00:00
|
|
|
global.display.set_cursor(Meta.Cursor.POINTING_HAND);
|
2016-02-15 11:02:31 +00:00
|
|
|
this._cursorChanged = true;
|
|
|
|
} else if (urlId == -1) {
|
2018-01-03 07:55:38 +00:00
|
|
|
global.display.set_cursor(Meta.Cursor.DEFAULT);
|
2016-02-15 11:02:31 +00:00
|
|
|
this._cursorChanged = false;
|
|
|
|
}
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
|
|
|
this.actor.connect('leave-event', () => {
|
2016-02-15 11:02:31 +00:00
|
|
|
if (!this.actor.visible || this.actor.get_paint_opacity() == 0)
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
if (this._cursorChanged) {
|
|
|
|
this._cursorChanged = false;
|
2018-01-03 07:55:38 +00:00
|
|
|
global.display.set_cursor(Meta.Cursor.DEFAULT);
|
2016-02-15 11:02:31 +00:00
|
|
|
}
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setMarkup(text, allowMarkup) {
|
2016-02-15 11:02:31 +00:00
|
|
|
text = text ? _fixMarkup(text, allowMarkup) : '';
|
|
|
|
this._text = text;
|
|
|
|
|
|
|
|
this.actor.clutter_text.set_markup(text);
|
|
|
|
/* clutter_text.text contain text without markup */
|
|
|
|
this._urls = Util.findUrls(this.actor.clutter_text.text);
|
|
|
|
this._highlightUrls();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_highlightUrls() {
|
2016-02-15 11:02:31 +00: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);
|
|
|
|
markup += str + '<span foreground="' + this._linkColor + '"><u>' + url.url + '</u></span>';
|
|
|
|
pos = url.pos + url.url.length;
|
|
|
|
}
|
|
|
|
markup += this._text.substr(pos);
|
|
|
|
this.actor.clutter_text.set_markup(markup);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_findUrlAtPos(event) {
|
2019-01-31 14:08:00 +00:00
|
|
|
let success_;
|
2016-02-15 11:02:31 +00:00
|
|
|
let [x, y] = event.get_coords();
|
2019-01-31 14:08:00 +00:00
|
|
|
[success_, x, y] = this.actor.transform_stage_point(x, y);
|
2019-01-31 13:43:52 +00:00
|
|
|
let findPos = -1;
|
2016-02-15 11:02:31 +00:00
|
|
|
for (let i = 0; i < this.actor.clutter_text.text.length; i++) {
|
2019-01-31 14:08:00 +00:00
|
|
|
let [success_, px, py, lineHeight] = this.actor.clutter_text.position_to_coords(i);
|
2019-01-31 13:43:52 +00:00
|
|
|
if (py > y || py + lineHeight < y || x < px)
|
2016-02-15 11:02:31 +00:00
|
|
|
continue;
|
2019-01-31 13:43:52 +00:00
|
|
|
findPos = i;
|
2016-02-15 11:02:31 +00:00
|
|
|
}
|
2019-01-31 13:43:52 +00:00
|
|
|
if (findPos != -1) {
|
2016-02-15 11:02:31 +00:00
|
|
|
for (let i = 0; i < this._urls.length; i++)
|
2019-01-29 19:36:54 +00:00
|
|
|
if (findPos >= this._urls[i].pos &&
|
|
|
|
this._urls[i].pos + this._urls[i].url.length > findPos)
|
|
|
|
return i;
|
2016-02-15 11:02:31 +00:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2019-01-31 19:38:24 +00:00
|
|
|
var ScaleLayout = GObject.registerClass(
|
2017-10-31 01:23:39 +00:00
|
|
|
class ScaleLayout extends Clutter.BinLayout {
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(params) {
|
2017-06-13 02:24:12 +00:00
|
|
|
this._container = null;
|
2017-10-31 01:23:39 +00:00
|
|
|
super._init(params);
|
|
|
|
}
|
2017-06-13 02:24:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_connectContainer(container) {
|
2016-02-15 11:02:31 +00:00
|
|
|
if (this._container == container)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._container)
|
|
|
|
for (let id of this._signals)
|
|
|
|
this._container.disconnect(id);
|
|
|
|
|
|
|
|
this._container = container;
|
|
|
|
this._signals = [];
|
|
|
|
|
|
|
|
if (this._container)
|
|
|
|
for (let signal of ['notify::scale-x', 'notify::scale-y']) {
|
2017-10-31 00:38:18 +00:00
|
|
|
let id = this._container.connect(signal, () => {
|
|
|
|
this.layout_changed();
|
|
|
|
});
|
2016-02-15 11:02:31 +00:00
|
|
|
this._signals.push(id);
|
|
|
|
}
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
vfunc_get_preferred_width(container, forHeight) {
|
2016-02-15 11:02:31 +00:00
|
|
|
this._connectContainer(container);
|
|
|
|
|
2017-10-31 01:23:39 +00:00
|
|
|
let [min, nat] = super.vfunc_get_preferred_width(container, forHeight);
|
2016-02-15 11:02:31 +00:00
|
|
|
return [Math.floor(min * container.scale_x),
|
|
|
|
Math.floor(nat * container.scale_x)];
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
vfunc_get_preferred_height(container, forWidth) {
|
2016-02-15 11:02:31 +00:00
|
|
|
this._connectContainer(container);
|
|
|
|
|
2017-10-31 01:23:39 +00:00
|
|
|
let [min, nat] = super.vfunc_get_preferred_height(container, forWidth);
|
2016-02-15 11:02:31 +00:00
|
|
|
return [Math.floor(min * container.scale_y),
|
|
|
|
Math.floor(nat * container.scale_y)];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-10-31 01:23:39 +00:00
|
|
|
var LabelExpanderLayout = GObject.registerClass({
|
2019-01-29 18:15:23 +00: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,
|
|
|
|
0, 1, 0)
|
|
|
|
},
|
2017-10-31 01:23:39 +00:00
|
|
|
}, class LabelExpanderLayout extends Clutter.LayoutManager {
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(params) {
|
2016-02-15 11:02:31 +00:00
|
|
|
this._expansion = 0;
|
|
|
|
this._expandLines = DEFAULT_EXPAND_LINES;
|
|
|
|
|
2017-10-31 01:23:39 +00:00
|
|
|
super._init(params);
|
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
|
|
|
get expansion() {
|
|
|
|
return this._expansion;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00: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++)
|
|
|
|
this._container.get_child_at_index(i).visible = (i == visibleIndex);
|
|
|
|
|
|
|
|
this.layout_changed();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
|
|
|
set expandLines(v) {
|
|
|
|
if (v == this._expandLines)
|
|
|
|
return;
|
|
|
|
this._expandLines = v;
|
|
|
|
if (this._expansion > 0)
|
|
|
|
this.layout_changed();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
vfunc_set_container(container) {
|
2016-02-15 11:02:31 +00:00
|
|
|
this._container = container;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
vfunc_get_preferred_width(container, forHeight) {
|
2016-02-15 11:02:31 +00: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-31 01:23:39 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
vfunc_get_preferred_height(container, forWidth) {
|
2016-02-15 11:02:31 +00: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-31 01:23:39 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
vfunc_allocate(container, box, flags) {
|
2016-02-15 11:02:31 +00:00
|
|
|
for (let i = 0; i < container.get_n_children(); i++) {
|
|
|
|
let child = container.get_child_at_index(i);
|
|
|
|
|
|
|
|
if (child.visible)
|
|
|
|
child.allocate(box, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var Message = class Message {
|
|
|
|
constructor(title, body) {
|
2016-02-15 11:02:31 +00:00
|
|
|
this.expanded = false;
|
|
|
|
|
2017-06-13 02:24:12 +00:00
|
|
|
this._useBodyMarkup = false;
|
|
|
|
|
2016-02-15 11:02:31 +00:00
|
|
|
this.actor = new St.Button({ style_class: 'message',
|
|
|
|
accessible_role: Atk.Role.NOTIFICATION,
|
|
|
|
can_focus: true,
|
|
|
|
x_expand: true, x_fill: true });
|
|
|
|
this.actor.connect('key-press-event',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._onKeyPressed.bind(this));
|
2016-02-15 11:02:31 +00:00
|
|
|
|
|
|
|
let vbox = new St.BoxLayout({ vertical: true });
|
|
|
|
this.actor.set_child(vbox);
|
|
|
|
|
|
|
|
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,
|
2017-02-26 00:54:45 +00:00
|
|
|
y_align: St.Align.START,
|
2016-02-15 11:02:31 +00: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 11:13:22 +00:00
|
|
|
this._mediaControls = new St.BoxLayout();
|
|
|
|
hbox.add_actor(this._mediaControls);
|
|
|
|
|
2016-02-15 11:02:31 +00:00
|
|
|
let titleBox = new St.BoxLayout();
|
|
|
|
contentBox.add_actor(titleBox);
|
|
|
|
|
2017-02-26 02:33:26 +00:00
|
|
|
this.titleLabel = new St.Label({ style_class: 'message-title' });
|
2016-02-15 11:02:31 +00:00
|
|
|
this.setTitle(title);
|
|
|
|
titleBox.add_actor(this.titleLabel);
|
|
|
|
|
2017-02-26 02:33:26 +00:00
|
|
|
this._secondaryBin = new St.Bin({ style_class: 'message-secondary-bin',
|
|
|
|
x_expand: true, y_expand: true,
|
|
|
|
x_fill: true, y_fill: true });
|
2016-02-15 11:02:31 +00:00
|
|
|
titleBox.add_actor(this._secondaryBin);
|
|
|
|
|
|
|
|
let closeIcon = new St.Icon({ icon_name: 'window-close-symbolic',
|
|
|
|
icon_size: 16 });
|
2017-02-26 02:33:26 +00:00
|
|
|
this._closeButton = new St.Button({ child: closeIcon, opacity: 0 });
|
2016-02-15 11:02:31 +00: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);
|
|
|
|
this.bodyLabel.actor.add_style_class_name('message-body');
|
|
|
|
this._bodyStack.add_actor(this.bodyLabel.actor);
|
|
|
|
this.setBody(body);
|
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
this._closeButton.connect('clicked', this.close.bind(this));
|
2018-07-04 13:56:25 +00:00
|
|
|
let actorHoverId = this.actor.connect('notify::hover', this._sync.bind(this));
|
|
|
|
this._closeButton.connect('destroy', this.actor.disconnect.bind(this.actor, actorHoverId));
|
2017-12-02 00:27:35 +00:00
|
|
|
this.actor.connect('clicked', this._onClicked.bind(this));
|
|
|
|
this.actor.connect('destroy', this._onDestroy.bind(this));
|
2016-02-15 11:02:31 +00:00
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
close() {
|
2016-02-15 11:02:31 +00:00
|
|
|
this.emit('close');
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setIcon(actor) {
|
2016-02-15 11:02:31 +00:00
|
|
|
this._iconBin.child = actor;
|
|
|
|
this._iconBin.visible = (actor != null);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setSecondaryActor(actor) {
|
2016-02-15 11:02:31 +00:00
|
|
|
this._secondaryBin.child = actor;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setTitle(text) {
|
2016-02-15 11:02:31 +00:00
|
|
|
let title = text ? _fixMarkup(text.replace(/\n/g, ' '), false) : '';
|
|
|
|
this.titleLabel.clutter_text.set_markup(title);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setBody(text) {
|
2016-02-15 11:02:31 +00: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-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setUseBodyMarkup(enable) {
|
2016-02-15 11:02:31 +00:00
|
|
|
if (this._useBodyMarkup === enable)
|
|
|
|
return;
|
|
|
|
this._useBodyMarkup = enable;
|
|
|
|
if (this.bodyLabel)
|
|
|
|
this.setBody(this._bodyText);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setActionArea(actor) {
|
2016-02-15 11:02:31 +00: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-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
addMediaControl(iconName, callback) {
|
2016-02-15 11:13:22 +00: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-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:13:22 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setExpandedBody(actor) {
|
2016-02-15 11:02:31 +00: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-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setExpandedLines(nLines) {
|
2016-02-15 11:02:31 +00:00
|
|
|
this._bodyStack.layout_manager.expandLines = nLines;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
expand(animate) {
|
2016-02-15 11:02:31 +00:00
|
|
|
this.expanded = true;
|
|
|
|
|
|
|
|
this._actionBin.visible = (this._actionBin.get_n_children() > 0);
|
|
|
|
|
|
|
|
if (this._bodyStack.get_n_children() < 2) {
|
|
|
|
this._expandedLabel = new URLHighlighter(this._bodyText,
|
|
|
|
true, this._useBodyMarkup);
|
|
|
|
this.setExpandedBody(this._expandedLabel.actor);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (animate) {
|
|
|
|
Tweener.addTween(this._bodyStack.layout_manager,
|
|
|
|
{ expansion: 1,
|
2019-08-01 23:13:10 +00:00
|
|
|
time: MessageTray.ANIMATION_TIME / 1000,
|
2016-02-15 11:02:31 +00:00
|
|
|
transition: 'easeOutQuad' });
|
|
|
|
this._actionBin.scale_y = 0;
|
|
|
|
Tweener.addTween(this._actionBin,
|
|
|
|
{ scale_y: 1,
|
2019-08-01 23:13:10 +00:00
|
|
|
time: MessageTray.ANIMATION_TIME / 1000,
|
2016-02-15 11:02:31 +00:00
|
|
|
transition: 'easeOutQuad' });
|
|
|
|
} else {
|
|
|
|
this._bodyStack.layout_manager.expansion = 1;
|
|
|
|
this._actionBin.scale_y = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.emit('expanded');
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
unexpand(animate) {
|
2016-02-15 11:02:31 +00:00
|
|
|
if (animate) {
|
|
|
|
Tweener.addTween(this._bodyStack.layout_manager,
|
|
|
|
{ expansion: 0,
|
2019-08-01 23:13:10 +00:00
|
|
|
time: MessageTray.ANIMATION_TIME / 1000,
|
2016-02-15 11:02:31 +00:00
|
|
|
transition: 'easeOutQuad' });
|
|
|
|
Tweener.addTween(this._actionBin,
|
|
|
|
{ scale_y: 0,
|
2019-08-01 23:13:10 +00:00
|
|
|
time: MessageTray.ANIMATION_TIME / 1000,
|
2016-02-15 11:02:31 +00:00
|
|
|
transition: 'easeOutQuad',
|
2019-06-29 15:37:59 +00:00
|
|
|
onComplete: () => {
|
2016-02-15 11:02:31 +00:00
|
|
|
this._actionBin.hide();
|
|
|
|
this.expanded = false;
|
2019-01-29 01:27:05 +00:00
|
|
|
} });
|
2016-02-15 11:02:31 +00:00
|
|
|
} else {
|
|
|
|
this._bodyStack.layout_manager.expansion = 0;
|
|
|
|
this._actionBin.scale_y = 0;
|
|
|
|
this.expanded = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.emit('unexpanded');
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
canClose() {
|
2018-12-17 17:36:03 +00:00
|
|
|
return false;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sync() {
|
2017-02-26 02:33:26 +00:00
|
|
|
let visible = this.actor.hover && this.canClose();
|
|
|
|
this._closeButton.opacity = visible ? 255 : 0;
|
2018-02-23 09:27:07 +00:00
|
|
|
this._closeButton.reactive = visible;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onClicked() {
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onDestroy() {
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onKeyPressed(a, event) {
|
2016-02-15 11:02:31 +00:00
|
|
|
let keysym = event.get_key_symbol();
|
|
|
|
|
|
|
|
if (keysym == Clutter.KEY_Delete ||
|
|
|
|
keysym == Clutter.KEY_KP_Delete) {
|
|
|
|
this.close();
|
|
|
|
return Clutter.EVENT_STOP;
|
|
|
|
}
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2016-02-15 11:02:31 +00:00
|
|
|
Signals.addSignalMethods(Message.prototype);
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var MessageListSection = class MessageListSection {
|
|
|
|
constructor() {
|
2016-02-15 11:02:31 +00:00
|
|
|
this.actor = new St.BoxLayout({ style_class: 'message-list-section',
|
|
|
|
clip_to_allocation: true,
|
|
|
|
x_expand: true, vertical: true });
|
|
|
|
|
|
|
|
this._list = new St.BoxLayout({ style_class: 'message-list-section-list',
|
|
|
|
vertical: true });
|
|
|
|
this.actor.add_actor(this._list);
|
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
this._list.connect('actor-added', this._sync.bind(this));
|
|
|
|
this._list.connect('actor-removed', this._sync.bind(this));
|
2016-02-15 11:02:31 +00:00
|
|
|
|
|
|
|
let id = Main.sessionMode.connect('updated',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._sync.bind(this));
|
2017-10-31 00:38:18 +00:00
|
|
|
this.actor.connect('destroy', () => {
|
2016-02-15 11:02:31 +00:00
|
|
|
Main.sessionMode.disconnect(id);
|
|
|
|
});
|
|
|
|
|
|
|
|
this._messages = new Map();
|
|
|
|
this._date = new Date();
|
|
|
|
this.empty = true;
|
2017-02-26 21:23:11 +00:00
|
|
|
this.canClear = false;
|
2016-02-15 11:02:31 +00:00
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onKeyFocusIn(actor) {
|
2016-02-15 11:02:31 +00:00
|
|
|
this.emit('key-focus-in', actor);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
|
|
|
get allowed() {
|
|
|
|
return true;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setDate(date) {
|
2016-02-15 11:02:31 +00:00
|
|
|
if (Calendar.sameDay(date, this._date))
|
|
|
|
return;
|
|
|
|
this._date = date;
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
addMessage(message, animate) {
|
2016-02-15 11:02:31 +00:00
|
|
|
this.addMessageAtIndex(message, -1, animate);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
addMessageAtIndex(message, index, animate) {
|
2016-02-15 11:02:31 +00:00
|
|
|
let obj = {
|
|
|
|
container: null,
|
|
|
|
destroyId: 0,
|
|
|
|
keyFocusId: 0,
|
|
|
|
closeId: 0
|
|
|
|
};
|
|
|
|
let pivot = new Clutter.Point({ x: .5, y: .5 });
|
|
|
|
let scale = animate ? 0 : 1;
|
|
|
|
obj.container = new St.Widget({ layout_manager: new ScaleLayout(),
|
|
|
|
pivot_point: pivot,
|
|
|
|
scale_x: scale, scale_y: scale });
|
|
|
|
obj.keyFocusId = message.actor.connect('key-focus-in',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._onKeyFocusIn.bind(this));
|
2017-10-31 00:38:18 +00:00
|
|
|
obj.destroyId = message.actor.connect('destroy', () => {
|
|
|
|
this.removeMessage(message, false);
|
|
|
|
});
|
|
|
|
obj.closeId = message.connect('close', () => {
|
|
|
|
this.removeMessage(message, true);
|
|
|
|
});
|
2016-02-15 11:02:31 +00:00
|
|
|
|
|
|
|
this._messages.set(message, obj);
|
|
|
|
obj.container.add_actor(message.actor);
|
|
|
|
|
|
|
|
this._list.insert_child_at_index(obj.container, index);
|
|
|
|
|
|
|
|
if (animate)
|
|
|
|
Tweener.addTween(obj.container, { scale_x: 1,
|
|
|
|
scale_y: 1,
|
2019-08-01 23:13:10 +00:00
|
|
|
time: MESSAGE_ANIMATION_TIME / 1000,
|
2016-02-15 11:02:31 +00:00
|
|
|
transition: 'easeOutQuad' });
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
moveMessage(message, index, animate) {
|
2016-02-15 11:02:31 +00:00
|
|
|
let obj = this._messages.get(message);
|
|
|
|
|
|
|
|
if (!animate) {
|
|
|
|
this._list.set_child_at_index(obj.container, index);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
let onComplete = () => {
|
2016-02-15 11:02:31 +00:00
|
|
|
this._list.set_child_at_index(obj.container, index);
|
|
|
|
Tweener.addTween(obj.container, { scale_x: 1,
|
|
|
|
scale_y: 1,
|
2019-08-01 23:13:10 +00:00
|
|
|
time: MESSAGE_ANIMATION_TIME / 1000,
|
2016-02-15 11:02:31 +00:00
|
|
|
transition: 'easeOutQuad' });
|
2017-10-31 00:38:18 +00:00
|
|
|
};
|
2016-02-15 11:02:31 +00:00
|
|
|
Tweener.addTween(obj.container, { scale_x: 0,
|
|
|
|
scale_y: 0,
|
2019-08-01 23:13:10 +00:00
|
|
|
time: MESSAGE_ANIMATION_TIME / 1000,
|
2016-02-15 11:02:31 +00:00
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: onComplete });
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
removeMessage(message, animate) {
|
2016-02-15 11:02:31 +00:00
|
|
|
let obj = this._messages.get(message);
|
|
|
|
|
|
|
|
message.actor.disconnect(obj.destroyId);
|
|
|
|
message.actor.disconnect(obj.keyFocusId);
|
|
|
|
message.disconnect(obj.closeId);
|
|
|
|
|
|
|
|
this._messages.delete(message);
|
|
|
|
|
|
|
|
if (animate) {
|
|
|
|
Tweener.addTween(obj.container, { scale_x: 0, scale_y: 0,
|
2019-08-01 23:13:10 +00:00
|
|
|
time: MESSAGE_ANIMATION_TIME / 1000,
|
2016-02-15 11:02:31 +00:00
|
|
|
transition: 'easeOutQuad',
|
2017-10-31 00:03:21 +00:00
|
|
|
onComplete() {
|
2016-02-15 11:02:31 +00:00
|
|
|
obj.container.destroy();
|
|
|
|
global.sync_pointer();
|
2019-01-29 01:27:05 +00:00
|
|
|
} });
|
2016-02-15 11:02:31 +00:00
|
|
|
} else {
|
|
|
|
obj.container.destroy();
|
|
|
|
global.sync_pointer();
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
clear() {
|
2017-10-31 00:38:18 +00:00
|
|
|
let messages = [...this._messages.keys()].filter(msg => msg.canClose());
|
2016-02-15 11:02:31 +00:00
|
|
|
|
|
|
|
// If there are few messages, letting them all zoom out looks OK
|
|
|
|
if (messages.length < 2) {
|
2017-10-31 00:38:18 +00:00
|
|
|
messages.forEach(message => {
|
2016-02-15 11:02:31 +00: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];
|
|
|
|
let obj = this._messages.get(message);
|
|
|
|
Tweener.addTween(obj.container,
|
|
|
|
{ anchor_x: this._list.width,
|
|
|
|
opacity: 0,
|
2019-08-01 23:13:10 +00:00
|
|
|
time: MESSAGE_ANIMATION_TIME / 1000,
|
|
|
|
delay: i * delay / 1000,
|
2016-02-15 11:02:31 +00:00
|
|
|
transition: 'easeOutQuad',
|
2017-10-31 00:03:21 +00:00
|
|
|
onComplete() {
|
2016-02-15 11:02:31 +00:00
|
|
|
message.close();
|
2019-01-29 01:27:05 +00:00
|
|
|
} });
|
2016-02-15 11:02:31 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_canClear() {
|
2016-02-15 11:02:31 +00:00
|
|
|
for (let message of this._messages.keys())
|
|
|
|
if (message.canClose())
|
|
|
|
return true;
|
|
|
|
return false;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_shouldShow() {
|
2016-02-15 11:02:31 +00:00
|
|
|
return !this.empty;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-02-15 11:02:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sync() {
|
2016-02-15 11:02:31 +00:00
|
|
|
let empty = this._list.get_n_children() == 0;
|
|
|
|
let changed = this.empty !== empty;
|
|
|
|
this.empty = empty;
|
|
|
|
|
|
|
|
if (changed)
|
|
|
|
this.emit('empty-changed');
|
|
|
|
|
2017-02-26 21:23:11 +00:00
|
|
|
let canClear = this._canClear();
|
|
|
|
changed = this.canClear !== canClear;
|
|
|
|
this.canClear = canClear;
|
|
|
|
|
|
|
|
if (changed)
|
|
|
|
this.emit('can-clear-changed');
|
|
|
|
|
2016-02-15 11:02:31 +00:00
|
|
|
this.actor.visible = this.allowed && this._shouldShow();
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2016-02-15 11:02:31 +00:00
|
|
|
Signals.addSignalMethods(MessageListSection.prototype);
|