From 5457a4ce32f02991551e69fb68e7aaf49b445d87 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 2 May 2021 21:04:39 -0400 Subject: Add "Move to" menu option for moving dictionary options to a specific location (#1651) * Add "Move to" option * Fix IDs --- ext/css/settings.css | 5 +++- ext/js/pages/settings/dictionary-controller.js | 35 +++++++++++++++++++++++++- ext/settings.html | 20 ++++++++++++++- 3 files changed, 57 insertions(+), 3 deletions(-) (limited to 'ext') diff --git a/ext/css/settings.css b/ext/css/settings.css index f0070a1f..588a5f90 100644 --- a/ext/css/settings.css +++ b/ext/css/settings.css @@ -2124,11 +2124,14 @@ button.hotkey-list-item-enabled-button[data-scope-count='0'] { .dictionary-list { width: 100%; display: grid; - grid-template-columns: auto 1fr auto auto; + grid-template-columns: auto auto 1fr auto auto; grid-template-rows: auto; place-items: center start; margin-top: 0.5em; } +.dictionary-list-index { + margin-right: 0.5em; +} .dictionary-list[data-count='0']>.dictionary-item-top { display: none; } 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(); diff --git a/ext/settings.html b/ext/settings.html index 6f0c67ad..f7730eb4 100644 --- a/ext/settings.html +++ b/ext/settings.html @@ -2080,7 +2080,8 @@ for a list free dictionaries or click the Import button below to select a dictionary file to import. -
+
+
All
Priority
@@ -2226,9 +2227,24 @@
+ + -- cgit v1.2.3