Add QR set duplicate button
| @@ -51,6 +51,7 @@ | ||
| 51 | 51 | <div class="qr--add menu_button menu_button_icon fa-solid fa-file-import" id="qr--set-import" title="Import quick reply set"></div> |
| 52 | 52 | <input type="file" id="qr--set-importFile" accept=".json" hidden> |
| 53 | 53 | <div class="qr--add menu_button menu_button_icon fa-solid fa-file-export" id="qr--set-export" title="Export quick reply set"></div> |
| 54 | + <div class="qr-add menu_button menu_button_icon fa-solid fa-paste" id="qr--set-duplicate" title="Duplicate quick reply set"></div> | |
| 54 | 55 | <div class="qr--del menu_button menu_button_icon fa-solid fa-trash redWarningBG" id="qr--set-delete" title="Delete quick reply set"></div> |
| 55 | 56 | </div> |
| 56 | 57 | </div> |
| @@ -120,7 +120,8 @@ export class SettingsUi { | ||
| 120 | 120 | importFile.value = null; |
| 121 | 121 | }); |
| 122 | 122 | this.dom.querySelector('#qr--set-import').addEventListener('click', ()=>importFile.click()); |
| 123 | 123 | this.dom.querySelector('#qr--set-export').addEventListener('click', async () => this.exportQrSet()); |
| 124 | + this.dom.querySelector('#qr--set-duplicate').addEventListener('click', async () => this.duplicateQrSet()); | |
| 124 | 125 | this.dom.querySelector('#qr--set-delete').addEventListener('click', async()=>this.deleteQrSet()); |
| 125 | 126 | this.dom.querySelector('#qr--set-add').addEventListener('click', async()=>{ |
| 126 | 127 | this.currentQrSet.addQuickReply(); |
| @@ -460,6 +461,40 @@ export class SettingsUi { | ||
| 460 | 461 | URL.revokeObjectURL(url); |
| 461 | 462 | } |
| 462 | 463 | |
| 464 | + async duplicateQrSet() { | |
| 465 | + const newName = await Popup.show.input('Duplicate Quick Reply Set', 'Enter a name for the new Quick Reply Set:', `${this.currentQrSet.name} (Copy)`); | |
| 466 | + if (newName && newName.length > 0) { | |
| 467 | + const existingSet = QuickReplySet.get(newName); | |
| 468 | + if (existingSet) { | |
| 469 | + toastr.error(`A Quick Reply Set named "${newName}" already exists.`); | |
| 470 | + return; | |
| 471 | + } | |
| 472 | + const newQrSet = QuickReplySet.from(JSON.parse(JSON.stringify(this.currentQrSet))); | |
| 473 | + newQrSet.name = newName; | |
| 474 | + newQrSet.qrList = this.currentQrSet.qrList.map(qr => QuickReply.from(JSON.parse(JSON.stringify(qr)))); | |
| 475 | + newQrSet.addQuickReply(); | |
| 476 | + const idx = QuickReplySet.list.findIndex(it => it.name.toLowerCase().localeCompare(newName.toLowerCase()) == 1); | |
| 477 | + if (idx > -1) { | |
| 478 | + QuickReplySet.list.splice(idx, 0, newQrSet); | |
| 479 | + } else { | |
| 480 | + QuickReplySet.list.push(newQrSet); | |
| 481 | + } | |
| 482 | + const opt = document.createElement('option'); { | |
| 483 | + opt.value = newQrSet.name; | |
| 484 | + opt.textContent = newQrSet.name; | |
| 485 | + if (idx > -1) { | |
| 486 | + this.currentSet.children[idx].insertAdjacentElement('beforebegin', opt); | |
| 487 | + } else { | |
| 488 | + this.currentSet.append(opt); | |
| 489 | + } | |
| 490 | + } | |
| 491 | + this.currentSet.value = newName; | |
| 492 | + this.onQrSetChange(); | |
| 493 | + this.prepareGlobalSetList(); | |
| 494 | + this.prepareChatSetList(); | |
| 495 | + } | |
| 496 | + } | |
| 497 | + | |
| 463 | 498 | selectQrSet(qrs) { |
| 464 | 499 | this.currentSet.value = qrs.name; |
| 465 | 500 | this.onQrSetChange(); |