From 72fb67d15b4baa7637b9678a72340f1570b36eb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Wed, 6 Mar 2019 16:22:01 +0200 Subject: [PATCH] Restore "Delete All Automatic Tags" menu option for tag selector. Closes #1660 --- .../content/zotero/containers/tagSelector.jsx | 37 +++++++++++++++++++ .../content/zotero/containers/tagSelector.xul | 4 ++ test/tests/tagSelectorTest.js | 31 ++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/chrome/content/zotero/containers/tagSelector.jsx b/chrome/content/zotero/containers/tagSelector.jsx index 118c67fcf2..3548fa3a21 100644 --- a/chrome/content/zotero/containers/tagSelector.jsx +++ b/chrome/content/zotero/containers/tagSelector.jsx @@ -389,6 +389,43 @@ Zotero.TagSelector = class TagSelectorContainer extends React.Component { this.props.onSelection(this.selectedTags); } } + + async deleteAutomatic() { + var num = (await Zotero.Tags.getAutomaticInLibrary(this.libraryID)).length; + if (!num) { + return; + } + + var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] + .getService(Components.interfaces.nsIPromptService); + var confirmed = ps.confirm( + window, + Zotero.getString('pane.tagSelector.deleteAutomatic.title'), + Zotero.getString( + 'pane.tagSelector.deleteAutomatic.message', + new Intl.NumberFormat().format(num), + num + ) + + "\n\n" + + Zotero.getString('general.actionCannotBeUndone') + ); + if (confirmed) { + Zotero.showZoteroPaneProgressMeter(null, true); + try { + await Zotero.Tags.removeAutomaticFromLibrary( + this.libraryID, + (progress, progressMax) => { + Zotero.updateZoteroPaneProgressMeter( + Math.round(progress / progressMax * 100) + ); + } + ); + } + finally { + Zotero.hideZoteroPaneOverlays(); + } + } + } get label() { let count = this.selectedTags.size; diff --git a/chrome/content/zotero/containers/tagSelector.xul b/chrome/content/zotero/containers/tagSelector.xul index 5022281054..d84e384080 100644 --- a/chrome/content/zotero/containers/tagSelector.xul +++ b/chrome/content/zotero/containers/tagSelector.xul @@ -54,5 +54,9 @@ type="checkbox" oncommand="ZoteroPane.tagSelector.toggleDisplayAllTags(); event.stopPropagation();" /> + \ No newline at end of file diff --git a/test/tests/tagSelectorTest.js b/test/tests/tagSelectorTest.js index 989985a2a6..870ef29a2d 100644 --- a/test/tests/tagSelectorTest.js +++ b/test/tests/tagSelectorTest.js @@ -533,4 +533,35 @@ describe("Tag Selector", function () { assert.notInclude(getRegularTags(), tag); }) }); + + describe("#deleteAutomatic()", function() { + it('should delete automatic tags', async function() { + await selectLibrary(win); + var item = createUnsavedDataObject('item'); + item.setTags([ + { + tag: "automatic", + type: 1 + }, + { + tag: 'manual' + } + ]); + var promise = waitForTagSelector(win); + await item.saveTx(); + await promise; + + assert.include(getRegularTags(), "automatic"); + assert.include(getRegularTags(), "manual"); + + var dialogPromise = waitForDialog(); + var tagSelectorPromise = waitForTagSelector(win); + tagSelector.deleteAutomatic(); + await dialogPromise; + await tagSelectorPromise; + + assert.include(getRegularTags(), 'manual'); + assert.notInclude(getRegularTags(), 'automatic'); + }); + }); })