Tweaks to trash functionality for collections and searches

- Use SVG icons
- Show "[x] collection selected" or "[x] searches selected" in the item pane
- Show "[x] objects selected" if multiple types are selected, which I
  don't love, but I don't have a better idea
- Use existing strings for ARIA labels
This commit is contained in:
Dan Stillman 2024-05-13 07:07:12 -04:00
parent 6f53cf2f68
commit c537d1ad28
6 changed files with 64 additions and 29 deletions

View file

@ -222,19 +222,30 @@
// Display label in the middle of the item pane
else {
if (count) {
if (count == 1) {
let item = this.data[0];
// If a collection or search is selected, it must be in the trash.
if (item.isCollection()) {
let subcollectionsCount = item.getDescendents(false, 'collection', true).length;
msg = Zotero.getString('pane.collections.deletedCollection', subcollectionsCount);
let key;
// In the trash, we have to check the object type
if (this.collectionTreeRow.isTrash()) {
let obj = this.data[0];
if (this.data.every(x => x.isCollection())) {
key = 'item-pane-message-collections-selected';
}
else if (item.isSearch()) {
msg = Zotero.getString('pane.collections.deletedSearch');
else if (this.data.every(x => x.isSearch())) {
key = 'item-pane-message-searches-selected';
}
else if (this.data.every(x => x.isItem())) {
key = 'item-pane-message-items-selected';
}
else {
key = 'item-pane-message-objects-selected';
}
}
msg = Zotero.getString('pane.item.selected.multiple', count);
else {
key = 'item-pane-message-items-selected';
}
// TODO: Add mechanism for this to setItemPaneMessage()
let elem = document.createXULElement('description');
document.l10n.setAttributes(elem, key, { count });
msg = elem;
}
else {
let rowCount = this.itemsView.rowCount;

View file

@ -2813,10 +2813,13 @@ var ItemTree = class ItemTree extends LibraryTree {
let itemTypeAriaLabel;
try {
if (item.isSearch() || item.isCollection()) {
// Special treatment for trashed collections or searches since they are not an actual
// item and do not have an item type
itemTypeAriaLabel = Zotero.getString(`pane.collections.deleted${item._ObjectType}Aria`) + '.';
// Special treatment for trashed collections or searches since they are not an actual
// item and do not have an item type
if (item.isSearch()) {
itemTypeAriaLabel = Zotero.getString('searchConditions.collection') + '.';
}
else if (item.isCollection()) {
itemTypeAriaLabel = Zotero.getString('searchConditions.savedSearch') + '.';
}
else {
var itemType = Zotero.ItemTypes.getName(item.itemTypeID);
@ -3823,20 +3826,16 @@ var ItemTree = class ItemTree extends LibraryTree {
_getIcon(index) {
var item = this.getRow(index).ref;
// TEMP
// Non-item objects that can be appear in the trash
if (item.isCollection() || item.isSearch()) {
let iconClsName;
let icon;
if (item.isCollection()) {
iconClsName = "IconTreeitemCollection";
icon = getCSSIcon('collection');
}
if (item.isSearch()) {
iconClsName = "IconTreeitemSearch";
}
var icon = getDOMElement(iconClsName);
if (!icon) {
Zotero.debug('Could not find tree icon for "' + itemType + '"');
return document.createElement('span');
else if (item.isSearch()) {
icon = getCSSIcon('search');
}
icon.classList.add('icon-item-type');
return icon;
}

View file

@ -691,7 +691,7 @@ Zotero.Collection.prototype.trash = Zotero.Promise.coroutine(function* (env) {
});
/**
* Completely erases the collection and it's descendants.
* Completely erase the collection and its descendants.
**/
Zotero.Collection.prototype._eraseData = Zotero.Promise.coroutine(function* (env) {
Zotero.DB.requireTransaction();

View file

@ -509,3 +509,20 @@ item-pane-header-bibEntry =
.label = Bibliography Entry
item-pane-header-more-options =
.label = More Options
item-pane-message-items-selected = { $count ->
[one] { $count } item selected
*[other] { $count } items selected
}
item-pane-message-collections-selected = { $count ->
[one] { $count } collection selected
*[other] { $count } collections selected
}
item-pane-message-searches-selected = { $count ->
[one] { $count } search selected
*[other] { $count } searches selected
}
item-pane-message-objects-selected = { $count ->
[one] { $count } object selected
*[other] { $count } objects selected
}

View file

@ -276,10 +276,6 @@ pane.collections.retracted = Retracted Items
pane.collections.duplicate = Duplicate Items
pane.collections.removeLibrary = Remove Library
pane.collections.removeLibrary.text = Are you sure you want to permanently remove “%S” from this computer?
pane.collections.deletedCollection = Deleted collection with %1$S subcollections
pane.collections.deletedCollectionAria = Deleted collection
pane.collections.deletedSearch = Deleted search
pane.collections.deletedSearchAria = Deleted search
pane.collections.menu.duplicate.savedSearch = Duplicate Saved Search
pane.collections.menu.remove.library = Remove Library…

View file

@ -270,6 +270,12 @@ $-attachmentIcons: (
attachment-video
);
// Non-item objects that can appear in the trash
$-trashableObjectIcons: (
"collection",
"search"
);
.icon-item-type {
width: 16px;
height: 16px;
@ -320,5 +326,11 @@ $-attachmentIcons: (
background-origin: content-box;
}
}
@each $icon in $-trashableObjectIcons {
.icon-css.icon-#{$icon} {
@include svgicon($icon, $color, "16", "collection-tree");
}
}
}
}