diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-05-02 21:04:39 -0400 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-05-08 15:25:23 -0400 |
commit | 5457a4ce32f02991551e69fb68e7aaf49b445d87 (patch) | |
tree | f43246d4382c3ae22c0ba596d261e94b7e89e2c4 /ext/js/pages/settings/dictionary-controller.js | |
parent | 881170cf5a2a5923460e6b14b59daa3ca011a469 (diff) |
Add "Move to" menu option for moving dictionary options to a specific location (#1651)
* Add "Move to" option
* Fix IDs
Diffstat (limited to 'ext/js/pages/settings/dictionary-controller.js')
-rw-r--r-- | ext/js/pages/settings/dictionary-controller.js | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/ext/js/pages/settings/dictionary-controller.js b/ext/js/pages/settings/dictionary-controller.js index 6f37798c..eca2a7d2 100644 --- a/ext/js/pages/settings/dictionary-controller.js +++ b/ext/js/pages/settings/dictionary-controller.js @@ -83,6 +83,7 @@ class DictionaryEntry { const count = this._dictionaryController.dictionaryOptionCount; this._setMenuActionEnabled(bodyNode, 'moveUp', this._index > 0); this._setMenuActionEnabled(bodyNode, 'moveDown', this._index < count - 1); + this._setMenuActionEnabled(bodyNode, 'moveTo', count > 1); } _onMenuClose(e) { @@ -99,6 +100,9 @@ class DictionaryEntry { case 'moveDown': this._move(1); break; + case 'moveTo': + this._showMoveToModal(); + break; } } @@ -173,6 +177,20 @@ class DictionaryEntry { if (element === null) { return; } element.disabled = !enabled; } + + _showMoveToModal() { + const {title} = this._dictionaryInfo; + const count = this._dictionaryController.dictionaryOptionCount; + const modal = this._dictionaryController.modalController.getModal('dictionary-move-location'); + const input = modal.node.querySelector('#dictionary-move-location'); + + modal.node.dataset.index = `${this._index}`; + modal.node.querySelector('.dictionary-title').textContent = title; + input.value = `${this._index + 1}`; + input.max = `${count}`; + + modal.setVisible(true); + } } class DictionaryExtraInfo { @@ -269,6 +287,7 @@ class DictionaryController { this._settingsController.on('optionsChanged', this._onOptionsChanged.bind(this)); this._allCheckbox.addEventListener('change', this._onAllCheckboxChange.bind(this), false); document.querySelector('#dictionary-confirm-delete-button').addEventListener('click', this._onDictionaryConfirmDelete.bind(this), false); + document.querySelector('#dictionary-move-button').addEventListener('click', this._onDictionaryMoveButtonClick.bind(this), false); if (this._checkIntegrityButton !== null) { this._checkIntegrityButton.addEventListener('click', this._onCheckIntegrityButtonClick.bind(this), false); } @@ -291,7 +310,8 @@ class DictionaryController { const {dictionaries} = options; if ( index1 < 0 || index1 >= dictionaries.length || - index2 < 0 || index2 >= dictionaries.length + index2 < 0 || index2 >= dictionaries.length || + index1 === index2 ) { return; } @@ -497,6 +517,19 @@ class DictionaryController { this._checkIntegrity(); } + _onDictionaryMoveButtonClick() { + const modal = this._modalController.getModal('dictionary-move-location'); + let {index} = modal.node.dataset; + index = Number.parseInt(index, 10); + + let target = document.querySelector('#dictionary-move-location').value; + target = Number.parseInt(target, 10) - 1; + + if (!Number.isFinite(target) || !Number.isFinite(index) || index === target) { return; } + + this.swapDictionaryOptions(index, target); + } + _updateMainDictionarySelectOptions(dictionaries) { for (const select of document.querySelectorAll('[data-setting="general.mainDictionary"]')) { const fragment = document.createDocumentFragment(); |