Fixes to hasAttachments column
- Fix #1121, sorting of hasAttachments column -- doesn't work if hasAttachments is the active sort column on startup, since file states have to be cached, but works for subsequent clicks on the column - Don't sort linked URL attachments as missing - Use hiDPI icon in all cases
This commit is contained in:
parent
d70ebce108
commit
c6a2057340
|
@ -1116,6 +1116,7 @@ Zotero.ItemTreeView.prototype.getImageSrc = function(row, col)
|
||||||
}
|
}
|
||||||
|
|
||||||
var itemID = item.id;
|
var itemID = item.id;
|
||||||
|
let suffix = Zotero.hiDPISuffix;
|
||||||
|
|
||||||
if (treerow.level === 0) {
|
if (treerow.level === 0) {
|
||||||
if (item.isRegularItem()) {
|
if (item.isRegularItem()) {
|
||||||
|
@ -1123,10 +1124,10 @@ Zotero.ItemTreeView.prototype.getImageSrc = function(row, col)
|
||||||
if (state !== null) {
|
if (state !== null) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case 1:
|
case 1:
|
||||||
return "chrome://zotero/skin/bullet_blue.png";
|
return `chrome://zotero/skin/bullet_blue${suffix}.png`;
|
||||||
|
|
||||||
case -1:
|
case -1:
|
||||||
return "chrome://zotero/skin/bullet_blue_empty.png";
|
return `chrome://zotero/skin/bullet_blue_empty${suffix}.png`;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return "";
|
return "";
|
||||||
|
@ -1145,7 +1146,6 @@ Zotero.ItemTreeView.prototype.getImageSrc = function(row, col)
|
||||||
if (item.isFileAttachment()) {
|
if (item.isFileAttachment()) {
|
||||||
let exists = item.fileExistsCached();
|
let exists = item.fileExistsCached();
|
||||||
if (exists !== null) {
|
if (exists !== null) {
|
||||||
let suffix = Zotero.hiDPISuffix;
|
|
||||||
return exists
|
return exists
|
||||||
? `chrome://zotero/skin/bullet_blue${suffix}.png`
|
? `chrome://zotero/skin/bullet_blue${suffix}.png`
|
||||||
: `chrome://zotero/skin/bullet_blue_empty${suffix}.png`;
|
: `chrome://zotero/skin/bullet_blue_empty${suffix}.png`;
|
||||||
|
@ -1310,10 +1310,24 @@ Zotero.ItemTreeView.prototype.isSorted = function()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.ItemTreeView.prototype.cycleHeader = function (column) {
|
Zotero.ItemTreeView.prototype.cycleHeader = Zotero.Promise.coroutine(function* (column) {
|
||||||
if (this.collectionTreeRow.isFeed()) {
|
if (this.collectionTreeRow.isFeed()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (column.id == 'zotero-items-column-hasAttachment') {
|
||||||
|
Zotero.debug("Caching best attachment states");
|
||||||
|
if (!this._cachedBestAttachmentStates) {
|
||||||
|
let t = new Date();
|
||||||
|
for (let i = 0; i < this._rows.length; i++) {
|
||||||
|
let item = this.getRow(i).ref;
|
||||||
|
if (item.isRegularItem()) {
|
||||||
|
yield item.getBestAttachmentState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Zotero.debug("Cached best attachment states in " + (new Date - t) + " ms");
|
||||||
|
this._cachedBestAttachmentStates = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
for(var i=0, len=this._treebox.columns.count; i<len; i++)
|
for(var i=0, len=this._treebox.columns.count; i<len; i++)
|
||||||
{
|
{
|
||||||
col = this._treebox.columns.getColumnAt(i);
|
col = this._treebox.columns.getColumnAt(i);
|
||||||
|
@ -1353,7 +1367,7 @@ Zotero.ItemTreeView.prototype.cycleHeader = function (column) {
|
||||||
}
|
}
|
||||||
this._treebox.invalidate();
|
this._treebox.invalidate();
|
||||||
this.selection.selectEventsSuppressed = false;
|
this.selection.selectEventsSuppressed = false;
|
||||||
}
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sort the items by the currently sorted column.
|
* Sort the items by the currently sorted column.
|
||||||
|
@ -1416,20 +1430,23 @@ Zotero.ItemTreeView.prototype.sort = function (itemID) {
|
||||||
return Zotero.Items.getSortTitle(item.getDisplayTitle());
|
return Zotero.Items.getSortTitle(item.getDisplayTitle());
|
||||||
|
|
||||||
case 'hasAttachment':
|
case 'hasAttachment':
|
||||||
if (item.isAttachment()) {
|
if (item.isFileAttachment()) {
|
||||||
var state = item.fileExistsCached() ? 1 : -1;
|
var state = item.fileExistsCached() ? 1 : -1;
|
||||||
}
|
}
|
||||||
else if (item.isRegularItem()) {
|
else if (item.isRegularItem()) {
|
||||||
var state = item.getBestAttachmentState();
|
var state = item.getBestAttachmentStateCached();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// Make sort order present, missing, empty when ascending
|
// Make sort order present, missing, empty when ascending
|
||||||
if (state === -1) {
|
if (state === 1) {
|
||||||
state = 2;
|
state = 2;
|
||||||
}
|
}
|
||||||
return state * -1;
|
else if (state === -1) {
|
||||||
|
state = 1;
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
|
||||||
case 'numNotes':
|
case 'numNotes':
|
||||||
return row.numNotes(false, true) || 0;
|
return row.numNotes(false, true) || 0;
|
||||||
|
@ -1492,6 +1509,10 @@ Zotero.ItemTreeView.prototype.sort = function (itemID) {
|
||||||
if(fieldA !== '' && fieldB === '') return -1;
|
if(fieldA !== '' && fieldB === '') return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sortField == 'hasAttachment') {
|
||||||
|
return fieldB - fieldA;
|
||||||
|
}
|
||||||
|
|
||||||
return collation.compareString(1, fieldA, fieldB);
|
return collation.compareString(1, fieldA, fieldB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user