2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-10-03 15:48:56 -04:00
|
|
|
|
2019-02-08 22:21:36 -05:00
|
|
|
const { Clutter, Gio, GLib, GObject, Shell, St } = imports.gi;
|
2017-02-26 20:17:29 -05:00
|
|
|
const Gettext = imports.gettext;
|
2017-02-23 16:50:04 -05:00
|
|
|
const Mainloop = imports.mainloop;
|
|
|
|
const Signals = imports.signals;
|
2010-11-17 11:43:08 -05:00
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
2013-03-11 13:43:38 -04:00
|
|
|
const Tweener = imports.ui.tweener;
|
2015-02-25 10:43:59 -05:00
|
|
|
const Params = imports.misc.params;
|
2013-03-11 13:43:38 -04:00
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var SCROLL_TIME = 0.1;
|
2010-11-17 11:43:08 -05:00
|
|
|
|
2011-04-13 09:18:00 -04:00
|
|
|
// http://daringfireball.net/2010/07/improved_regex_for_matching_urls
|
2018-02-27 07:20:02 -05:00
|
|
|
const _balancedParens = '\\([^\\s()<>]+\\)';
|
2011-04-13 09:40:28 -04:00
|
|
|
const _leadingJunk = '[\\s`(\\[{\'\\"<\u00AB\u201C\u2018]';
|
2011-04-13 09:18:00 -04:00
|
|
|
const _notTrailingJunk = '[^\\s`!()\\[\\]{};:\'\\".,<>?\u00AB\u00BB\u201C\u201D\u2018\u2019]';
|
|
|
|
|
|
|
|
const _urlRegexp = new RegExp(
|
2011-04-13 09:40:28 -04:00
|
|
|
'(^|' + _leadingJunk + ')' +
|
|
|
|
'(' +
|
2011-04-13 09:18:00 -04:00
|
|
|
'(?:' +
|
2013-04-14 16:15:04 -04:00
|
|
|
'(?:http|https|ftp)://' + // scheme://
|
2011-04-13 09:18:00 -04:00
|
|
|
'|' +
|
|
|
|
'www\\d{0,3}[.]' + // www.
|
|
|
|
'|' +
|
|
|
|
'[a-z0-9.\\-]+[.][a-z]{2,4}/' + // foo.xx/
|
|
|
|
')' +
|
|
|
|
'(?:' + // one or more:
|
|
|
|
'[^\\s()<>]+' + // run of non-space non-()
|
|
|
|
'|' + // or
|
|
|
|
_balancedParens + // balanced parens
|
|
|
|
')+' +
|
|
|
|
'(?:' + // end with:
|
|
|
|
_balancedParens + // balanced parens
|
|
|
|
'|' + // or
|
|
|
|
_notTrailingJunk + // last non-junk char
|
|
|
|
')' +
|
|
|
|
')', 'gi');
|
2010-10-03 15:48:56 -04:00
|
|
|
|
2015-02-25 10:43:59 -05:00
|
|
|
let _desktopSettings = null;
|
|
|
|
|
2010-10-03 15:48:56 -04:00
|
|
|
// findUrls:
|
|
|
|
// @str: string to find URLs in
|
|
|
|
//
|
|
|
|
// Searches @str for URLs and returns an array of objects with %url
|
|
|
|
// properties showing the matched URL string, and %pos properties indicating
|
|
|
|
// the position within @str where the URL was found.
|
|
|
|
//
|
|
|
|
// Return value: the list of match objects, as described above
|
|
|
|
function findUrls(str) {
|
|
|
|
let res = [], match;
|
|
|
|
while ((match = _urlRegexp.exec(str)))
|
2011-04-13 09:40:28 -04:00
|
|
|
res.push({ url: match[2], pos: match.index + match[1].length });
|
2010-10-03 15:48:56 -04:00
|
|
|
return res;
|
|
|
|
}
|
2010-11-17 11:43:08 -05:00
|
|
|
|
|
|
|
// spawn:
|
|
|
|
// @argv: an argv array
|
|
|
|
//
|
|
|
|
// Runs @argv in the background, handling any errors that occur
|
|
|
|
// when trying to start the program.
|
|
|
|
function spawn(argv) {
|
|
|
|
try {
|
|
|
|
trySpawn(argv);
|
|
|
|
} catch (err) {
|
|
|
|
_handleSpawnError(argv[0], err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// spawnCommandLine:
|
|
|
|
// @command_line: a command line
|
|
|
|
//
|
|
|
|
// Runs @command_line in the background, handling any errors that
|
|
|
|
// occur when trying to parse or start the program.
|
|
|
|
function spawnCommandLine(command_line) {
|
|
|
|
try {
|
2011-06-23 18:04:12 -04:00
|
|
|
let [success, argv] = GLib.shell_parse_argv(command_line);
|
2010-11-17 11:43:08 -05:00
|
|
|
trySpawn(argv);
|
|
|
|
} catch (err) {
|
|
|
|
_handleSpawnError(command_line, err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-02 13:39:58 -04:00
|
|
|
// spawnApp:
|
|
|
|
// @argv: an argv array
|
|
|
|
//
|
|
|
|
// Runs @argv as if it was an application, handling startup notification
|
|
|
|
function spawnApp(argv) {
|
|
|
|
try {
|
|
|
|
let app = Gio.AppInfo.create_from_commandline(argv.join(' '), null,
|
|
|
|
Gio.AppInfoCreateFlags.SUPPORTS_STARTUP_NOTIFICATION);
|
|
|
|
|
2014-01-19 12:34:32 -05:00
|
|
|
let context = global.create_app_launch_context(0, -1);
|
2017-07-14 21:42:06 -04:00
|
|
|
app.launch([], context);
|
2013-10-02 13:39:58 -04:00
|
|
|
} catch(err) {
|
|
|
|
_handleSpawnError(argv[0], err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-17 11:43:08 -05:00
|
|
|
// trySpawn:
|
|
|
|
// @argv: an argv array
|
|
|
|
//
|
|
|
|
// Runs @argv in the background. If launching @argv fails,
|
|
|
|
// this will throw an error.
|
|
|
|
function trySpawn(argv)
|
|
|
|
{
|
2012-05-09 21:23:19 -04:00
|
|
|
var success, pid;
|
2010-11-17 11:43:08 -05:00
|
|
|
try {
|
2012-05-09 21:23:19 -04:00
|
|
|
[success, pid] = GLib.spawn_async(null, argv, null,
|
|
|
|
GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD,
|
2012-08-07 14:07:34 -04:00
|
|
|
null);
|
2010-11-17 11:43:08 -05:00
|
|
|
} catch (err) {
|
2012-06-19 17:32:45 -04:00
|
|
|
/* Rewrite the error in case of ENOENT */
|
|
|
|
if (err.matches(GLib.SpawnError, GLib.SpawnError.NOENT)) {
|
|
|
|
throw new GLib.SpawnError({ code: GLib.SpawnError.NOENT,
|
|
|
|
message: _("Command not found") });
|
|
|
|
} else if (err instanceof GLib.Error) {
|
2011-01-27 15:26:58 -05:00
|
|
|
// The exception from gjs contains an error string like:
|
|
|
|
// Error invoking GLib.spawn_command_line_async: Failed to
|
|
|
|
// execute child process "foo" (No such file or directory)
|
|
|
|
// We are only interested in the part in the parentheses. (And
|
|
|
|
// we can't pattern match the text, since it gets localized.)
|
2012-06-19 17:32:45 -04:00
|
|
|
let message = err.message.replace(/.*\((.+)\)/, '$1');
|
|
|
|
throw new (err.constructor)({ code: err.code,
|
|
|
|
message: message });
|
|
|
|
} else {
|
|
|
|
throw err;
|
2011-01-27 15:26:58 -05:00
|
|
|
}
|
2010-11-17 11:43:08 -05:00
|
|
|
}
|
2012-05-09 21:23:19 -04:00
|
|
|
// Dummy child watch; we don't want to double-fork internally
|
|
|
|
// because then we lose the parent-child relationship, which
|
|
|
|
// can break polkit. See https://bugzilla.redhat.com//show_bug.cgi?id=819275
|
2017-10-30 20:38:18 -04:00
|
|
|
GLib.child_watch_add(GLib.PRIORITY_DEFAULT, pid, () => {});
|
2010-11-17 11:43:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// trySpawnCommandLine:
|
|
|
|
// @command_line: a command line
|
|
|
|
//
|
|
|
|
// Runs @command_line in the background. If launching @command_line
|
|
|
|
// fails, this will throw an error.
|
|
|
|
function trySpawnCommandLine(command_line) {
|
2011-06-23 17:55:49 -04:00
|
|
|
let success, argv;
|
2010-11-17 11:43:08 -05:00
|
|
|
|
|
|
|
try {
|
2011-06-23 17:55:49 -04:00
|
|
|
[success, argv] = GLib.shell_parse_argv(command_line);
|
2010-11-17 11:43:08 -05:00
|
|
|
} catch (err) {
|
|
|
|
// Replace "Error invoking GLib.shell_parse_argv: " with
|
|
|
|
// something nicer
|
|
|
|
err.message = err.message.replace(/[^:]*: /, _("Could not parse command:") + "\n");
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
trySpawn(argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
function _handleSpawnError(command, err) {
|
2014-01-17 16:30:49 -05:00
|
|
|
let title = _("Execution of “%s” failed:").format(command);
|
2011-03-19 13:59:22 -04:00
|
|
|
Main.notifyError(title, err.message);
|
2010-11-17 11:43:08 -05:00
|
|
|
}
|
2010-12-17 15:30:12 -05:00
|
|
|
|
2017-02-26 20:17:29 -05:00
|
|
|
function formatTimeSpan(date) {
|
|
|
|
let now = GLib.DateTime.new_now_local();
|
|
|
|
|
|
|
|
let timespan = now.difference(date);
|
|
|
|
|
|
|
|
let minutesAgo = timespan / GLib.TIME_SPAN_MINUTE;
|
|
|
|
let hoursAgo = timespan / GLib.TIME_SPAN_HOUR;
|
|
|
|
let daysAgo = timespan / GLib.TIME_SPAN_DAY;
|
|
|
|
let weeksAgo = daysAgo / 7;
|
|
|
|
let monthsAgo = daysAgo / 30;
|
|
|
|
let yearsAgo = weeksAgo / 52;
|
|
|
|
|
|
|
|
if (minutesAgo < 5)
|
|
|
|
return _("Just now");
|
|
|
|
if (hoursAgo < 1)
|
|
|
|
return Gettext.ngettext("%d minute ago",
|
|
|
|
"%d minutes ago", minutesAgo).format(minutesAgo);
|
|
|
|
if (daysAgo < 1)
|
|
|
|
return Gettext.ngettext("%d hour ago",
|
|
|
|
"%d hours ago", hoursAgo).format(hoursAgo);
|
|
|
|
if (daysAgo < 2)
|
|
|
|
return _("Yesterday");
|
|
|
|
if (daysAgo < 15)
|
|
|
|
return Gettext.ngettext("%d day ago",
|
|
|
|
"%d days ago", daysAgo).format(daysAgo);
|
|
|
|
if (weeksAgo < 8)
|
|
|
|
return Gettext.ngettext("%d week ago",
|
|
|
|
"%d weeks ago", weeksAgo).format(weeksAgo);
|
|
|
|
if (yearsAgo < 1)
|
|
|
|
return Gettext.ngettext("%d month ago",
|
|
|
|
"%d months ago", monthsAgo).format(monthsAgo);
|
|
|
|
return Gettext.ngettext("%d year ago",
|
|
|
|
"%d years ago", yearsAgo).format(yearsAgo);
|
|
|
|
}
|
|
|
|
|
2015-02-25 14:25:04 -05:00
|
|
|
function formatTime(time, params) {
|
|
|
|
let date;
|
|
|
|
// HACK: The built-in Date type sucks at timezones, which we need for the
|
|
|
|
// world clock; it's often more convenient though, so allow either
|
|
|
|
// Date or GLib.DateTime as parameter
|
|
|
|
if (time instanceof Date)
|
|
|
|
date = GLib.DateTime.new_from_unix_local(time.getTime() / 1000);
|
|
|
|
else
|
|
|
|
date = time;
|
2015-02-25 10:43:59 -05:00
|
|
|
|
2015-02-25 14:25:04 -05:00
|
|
|
let now = GLib.DateTime.new_now_local();
|
|
|
|
|
|
|
|
let daysAgo = now.difference(date) / (24 * 60 * 60 * 1000 * 1000);
|
2015-02-25 10:43:59 -05:00
|
|
|
|
|
|
|
let format;
|
|
|
|
|
|
|
|
if (_desktopSettings == null)
|
|
|
|
_desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
|
|
|
|
let clockFormat = _desktopSettings.get_string('clock-format');
|
|
|
|
|
|
|
|
params = Params.parse(params, { timeOnly: false });
|
|
|
|
|
2017-05-21 15:12:49 -04:00
|
|
|
if (clockFormat == '24h') {
|
2015-02-25 10:43:59 -05:00
|
|
|
// Show only the time if date is on today
|
|
|
|
if (daysAgo < 1 || params.timeOnly)
|
|
|
|
/* Translators: Time in 24h format */
|
|
|
|
format = N_("%H\u2236%M");
|
|
|
|
// Show the word "Yesterday" and time if date is on yesterday
|
|
|
|
else if (daysAgo <2)
|
|
|
|
/* Translators: this is the word "Yesterday" followed by a
|
|
|
|
time string in 24h format. i.e. "Yesterday, 14:30" */
|
|
|
|
// xgettext:no-c-format
|
|
|
|
format = N_("Yesterday, %H\u2236%M");
|
|
|
|
// Show a week day and time if date is in the last week
|
|
|
|
else if (daysAgo < 7)
|
|
|
|
/* Translators: this is the week day name followed by a time
|
|
|
|
string in 24h format. i.e. "Monday, 14:30" */
|
|
|
|
// xgettext:no-c-format
|
|
|
|
format = N_("%A, %H\u2236%M");
|
2015-02-25 14:25:04 -05:00
|
|
|
else if (date.get_year() == now.get_year())
|
2015-02-25 10:43:59 -05:00
|
|
|
/* Translators: this is the month name and day number
|
|
|
|
followed by a time string in 24h format.
|
|
|
|
i.e. "May 25, 14:30" */
|
|
|
|
// xgettext:no-c-format
|
2018-10-15 10:50:02 -04:00
|
|
|
format = N_("%B %-d, %H\u2236%M");
|
2015-02-25 10:43:59 -05:00
|
|
|
else
|
|
|
|
/* Translators: this is the month name, day number, year
|
|
|
|
number followed by a time string in 24h format.
|
|
|
|
i.e. "May 25 2012, 14:30" */
|
|
|
|
// xgettext:no-c-format
|
2018-10-15 10:50:02 -04:00
|
|
|
format = N_("%B %-d %Y, %H\u2236%M");
|
2015-02-25 10:43:59 -05:00
|
|
|
} else {
|
|
|
|
// Show only the time if date is on today
|
|
|
|
if (daysAgo < 1 || params.timeOnly)
|
|
|
|
/* Translators: Time in 12h format */
|
|
|
|
format = N_("%l\u2236%M %p");
|
|
|
|
// Show the word "Yesterday" and time if date is on yesterday
|
|
|
|
else if (daysAgo <2)
|
|
|
|
/* Translators: this is the word "Yesterday" followed by a
|
|
|
|
time string in 12h format. i.e. "Yesterday, 2:30 pm" */
|
|
|
|
// xgettext:no-c-format
|
|
|
|
format = N_("Yesterday, %l\u2236%M %p");
|
|
|
|
// Show a week day and time if date is in the last week
|
|
|
|
else if (daysAgo < 7)
|
|
|
|
/* Translators: this is the week day name followed by a time
|
|
|
|
string in 12h format. i.e. "Monday, 2:30 pm" */
|
|
|
|
// xgettext:no-c-format
|
|
|
|
format = N_("%A, %l\u2236%M %p");
|
2015-02-25 14:25:04 -05:00
|
|
|
else if (date.get_year() == now.get_year())
|
2015-02-25 10:43:59 -05:00
|
|
|
/* Translators: this is the month name and day number
|
|
|
|
followed by a time string in 12h format.
|
|
|
|
i.e. "May 25, 2:30 pm" */
|
|
|
|
// xgettext:no-c-format
|
2018-10-15 10:50:02 -04:00
|
|
|
format = N_("%B %-d, %l\u2236%M %p");
|
2015-02-25 10:43:59 -05:00
|
|
|
else
|
|
|
|
/* Translators: this is the month name, day number, year
|
|
|
|
number followed by a time string in 12h format.
|
|
|
|
i.e. "May 25 2012, 2:30 pm"*/
|
|
|
|
// xgettext:no-c-format
|
2018-10-15 10:50:02 -04:00
|
|
|
format = N_("%B %-d %Y, %l\u2236%M %p");
|
2015-02-25 10:43:59 -05:00
|
|
|
}
|
2017-06-23 11:37:13 -04:00
|
|
|
|
|
|
|
let formattedTime = date.format(Shell.util_translate_time_string(format));
|
|
|
|
// prepend LTR-mark to colon/ratio to force a text direction on times
|
|
|
|
return formattedTime.replace(/([:\u2236])/g, '\u200e$1');
|
2015-02-25 10:43:59 -05:00
|
|
|
}
|
|
|
|
|
2015-02-25 17:23:49 -05:00
|
|
|
function createTimeLabel(date, params) {
|
|
|
|
if (_desktopSettings == null)
|
|
|
|
_desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
|
|
|
|
|
|
|
|
let label = new St.Label({ text: formatTime(date, params) });
|
2017-10-30 20:38:18 -04:00
|
|
|
let id = _desktopSettings.connect('changed::clock-format', () => {
|
2015-02-25 17:23:49 -05:00
|
|
|
label.text = formatTime(date, params);
|
|
|
|
});
|
2017-10-30 20:38:18 -04:00
|
|
|
label.connect('destroy', () => { _desktopSettings.disconnect(id); });
|
2015-02-25 17:23:49 -05:00
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
2011-12-17 17:52:11 -05:00
|
|
|
// lowerBound:
|
|
|
|
// @array: an array or array-like object, already sorted
|
|
|
|
// according to @cmp
|
|
|
|
// @val: the value to add
|
|
|
|
// @cmp: a comparator (or undefined to compare as numbers)
|
|
|
|
//
|
|
|
|
// Returns the position of the first element that is not
|
|
|
|
// lower than @val, according to @cmp.
|
|
|
|
// That is, returns the first position at which it
|
|
|
|
// is possible to insert @val without violating the
|
|
|
|
// order.
|
|
|
|
// This is quite like an ordinary binary search, except
|
|
|
|
// that it doesn't stop at first element comparing equal.
|
|
|
|
|
|
|
|
function lowerBound(array, val, cmp) {
|
|
|
|
let min, max, mid, v;
|
2017-10-30 20:38:18 -04:00
|
|
|
cmp = cmp || ((a, b) => a - b);
|
2011-12-17 17:52:11 -05:00
|
|
|
|
|
|
|
if (array.length == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
min = 0; max = array.length;
|
|
|
|
while (min < (max - 1)) {
|
|
|
|
mid = Math.floor((min + max) / 2);
|
|
|
|
v = cmp(array[mid], val);
|
|
|
|
|
|
|
|
if (v < 0)
|
|
|
|
min = mid + 1;
|
|
|
|
else
|
|
|
|
max = mid;
|
|
|
|
}
|
|
|
|
|
2011-12-20 15:30:30 -05:00
|
|
|
return (min == max || cmp(array[min], val) < 0) ? max : min;
|
2011-12-17 17:52:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// insertSorted:
|
|
|
|
// @array: an array sorted according to @cmp
|
|
|
|
// @val: a value to insert
|
|
|
|
// @cmp: the sorting function
|
|
|
|
//
|
|
|
|
// Inserts @val into @array, preserving the
|
|
|
|
// sorting invariants.
|
|
|
|
// Returns the position at which it was inserted
|
|
|
|
function insertSorted(array, val, cmp) {
|
|
|
|
let pos = lowerBound(array, val, cmp);
|
|
|
|
array.splice(pos, 0, val);
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
2013-02-18 15:35:02 -05:00
|
|
|
|
2017-10-30 21:23:39 -04:00
|
|
|
var CloseButton = GObject.registerClass(
|
|
|
|
class CloseButton extends St.Button {
|
2017-10-30 20:03:21 -04:00
|
|
|
_init(boxpointer) {
|
2017-10-30 21:23:39 -04:00
|
|
|
super._init({ style_class: 'notification-close'});
|
2013-09-10 05:48:55 -04:00
|
|
|
|
|
|
|
// This is a bit tricky. St.Bin has its own x-align/y-align properties
|
|
|
|
// that compete with Clutter's properties. This should be fixed for
|
|
|
|
// Clutter 2.0. Since St.Bin doesn't define its own setters, the
|
|
|
|
// setters are a workaround to get Clutter's version.
|
|
|
|
this.set_x_align(Clutter.ActorAlign.END);
|
|
|
|
this.set_y_align(Clutter.ActorAlign.START);
|
|
|
|
|
|
|
|
// XXX Clutter 2.0 workaround: ClutterBinLayout needs expand
|
|
|
|
// to respect the alignments.
|
|
|
|
this.set_x_expand(true);
|
|
|
|
this.set_y_expand(true);
|
|
|
|
|
|
|
|
this._boxPointer = boxpointer;
|
|
|
|
if (boxpointer)
|
2017-12-01 19:27:35 -05:00
|
|
|
this._boxPointer.connect('arrow-side-changed', this._sync.bind(this));
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2013-09-10 05:48:55 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_computeBoxPointerOffset() {
|
2013-09-10 05:48:55 -04:00
|
|
|
if (!this._boxPointer || !this._boxPointer.actor.get_stage())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
let side = this._boxPointer.arrowSide;
|
|
|
|
if (side == St.Side.TOP)
|
|
|
|
return this._boxPointer.getArrowHeight();
|
|
|
|
else
|
|
|
|
return 0;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2013-02-18 15:35:02 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sync() {
|
2013-09-10 05:48:55 -04:00
|
|
|
let themeNode = this.get_theme_node();
|
2013-02-18 15:35:02 -05:00
|
|
|
|
2013-09-10 05:48:55 -04:00
|
|
|
let offY = this._computeBoxPointerOffset();
|
|
|
|
this.translation_x = themeNode.get_length('-shell-close-overlap-x')
|
|
|
|
this.translation_y = themeNode.get_length('-shell-close-overlap-y') + offY;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2013-02-18 15:35:02 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
vfunc_style_changed() {
|
2013-09-10 05:48:55 -04:00
|
|
|
this._sync();
|
2017-10-30 21:23:39 -04:00
|
|
|
super.vfunc_style_changed();
|
|
|
|
}
|
2013-09-10 05:48:55 -04:00
|
|
|
});
|
2013-02-18 15:35:02 -05:00
|
|
|
|
2013-09-10 05:48:55 -04:00
|
|
|
function makeCloseButton(boxpointer) {
|
|
|
|
return new CloseButton(boxpointer);
|
2013-02-18 15:35:02 -05:00
|
|
|
}
|
2013-03-11 13:43:38 -04:00
|
|
|
|
|
|
|
function ensureActorVisibleInScrollView(scrollView, actor) {
|
|
|
|
let adjustment = scrollView.vscroll.adjustment;
|
|
|
|
let [value, lower, upper, stepIncrement, pageIncrement, pageSize] = adjustment.get_values();
|
|
|
|
|
|
|
|
let offset = 0;
|
|
|
|
let vfade = scrollView.get_effect("fade");
|
|
|
|
if (vfade)
|
|
|
|
offset = vfade.vfade_offset;
|
|
|
|
|
|
|
|
let box = actor.get_allocation_box();
|
|
|
|
let y1 = box.y1, y2 = box.y2;
|
|
|
|
|
|
|
|
let parent = actor.get_parent();
|
|
|
|
while (parent != scrollView) {
|
|
|
|
if (!parent)
|
|
|
|
throw new Error("actor not in scroll view");
|
|
|
|
|
|
|
|
let box = parent.get_allocation_box();
|
|
|
|
y1 += box.y1;
|
|
|
|
y2 += box.y1;
|
|
|
|
parent = parent.get_parent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (y1 < value + offset)
|
|
|
|
value = Math.max(0, y1 - offset);
|
|
|
|
else if (y2 > value + pageSize - offset)
|
|
|
|
value = Math.min(upper, y2 + offset - pageSize);
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
Tweener.addTween(adjustment,
|
|
|
|
{ value: value,
|
|
|
|
time: SCROLL_TIME,
|
|
|
|
transition: 'easeOutQuad' });
|
|
|
|
}
|
2017-02-23 16:50:04 -05:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var AppSettingsMonitor = class {
|
|
|
|
constructor(appId, schemaId) {
|
2017-02-23 16:50:04 -05:00
|
|
|
this._appId = appId;
|
|
|
|
this._schemaId = schemaId;
|
|
|
|
|
|
|
|
this._app = null;
|
|
|
|
this._settings = null;
|
|
|
|
this._handlers = [];
|
|
|
|
|
|
|
|
this._schemaSource = Gio.SettingsSchemaSource.get_default();
|
|
|
|
|
|
|
|
this._appSystem = Shell.AppSystem.get_default();
|
|
|
|
this._appSystem.connect('installed-changed',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onInstalledChanged.bind(this));
|
2017-02-23 16:50:04 -05:00
|
|
|
this._onInstalledChanged();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2017-02-23 16:50:04 -05:00
|
|
|
|
|
|
|
get available() {
|
|
|
|
return this._app != null && this._settings != null;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2017-02-23 16:50:04 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
activateApp() {
|
2017-02-23 16:50:04 -05:00
|
|
|
if (this._app)
|
|
|
|
this._app.activate();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2017-02-23 16:50:04 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
watchSetting(key, callback) {
|
2017-02-23 16:50:04 -05:00
|
|
|
let handler = { id: 0, key: key, callback: callback };
|
|
|
|
this._handlers.push(handler);
|
|
|
|
|
|
|
|
this._connectHandler(handler);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2017-02-23 16:50:04 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_connectHandler(handler) {
|
2017-02-23 16:50:04 -05:00
|
|
|
if (!this._settings || handler.id > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
handler.id = this._settings.connect('changed::' + handler.key,
|
|
|
|
handler.callback);
|
|
|
|
handler.callback(this._settings, handler.key);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2017-02-23 16:50:04 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_disconnectHandler(handler) {
|
2017-02-23 16:50:04 -05:00
|
|
|
if (this._settings && handler.id > 0)
|
|
|
|
this._settings.disconnect(handler.id);
|
|
|
|
handler.id = 0;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2017-02-23 16:50:04 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onInstalledChanged() {
|
2017-02-23 16:50:04 -05:00
|
|
|
let hadApp = (this._app != null);
|
|
|
|
this._app = this._appSystem.lookup_app(this._appId);
|
|
|
|
let haveApp = (this._app != null);
|
|
|
|
|
|
|
|
if (hadApp == haveApp)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (haveApp)
|
|
|
|
this._checkSettings();
|
|
|
|
else
|
|
|
|
this._setSettings(null);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2017-02-23 16:50:04 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_setSettings(settings) {
|
2017-02-23 16:50:04 -05:00
|
|
|
this._handlers.forEach((handler) => { this._disconnectHandler(handler); });
|
|
|
|
|
|
|
|
let hadSettings = (this._settings != null);
|
|
|
|
this._settings = settings;
|
|
|
|
let haveSettings = (this._settings != null);
|
|
|
|
|
|
|
|
this._handlers.forEach((handler) => { this._connectHandler(handler); });
|
|
|
|
|
|
|
|
if (hadSettings != haveSettings)
|
|
|
|
this.emit('available-changed');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2017-02-23 16:50:04 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_checkSettings() {
|
2017-02-23 16:50:04 -05:00
|
|
|
let schema = this._schemaSource.lookup(this._schemaId, true);
|
|
|
|
if (schema) {
|
|
|
|
this._setSettings(new Gio.Settings({ settings_schema: schema }));
|
|
|
|
} else if (this._app) {
|
|
|
|
Mainloop.timeout_add_seconds(1, () => {
|
|
|
|
this._checkSettings();
|
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2017-02-23 16:50:04 -05:00
|
|
|
Signals.addSignalMethods(AppSettingsMonitor.prototype);
|