Update dictionary settings structure (#1587)
* Update dictionary settings structure to use an array instead of an object * Update ensureDictionarySettings implementation * Remove some usage of ObjectPropertyAccessor
This commit is contained in:
parent
0d2d342cd3
commit
a9fe2d03b2
@ -726,16 +726,21 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dictionaries": {
|
"dictionaries": {
|
||||||
"type": "object",
|
"type": "array",
|
||||||
"additionalProperties": {
|
"items": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
|
"name",
|
||||||
"priority",
|
"priority",
|
||||||
"enabled",
|
"enabled",
|
||||||
"allowSecondarySearches",
|
"allowSecondarySearches",
|
||||||
"definitionsCollapsible"
|
"definitionsCollapsible"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"name": {
|
||||||
|
"type": "string",
|
||||||
|
"default": ""
|
||||||
|
},
|
||||||
"priority": {
|
"priority": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"default": 0
|
"default": 0
|
||||||
|
@ -1271,6 +1271,17 @@ class Backend {
|
|||||||
if (!Array.isArray(array)) { throw new Error('Invalid target type'); }
|
if (!Array.isArray(array)) { throw new Error('Invalid target type'); }
|
||||||
return array.splice(start, deleteCount, ...items);
|
return array.splice(start, deleteCount, ...items);
|
||||||
}
|
}
|
||||||
|
case 'push':
|
||||||
|
{
|
||||||
|
const {path, items} = target;
|
||||||
|
if (typeof path !== 'string') { throw new Error('Invalid path'); }
|
||||||
|
if (!Array.isArray(items)) { throw new Error('Invalid items'); }
|
||||||
|
const array = accessor.get(ObjectPropertyAccessor.getPathArray(path));
|
||||||
|
if (!Array.isArray(array)) { throw new Error('Invalid target type'); }
|
||||||
|
const start = array.length;
|
||||||
|
array.push(...items);
|
||||||
|
return start;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unknown action: ${action}`);
|
throw new Error(`Unknown action: ${action}`);
|
||||||
}
|
}
|
||||||
@ -1358,7 +1369,7 @@ class Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_isAnyDictionaryEnabled(options) {
|
_isAnyDictionaryEnabled(options) {
|
||||||
for (const {enabled} of Object.values(options.dictionaries)) {
|
for (const {enabled} of options.dictionaries) {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1900,12 +1911,9 @@ class Backend {
|
|||||||
|
|
||||||
_getTranslatorEnabledDictionaryMap(options) {
|
_getTranslatorEnabledDictionaryMap(options) {
|
||||||
const enabledDictionaryMap = new Map();
|
const enabledDictionaryMap = new Map();
|
||||||
const {dictionaries} = options;
|
for (const dictionary of options.dictionaries) {
|
||||||
for (const title in dictionaries) {
|
|
||||||
if (!Object.prototype.hasOwnProperty.call(dictionaries, title)) { continue; }
|
|
||||||
const dictionary = dictionaries[title];
|
|
||||||
if (!dictionary.enabled) { continue; }
|
if (!dictionary.enabled) { continue; }
|
||||||
enabledDictionaryMap.set(title, {
|
enabledDictionaryMap.set(dictionary.name, {
|
||||||
index: enabledDictionaryMap.size,
|
index: enabledDictionaryMap.size,
|
||||||
priority: dictionary.priority,
|
priority: dictionary.priority,
|
||||||
allowSecondarySearches: dictionary.allowSecondarySearches
|
allowSecondarySearches: dictionary.allowSecondarySearches
|
||||||
|
@ -459,7 +459,8 @@ class OptionsUtil {
|
|||||||
{async: false, update: this._updateVersion7.bind(this)},
|
{async: false, update: this._updateVersion7.bind(this)},
|
||||||
{async: true, update: this._updateVersion8.bind(this)},
|
{async: true, update: this._updateVersion8.bind(this)},
|
||||||
{async: false, update: this._updateVersion9.bind(this)},
|
{async: false, update: this._updateVersion9.bind(this)},
|
||||||
{async: true, update: this._updateVersion10.bind(this)}
|
{async: true, update: this._updateVersion10.bind(this)},
|
||||||
|
{async: true, update: this._updateVersion11.bind(this)}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -786,4 +787,17 @@ class OptionsUtil {
|
|||||||
}
|
}
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_updateVersion11(options) {
|
||||||
|
// Version 11 changes:
|
||||||
|
// Changed dictionaries to an array.
|
||||||
|
for (const profile of options.profiles) {
|
||||||
|
const dictionariesNew = [];
|
||||||
|
for (const [name, {priority, enabled, allowSecondarySearches, definitionsCollapsible}] of Object.entries(profile.options.dictionaries)) {
|
||||||
|
dictionariesNew.push({name, priority, enabled, allowSecondarySearches, definitionsCollapsible});
|
||||||
|
}
|
||||||
|
profile.options.dictionaries = dictionariesNew;
|
||||||
|
}
|
||||||
|
return options;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ class ElementOverflowController {
|
|||||||
|
|
||||||
setOptions(options) {
|
setOptions(options) {
|
||||||
this._dictionaries.clear();
|
this._dictionaries.clear();
|
||||||
for (const [dictionary, {definitionsCollapsible}] of Object.entries(options.dictionaries)) {
|
for (const {name, definitionsCollapsible} of options.dictionaries) {
|
||||||
let collapsible = false;
|
let collapsible = false;
|
||||||
let collapsed = false;
|
let collapsed = false;
|
||||||
switch (definitionsCollapsible) {
|
switch (definitionsCollapsible) {
|
||||||
@ -42,7 +42,7 @@ class ElementOverflowController {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!collapsible) { continue; }
|
if (!collapsible) { continue; }
|
||||||
this._dictionaries.set(dictionary, {collapsed});
|
this._dictionaries.set(name, {collapsed});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,12 +191,16 @@ class DisplayController {
|
|||||||
const noDictionariesEnabledWarnings = document.querySelectorAll('.no-dictionaries-enabled-warning');
|
const noDictionariesEnabledWarnings = document.querySelectorAll('.no-dictionaries-enabled-warning');
|
||||||
const dictionaries = await yomichan.api.getDictionaryInfo();
|
const dictionaries = await yomichan.api.getDictionaryInfo();
|
||||||
|
|
||||||
|
const enabledDictionaries = new Set();
|
||||||
|
for (const {name, enabled} of options.dictionaries) {
|
||||||
|
if (enabled) {
|
||||||
|
enabledDictionaries.add(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let enabledCount = 0;
|
let enabledCount = 0;
|
||||||
for (const {title} of dictionaries) {
|
for (const {title} of dictionaries) {
|
||||||
if (
|
if (enabledDictionaries.has(title)) {
|
||||||
Object.prototype.hasOwnProperty.call(options.dictionaries, title) &&
|
|
||||||
options.dictionaries[title].enabled
|
|
||||||
) {
|
|
||||||
++enabledCount;
|
++enabledCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -368,7 +368,7 @@ class BackupController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update dictionaries
|
// Update dictionaries
|
||||||
await DictionaryController.ensureDictionarySettings(this._settingsController, void 0, optionsFull, true, false);
|
await DictionaryController.ensureDictionarySettings(this._settingsController, void 0, optionsFull, false, false);
|
||||||
|
|
||||||
// Assign options
|
// Assign options
|
||||||
await this._settingsImportSetOptionsFull(optionsFull);
|
await this._settingsImportSetOptionsFull(optionsFull);
|
||||||
@ -404,7 +404,7 @@ class BackupController {
|
|||||||
const optionsFull = this._optionsUtil.getDefault();
|
const optionsFull = this._optionsUtil.getDefault();
|
||||||
|
|
||||||
// Update dictionaries
|
// Update dictionaries
|
||||||
await DictionaryController.ensureDictionarySettings(this._settingsController, void 0, optionsFull, true, false);
|
await DictionaryController.ensureDictionarySettings(this._settingsController, void 0, optionsFull, false, false);
|
||||||
|
|
||||||
// Assign options
|
// Assign options
|
||||||
try {
|
try {
|
||||||
|
@ -15,10 +15,6 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* global
|
|
||||||
* ObjectPropertyAccessor
|
|
||||||
*/
|
|
||||||
|
|
||||||
class CollapsibleDictionaryController {
|
class CollapsibleDictionaryController {
|
||||||
constructor(settingsController) {
|
constructor(settingsController) {
|
||||||
this._settingsController = settingsController;
|
this._settingsController = settingsController;
|
||||||
@ -65,12 +61,14 @@ class CollapsibleDictionaryController {
|
|||||||
|
|
||||||
this._setupAllSelect(fragment, options);
|
this._setupAllSelect(fragment, options);
|
||||||
|
|
||||||
for (const dictionary of Object.keys(options.dictionaries)) {
|
const {dictionaries} = options;
|
||||||
const dictionaryInfo = this._dictionaryInfoMap.get(dictionary);
|
for (let i = 0, ii = dictionaries.length; i < ii; ++i) {
|
||||||
|
const {name} = dictionaries[i];
|
||||||
|
const dictionaryInfo = this._dictionaryInfoMap.get(name);
|
||||||
if (typeof dictionaryInfo === 'undefined') { continue; }
|
if (typeof dictionaryInfo === 'undefined') { continue; }
|
||||||
|
|
||||||
const select = this._addSelect(fragment, dictionary, `rev.${dictionaryInfo.revision}`);
|
const select = this._addSelect(fragment, name, `rev.${dictionaryInfo.revision}`);
|
||||||
select.dataset.setting = ObjectPropertyAccessor.getPathString(['dictionaries', dictionary, 'definitionsCollapsible']);
|
select.dataset.setting = `dictionaries[${i}].definitionsCollapsible`;
|
||||||
this._eventListeners.addEventListener(select, 'settingChanged', this._onDefinitionsCollapsibleChange.bind(this), false);
|
this._eventListeners.addEventListener(select, 'settingChanged', this._onDefinitionsCollapsibleChange.bind(this), false);
|
||||||
|
|
||||||
this._selects.push(select);
|
this._selects.push(select);
|
||||||
@ -125,7 +123,7 @@ class CollapsibleDictionaryController {
|
|||||||
_updateAllSelect(options) {
|
_updateAllSelect(options) {
|
||||||
let value = null;
|
let value = null;
|
||||||
let varies = false;
|
let varies = false;
|
||||||
for (const {definitionsCollapsible} of Object.values(options.dictionaries)) {
|
for (const {definitionsCollapsible} of options.dictionaries) {
|
||||||
if (value === null) {
|
if (value === null) {
|
||||||
value = definitionsCollapsible;
|
value = definitionsCollapsible;
|
||||||
} else if (value !== definitionsCollapsible) {
|
} else if (value !== definitionsCollapsible) {
|
||||||
@ -140,8 +138,9 @@ class CollapsibleDictionaryController {
|
|||||||
async _setDefinitionsCollapsibleAll(value) {
|
async _setDefinitionsCollapsibleAll(value) {
|
||||||
const options = await this._settingsController.getOptions();
|
const options = await this._settingsController.getOptions();
|
||||||
const targets = [];
|
const targets = [];
|
||||||
for (const dictionary of Object.keys(options.dictionaries)) {
|
const {dictionaries} = options;
|
||||||
const path = ObjectPropertyAccessor.getPathString(['dictionaries', dictionary, 'definitionsCollapsible']);
|
for (let i = 0, ii = dictionaries.length; i < ii; ++i) {
|
||||||
|
const path = `dictionaries[${i}].definitionsCollapsible`;
|
||||||
targets.push({action: 'set', path, value});
|
targets.push({action: 'set', path, value});
|
||||||
}
|
}
|
||||||
await this._settingsController.modifyProfileSettings(targets);
|
await this._settingsController.modifyProfileSettings(targets);
|
||||||
|
@ -17,13 +17,13 @@
|
|||||||
|
|
||||||
/* global
|
/* global
|
||||||
* DictionaryDatabase
|
* DictionaryDatabase
|
||||||
* ObjectPropertyAccessor
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class DictionaryEntry {
|
class DictionaryEntry {
|
||||||
constructor(dictionaryController, node, dictionaryInfo) {
|
constructor(dictionaryController, node, index, dictionaryInfo) {
|
||||||
this._dictionaryController = dictionaryController;
|
this._dictionaryController = dictionaryController;
|
||||||
this._node = node;
|
this._node = node;
|
||||||
|
this._index = index;
|
||||||
this._dictionaryInfo = dictionaryInfo;
|
this._dictionaryInfo = dictionaryInfo;
|
||||||
this._eventListeners = new EventListenerCollection();
|
this._eventListeners = new EventListenerCollection();
|
||||||
this._detailsContainer = null;
|
this._detailsContainer = null;
|
||||||
@ -41,6 +41,7 @@ class DictionaryEntry {
|
|||||||
|
|
||||||
prepare() {
|
prepare() {
|
||||||
const node = this._node;
|
const node = this._node;
|
||||||
|
const index = this._index;
|
||||||
const {title, revision, prefixWildcardsSupported, version} = this._dictionaryInfo;
|
const {title, revision, prefixWildcardsSupported, version} = this._dictionaryInfo;
|
||||||
|
|
||||||
this._detailsContainer = node.querySelector('.dictionary-details');
|
this._detailsContainer = node.querySelector('.dictionary-details');
|
||||||
@ -72,14 +73,14 @@ class DictionaryEntry {
|
|||||||
detailsToggleLink.hidden = !hasDetails;
|
detailsToggleLink.hidden = !hasDetails;
|
||||||
}
|
}
|
||||||
if (enabledCheckbox !== null) {
|
if (enabledCheckbox !== null) {
|
||||||
enabledCheckbox.dataset.setting = ObjectPropertyAccessor.getPathString(['dictionaries', title, 'enabled']);
|
enabledCheckbox.dataset.setting = `dictionaries[${index}].enabled`;
|
||||||
this._eventListeners.addEventListener(enabledCheckbox, 'settingChanged', this._onEnabledChanged.bind(this), false);
|
this._eventListeners.addEventListener(enabledCheckbox, 'settingChanged', this._onEnabledChanged.bind(this), false);
|
||||||
}
|
}
|
||||||
if (priorityInput !== null) {
|
if (priorityInput !== null) {
|
||||||
priorityInput.dataset.setting = ObjectPropertyAccessor.getPathString(['dictionaries', title, 'priority']);
|
priorityInput.dataset.setting = `dictionaries[${index}].priority`;
|
||||||
}
|
}
|
||||||
if (allowSecondarySearchesCheckbox !== null) {
|
if (allowSecondarySearchesCheckbox !== null) {
|
||||||
allowSecondarySearchesCheckbox.dataset.setting = ObjectPropertyAccessor.getPathString(['dictionaries', title, 'allowSecondarySearches']);
|
allowSecondarySearchesCheckbox.dataset.setting = `dictionaries[${index}].allowSecondarySearches`;
|
||||||
}
|
}
|
||||||
if (deleteButton !== null) {
|
if (deleteButton !== null) {
|
||||||
this._eventListeners.addEventListener(deleteButton, 'click', this._onDeleteButtonClicked.bind(this), false);
|
this._eventListeners.addEventListener(deleteButton, 'click', this._onDeleteButtonClicked.bind(this), false);
|
||||||
@ -248,8 +249,9 @@ class DictionaryController {
|
|||||||
this._updateDictionariesEnabledWarnings(options);
|
this._updateDictionariesEnabledWarnings(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
static createDefaultDictionarySettings(enabled) {
|
static createDefaultDictionarySettings(name, enabled) {
|
||||||
return {
|
return {
|
||||||
|
name,
|
||||||
priority: 0,
|
priority: 0,
|
||||||
enabled,
|
enabled,
|
||||||
allowSecondarySearches: false,
|
allowSecondarySearches: false,
|
||||||
@ -257,7 +259,7 @@ class DictionaryController {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static async ensureDictionarySettings(settingsController, dictionaries, optionsFull, modifyOptionsFull, newDictionariesEnabled) {
|
static async ensureDictionarySettings(settingsController, dictionaries, optionsFull, modifyGlobalSettings, newDictionariesEnabled) {
|
||||||
if (typeof dictionaries === 'undefined') {
|
if (typeof dictionaries === 'undefined') {
|
||||||
dictionaries = await settingsController.getDictionaryInfo();
|
dictionaries = await settingsController.getDictionaryInfo();
|
||||||
}
|
}
|
||||||
@ -265,24 +267,43 @@ class DictionaryController {
|
|||||||
optionsFull = await settingsController.getOptionsFull();
|
optionsFull = await settingsController.getOptionsFull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const installedDictionaries = new Set();
|
||||||
|
for (const {title} of dictionaries) {
|
||||||
|
installedDictionaries.add(title);
|
||||||
|
}
|
||||||
|
|
||||||
const targets = [];
|
const targets = [];
|
||||||
const {profiles} = optionsFull;
|
const {profiles} = optionsFull;
|
||||||
for (const {title} of dictionaries) {
|
|
||||||
for (let i = 0, ii = profiles.length; i < ii; ++i) {
|
for (let i = 0, ii = profiles.length; i < ii; ++i) {
|
||||||
const {options: {dictionaries: dictionaryOptions}} = profiles[i];
|
let modified = false;
|
||||||
if (Object.prototype.hasOwnProperty.call(dictionaryOptions, title)) { continue; }
|
const missingDictionaries = new Set([...installedDictionaries]);
|
||||||
|
const dictionaryOptionsArray = profiles[i].options.dictionaries;
|
||||||
const value = DictionaryController.createDefaultDictionarySettings(newDictionariesEnabled);
|
for (let j = dictionaryOptionsArray.length - 1; j >= 0; --j) {
|
||||||
if (modifyOptionsFull) {
|
const {name} = dictionaryOptionsArray[j];
|
||||||
dictionaryOptions[title] = value;
|
if (installedDictionaries.has(name)) {
|
||||||
|
missingDictionaries.delete(name);
|
||||||
} else {
|
} else {
|
||||||
const path = ObjectPropertyAccessor.getPathString(['profiles', i, 'options', 'dictionaries', title]);
|
dictionaryOptionsArray.splice(j, 1);
|
||||||
targets.push({action: 'set', path, value});
|
modified = true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!modifyOptionsFull && targets.length > 0) {
|
for (const name of missingDictionaries) {
|
||||||
|
const value = DictionaryController.createDefaultDictionarySettings(name, newDictionariesEnabled);
|
||||||
|
dictionaryOptionsArray.push(value);
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modified) {
|
||||||
|
targets.push({
|
||||||
|
action: 'set',
|
||||||
|
path: `profiles[${i}].options.dictionaries`,
|
||||||
|
value: dictionaryOptionsArray
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modifyGlobalSettings && targets.length > 0) {
|
||||||
await settingsController.modifyGlobalSettings(targets);
|
await settingsController.modifyGlobalSettings(targets);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -291,6 +312,9 @@ class DictionaryController {
|
|||||||
|
|
||||||
_onOptionsChanged({options}) {
|
_onOptionsChanged({options}) {
|
||||||
this._updateDictionariesEnabledWarnings(options);
|
this._updateDictionariesEnabledWarnings(options);
|
||||||
|
if (this._dictionaries !== null) {
|
||||||
|
this._updateEntries();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async _onDatabaseUpdated() {
|
async _onDatabaseUpdated() {
|
||||||
@ -298,10 +322,14 @@ class DictionaryController {
|
|||||||
this._databaseStateToken = token;
|
this._databaseStateToken = token;
|
||||||
this._dictionaries = null;
|
this._dictionaries = null;
|
||||||
const dictionaries = await this._settingsController.getDictionaryInfo();
|
const dictionaries = await this._settingsController.getDictionaryInfo();
|
||||||
const options = await this._settingsController.getOptions();
|
|
||||||
if (this._databaseStateToken !== token) { return; }
|
if (this._databaseStateToken !== token) { return; }
|
||||||
this._dictionaries = dictionaries;
|
this._dictionaries = dictionaries;
|
||||||
|
|
||||||
|
await this._updateEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
async _updateEntries() {
|
||||||
|
const dictionaries = this._dictionaries;
|
||||||
this._updateMainDictionarySelectOptions(dictionaries);
|
this._updateMainDictionarySelectOptions(dictionaries);
|
||||||
|
|
||||||
for (const entry of this._dictionaryEntries) {
|
for (const entry of this._dictionaryEntries) {
|
||||||
@ -318,24 +346,39 @@ class DictionaryController {
|
|||||||
node.hidden = hasDictionary;
|
node.hidden = hasDictionary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await DictionaryController.ensureDictionarySettings(this._settingsController, dictionaries, void 0, true, false);
|
||||||
|
|
||||||
|
const options = await this._settingsController.getOptions();
|
||||||
this._updateDictionariesEnabledWarnings(options);
|
this._updateDictionariesEnabledWarnings(options);
|
||||||
|
|
||||||
await DictionaryController.ensureDictionarySettings(this._settingsController, dictionaries, void 0, false, false);
|
const dictionaryInfoMap = new Map();
|
||||||
for (const dictionary of dictionaries) {
|
for (const dictionary of this._dictionaries) {
|
||||||
this._createDictionaryEntry(dictionary);
|
dictionaryInfoMap.set(dictionary.title, dictionary);
|
||||||
|
}
|
||||||
|
|
||||||
|
const dictionaryOptionsArray = options.dictionaries;
|
||||||
|
for (let i = 0, ii = dictionaryOptionsArray.length; i < ii; ++i) {
|
||||||
|
const {name} = dictionaryOptionsArray[i];
|
||||||
|
const dictionaryInfo = dictionaryInfoMap.get(name);
|
||||||
|
if (typeof dictionaryInfo === 'undefined') { continue; }
|
||||||
|
this._createDictionaryEntry(i, dictionaryInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateDictionariesEnabledWarnings(options) {
|
_updateDictionariesEnabledWarnings(options) {
|
||||||
let enabledCount = 0;
|
let enabledCount = 0;
|
||||||
if (this._dictionaries !== null) {
|
if (this._dictionaries !== null) {
|
||||||
for (const {title} of this._dictionaries) {
|
const enabledDictionaries = new Set();
|
||||||
if (Object.prototype.hasOwnProperty.call(options.dictionaries, title)) {
|
for (const {name, enabled} of options.dictionaries) {
|
||||||
const {enabled} = options.dictionaries[title];
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
++enabledCount;
|
enabledDictionaries.add(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const {title} of this._dictionaries) {
|
||||||
|
if (enabledDictionaries.has(title)) {
|
||||||
|
++enabledCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,11 +502,11 @@ class DictionaryController {
|
|||||||
parent.removeChild(node);
|
parent.removeChild(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
_createDictionaryEntry(dictionary) {
|
_createDictionaryEntry(index, dictionaryInfo) {
|
||||||
const node = this.instantiateTemplate('dictionary');
|
const node = this.instantiateTemplate('dictionary');
|
||||||
this._dictionaryEntryContainer.appendChild(node);
|
this._dictionaryEntryContainer.appendChild(node);
|
||||||
|
|
||||||
const entry = new DictionaryEntry(this, node, dictionary);
|
const entry = new DictionaryEntry(this, node, index, dictionaryInfo);
|
||||||
this._dictionaryEntries.push(entry);
|
this._dictionaryEntries.push(entry);
|
||||||
entry.prepare();
|
entry.prepare();
|
||||||
}
|
}
|
||||||
@ -553,9 +596,16 @@ class DictionaryController {
|
|||||||
const targets = [];
|
const targets = [];
|
||||||
for (let i = 0, ii = profiles.length; i < ii; ++i) {
|
for (let i = 0, ii = profiles.length; i < ii; ++i) {
|
||||||
const {options: {dictionaries}} = profiles[i];
|
const {options: {dictionaries}} = profiles[i];
|
||||||
if (Object.prototype.hasOwnProperty.call(dictionaries, dictionaryTitle)) {
|
for (let j = 0, jj = dictionaries.length; j < jj; ++j) {
|
||||||
const path = ObjectPropertyAccessor.getPathString(['profiles', i, 'options', 'dictionaries', dictionaryTitle]);
|
if (dictionaries[j].name !== dictionaryTitle) { continue; }
|
||||||
targets.push({action: 'delete', path});
|
const path = `profiles[${i}].options.dictionaries`;
|
||||||
|
targets.push({
|
||||||
|
action: 'splice',
|
||||||
|
path,
|
||||||
|
start: j,
|
||||||
|
deleteCount: 1,
|
||||||
|
items: []
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await this._settingsController.modifyGlobalSettings(targets);
|
await this._settingsController.modifyGlobalSettings(targets);
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
* DictionaryController
|
* DictionaryController
|
||||||
* DictionaryDatabase
|
* DictionaryDatabase
|
||||||
* DictionaryImporter
|
* DictionaryImporter
|
||||||
* ObjectPropertyAccessor
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class DictionaryImportController {
|
class DictionaryImportController {
|
||||||
@ -213,12 +212,12 @@ class DictionaryImportController {
|
|||||||
const profileCount = optionsFull.profiles.length;
|
const profileCount = optionsFull.profiles.length;
|
||||||
for (let i = 0; i < profileCount; ++i) {
|
for (let i = 0; i < profileCount; ++i) {
|
||||||
const {options} = optionsFull.profiles[i];
|
const {options} = optionsFull.profiles[i];
|
||||||
const value = DictionaryController.createDefaultDictionarySettings(true);
|
const value = DictionaryController.createDefaultDictionarySettings(title, true);
|
||||||
const path1 = ObjectPropertyAccessor.getPathString(['profiles', i, 'options', 'dictionaries', title]);
|
const path1 = `profiles[${i}].options.dictionaries`;
|
||||||
targets.push({action: 'set', path: path1, value});
|
targets.push({action: 'push', path: path1, items: [value]});
|
||||||
|
|
||||||
if (sequenced && options.general.mainDictionary === '') {
|
if (sequenced && options.general.mainDictionary === '') {
|
||||||
const path2 = ObjectPropertyAccessor.getPathString(['profiles', i, 'options', 'general', 'mainDictionary']);
|
const path2 = `profiles[${i}].options.general.mainDictionary`;
|
||||||
targets.push({action: 'set', path: path2, value: title});
|
targets.push({action: 'set', path: path2, value: title});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -230,9 +229,9 @@ class DictionaryImportController {
|
|||||||
const targets = [];
|
const targets = [];
|
||||||
const profileCount = optionsFull.profiles.length;
|
const profileCount = optionsFull.profiles.length;
|
||||||
for (let i = 0; i < profileCount; ++i) {
|
for (let i = 0; i < profileCount; ++i) {
|
||||||
const path1 = ObjectPropertyAccessor.getPathString(['profiles', i, 'options', 'dictionaries']);
|
const path1 = `profiles[${i}].options.dictionaries`;
|
||||||
targets.push({action: 'set', path: path1, value: {}});
|
targets.push({action: 'set', path: path1, value: []});
|
||||||
const path2 = ObjectPropertyAccessor.getPathString(['profiles', i, 'options', 'general', 'mainDictionary']);
|
const path2 = `profiles[${i}].options.general.mainDictionary`;
|
||||||
targets.push({action: 'set', path: path2, value: ''});
|
targets.push({action: 'set', path: path2, value: ''});
|
||||||
}
|
}
|
||||||
return await this._modifyGlobalSettings(targets);
|
return await this._modifyGlobalSettings(targets);
|
||||||
|
@ -15,10 +15,6 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* global
|
|
||||||
* ObjectPropertyAccessor
|
|
||||||
*/
|
|
||||||
|
|
||||||
class SecondarySearchDictionaryController {
|
class SecondarySearchDictionaryController {
|
||||||
constructor(settingsController) {
|
constructor(settingsController) {
|
||||||
this._settingsController = settingsController;
|
this._settingsController = settingsController;
|
||||||
@ -60,21 +56,23 @@ class SecondarySearchDictionaryController {
|
|||||||
|
|
||||||
const fragment = document.createDocumentFragment();
|
const fragment = document.createDocumentFragment();
|
||||||
|
|
||||||
for (const dictionary of Object.keys(options.dictionaries)) {
|
const {dictionaries} = options;
|
||||||
const dictionaryInfo = this._dictionaryInfoMap.get(dictionary);
|
for (let i = 0, ii = dictionaries.length; i < ii; ++i) {
|
||||||
|
const {name} = dictionaries[i];
|
||||||
|
const dictionaryInfo = this._dictionaryInfoMap.get(name);
|
||||||
if (typeof dictionaryInfo === 'undefined') { continue; }
|
if (typeof dictionaryInfo === 'undefined') { continue; }
|
||||||
|
|
||||||
const node = this._settingsController.instantiateTemplate('secondary-search-dictionary');
|
const node = this._settingsController.instantiateTemplate('secondary-search-dictionary');
|
||||||
fragment.appendChild(node);
|
fragment.appendChild(node);
|
||||||
|
|
||||||
const nameNode = node.querySelector('.dictionary-title');
|
const nameNode = node.querySelector('.dictionary-title');
|
||||||
nameNode.textContent = dictionary;
|
nameNode.textContent = name;
|
||||||
|
|
||||||
const versionNode = node.querySelector('.dictionary-version');
|
const versionNode = node.querySelector('.dictionary-version');
|
||||||
versionNode.textContent = `rev.${dictionaryInfo.revision}`;
|
versionNode.textContent = `rev.${dictionaryInfo.revision}`;
|
||||||
|
|
||||||
const toggle = node.querySelector('.dictionary-allow-secondary-searches');
|
const toggle = node.querySelector('.dictionary-allow-secondary-searches');
|
||||||
toggle.dataset.setting = ObjectPropertyAccessor.getPathString(['dictionaries', dictionary, 'allowSecondarySearches']);
|
toggle.dataset.setting = `dictionaries[${i}].allowSecondarySearches`;
|
||||||
this._eventListeners.addEventListener(toggle, 'settingChanged', this._onEnabledChanged.bind(this, node), false);
|
this._eventListeners.addEventListener(toggle, 'settingChanged', this._onEnabledChanged.bind(this, node), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,14 +407,15 @@ function createProfileOptionsUpdatedTestData1() {
|
|||||||
groups: []
|
groups: []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
dictionaries: {
|
dictionaries: [
|
||||||
'Test Dictionary': {
|
{
|
||||||
|
name: 'Test Dictionary',
|
||||||
priority: 0,
|
priority: 0,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
allowSecondarySearches: false,
|
allowSecondarySearches: false,
|
||||||
definitionsCollapsible: 'not-collapsible'
|
definitionsCollapsible: 'not-collapsible'
|
||||||
}
|
}
|
||||||
},
|
],
|
||||||
parsing: {
|
parsing: {
|
||||||
enableScanningParser: true,
|
enableScanningParser: true,
|
||||||
enableMecabParser: false,
|
enableMecabParser: false,
|
||||||
@ -574,7 +575,7 @@ function createOptionsUpdatedTestData1() {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
profileCurrent: 0,
|
profileCurrent: 0,
|
||||||
version: 10,
|
version: 11,
|
||||||
global: {
|
global: {
|
||||||
database: {
|
database: {
|
||||||
prefixWildcardsSupported: false
|
prefixWildcardsSupported: false
|
||||||
|
Loading…
Reference in New Issue
Block a user