Fix feed item read shortcut, and delay 1 second before marking as read

This allows keyboard navigation without marking all items in between as
read.
This commit is contained in:
Dan Stillman 2017-11-03 04:36:42 -04:00
parent c40e321c4b
commit a3e711b7b5
3 changed files with 58 additions and 50 deletions

View File

@ -321,30 +321,18 @@ var ZoteroItemPane = new function() {
ZoteroItemPane.setTranslateButton(); ZoteroItemPane.setTranslateButton();
}; };
this.setToggleReadLabel = function() { this.setReadLabel = function (isRead) {
var markRead = false;
var items = ZoteroPane_Local.itemsView.getSelectedItems();
for (let item of items) {
if (!item.isRead) {
markRead = true;
break;
}
}
var elem = document.getElementById('zotero-feed-item-toggleRead-button'); var elem = document.getElementById('zotero-feed-item-toggleRead-button');
if (markRead) { var label = Zotero.getString('pane.item.' + (isRead ? 'markAsUnread' : 'markAsRead'));
var label = Zotero.getString('pane.item.markAsRead');
} else {
label = Zotero.getString('pane.item.markAsUnread');
}
elem.setAttribute('label', label); elem.setAttribute('label', label);
var key = Zotero.Keys.getKeyForCommand('toggleRead'); var key = Zotero.Keys.getKeyForCommand('toggleRead');
var tooltip = label + (Zotero.rtl ? ' \u202B' : ' ') + '(' + key + ')' var tooltip = label + (Zotero.rtl ? ' \u202B' : ' ') + '(' + key + ')'
elem.setAttribute('tooltiptext', tooltip); elem.setAttribute('tooltiptext', tooltip);
}; };
function _updateNoteCount() { function _updateNoteCount() {
var c = _notesList.childNodes.length; var c = _notesList.childNodes.length;

View File

@ -185,6 +185,7 @@ Zotero.ItemTreeView.prototype.setTree = async function (treebox) {
} }
event.preventDefault(); event.preventDefault();
event.stopPropagation();
Zotero.spawn(function* () { Zotero.spawn(function* () {
if (coloredTagsRE.test(key)) { if (coloredTagsRE.test(key)) {
@ -711,7 +712,7 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio
} }
else if (collectionTreeRow.isFeed()) { else if (collectionTreeRow.isFeed()) {
this._ownerDocument.defaultView.ZoteroItemPane.setToggleReadLabel(); this._ownerDocument.defaultView.ZoteroPane.updateReadLabel();
} }
// If no quicksearch, process modifications manually // If no quicksearch, process modifications manually

View File

@ -619,6 +619,11 @@ var ZoteroPane = new function()
let row = this.collectionsView.getRow(this.collectionsView.selection.currentIndex); let row = this.collectionsView.getRow(this.collectionsView.selection.currentIndex);
if (!row || !row.isFeed()) return; if (!row || !row.isFeed()) return;
this.toggleSelectedItemsRead(); this.toggleSelectedItemsRead();
if (itemReadPromise) {
itemReadPromise.cancel();
itemReadPromise = null;
}
return;
} }
} }
@ -1503,17 +1508,15 @@ var ZoteroPane = new function()
// if (!item.isTranslated) { // if (!item.isTranslated) {
// item.translate(); // item.translate();
// } // }
item.isRead = true; this.updateReadLabel();
ZoteroItemPane.setToggleReadLabel(); this.startItemReadTimeout(item.id);
yield item.saveTx();
// this.startItemReadTimeout(item.id);
} }
} }
} }
// Zero or multiple items selected // Zero or multiple items selected
else { else {
if (collectionTreeRow.isFeed()) { if (collectionTreeRow.isFeed()) {
ZoteroItemPane.setToggleReadLabel(); this.updateReadLabel();
} }
let count = selectedItems.length; let count = selectedItems.length;
@ -4610,41 +4613,57 @@ var ZoteroPane = new function()
}); });
let itemReadTimeout; this.updateReadLabel = function () {
this.startItemReadTimeout = function(feedItemID) { var items = this.getSelectedItems();
if (itemReadTimeout) { var isUnread = false;
itemReadTimeout.cancel(); for (let item of items) {
itemReadTimeout = null; if (!item.isRead) {
isUnread = true;
break;
}
}
ZoteroItemPane.setReadLabel(!isUnread);
};
var itemReadPromise;
this.startItemReadTimeout = function (feedItemID) {
if (itemReadPromise) {
itemReadPromise.cancel();
} }
let feedItem; const FEED_READ_TIMEOUT = 1000;
itemReadTimeout = Zotero.FeedItems.getAsync(feedItemID)
.then(function(newFeedItem) { itemReadPromise = Zotero.Promise.delay(FEED_READ_TIMEOUT)
if (!newFeedItem) { .then(async function () {
throw new Zotero.Promise.CancellationError('Not a FeedItem'); itemReadPromise = null;
} else if(newFeedItem.isRead) {
throw new Zotero.Promise.CancellationError('FeedItem already read.');
}
feedItem = newFeedItem;
})
.delay(3000)
.then(() => {
itemReadTimeout = null;
// Check to make sure we're still on the same item // Check to make sure we're still on the same item
if (this.itemsView.selection.count !== 1) return; var items = this.getSelectedItems();
if (items.length != 1 || items[0].id != feedItemID) {
Zotero.debug(items.length);
Zotero.debug(items[0].id);
Zotero.debug(feedItemID);
return;
}
var feedItem = items[0];
if (!(feedItem instanceof Zotero.FeedItem)) {
throw new Zotero.Promise.CancellationError('Not a FeedItem');
}
if (feedItem.isRead) {
return;
}
let row = this.itemsView.getRow(this.itemsView.selection.currentIndex); await feedItem.toggleRead(true);
if (!row || !row.ref || !row.ref.id == feedItemID) return; ZoteroItemPane.setReadLabel(true);
}.bind(this))
return feedItem.toggleRead(true); .catch(function (e) {
})
.catch(function(e) {
if (e instanceof Zotero.Promise.CancellationError) { if (e instanceof Zotero.Promise.CancellationError) {
Zotero.debug(e.message); Zotero.debug(e.message);
return; return;
} }
Zotero.logError(e);
Zotero.debug(e, 1);
}); });
} }