"Hide/Keep items with tag" context menus

This commit is contained in:
Bogdan Abaev 2025-03-24 13:05:20 -07:00
parent 7aa4fd24b4
commit 0f29a981e3
3 changed files with 31 additions and 8 deletions

View file

@ -583,8 +583,12 @@ Zotero.TagSelector = class TagSelectorContainer extends React.PureComponent {
true
);
this.contextTag = tag;
// Disable "Exclude tag" for disabled tags
// Disable options for disabled tags, mark if the tag is included vs excluded
let tagSelected = this.selectedTags.get(this.contextTag.name);
tagContextMenu.querySelector("#tag-menu-exclude-tag").disabled = tag.disabled;
tagContextMenu.querySelector("#tag-menu-exclude-tag").setAttribute("checked", tagSelected?.excluded);
tagContextMenu.querySelector("#tag-menu-include-tag").disabled = tag.disabled;
tagContextMenu.querySelector("#tag-menu-include-tag").setAttribute("checked", tagSelected && !tagSelected.excluded);
}
handleSettings = (ev) => {
@ -595,9 +599,17 @@ Zotero.TagSelector = class TagSelectorContainer extends React.PureComponent {
handleTagSelected = (tag) => {
let selectedTags = this.selectedTags;
if(selectedTags.has(tag)) {
let viaClick = true;
if (!tag) {
tag = this.contextTag.name;
viaClick = false;
}
// remove tag from selection on click or on context-menu selection if it is not excluded
if (selectedTags.has(tag) && (viaClick || !selectedTags.get(tag).excluded)) {
selectedTags.delete(tag);
} else {
}
// otherwise, select the tag
else {
selectedTags.set(tag, {});
}
@ -809,8 +821,14 @@ Zotero.TagSelector = class TagSelectorContainer extends React.PureComponent {
if (!tag) {
tag = this.contextTag.name;
}
this.selectedTags.set(tag, { excluded: true })
if (typeof(this.props.onSelection) === 'function') {
// If the tag is already excluded - remove it from selection
if (this.selectedTags.get(tag)?.excluded) {
this.selectedTags.delete(tag);
}
else {
this.selectedTags.set(tag, { excluded: true });
}
if (typeof (this.props.onSelection) === 'function') {
this.props.onSelection(this.selectedTags);
}
}

View file

@ -1017,6 +1017,11 @@
<!-- Tag Selector -->
<menupopup id="tag-menu">
<menuitem id="tag-menu-include-tag" data-l10n-id="tagselector-include-tag"
oncommand="ZoteroPane.tagSelector.handleTagSelected(); event.stopPropagation();"/>
<menuitem id="tag-menu-exclude-tag" data-l10n-id="tagselector-exclude-tag"
oncommand="ZoteroPane.tagSelector.excludeTag(); event.stopPropagation();"/>
<menuseparator/>
<menuitem label="&zotero.tagSelector.assignColor;"
oncommand="ZoteroPane.tagSelector.openColorPickerWindow(); event.stopPropagation();"/>
<menuitem label="&zotero.tagSelector.renameTag;"
@ -1026,8 +1031,6 @@
<menuitem label="&zotero.tagSelector.deleteTag;"
oncommand="ZoteroPane.tagSelector.openDeletePrompt(); event.stopPropagation();"/>
<menuseparator/>
<menuitem id="tag-menu-exclude-tag" data-l10n-id="tagselector-exclude-tag"
oncommand="ZoteroPane.tagSelector.excludeTag(); event.stopPropagation();"/>
</menupopup>
<menupopup id="tag-selector-view-settings-menu"
onpopupshowing="

View file

@ -542,7 +542,9 @@ tag-field =
tagselector-search =
.placeholder = Filter Tags
tagselector-exclude-tag =
.label = Exclude tag
.label = Hide Items with Tag
tagselector-include-tag =
.label = Keep Items with Tag
tag-excluded =
.aria-description = This tag is excluded from item's list.