Remove all colored tags on selected items if 0 is pressed
Like Thunderbird
This commit is contained in:
parent
e64273fb93
commit
c25fbe7c1c
3 changed files with 56 additions and 1 deletions
|
@ -757,6 +757,32 @@ Zotero.Tags = new function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Zotero.Item[]}
|
||||||
|
* @return {Promise}
|
||||||
|
*/
|
||||||
|
this.removeColoredTagsFromItems = async function (items) {
|
||||||
|
return Zotero.DB.executeTransaction(async function () {
|
||||||
|
for (let item of items) {
|
||||||
|
let colors = this.getColors(item.libraryID);
|
||||||
|
let tags = item.getTags();
|
||||||
|
let changed = false;
|
||||||
|
for (let tag of tags) {
|
||||||
|
if (colors.has(tag.tag)) {
|
||||||
|
item.removeTag(tag.tag);
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (changed) {
|
||||||
|
await item.save({
|
||||||
|
skipDateModifiedUpdate: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A tree cell can show only one image, and (as of Fx19) it can't be an SVG,
|
* A tree cell can show only one image, and (as of Fx19) it can't be an SVG,
|
||||||
* so we need to generate a composite image containing the existing item type
|
* so we need to generate a composite image containing the existing item type
|
||||||
|
|
|
@ -148,7 +148,7 @@ Zotero.ItemTreeView.prototype.setTree = async function (treebox) {
|
||||||
// Add a keypress listener for expand/collapse
|
// Add a keypress listener for expand/collapse
|
||||||
var tree = this._getTreeElement();
|
var tree = this._getTreeElement();
|
||||||
var self = this;
|
var self = this;
|
||||||
var coloredTagsRE = new RegExp("^[1-" + Zotero.Tags.MAX_COLORED_TAGS + "]{1}$");
|
var coloredTagsRE = new RegExp("^[0-" + Zotero.Tags.MAX_COLORED_TAGS + "]{1}$");
|
||||||
var listener = function(event) {
|
var listener = function(event) {
|
||||||
if (self._skipKeyPress) {
|
if (self._skipKeyPress) {
|
||||||
self._skipKeyPress = false;
|
self._skipKeyPress = false;
|
||||||
|
@ -199,6 +199,11 @@ Zotero.ItemTreeView.prototype.setTree = async function (treebox) {
|
||||||
if (coloredTagsRE.test(key)) {
|
if (coloredTagsRE.test(key)) {
|
||||||
let libraryID = self.collectionTreeRow.ref.libraryID;
|
let libraryID = self.collectionTreeRow.ref.libraryID;
|
||||||
let position = parseInt(key) - 1;
|
let position = parseInt(key) - 1;
|
||||||
|
// When 0 is pressed, remove all colored tags
|
||||||
|
if (position == -1) {
|
||||||
|
let items = self.getSelectedItems();
|
||||||
|
return Zotero.Tags.removeColoredTagsFromItems(items);
|
||||||
|
}
|
||||||
let colorData = Zotero.Tags.getColorByPosition(libraryID, position);
|
let colorData = Zotero.Tags.getColorByPosition(libraryID, position);
|
||||||
// If a color isn't assigned to this number or any
|
// If a color isn't assigned to this number or any
|
||||||
// other numbers, allow key navigation
|
// other numbers, allow key navigation
|
||||||
|
|
|
@ -198,4 +198,28 @@ describe("Zotero.Tags", function () {
|
||||||
assert.isNull(o);
|
assert.isNull(o);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe("#removeColoredTagsFromItems()", function () {
|
||||||
|
it("shouldn't remove regular tags", async function () {
|
||||||
|
var libraryID = Zotero.Libraries.userLibraryID;
|
||||||
|
var item = await createDataObject('item', {
|
||||||
|
tags: [
|
||||||
|
{ tag: 'A' },
|
||||||
|
{ tag: 'B', type: 1 },
|
||||||
|
{ tag: 'C' },
|
||||||
|
{ tag: 'D', type: 1 }
|
||||||
|
]
|
||||||
|
});
|
||||||
|
await Zotero.Tags.setColor(libraryID, 'C', '#111111', 0);
|
||||||
|
await Zotero.Tags.setColor(libraryID, 'D', '#222222', 1);
|
||||||
|
|
||||||
|
await Zotero.Tags.removeColoredTagsFromItems([item]);
|
||||||
|
|
||||||
|
assert.sameDeepMembers(item.getTags(), [
|
||||||
|
{ tag: 'A' },
|
||||||
|
{ tag: 'B', type: 1 }
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue