Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion js/ui/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,12 @@ XletSettingsBase.prototype = {
}
},


/**
* _checkSettings:
*
* Checks whether any settings have been changed and handles callbacks/signals if they have.
*/
_checkSettings: function() {
let oldSettings = this.settingsData;
try {
Expand All @@ -592,14 +598,18 @@ XletSettingsBase.prototype = {
for (let key in this.settingsData) {
if (!this.settingsData[key]
|| this.settingsData[key].value === undefined
|| this.settingsData[key].type === undefined
|| !oldSettings[key]
|| oldSettings[key].value === undefined) continue;

let oldValue = oldSettings[key].value;
let value = this.settingsData[key].value;
if (value == oldValue) continue;
let valueType = this.settingsData[key].type;

if (!this._hasSettingChanged(value, valueType, oldValue)) continue;

changed = true;

if (key in this.bindings) {
for (let info of this.bindings[key]) {
// if the property had a save function, it is gone now and we need to re-add it
Expand Down Expand Up @@ -632,6 +642,47 @@ XletSettingsBase.prototype = {
}
},

/**
* _hasSettingChanged:
* @value: current value
* @valueType: current value setting type
* @oldValue: previous value
*
* Checks whether a setting has changed by comparing is current value to the previous one
*/
_hasSettingChanged: function(value, valueType, oldValue) {
// It's easy to evaluate whether strings or ints changes, but
// some settings are objects in such case every property needs to be checked

let equal = false;
if (valueType === "timechooser" || valueType === "datechooser") {

equal = Object.keys(value).every(
key => oldValue.hasOwnProperty(key)
&& value[key] === oldValue[key]);

} else if (valueType === "list") {

// If lists differ in length they definitely changed
if (value.length !== oldValue.length) return true;

// Each row of the list needs to be checked
equal = Object.keys(value).every(row => {
if(value[row].length === oldValue[row].length) {
return Object.keys(value[row]).every(
key => oldValue[row].hasOwnProperty(key)
&& value[row][key] === oldValue[row][key]
);
};
});

} else {
equal = (value === oldValue);
}

return !equal;
},

_loadTemplate: function(checksum) {
let xletDir = Extension.getExtension(this.uuid).dir;
let templateFile = xletDir.get_child("settings-schema.json");
Expand Down