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:
parent
c40e321c4b
commit
a3e711b7b5
3 changed files with 58 additions and 50 deletions
|
@ -321,30 +321,18 @@ var ZoteroItemPane = new function() {
|
|||
ZoteroItemPane.setTranslateButton();
|
||||
};
|
||||
|
||||
|
||||
this.setToggleReadLabel = function() {
|
||||
var markRead = false;
|
||||
var items = ZoteroPane_Local.itemsView.getSelectedItems();
|
||||
for (let item of items) {
|
||||
if (!item.isRead) {
|
||||
markRead = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.setReadLabel = function (isRead) {
|
||||
var elem = document.getElementById('zotero-feed-item-toggleRead-button');
|
||||
if (markRead) {
|
||||
var label = Zotero.getString('pane.item.markAsRead');
|
||||
} else {
|
||||
label = Zotero.getString('pane.item.markAsUnread');
|
||||
}
|
||||
var label = Zotero.getString('pane.item.' + (isRead ? 'markAsUnread' : 'markAsRead'));
|
||||
elem.setAttribute('label', label);
|
||||
|
||||
var key = Zotero.Keys.getKeyForCommand('toggleRead');
|
||||
var tooltip = label + (Zotero.rtl ? ' \u202B' : ' ') + '(' + key + ')'
|
||||
elem.setAttribute('tooltiptext', tooltip);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
function _updateNoteCount() {
|
||||
var c = _notesList.childNodes.length;
|
||||
|
||||
|
|
|
@ -185,6 +185,7 @@ Zotero.ItemTreeView.prototype.setTree = async function (treebox) {
|
|||
}
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
Zotero.spawn(function* () {
|
||||
if (coloredTagsRE.test(key)) {
|
||||
|
@ -711,7 +712,7 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio
|
|||
}
|
||||
|
||||
else if (collectionTreeRow.isFeed()) {
|
||||
this._ownerDocument.defaultView.ZoteroItemPane.setToggleReadLabel();
|
||||
this._ownerDocument.defaultView.ZoteroPane.updateReadLabel();
|
||||
}
|
||||
|
||||
// If no quicksearch, process modifications manually
|
||||
|
|
|
@ -619,6 +619,11 @@ var ZoteroPane = new function()
|
|||
let row = this.collectionsView.getRow(this.collectionsView.selection.currentIndex);
|
||||
if (!row || !row.isFeed()) return;
|
||||
this.toggleSelectedItemsRead();
|
||||
if (itemReadPromise) {
|
||||
itemReadPromise.cancel();
|
||||
itemReadPromise = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1503,17 +1508,15 @@ var ZoteroPane = new function()
|
|||
// if (!item.isTranslated) {
|
||||
// item.translate();
|
||||
// }
|
||||
item.isRead = true;
|
||||
ZoteroItemPane.setToggleReadLabel();
|
||||
yield item.saveTx();
|
||||
// this.startItemReadTimeout(item.id);
|
||||
this.updateReadLabel();
|
||||
this.startItemReadTimeout(item.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Zero or multiple items selected
|
||||
else {
|
||||
if (collectionTreeRow.isFeed()) {
|
||||
ZoteroItemPane.setToggleReadLabel();
|
||||
this.updateReadLabel();
|
||||
}
|
||||
|
||||
let count = selectedItems.length;
|
||||
|
@ -4610,41 +4613,57 @@ var ZoteroPane = new function()
|
|||
});
|
||||
|
||||
|
||||
let itemReadTimeout;
|
||||
this.startItemReadTimeout = function(feedItemID) {
|
||||
if (itemReadTimeout) {
|
||||
itemReadTimeout.cancel();
|
||||
itemReadTimeout = null;
|
||||
this.updateReadLabel = function () {
|
||||
var items = this.getSelectedItems();
|
||||
var isUnread = false;
|
||||
for (let item of items) {
|
||||
if (!item.isRead) {
|
||||
isUnread = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ZoteroItemPane.setReadLabel(!isUnread);
|
||||
};
|
||||
|
||||
|
||||
var itemReadPromise;
|
||||
this.startItemReadTimeout = function (feedItemID) {
|
||||
if (itemReadPromise) {
|
||||
itemReadPromise.cancel();
|
||||
}
|
||||
|
||||
let feedItem;
|
||||
itemReadTimeout = Zotero.FeedItems.getAsync(feedItemID)
|
||||
.then(function(newFeedItem) {
|
||||
if (!newFeedItem) {
|
||||
throw new Zotero.Promise.CancellationError('Not a FeedItem');
|
||||
} else if(newFeedItem.isRead) {
|
||||
throw new Zotero.Promise.CancellationError('FeedItem already read.');
|
||||
}
|
||||
feedItem = newFeedItem;
|
||||
})
|
||||
.delay(3000)
|
||||
.then(() => {
|
||||
itemReadTimeout = null;
|
||||
const FEED_READ_TIMEOUT = 1000;
|
||||
|
||||
itemReadPromise = Zotero.Promise.delay(FEED_READ_TIMEOUT)
|
||||
.then(async function () {
|
||||
itemReadPromise = null;
|
||||
|
||||
// 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);
|
||||
if (!row || !row.ref || !row.ref.id == feedItemID) return;
|
||||
|
||||
return feedItem.toggleRead(true);
|
||||
})
|
||||
.catch(function(e) {
|
||||
await feedItem.toggleRead(true);
|
||||
ZoteroItemPane.setReadLabel(true);
|
||||
}.bind(this))
|
||||
.catch(function (e) {
|
||||
if (e instanceof Zotero.Promise.CancellationError) {
|
||||
Zotero.debug(e.message);
|
||||
return;
|
||||
}
|
||||
|
||||
Zotero.debug(e, 1);
|
||||
Zotero.logError(e);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue