Beautify with js-beautify 1.10.2

This commit is contained in:
Olaf Leidinger 2021-09-12 19:31:57 +02:00
parent 9d1e631ec2
commit 5d15efdc4d
3 changed files with 536 additions and 537 deletions

View File

@ -29,283 +29,282 @@ const N_ = function (e) {
let PopupTeaMenuItem = GObject.registerClass(
class PopupTeaMenuItem extends PopupMenu.PopupBaseMenuItem {
_init(sTeaname, nBrewtime, params) {
super._init(params);
class PopupTeaMenuItem extends PopupMenu.PopupBaseMenuItem {
_init(sTeaname, nBrewtime, params) {
super._init(params);
this.tealabel = new St.Label({
text: sTeaname
});
if (nBrewtime != 0) {
this.timelabel = new St.Label({
text: Utils.formatTime(nBrewtime)
this.tealabel = new St.Label({
text: sTeaname
});
}
if (nBrewtime != 0) {
this.timelabel = new St.Label({
text: Utils.formatTime(nBrewtime)
});
}
this.add(this.tealabel);
if (nBrewtime != 0) {
this.add(this.timelabel);
}
this.add(this.tealabel);
if (nBrewtime != 0) {
this.add(this.timelabel);
}
this._delegate = this;
}
});
this._delegate = this;
}
});
let TeaTime = GObject.registerClass(
class TeaTime extends PanelMenu.Button {
_init() {
super._init(1.0, "TeaTime");
class TeaTime extends PanelMenu.Button {
_init() {
super._init(1.0, "TeaTime");
this.config_keys = Utils.GetConfigKeys();
this.config_keys = Utils.GetConfigKeys();
this._settings = Utils.getSettings();
this._settings = Utils.getSettings();
this._logo = new Icon.TwoColorIcon(20, Icon.TeaPot);
this._logo = new Icon.TwoColorIcon(20, Icon.TeaPot);
// set timer widget
this._textualTimer = new St.Label({
text: "",
x_align: Clutter.ActorAlign.END,
y_align: Clutter.ActorAlign.CENTER
});
this._graphicalTimer = new Icon.TwoColorIcon(20, Icon.Pie);
// set timer widget
this._textualTimer = new St.Label({
text: "",
x_align: Clutter.ActorAlign.END,
y_align: Clutter.ActorAlign.CENTER
});
this._graphicalTimer = new Icon.TwoColorIcon(20, Icon.Pie);
this.add_actor(this._logo);
this.add_style_class_name('panel-status-button');
this.connect('style-changed', this._onStyleChanged.bind(this));
this.add_actor(this._logo);
this.add_style_class_name('panel-status-button');
this.connect('style-changed', this._onStyleChanged.bind(this));
this._idleTimeout = null;
this._idleTimeout = null;
this._createMenu();
}
this._createMenu();
}
_createMenu() {
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
this._settings.connect("changed::" + this.config_keys.steep_times,
this._updateTeaList.bind(this));
this._settings.connect("changed::" + this.config_keys.graphical_countdown,
this._updateCountdownType.bind(this));
_createMenu() {
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
this._settings.connect("changed::" + this.config_keys.steep_times,
this._updateTeaList.bind(this));
this._settings.connect("changed::" + this.config_keys.graphical_countdown,
this._updateCountdownType.bind(this));
this.teaItemCont = new PopupMenu.PopupMenuSection();
this.teaItemCont = new PopupMenu.PopupMenuSection();
/*******************/
// maybe one day the PopupImageMenuItem works^^
let head = new PopupMenu.PopupMenuSection();
let item = new PopupMenu.PopupMenuItem(_("Show settings")); //, 'gtk-preferences');
// item._icon.icon_size = 15;
item.connect('activate', this._showPreferences.bind(this));
head.addMenuItem(item);
/*******************/
// maybe one day the PopupImageMenuItem works^^
let head = new PopupMenu.PopupMenuSection();
let item = new PopupMenu.PopupMenuItem(_("Show settings")); //, 'gtk-preferences');
// item._icon.icon_size = 15;
item.connect('activate', this._showPreferences.bind(this));
head.addMenuItem(item);
/*******************/
let bottom = new PopupMenu.PopupMenuSection();
this._customEntry = new St.Entry({
style_class: 'teatime-custom-entry',
track_hover: true,
hint_text: _("min:sec")
});
this._customEntry.get_clutter_text().set_max_length(10);
this._customEntry.get_clutter_text().connect("key-press-event", this._createCustomTimer.bind(this));
bottom.box.add(this._customEntry);
bottom.actor.set_style("padding: 0px 18px;")
/*******************/
let bottom = new PopupMenu.PopupMenuSection();
this._customEntry = new St.Entry({
style_class: 'teatime-custom-entry',
track_hover: true,
hint_text: _("min:sec")
});
this._customEntry.get_clutter_text().set_max_length(10);
this._customEntry.get_clutter_text().connect("key-press-event", this._createCustomTimer.bind(this));
bottom.box.add(this._customEntry);
bottom.actor.set_style("padding: 0px 18px;")
/*******************/
/*******************/
this.menu.addMenuItem(head);
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
this.menu.addMenuItem(this.teaItemCont);
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
this.menu.addMenuItem(bottom);
this.menu.addMenuItem(head);
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
this.menu.addMenuItem(this.teaItemCont);
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
this.menu.addMenuItem(bottom);
this._updateTeaList();
}
this._updateTeaList();
}
_updateTeaList(config, output) {
// make sure the menu is empty
this.teaItemCont.removeAll();
_updateTeaList(config, output) {
// make sure the menu is empty
this.teaItemCont.removeAll();
// fill with new teas
let list = this._settings.get_value(this.config_keys.steep_times).unpack();
let menuItem = new PopupTeaMenuItem("Stop Timer", 0);
menuItem.connect('activate', function () {
this._stopCountdown();
}.bind(this));
this.teaItemCont.addMenuItem(menuItem);
for (let teaname in list) {
let time = list[teaname].get_uint32();
let menuItem = new PopupTeaMenuItem(_(teaname), time);
// fill with new teas
let list = this._settings.get_value(this.config_keys.steep_times).unpack();
let menuItem = new PopupTeaMenuItem("Stop Timer", 0);
menuItem.connect('activate', function () {
this._initCountdown(time);
this._stopCountdown();
}.bind(this));
this.teaItemCont.addMenuItem(menuItem);
}
}
for (let teaname in list) {
let time = list[teaname].get_uint32();
_updateCountdownType(config, output) {
let bWantGraphicalCountdown = this._settings.get_boolean(this.config_keys.graphical_countdown);
if (bWantGraphicalCountdown != this._bGraphicalCountdown) {
if (this._idleTimeout != null) {
// we have a running countdown, replace the display
this.remove_actor(this._bGraphicalCountdown ?
this._graphicalTimer : this._textualTimer);
this._bGraphicalCountdown = bWantGraphicalCountdown;
this.add_actor(this._bGraphicalCountdown ?
this._graphicalTimer : this._textualTimer);
this._updateTimerDisplay(this._getRemainingSec());
} // if timeout active
} // value changed
}
_createCustomTimer(text, event) {
if (event.get_key_symbol() == Clutter.KEY_Enter ||
event.get_key_symbol() == Clutter.KEY_Return ||
event.get_key_symbol() == Clutter.KEY_KP_Enter) {
let customTime = text.get_text();
let seconds = 0;
let match = customTime.match(/^(?:(\d+)(?::(\d{0,2}))?|:(\d+))$/)
if (match) {
let factor = 1;
if (match[3] === undefined) { // minutes and seconds?
for (var i = match.length - 2; i > 0; i--) {
let s = match[i] === undefined ? "" : match[i].replace(/^0/, ''); // fix for elder GNOME <= 3.10 which don't like leading zeros
if (s.match(/^\d+$/)) { // only if something left
seconds += factor * parseInt(s);
}
factor *= 60;
}
} else { // only seconds?
let s = match[3].replace(/^0/, '');
seconds = parseInt(s);
}
if (seconds > 0) {
this._initCountdown(seconds);
this.menu.close();
}
let menuItem = new PopupTeaMenuItem(_(teaname), time);
menuItem.connect('activate', function () {
this._initCountdown(time);
}.bind(this));
this.teaItemCont.addMenuItem(menuItem);
}
this._customEntry.set_text("");
}
}
_showNotification(subject, text) {
let source = new MessageTray.Source(_("TeaTime applet"), 'utilities-teatime');
Main.messageTray.add(source);
_updateCountdownType(config, output) {
let bWantGraphicalCountdown = this._settings.get_boolean(this.config_keys.graphical_countdown);
let notification = new MessageTray.Notification(source, subject, text);
notification.setTransient(true);
if (typeof source.showNotification === 'function') {
source.showNotification(notification);
} else {
source.notify(notification);
if (bWantGraphicalCountdown != this._bGraphicalCountdown) {
if (this._idleTimeout != null) {
// we have a running countdown, replace the display
this.remove_actor(this._bGraphicalCountdown ?
this._graphicalTimer : this._textualTimer);
this._bGraphicalCountdown = bWantGraphicalCountdown;
this.add_actor(this._bGraphicalCountdown ?
this._graphicalTimer : this._textualTimer);
this._updateTimerDisplay(this._getRemainingSec());
} // if timeout active
} // value changed
}
}
_initCountdown(time) {
this._startTime = new Date();
this._stopTime = new Date();
this._cntdownStart = time;
_createCustomTimer(text, event) {
if (event.get_key_symbol() == Clutter.KEY_Enter ||
event.get_key_symbol() == Clutter.KEY_Return ||
event.get_key_symbol() == Clutter.KEY_KP_Enter) {
this._bGraphicalCountdown = this._settings.get_boolean(this.config_keys.graphical_countdown);
let dt = this._bGraphicalCountdown ?
Math.max(1.0, time / 90) // set time step to fit animation
:
1.0; // show every second for the textual countdown
this._stopTime.setTime(this._startTime.getTime() + time * 1000); // in msec
this.remove_actor(this._logo); // show timer instead of default icon
this._updateTimerDisplay(time);
this.add_actor(this._bGraphicalCountdown ?
this._graphicalTimer : this._textualTimer);
if (this._idleTimeout != null) Mainloop.source_remove(this._idleTimeout);
this._idleTimeout = Mainloop.timeout_add_seconds(dt, this._doCountdown.bind(this));
}
_stopCountdown() {
if (this._idleTimeout != null) Mainloop.source_remove(this._idleTimeout);
this.remove_actor(this._bGraphicalCountdown ?
this._graphicalTimer : this._textualTimer);
this.add_actor(this._logo);
this._idleTimeout = null;
}
_getRemainingSec() {
let a = new Date();
return (this._stopTime.getTime() - a.getTime()) * 1e-3;
}
_updateTimerDisplay(remainingTime) {
if (this._bGraphicalCountdown) {
this._graphicalTimer.setStatus((this._cntdownStart - remainingTime) / this._cntdownStart);
} else {
this._textualTimer.text = Utils.formatTime(remainingTime);
let customTime = text.get_text();
let seconds = 0;
let match = customTime.match(/^(?:(\d+)(?::(\d{0,2}))?|:(\d+))$/)
if (match) {
let factor = 1;
if (match[3] === undefined) { // minutes and seconds?
for (var i = match.length - 2; i > 0; i--) {
let s = match[i] === undefined ? "" : match[i].replace(/^0/, ''); // fix for elder GNOME <= 3.10 which don't like leading zeros
if (s.match(/^\d+$/)) { // only if something left
seconds += factor * parseInt(s);
}
factor *= 60;
}
} else { // only seconds?
let s = match[3].replace(/^0/, '');
seconds = parseInt(s);
}
if (seconds > 0) {
this._initCountdown(seconds);
this.menu.close();
}
}
this._customEntry.set_text("");
}
}
}
_doCountdown() {
let remainingTime = this._getRemainingSec();
_showNotification(subject, text) {
let source = new MessageTray.Source(_("TeaTime applet"), 'utilities-teatime');
Main.messageTray.add(source);
if (remainingTime <= 0) {
// count down finished, switch display again
this._stopCountdown();
this._playSound();
this._showNotification(_("Your tea is ready!"),
_("Drink it, while it is hot!"));
return false;
} else {
this._updateTimerDisplay(remainingTime);
return true; // continue timer
let notification = new MessageTray.Notification(source, subject, text);
notification.setTransient(true);
if (typeof source.showNotification === 'function') {
source.showNotification(notification);
} else {
source.notify(notification);
}
}
}
_playSound() {
let bPlayAlarmSound = this._settings.get_boolean(this.config_keys.use_alarm_sound);
if (bPlayAlarmSound) {
Utils.playSound(this._settings.get_string(this.config_keys.alarm_sound));
_initCountdown(time) {
this._startTime = new Date();
this._stopTime = new Date();
this._cntdownStart = time;
this._bGraphicalCountdown = this._settings.get_boolean(this.config_keys.graphical_countdown);
let dt = this._bGraphicalCountdown ?
Math.max(1.0, time / 90) // set time step to fit animation
:
1.0; // show every second for the textual countdown
this._stopTime.setTime(this._startTime.getTime() + time * 1000); // in msec
this.remove_actor(this._logo); // show timer instead of default icon
this._updateTimerDisplay(time);
this.add_actor(this._bGraphicalCountdown ?
this._graphicalTimer : this._textualTimer);
if (this._idleTimeout != null) Mainloop.source_remove(this._idleTimeout);
this._idleTimeout = Mainloop.timeout_add_seconds(dt, this._doCountdown.bind(this));
}
}
_showPreferences() {
const currExt = ExtensionUtils.getCurrentExtension();
imports.misc.util.spawn(["gnome-shell-extension-prefs", currExt.metadata['uuid']]);
return 0;
}
_stopCountdown() {
if (this._idleTimeout != null) Mainloop.source_remove(this._idleTimeout);
this.remove_actor(this._bGraphicalCountdown ?
this._graphicalTimer : this._textualTimer);
this.add_actor(this._logo);
this._idleTimeout = null;
}
_onStyleChanged(actor) {
let themeNode = actor.get_theme_node();
let color = themeNode.get_foreground_color()
let [bHasPadding, padding] = themeNode.lookup_length("-natural-hpadding", false);
_getRemainingSec() {
let a = new Date();
return (this._stopTime.getTime() - a.getTime()) * 1e-3;
}
this._primaryColor = color;
this._secondaryColor = new Clutter.Color({
red: color.red,
green: color.green,
blue: color.blue,
alpha: color.alpha * 0.3
});
this._logo.setPadding(bHasPadding * padding);
this._graphicalTimer.setPadding(bHasPadding * padding);
this._textualTimer.margin_right = bHasPadding * padding;
this._textualTimer.margin_left = bHasPadding * padding;
_updateTimerDisplay(remainingTime) {
if (this._bGraphicalCountdown) {
this._graphicalTimer.setStatus((this._cntdownStart - remainingTime) / this._cntdownStart);
} else {
this._textualTimer.text = Utils.formatTime(remainingTime);
}
}
this._logo.setColor(this._primaryColor, this._secondaryColor);
this._graphicalTimer.setColor(this._primaryColor, this._secondaryColor);
_doCountdown() {
let remainingTime = this._getRemainingSec();
// forward (possible) scaling style change to child
let scaling = Utils.getGlobalDisplayScaleFactor();
this._logo.setScaling(scaling);
this._graphicalTimer.setScaling(scaling);
}
});
if (remainingTime <= 0) {
// count down finished, switch display again
this._stopCountdown();
this._playSound();
this._showNotification(_("Your tea is ready!"),
_("Drink it, while it is hot!"));
return false;
} else {
this._updateTimerDisplay(remainingTime);
return true; // continue timer
}
}
function init(metadata) {
}
_playSound() {
let bPlayAlarmSound = this._settings.get_boolean(this.config_keys.use_alarm_sound);
if (bPlayAlarmSound) {
Utils.playSound(this._settings.get_string(this.config_keys.alarm_sound));
}
}
_showPreferences() {
const currExt = ExtensionUtils.getCurrentExtension();
imports.misc.util.spawn(["gnome-shell-extension-prefs", currExt.metadata['uuid']]);
return 0;
}
_onStyleChanged(actor) {
let themeNode = actor.get_theme_node();
let color = themeNode.get_foreground_color()
let [bHasPadding, padding] = themeNode.lookup_length("-natural-hpadding", false);
this._primaryColor = color;
this._secondaryColor = new Clutter.Color({
red: color.red,
green: color.green,
blue: color.blue,
alpha: color.alpha * 0.3
});
this._logo.setPadding(bHasPadding * padding);
this._graphicalTimer.setPadding(bHasPadding * padding);
this._textualTimer.margin_right = bHasPadding * padding;
this._textualTimer.margin_left = bHasPadding * padding;
this._logo.setColor(this._primaryColor, this._secondaryColor);
this._graphicalTimer.setColor(this._primaryColor, this._secondaryColor);
// forward (possible) scaling style change to child
let scaling = Utils.getGlobalDisplayScaleFactor();
this._logo.setScaling(scaling);
this._graphicalTimer.setScaling(scaling);
}
});
function init(metadata) {}
let _TeaTime;

View File

@ -18,81 +18,81 @@ const Me = ExUt.getCurrentExtension();
const Utils = Me.imports.utils;
var TwoColorIcon = GObject.registerClass(
class TwoColorIcon extends St.DrawingArea {
_init(size, drawingObject) {
super._init({
reactive: true,
style: 'padding: 0px 0px'
});
this._base_size = size;
//this.setScaling(Utils.getGlobalDisplayScaleFactor());
class TwoColorIcon extends St.DrawingArea {
_init(size, drawingObject) {
super._init({
reactive: true,
style: 'padding: 0px 0px'
});
this._base_size = size;
//this.setScaling(Utils.getGlobalDisplayScaleFactor());
this._drawingObject = drawingObject;
this._drawingObject = drawingObject;
this.connect('repaint', function () {
this._drawIcon();
}.bind(this));
this.connect('repaint', function () {
this._drawIcon();
}.bind(this));
// some fallback color
this._primaryColor = new Clutter.Color({
red: 150,
green: 150,
blue: 150,
alpha: 255
});
this._secundaryColor = this._primaryColor;
this._customStatus = null;
}
setPadding(padding) {
this.margin_left = padding;
this.margin_right = padding;
}
setColor(primary, secundary) {
this._primaryColor = primary;
this._secundaryColor = secundary;
this.queue_repaint();
}
setScaling(newScale) {
this._default_scale = newScale;
this.set_width(this._base_size * this._default_scale);
this.set_height(this._base_size * this._default_scale);
this.queue_repaint();
}
setStatus(newStatus) {
this._customStatus = newStatus;
this.queue_repaint();
}
_drawIcon() {
let cr = this.get_context();
let orWdt = this._drawingObject.width;
let orHgt = this._drawingObject.height;
let [width, height] = this.get_surface_size();
cr.save();
let object_longest_edge = Math.max(orWdt, orHgt);
let surface_shortest_edge = Math.min(width, height);
let scaling = surface_shortest_edge / object_longest_edge;
let padding_x = (width - orWdt * scaling) * 0.5;
let padding_y = (height - orHgt * scaling) * 0.5;
cr.translate(padding_x, padding_y);
try {
cr.scale(scaling, scaling);
this._drawingObject.draw(cr, this._customStatus, this._primaryColor, this._secundaryColor);
cr.restore();
} catch (e) {
// ignore
// some fallback color
this._primaryColor = new Clutter.Color({
red: 150,
green: 150,
blue: 150,
alpha: 255
});
this._secundaryColor = this._primaryColor;
this._customStatus = null;
}
}
});
setPadding(padding) {
this.margin_left = padding;
this.margin_right = padding;
}
setColor(primary, secundary) {
this._primaryColor = primary;
this._secundaryColor = secundary;
this.queue_repaint();
}
setScaling(newScale) {
this._default_scale = newScale;
this.set_width(this._base_size * this._default_scale);
this.set_height(this._base_size * this._default_scale);
this.queue_repaint();
}
setStatus(newStatus) {
this._customStatus = newStatus;
this.queue_repaint();
}
_drawIcon() {
let cr = this.get_context();
let orWdt = this._drawingObject.width;
let orHgt = this._drawingObject.height;
let [width, height] = this.get_surface_size();
cr.save();
let object_longest_edge = Math.max(orWdt, orHgt);
let surface_shortest_edge = Math.min(width, height);
let scaling = surface_shortest_edge / object_longest_edge;
let padding_x = (width - orWdt * scaling) * 0.5;
let padding_y = (height - orHgt * scaling) * 0.5;
cr.translate(padding_x, padding_y);
try {
cr.scale(scaling, scaling);
this._drawingObject.draw(cr, this._customStatus, this._primaryColor, this._secundaryColor);
cr.restore();
} catch (e) {
// ignore
}
}
});
var TeaPot = {
width: 484,

View File

@ -27,289 +27,289 @@ const Columns = {
}
var TeaTimePrefsWidget = GObject.registerClass(
class TeaTimePrefsWidget extends Gtk.Grid {
_init() {
super._init({
orientation: Gtk.Orientation.VERTICAL,
column_homogeneous: false,
vexpand: true,
margin_start: 5,
margin_end: 5,
margin_top: 5,
margin_bottom: 5,
row_spacing: 5
});
class TeaTimePrefsWidget extends Gtk.Grid {
_init() {
super._init({
orientation: Gtk.Orientation.VERTICAL,
column_homogeneous: false,
vexpand: true,
margin_start: 5,
margin_end: 5,
margin_top: 5,
margin_bottom: 5,
row_spacing: 5
});
this.config_keys = Utils.GetConfigKeys();
this.config_keys = Utils.GetConfigKeys();
this._tealist = new Gtk.ListStore();
this._tealist.set_column_types([
GObject.TYPE_STRING,
GObject.TYPE_INT,
Gtk.Adjustment
]);
this._tealist = new Gtk.ListStore();
this._tealist.set_column_types([
GObject.TYPE_STRING,
GObject.TYPE_INT,
Gtk.Adjustment
]);
this.set_column_spacing(3);
this.set_column_spacing(3);
this._settings = Utils.getSettings();
this._inhibitUpdate = true;
this._settings.connect("changed", this._refresh.bind(this));
this._settings = Utils.getSettings();
this._inhibitUpdate = true;
this._settings.connect("changed", this._refresh.bind(this));
this._initWindow();
this._inhibitUpdate = false;
this._refresh();
this._tealist.connect("row-changed", this._save.bind(this));
this._tealist.connect("row-deleted", this._save.bind(this));
}
this._initWindow();
this._inhibitUpdate = false;
this._refresh();
this._tealist.connect("row-changed", this._save.bind(this));
this._tealist.connect("row-deleted", this._save.bind(this));
}
_initWindow() {
let curRow = 0;
let labelGC = new Gtk.Label({
label: _("Graphical Countdown"),
hexpand: true,
halign: Gtk.Align.START
});
_initWindow() {
let curRow = 0;
let labelGC = new Gtk.Label({
label: _("Graphical Countdown"),
hexpand: true,
halign: Gtk.Align.START
});
let labelAS = new Gtk.Label({
label: _("Alarm sound"),
hexpand: true,
halign: Gtk.Align.START
});
let labelAS = new Gtk.Label({
label: _("Alarm sound"),
hexpand: true,
halign: Gtk.Align.START
});
this.graphicalCountdownSwitch = new Gtk.Switch();
this.graphicalCountdownSwitch.connect("notify::active", this._saveGraphicalCountdown.bind(this));
this.graphicalCountdownSwitch = new Gtk.Switch();
this.graphicalCountdownSwitch.connect("notify::active", this._saveGraphicalCountdown.bind(this));
// alarm sound file chooser
this.alarmSoundSwitch = new Gtk.Switch();
this.alarmSoundSwitch.connect("notify::active", this._saveUseAlarm.bind(this));
// alarm sound file chooser
this.alarmSoundSwitch = new Gtk.Switch();
this.alarmSoundSwitch.connect("notify::active", this._saveUseAlarm.bind(this));
this.alarmSoundFileFilter = new Gtk.FileFilter();
this.alarmSoundFileFilter.add_mime_type("audio/*");
this.alarmSoundFileFilter = new Gtk.FileFilter();
this.alarmSoundFileFilter.add_mime_type("audio/*");
this.alarmSoundFileButton = new Gtk.Button({
label: _("Select alarm sound file")
});
this.alarmSoundFileButton.connect("clicked", this._selectAlarmSoundFile.bind(this));
this.alarmSoundFileButton = new Gtk.Button({
label: _("Select alarm sound file")
});
this.alarmSoundFileButton.connect("clicked", this._selectAlarmSoundFile.bind(this));
this.attach(labelGC, 0 /*col*/ , curRow /*row*/ , 2 /*col span*/ , 1 /*row span*/ );
this.attach(this.graphicalCountdownSwitch, 3, curRow, 2, 1);
curRow += 1;
this.attach(labelGC, 0 /*col*/ , curRow /*row*/ , 2 /*col span*/ , 1 /*row span*/ );
this.attach(this.graphicalCountdownSwitch, 3, curRow, 2, 1);
curRow += 1;
this.attach(labelAS, 0 /*col*/ , curRow+1 /*row*/ , 1 /*col span*/ , 1 /*row span*/ );
this.attach(this.alarmSoundFileButton, 1, curRow, 1, 2);
this.attach(this.alarmSoundSwitch, 3, curRow+1, 2, 1);
curRow += 2;
this.attach(labelAS, 0 /*col*/ , curRow + 1 /*row*/ , 1 /*col span*/ , 1 /*row span*/ );
this.attach(this.alarmSoundFileButton, 1, curRow, 1, 2);
this.attach(this.alarmSoundSwitch, 3, curRow + 1, 2, 1);
curRow += 2;
this.treeview = new Gtk.TreeView({
model: this._tealist
});
this.treeview.set_reorderable(true);
this.treeview.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE);
this.attach(this.treeview, 0, curRow, 6, 1);
curRow += 1;
this.treeview = new Gtk.TreeView({
model: this._tealist
});
this.treeview.set_reorderable(true);
this.treeview.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE);
this.attach(this.treeview, 0, curRow, 6, 1);
curRow += 1;
let teaname = new Gtk.TreeViewColumn({
title: _("Tea"),
expand: true
});
let renderer = new Gtk.CellRendererText({
editable: true
});
// When the renderer is done editing it's value, we first write
// the new value to the view's model, i.e. this._tealist.
// This makes life a little harder due to chaining of callbacks
// and the need for this._inhibitUpdate, but it feels a lot cleaner
// when the UI does not know about the config storage backend.
renderer.connect("edited", function (renderer, pathString, newValue) {
let [store, iter] = this._tealist.get_iter(Gtk.TreePath.new_from_string(pathString));
this._tealist.set(iter, [Columns.TEA_NAME], [newValue]);
}.bind(this));
teaname.pack_start(renderer, true);
teaname.add_attribute(renderer, "text", Columns.TEA_NAME);
this.treeview.append_column(teaname);
let teaname = new Gtk.TreeViewColumn({
title: _("Tea"),
expand: true
});
let renderer = new Gtk.CellRendererText({
editable: true
});
// When the renderer is done editing it's value, we first write
// the new value to the view's model, i.e. this._tealist.
// This makes life a little harder due to chaining of callbacks
// and the need for this._inhibitUpdate, but it feels a lot cleaner
// when the UI does not know about the config storage backend.
renderer.connect("edited", function (renderer, pathString, newValue) {
let [store, iter] = this._tealist.get_iter(Gtk.TreePath.new_from_string(pathString));
this._tealist.set(iter, [Columns.TEA_NAME], [newValue]);
}.bind(this));
teaname.pack_start(renderer, true);
teaname.add_attribute(renderer, "text", Columns.TEA_NAME);
this.treeview.append_column(teaname);
let steeptime = new Gtk.TreeViewColumn({
title: _("Steep time"),
min_width: 150
});
let spinrenderer = new Gtk.CellRendererSpin({
editable: true
});
// See comment above.
spinrenderer.connect("edited", function (renderer, pathString, newValue) {
let [store, iter] = this._tealist.get_iter(Gtk.TreePath.new_from_string(pathString));
this._tealist.set(iter, [Columns.STEEP_TIME], [parseInt(newValue)]);
}.bind(this));
let steeptime = new Gtk.TreeViewColumn({
title: _("Steep time"),
min_width: 150
});
let spinrenderer = new Gtk.CellRendererSpin({
editable: true
});
// See comment above.
spinrenderer.connect("edited", function (renderer, pathString, newValue) {
let [store, iter] = this._tealist.get_iter(Gtk.TreePath.new_from_string(pathString));
this._tealist.set(iter, [Columns.STEEP_TIME], [parseInt(newValue)]);
}.bind(this));
steeptime.pack_start(spinrenderer, true);
steeptime.add_attribute(spinrenderer, "adjustment", Columns.ADJUSTMENT);
steeptime.add_attribute(spinrenderer, "text", Columns.STEEP_TIME);
this.treeview.append_column(steeptime);
this.treeview.expand_all();
steeptime.pack_start(spinrenderer, true);
steeptime.add_attribute(spinrenderer, "adjustment", Columns.ADJUSTMENT);
steeptime.add_attribute(spinrenderer, "text", Columns.STEEP_TIME);
this.treeview.append_column(steeptime);
this.treeview.expand_all();
//this.toolbar = new Gtk.Toolbar({
// icon_size: 1
//});
// this.toolbar.get_style_context().add_class("inline-toolbar");
// this.attach(this.toolbar, 0 /*col*/ , curRow /*row*/ , 3 /*col span*/ , 1 /*row span*/ );
this.addButton = Gtk.Button.new_from_icon_name("list-add-symbolic", 0 /* size: 0 - inherit */);
this.addButton.connect("clicked", this._addTea.bind(this));
this.attach(this.addButton, 2 /*col*/ , curRow /*row*/ , 2 /*col span*/ , 1 /*row span*/ );
this.removeButton = Gtk.Button.new_from_icon_name("list-remove-symbolic", 0);
this.removeButton.connect("clicked", this._removeSelectedTea.bind(this));
this.attach(this.removeButton, 4 /*col*/ , curRow /*row*/ , 2 /*col span*/ , 1 /*row span*/ );
}
//this.toolbar = new Gtk.Toolbar({
// icon_size: 1
//});
// this.toolbar.get_style_context().add_class("inline-toolbar");
// this.attach(this.toolbar, 0 /*col*/ , curRow /*row*/ , 3 /*col span*/ , 1 /*row span*/ );
this.addButton = Gtk.Button.new_from_icon_name("list-add-symbolic", 0 /* size: 0 - inherit */ );
this.addButton.connect("clicked", this._addTea.bind(this));
this.attach(this.addButton, 2 /*col*/ , curRow /*row*/ , 2 /*col span*/ , 1 /*row span*/ );
this.removeButton = Gtk.Button.new_from_icon_name("list-remove-symbolic", 0);
this.removeButton.connect("clicked", this._removeSelectedTea.bind(this));
this.attach(this.removeButton, 4 /*col*/ , curRow /*row*/ , 2 /*col span*/ , 1 /*row span*/ );
}
_selectAlarmSoundFile() {
// recreate -> preselecting file doesn't work on second call if not ...
this.alarmSoundFile = new Gtk.FileChooserNative({
title: _("Select alarm sound file"),
action: Gtk.FileChooserAction.OPEN,
_selectAlarmSoundFile() {
// recreate -> preselecting file doesn't work on second call if not ...
this.alarmSoundFile = new Gtk.FileChooserNative({
title: _("Select alarm sound file"),
action: Gtk.FileChooserAction.OPEN,
});
this.alarmSoundFile.set_filter(this.alarmSoundFileFilter);
this.alarmSoundFile.connect("response", this._saveSoundFile.bind(this));
this.alarmSoundFile.set_file(Gio.File.new_for_uri(this.alarmSoundFileFile));
this.alarmSoundFile.show();
}
});
this.alarmSoundFile.set_filter(this.alarmSoundFileFilter);
this.alarmSoundFile.connect("response", this._saveSoundFile.bind(this));
this.alarmSoundFile.set_file(Gio.File.new_for_uri(this.alarmSoundFileFile));
this.alarmSoundFile.show();
}
_refresh() {
// don't update the model if someone else is messing with the backend
if (this._inhibitUpdate)
return;
_refresh() {
// don't update the model if someone else is messing with the backend
if (this._inhibitUpdate)
return;
this.graphicalCountdownSwitch.active = this._settings.get_boolean(this.config_keys.graphical_countdown)
this.alarmSoundSwitch.active = this._settings.get_boolean(this.config_keys.use_alarm_sound)
let list = this._settings.get_value(this.config_keys.steep_times).unpack();
this.alarmSoundFileFile = this._settings.get_string(this.config_keys.alarm_sound);
this.alarmSoundFileButton.label = Gio.File.new_for_uri(this.alarmSoundFileFile).get_basename();
this.graphicalCountdownSwitch.active = this._settings.get_boolean(this.config_keys.graphical_countdown)
this.alarmSoundSwitch.active = this._settings.get_boolean(this.config_keys.use_alarm_sound)
let list = this._settings.get_value(this.config_keys.steep_times).unpack();
this.alarmSoundFileFile = this._settings.get_string(this.config_keys.alarm_sound);
this.alarmSoundFileButton.label = Gio.File.new_for_uri(this.alarmSoundFileFile).get_basename();
// stop everyone from reacting to the changes we are about to produce
// in the model
this._inhibitUpdate = true;
// stop everyone from reacting to the changes we are about to produce
// in the model
this._inhibitUpdate = true;
this._tealist.clear();
for (let teaname in list) {
let time = list[teaname].get_uint32();
this._tealist.clear();
for (let teaname in list) {
let time = list[teaname].get_uint32();
let adj = new Gtk.Adjustment({
lower: 1,
step_increment: 1,
upper: 65535,
value: time
});
this._tealist.set(this._tealist.append(), [Columns.TEA_NAME, Columns.STEEP_TIME, Columns.ADJUSTMENT], [teaname, time, adj]);
}
this._inhibitUpdate = false;
}
_addTea() {
let adj = new Gtk.Adjustment({
lower: 1,
step_increment: 1,
upper: 65535,
value: time
value: 1
});
this._tealist.set(this._tealist.append(), [Columns.TEA_NAME, Columns.STEEP_TIME, Columns.ADJUSTMENT], [teaname, time, adj]);
let item = this._tealist.append();
this._tealist.set(item, [Columns.TEA_NAME, Columns.STEEP_TIME, Columns.ADJUSTMENT], ["", 1, adj]);
this.treeview.set_cursor(this._tealist.get_path(item),
this.treeview.get_column(Columns.TEA_NAME),
true);
}
this._inhibitUpdate = false;
}
_removeSelectedTea() {
let [selection, store] = this.treeview.get_selection().get_selected_rows();
let iters = [];
for (let i = 0; i < selection.length; ++i) {
let [isSet, iter] = store.get_iter(selection[i]);
if (isSet) {
iters.push(iter);
}
}
// it's ok not to inhibit updates here as remove != change
iters.forEach(function (value, index, array) {
store.remove(value)
});
_addTea() {
let adj = new Gtk.Adjustment({
lower: 1,
step_increment: 1,
upper: 65535,
value: 1
});
let item = this._tealist.append();
this._tealist.set(item, [Columns.TEA_NAME, Columns.STEEP_TIME, Columns.ADJUSTMENT], ["", 1, adj]);
this.treeview.set_cursor(this._tealist.get_path(item),
this.treeview.get_column(Columns.TEA_NAME),
true);
}
this.treeview.get_selection().unselect_all();
}
_removeSelectedTea() {
let [selection, store] = this.treeview.get_selection().get_selected_rows();
let iters = [];
for (let i = 0; i < selection.length; ++i) {
let [isSet, iter] = store.get_iter(selection[i]);
if (isSet) {
iters.push(iter);
_saveGraphicalCountdown(sw, data) {
// don't update the backend if someone else is messing with the model
if (this._inhibitUpdate)
return;
this._inhibitUpdate = true;
this._settings.set_boolean(this.config_keys.graphical_countdown,
sw.active);
this._inhibitUpdate = false;
}
_saveUseAlarm(sw, data) {
// don't update the backend if someone else is messing with the model
if (this._inhibitUpdate)
return;
this._inhibitUpdate = true;
this._settings.set_boolean(this.config_keys.use_alarm_sound,
sw.active);
this._inhibitUpdate = false;
}
_saveSoundFile(sw, response_id, data) {
// don't update the backend if someone else is messing with the model or not accept new file
if (this._inhibitUpdate || response_id != Gtk.ResponseType.ACCEPT)
return;
let alarm_sound = this.alarmSoundFile.get_file().get_uri();
Utils.debug(this._settings.get_string(this.config_keys.alarm_sound) + "-->" + alarm_sound);
let have_value = Utils.isType(alarm_sound, "string");
let setting_is_different =
this._settings.get_string(this.config_keys.alarm_sound) != alarm_sound;
if (have_value && setting_is_different) {
this._inhibitUpdate = true;
Utils.playSound(alarm_sound);
this._settings.set_string(this.config_keys.alarm_sound, alarm_sound);
this._inhibitUpdate = false;
this.alarmSoundFileFile = alarm_sound;
this.alarmSoundFileButton.label = Gio.File.new_for_uri(this.alarmSoundFileFile).get_basename();
}
}
// it's ok not to inhibit updates here as remove != change
iters.forEach(function (value, index, array) {
store.remove(value)
});
this.treeview.get_selection().unselect_all();
}
_save(store, path_, iter_) {
const GLib = imports.gi.GLib;
_saveGraphicalCountdown(sw, data) {
// don't update the backend if someone else is messing with the model
if (this._inhibitUpdate)
return;
this._inhibitUpdate = true;
this._settings.set_boolean(this.config_keys.graphical_countdown,
sw.active);
this._inhibitUpdate = false;
}
// don't update the backend if someone else is messing with the model
if (this._inhibitUpdate)
return;
_saveUseAlarm(sw, data) {
// don't update the backend if someone else is messing with the model
if (this._inhibitUpdate)
return;
this._inhibitUpdate = true;
this._settings.set_boolean(this.config_keys.use_alarm_sound,
sw.active);
this._inhibitUpdate = false;
}
let values = [];
this._tealist.foreach(function (store, path, iter) {
values.push(GLib.Variant.new_dict_entry(
GLib.Variant.new_string(store.get_value(iter, Columns.TEA_NAME)),
GLib.Variant.new_uint32(store.get_value(iter, Columns.STEEP_TIME))))
});
let settingsValue = GLib.Variant.new_array(GLib.VariantType.new("{su}"), values);
_saveSoundFile(sw, response_id, data) {
// don't update the backend if someone else is messing with the model or not accept new file
if (this._inhibitUpdate || response_id != Gtk.ResponseType.ACCEPT)
return;
let alarm_sound = this.alarmSoundFile.get_file().get_uri();
Utils.debug(this._settings.get_string(this.config_keys.alarm_sound) + "-->" + alarm_sound);
let have_value = Utils.isType(alarm_sound, "string");
let setting_is_different =
this._settings.get_string(this.config_keys.alarm_sound) != alarm_sound;
if (have_value && setting_is_different) {
// all changes have happened through the UI, we can safely
// disable updating it here to avoid an infinite loop
this._inhibitUpdate = true;
Utils.playSound(alarm_sound);
this._settings.set_string(this.config_keys.alarm_sound, alarm_sound);
this._settings.set_value(this.config_keys.steep_times, settingsValue);
this._inhibitUpdate = false;
this.alarmSoundFileFile = alarm_sound;
this.alarmSoundFileButton.label = Gio.File.new_for_uri(this.alarmSoundFileFile).get_basename();
}
}
_save(store, path_, iter_) {
const GLib = imports.gi.GLib;
// don't update the backend if someone else is messing with the model
if (this._inhibitUpdate)
return;
let values = [];
this._tealist.foreach(function (store, path, iter) {
values.push(GLib.Variant.new_dict_entry(
GLib.Variant.new_string(store.get_value(iter, Columns.TEA_NAME)),
GLib.Variant.new_uint32(store.get_value(iter, Columns.STEEP_TIME))))
});
let settingsValue = GLib.Variant.new_array(GLib.VariantType.new("{su}"), values);
// all changes have happened through the UI, we can safely
// disable updating it here to avoid an infinite loop
this._inhibitUpdate = true;
this._settings.set_value(this.config_keys.steep_times, settingsValue);
this._inhibitUpdate = false;
}
});
});
function init() {}
function buildPrefsWidget() {
let widget = new TeaTimePrefsWidget();
if (shellVersion < 40) {
widget.show_all();
} else {
widget.show();
}
if (shellVersion < 40) {
widget.show_all();
} else {
widget.show();
}
return widget;
}