fix prefs

master
JFH 2021-01-01 17:19:57 +01:00
parent 7e33ea2bdc
commit 16f05f1aee
20 changed files with 47 additions and 47 deletions

View File

@ -462,10 +462,10 @@ export default class ConfigObj {
* @returns {string|void} If val is missing or falsey and `mayBeEmpty` is not set, the * @returns {string|void} If val is missing or falsey and `mayBeEmpty` is not set, the
* value of the previously stored preference will be returned. * value of the previously stored preference will be returned.
* @todo Review whether any remaining existing direct references to * @todo Review whether any remaining existing direct references to
* getting `curPrefs` can be changed to use `svgEditor.pref()` getting to ensure * getting `curPrefs` can be changed to use `svgEditor.configObj.pref()` getting to ensure
* `defaultPrefs` fallback (also for sake of `allowInitialUserOverride`); * `defaultPrefs` fallback (also for sake of `allowInitialUserOverride`);
* specifically, `bkgd_color` could be changed so that the pref dialog has a * specifically, `bkgd_color` could be changed so that the pref dialog has a
* button to auto-calculate background, but otherwise uses `svgEditor.pref()` to * button to auto-calculate background, but otherwise uses `svgEditor.configObj.pref()` to
* be able to get default prefs or overridable settings * be able to get default prefs or overridable settings
*/ */
pref (key, val, mayBeEmpty) { pref (key, val, mayBeEmpty) {

View File

@ -23,7 +23,7 @@ export default {
name: 'arrows', name: 'arrows',
async init (S) { async init (S) {
const svgEditor = this; const svgEditor = this;
const strings = await loadExtensionTranslation(svgEditor.pref('lang')); const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang'));
const {svgCanvas} = svgEditor; const {svgCanvas} = svgEditor;
const const
addElem = svgCanvas.addSVGElementFromJson, addElem = svgCanvas.addSVGElementFromJson,

View File

@ -25,7 +25,7 @@ export default {
name: 'closepath', name: 'closepath',
async init ({importLocale, $}) { async init ({importLocale, $}) {
const svgEditor = this; const svgEditor = this;
const strings = await loadExtensionTranslation(svgEditor.pref('lang')); const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang'));
let selElems; let selElems;
const updateButton = function (path) { const updateButton = function (path) {
const seglist = path.pathSegList, const seglist = path.pathSegList,

View File

@ -356,7 +356,7 @@ export default {
} }
} }
}]; }];
const strings = await loadExtensionTranslation(svgEditor.pref('lang')); const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang'));
return { return {
/** @todo JFH special flag */ /** @todo JFH special flag */
newUI: true, newUI: true,

View File

@ -23,7 +23,7 @@ export default {
name: 'eyedropper', name: 'eyedropper',
async init (S) { async init (S) {
const svgEditor = this; const svgEditor = this;
const strings = await loadExtensionTranslation(svgEditor.pref('lang')); const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang'));
const {$, ChangeElementCommand} = S, // , svgcontent, const {$, ChangeElementCommand} = S, // , svgcontent,
// svgdoc = S.svgroot.parentNode.ownerDocument, // svgdoc = S.svgroot.parentNode.ownerDocument,
{svgCanvas} = svgEditor, {svgCanvas} = svgEditor,

View File

@ -31,7 +31,7 @@ export default {
// addElem = svgCanvas.addSVGElementFromJson, // addElem = svgCanvas.addSVGElementFromJson,
svgdoc = S.svgroot.parentNode.ownerDocument; svgdoc = S.svgroot.parentNode.ownerDocument;
const strings = await loadExtensionTranslation(svgEditor.pref('lang')); const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang'));
const properlySourceSizeTextArea = function () { const properlySourceSizeTextArea = function () {
// TODO: remove magic numbers here and get values from CSS // TODO: remove magic numbers here and get values from CSS

View File

@ -23,7 +23,7 @@ export default {
name: 'grid', name: 'grid',
async init ({$, NS, getTypeMap}) { async init ({$, NS, getTypeMap}) {
const svgEditor = this; const svgEditor = this;
const strings = await loadExtensionTranslation(svgEditor.pref('lang')); const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang'));
const {svgCanvas} = svgEditor; const {svgCanvas} = svgEditor;
const svgdoc = document.getElementById('svgcanvas').ownerDocument, const svgdoc = document.getElementById('svgcanvas').ownerDocument,
{assignAttributes} = svgCanvas, {assignAttributes} = svgCanvas,

View File

@ -29,7 +29,7 @@ export default {
name: 'helloworld', name: 'helloworld',
async init ({$, importLocale}) { async init ({$, importLocale}) {
const svgEditor = this; const svgEditor = this;
const strings = await loadExtensionTranslation(svgEditor.pref('lang')); const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang'));
const {svgCanvas} = svgEditor; const {svgCanvas} = svgEditor;
return { return {
name: strings.name, name: strings.name,

View File

@ -23,7 +23,7 @@ export default {
name: 'imagelib', name: 'imagelib',
async init ({$, decode64, dropXMLInternalSubset}) { async init ({$, decode64, dropXMLInternalSubset}) {
const svgEditor = this; const svgEditor = this;
const imagelibStrings = await loadExtensionTranslation(svgEditor.pref('lang')); const imagelibStrings = await loadExtensionTranslation(svgEditor.configObj.pref('lang'));
const {uiStrings, canvas: svgCanvas} = svgEditor; const {uiStrings, canvas: svgCanvas} = svgEditor;

View File

@ -45,7 +45,7 @@ export default {
name: 'markers', name: 'markers',
async init (S) { async init (S) {
const svgEditor = this; const svgEditor = this;
const strings = await loadExtensionTranslation(svgEditor.pref('lang')); const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang'));
const {$} = S; const {$} = S;
const {svgCanvas} = svgEditor; const {svgCanvas} = svgEditor;
const // {svgcontent} = S, const // {svgcontent} = S,

View File

@ -24,7 +24,7 @@ export default {
name: 'mathjax', name: 'mathjax',
async init ({$}) { async init ({$}) {
const svgEditor = this; const svgEditor = this;
const strings = await loadExtensionTranslation(svgEditor.pref('lang')); const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang'));
const {svgCanvas} = svgEditor; const {svgCanvas} = svgEditor;
// Configuration of the MathJax extention. // Configuration of the MathJax extention.

View File

@ -26,7 +26,7 @@ export default {
name: 'panning', name: 'panning',
async init ({importLocale}) { async init ({importLocale}) {
const svgEditor = this; const svgEditor = this;
const strings = await loadExtensionTranslation(svgEditor.pref('lang')); const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang'));
const {svgCanvas} = svgEditor; const {svgCanvas} = svgEditor;
const buttons = [{ const buttons = [{
id: 'ext-panning', id: 'ext-panning',

View File

@ -35,7 +35,7 @@ export default {
// newFOG, newFOGParent, newDef, newImageName, newMaskID, // newFOG, newFOGParent, newDef, newImageName, newMaskID,
// undoCommand = 'Not image', // undoCommand = 'Not image',
// modeChangeG, ccZoom, wEl, hEl, wOffset, hOffset, ccRgbEl, brushW, brushH; // modeChangeG, ccZoom, wEl, hEl, wOffset, hOffset, ccRgbEl, brushW, brushH;
const strings = await loadExtensionTranslation(svgEditor.pref('lang')); const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang'));
const markerTypes = { const markerTypes = {
nomarker: {}, nomarker: {},
forwardslash: forwardslash:

View File

@ -26,7 +26,7 @@ export default {
const {$} = S, // {svgcontent} const {$} = S, // {svgcontent}
// addElem = svgCanvas.addSVGElementFromJson, // addElem = svgCanvas.addSVGElementFromJson,
editingitex = false; editingitex = false;
const strings = await loadExtensionTranslation(svgEditor.pref('lang')); const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang'));
let selElems, let selElems,
// svgdoc = S.svgroot.parentNode.ownerDocument, // svgdoc = S.svgroot.parentNode.ownerDocument,
// newFOG, newFOGParent, newDef, newImageName, newMaskID, modeChangeG, // newFOG, newFOGParent, newDef, newImageName, newMaskID, modeChangeG,

View File

@ -25,7 +25,7 @@ export default {
name: 'server_moinsave', name: 'server_moinsave',
async init ({$, encode64, importLocale}) { async init ({$, encode64, importLocale}) {
const svgEditor = this; const svgEditor = this;
const strings = await loadExtensionTranslation(svgEditor.pref('lang')); const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang'));
const {svgCanvas} = svgEditor; const {svgCanvas} = svgEditor;
const saveSvgAction = '/+modify'; const saveSvgAction = '/+modify';

View File

@ -24,7 +24,7 @@ export default {
name: 'server_opensave', name: 'server_opensave',
async init ({$, decode64, encode64}) { async init ({$, decode64, encode64}) {
const svgEditor = this; const svgEditor = this;
const strings = await loadExtensionTranslation(svgEditor.pref('lang')); const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang'));
const { const {
curConfig: { curConfig: {
avoidClientSide, // Deprecated avoidClientSide, // Deprecated

View File

@ -35,7 +35,7 @@ export default {
// newFOG, newFOGParent, newDef, newImageName, newMaskID, // newFOG, newFOGParent, newDef, newImageName, newMaskID,
// undoCommand = 'Not image', // undoCommand = 'Not image',
// modeChangeG, ccZoom, wEl, hEl, wOffset, hOffset, ccRgbEl, brushW, brushH; // modeChangeG, ccZoom, wEl, hEl, wOffset, hOffset, ccRgbEl, brushW, brushH;
const strings = await loadExtensionTranslation(svgEditor.pref('lang')); const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang'));
/** /**
* *

View File

@ -22,7 +22,7 @@ export default {
name: 'webappfind', name: 'webappfind',
async init ({$}) { async init ({$}) {
const svgEditor = this; const svgEditor = this;
const strings = await loadExtensionTranslation(svgEditor.pref('lang')); const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang'));
const saveMessage = 'save', const saveMessage = 'save',
readMessage = 'read', readMessage = 'read',
excludedMessages = [readMessage, saveMessage]; excludedMessages = [readMessage, saveMessage];

View File

@ -411,13 +411,13 @@ class TopPanelHandlers {
if (attr !== 'id' && attr !== 'class') { if (attr !== 'id' && attr !== 'class') {
if (isNaN(val)) { if (isNaN(val)) {
val = this.svgCanvas.convertToNum(attr, val); val = this.svgCanvas.convertToNum(attr, val);
} else if (this.configObj.curConfig.baseUnit !== 'px') { } else if (this.editor.configObj.curConfig.baseUnit !== 'px') {
// Convert unitless value to one with given unit // Convert unitless value to one with given unit
const unitData = getTypeMap(); const unitData = getTypeMap();
if (this.selectedElement[attr] || this.svgCanvas.getMode() === 'pathedit' || attr === 'x' || attr === 'y') { if (this.selectedElement[attr] || this.svgCanvas.getMode() === 'pathedit' || attr === 'x' || attr === 'y') {
val *= unitData[this.configObj.curConfig.baseUnit]; val *= unitData[this.editor.configObj.curConfig.baseUnit];
} }
} }
} }

View File

@ -88,13 +88,13 @@ class Editor {
this.customExportImage = false; this.customExportImage = false;
this.customExportPDF = false; this.customExportPDF = false;
this.configObj = new ConfigObj(this); this.configObj = new ConfigObj(this);
this.pref = this.configObj.pref.bind(this.configObj); this.configObj.pref = this.configObj.pref.bind(this.configObj);
this.setConfig = this.configObj.setConfig.bind(this.configObj); this.setConfig = this.configObj.setConfig.bind(this.configObj);
this.callbacks = []; this.callbacks = [];
this.curContext = null; this.curContext = null;
this.exportWindowName = null; this.exportWindowName = null;
this.docprops = false; this.docprops = false;
this.preferences = false; this.configObj.preferences = false;
this.canvMenu = null; this.canvMenu = null;
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
this.goodLangs = ['ar', 'cs', 'de', 'en', 'es', 'fa', 'fr', 'fy', 'hi', 'it', 'ja', 'nl', 'pl', 'pt-BR', 'ro', 'ru', 'sk', 'sl', 'zh-CN', 'zh-TW']; this.goodLangs = ['ar', 'cs', 'de', 'en', 'es', 'fa', 'fr', 'fy', 'hi', 'it', 'ja', 'nl', 'pl', 'pt-BR', 'ro', 'ru', 'sk', 'sl', 'zh-CN', 'zh-TW'];
@ -349,7 +349,7 @@ class Editor {
* @returns {Promise<module:locale.LangAndData>} Resolves to result of {@link module:locale.readLang} * @returns {Promise<module:locale.LangAndData>} Resolves to result of {@link module:locale.readLang}
*/ */
async extAndLocaleFunc () { async extAndLocaleFunc () {
const {langParam, langData} = await this.putLocale(this.pref('lang'), this.goodLangs); const {langParam, langData} = await this.putLocale(this.configObj.pref('lang'), this.goodLangs);
await this.setLang(langParam, langData); await this.setLang(langParam, langData);
$id('svg_container').style.visibility = 'visible'; $id('svg_container').style.visibility = 'visible';
@ -589,7 +589,7 @@ class Editor {
this.svgCanvas.bind('extension_added', this.extAdded.bind(this)); this.svgCanvas.bind('extension_added', this.extAdded.bind(this));
this.svgCanvas.textActions.setInputElem($('#text')[0]); this.svgCanvas.textActions.setInputElem($('#text')[0]);
this.setBackground(this.pref('bkgd_color'), this.pref('bkgd_url')); this.setBackground(this.configObj.pref('bkgd_color'), this.configObj.pref('bkgd_url'));
// update resolution option with actual resolution // update resolution option with actual resolution
const res = this.svgCanvas.getResolution(); const res = this.svgCanvas.getResolution();
@ -601,7 +601,7 @@ class Editor {
$('#se-img-prop').attr('title', this.svgCanvas.getDocumentTitle()); $('#se-img-prop').attr('title', this.svgCanvas.getDocumentTitle());
$('#se-img-prop').attr('width', res.w); $('#se-img-prop').attr('width', res.w);
$('#se-img-prop').attr('height', res.h); $('#se-img-prop').attr('height', res.h);
$('#se-img-prop').attr('save', this.pref('img_save')); $('#se-img-prop').attr('save', this.configObj.pref('img_save'));
// Lose focus for select elements when changed (Allows keyboard shortcuts to work better) // Lose focus for select elements when changed (Allows keyboard shortcuts to work better)
$('select').change((evt) => { $(evt.currentTarget).blur(); }); $('select').change((evt) => { $(evt.currentTarget).blur(); });
@ -1197,7 +1197,7 @@ class Editor {
// Alert will only appear the first time saved OR the // Alert will only appear the first time saved OR the
// first time the bug is encountered // first time the bug is encountered
let done = this.pref('save_notice_done'); let done = this.configObj.pref('save_notice_done');
if (done !== 'all') { if (done !== 'all') {
let note = this.uiStrings.notification.saveFromBrowser.replace('%s', 'SVG'); let note = this.uiStrings.notification.saveFromBrowser.replace('%s', 'SVG');
@ -1206,13 +1206,13 @@ class Editor {
if (svg.includes('<defs')) { if (svg.includes('<defs')) {
// warning about Mozilla bug #308590 when applicable (seems to be fixed now in Feb 2013) // warning about Mozilla bug #308590 when applicable (seems to be fixed now in Feb 2013)
note += '\n\n' + this.uiStrings.notification.defsFailOnSave; note += '\n\n' + this.uiStrings.notification.defsFailOnSave;
this.pref('save_notice_done', 'all'); this.configObj.pref('save_notice_done', 'all');
done = 'all'; done = 'all';
} else { } else {
this.pref('save_notice_done', 'part'); this.configObj.pref('save_notice_done', 'part');
} }
} else { } else {
this.pref('save_notice_done', 'all'); this.configObj.pref('save_notice_done', 'all');
} }
if (done !== 'part') { if (done !== 'part') {
seAlert(note); seAlert(note);
@ -1237,7 +1237,7 @@ class Editor {
} }
this.exportWindow.location.href = data.bloburl || data.datauri; this.exportWindow.location.href = data.bloburl || data.datauri;
const done = this.pref('export_notice_done'); const done = this.configObj.pref('export_notice_done');
if (done !== 'all') { if (done !== 'all') {
let note = this.uiStrings.notification.saveFromBrowser.replace('%s', data.type); let note = this.uiStrings.notification.saveFromBrowser.replace('%s', data.type);
@ -1249,7 +1249,7 @@ class Editor {
// Note that this will also prevent the notice even though new issues may appear later. // Note that this will also prevent the notice even though new issues may appear later.
// May want to find a way to deal with that without annoying the user // May want to find a way to deal with that without annoying the user
this.pref('export_notice_done', 'all'); this.configObj.pref('export_notice_done', 'all');
this.exportWindow.seAlert(note); this.exportWindow.seAlert(note);
} }
} }
@ -1307,9 +1307,9 @@ class Editor {
* @returns {void} * @returns {void}
*/ */
setBackground (color, url) { setBackground (color, url) {
// if (color == this.pref('bkgd_color') && url == this.pref('bkgd_url')) { return; } // if (color == this.configObj.pref('bkgd_color') && url == this.configObj.pref('bkgd_url')) { return; }
this.pref('bkgd_color', color); this.configObj.pref('bkgd_color', color);
this.pref('bkgd_url', url, true); this.configObj.pref('bkgd_url', url, true);
// This should be done in this.svgCanvas.js for the borderRect fill // This should be done in this.svgCanvas.js for the borderRect fill
this.svgCanvas.setBackground(color, url); this.svgCanvas.setBackground(color, url);
@ -1707,7 +1707,7 @@ class Editor {
let cbCalled = false; let cbCalled = false;
if (ext.langReady && this.langChanged) { // We check for this since the "lang" pref could have been set by storage if (ext.langReady && this.langChanged) { // We check for this since the "lang" pref could have been set by storage
const lang = this.pref('lang'); const lang = this.configObj.pref('lang');
await ext.langReady({lang}); await ext.langReady({lang});
} }
@ -1951,7 +1951,7 @@ class Editor {
clickSave () { clickSave () {
// In the future, more options can be provided here // In the future, more options can be provided here
const saveOpts = { const saveOpts = {
images: this.pref('img_save'), images: this.configObj.pref('img_save'),
round_digits: 6 round_digits: 6
}; };
this.svgCanvas.save(saveOpts); this.svgCanvas.save(saveOpts);
@ -2055,7 +2055,7 @@ class Editor {
resolution.w = convertUnit(resolution.w) + this.configObj.curConfig.baseUnit; resolution.w = convertUnit(resolution.w) + this.configObj.curConfig.baseUnit;
resolution.h = convertUnit(resolution.h) + this.configObj.curConfig.baseUnit; resolution.h = convertUnit(resolution.h) + this.configObj.curConfig.baseUnit;
} }
$imgDialog.setAttribute('save', this.pref('img_save')); $imgDialog.setAttribute('save', this.configObj.pref('img_save'));
$imgDialog.setAttribute('width', resolution.w); $imgDialog.setAttribute('width', resolution.w);
$imgDialog.setAttribute('height', resolution.h); $imgDialog.setAttribute('height', resolution.h);
$imgDialog.setAttribute('title', this.svgCanvas.getDocumentTitle()); $imgDialog.setAttribute('title', this.svgCanvas.getDocumentTitle());
@ -2067,13 +2067,13 @@ class Editor {
* @returns {void} * @returns {void}
*/ */
showPreferences () { showPreferences () {
if (this.preferences) { return; } if (this.configObj.preferences) { return; }
this.preferences = true; this.configObj.preferences = true;
const $editDialog = document.getElementById('se-edit-prefs'); const $editDialog = document.getElementById('se-edit-prefs');
$('#main_menu').hide(); $('#main_menu').hide();
// Update background color with current one // Update background color with current one
const canvasBg = this.configObj.curPrefs.bkgd_color; const canvasBg = this.configObj.curPrefs.bkgd_color;
const url = this.pref('bkgd_url'); const url = this.configObj.pref('bkgd_url');
if (url) { if (url) {
$editDialog.setAttribute('bgurl', url); $editDialog.setAttribute('bgurl', url);
} }
@ -2137,7 +2137,7 @@ class Editor {
hideDocProperties () { hideDocProperties () {
const $imgDialog = document.getElementById('se-img-prop'); const $imgDialog = document.getElementById('se-img-prop');
$imgDialog.setAttribute('dialog', 'close'); $imgDialog.setAttribute('dialog', 'close');
$imgDialog.setAttribute('save', this.pref('img_save')); $imgDialog.setAttribute('save', this.configObj.pref('img_save'));
this.docprops = false; this.docprops = false;
} }
@ -2148,7 +2148,7 @@ class Editor {
hidePreferences () { hidePreferences () {
const $editDialog = document.getElementById('se-edit-prefs'); const $editDialog = document.getElementById('se-edit-prefs');
$editDialog.setAttribute('dialog', 'close'); $editDialog.setAttribute('dialog', 'close');
this.preferences = false; this.configObj.preferences = false;
} }
/** /**
@ -2174,7 +2174,7 @@ class Editor {
return false; return false;
} }
// Set image save option // Set image save option
this.pref('img_save', save); this.configObj.pref('img_save', save);
this.updateCanvas(); this.updateCanvas();
this.hideDocProperties(); this.hideDocProperties();
return true; return true;
@ -2192,7 +2192,7 @@ class Editor {
this.setBackground(bgcolor, bgurl); this.setBackground(bgcolor, bgurl);
// set language // set language
if (lang && lang !== this.pref('lang')) { if (lang && lang !== this.configObj.pref('lang')) {
const {langParam, langData} = await this.putLocale(lang, this.goodLangs); const {langParam, langData} = await this.putLocale(lang, this.goodLangs);
await this.setLang(langParam, langData); await this.setLang(langParam, langData);
} }
@ -2219,7 +2219,7 @@ class Editor {
$('#dialog_box').hide(); $('#dialog_box').hide();
const $editorDialog = document.getElementById('se-svg-editor-dialog'); const $editorDialog = document.getElementById('se-svg-editor-dialog');
const editingsource = $editorDialog.getAttribute('dialog') === 'open'; const editingsource = $editorDialog.getAttribute('dialog') === 'open';
if (!editingsource && !this.docprops && !this.preferences) { if (!editingsource && !this.docprops && !this.configObj.preferences) {
if (this.curContext) { if (this.curContext) {
this.svgCanvas.leaveContext(); this.svgCanvas.leaveContext();
} }
@ -2308,7 +2308,7 @@ class Editor {
*/ */
setLang (lang, allStrings) { setLang (lang, allStrings) {
this.langChanged = true; this.langChanged = true;
this.pref('lang', lang); this.configObj.pref('lang', lang);
const $editDialog = document.getElementById('se-edit-prefs'); const $editDialog = document.getElementById('se-edit-prefs');
$editDialog.setAttribute('lang', lang); $editDialog.setAttribute('lang', lang);
if (!allStrings) { if (!allStrings) {