Open PDF files over viewAttachment() to reuse its logic (download, etc.)

This commit is contained in:
Martynas Bagdonas 2021-07-22 17:54:33 +03:00
parent 966bee275c
commit a40ac2907e
3 changed files with 20 additions and 7 deletions

View file

@ -551,7 +551,13 @@ class EditorInstance {
this.onNavigate(uri, { position }); this.onNavigate(uri, { position });
} }
else { else {
await Zotero.Reader.openURI(uri, { position }); let zp = Zotero.getActiveZoteroPane();
if (zp) {
let item = await Zotero.URI.getURIItem(uri);
if (item) {
zp.viewPDF(item.id, { position });
}
}
} }
return; return;
} }
@ -567,7 +573,10 @@ class EditorInstance {
} }
let attachments = Zotero.Items.get(item.getAttachments()).filter(x => x.isPDFAttachment()); let attachments = Zotero.Items.get(item.getAttachments()).filter(x => x.isPDFAttachment());
if (citationItem.locator && attachments.length === 1) { if (citationItem.locator && attachments.length === 1) {
await Zotero.Reader.open(attachments[0].id, { pageLabel: citationItem.locator }); let zp = Zotero.getActiveZoteroPane();
if (zp) {
zp.viewPDF(attachments[0].id, { pageLabel: citationItem.locator });
}
} }
else { else {
this._showInLibrary(item.id); this._showInLibrary(item.id);

View file

@ -4175,7 +4175,7 @@ var ZoteroPane = new function()
}); });
this.viewAttachment = Zotero.serial(async function (itemIDs, event, noLocateOnMissing, forceExternalViewer) { this.viewAttachment = Zotero.serial(async function (itemIDs, event, noLocateOnMissing, extraData) {
// If view isn't editable, don't show Locate button, since the updated // If view isn't editable, don't show Locate button, since the updated
// path couldn't be sent back up // path couldn't be sent back up
if (!this.collectionsView.editable) { if (!this.collectionsView.editable) {
@ -4210,7 +4210,11 @@ var ZoteroPane = new function()
// TEMP // TEMP
if (Zotero.isPDFBuild && (library.libraryType == 'user' || Zotero.enablePDFBuildForGroups)) { if (Zotero.isPDFBuild && (library.libraryType == 'user' || Zotero.enablePDFBuildForGroups)) {
let originalEvent = event && event.originalEvent || event; let originalEvent = event && event.originalEvent || event;
this.viewPDF(itemID, originalEvent && originalEvent.shiftKey); await Zotero.Reader.open(
itemID,
extraData && extraData.location,
originalEvent && originalEvent.shiftKey
);
return; return;
} }
let pdfHandler = Zotero.Prefs.get("fileHandler.pdf"); let pdfHandler = Zotero.Prefs.get("fileHandler.pdf");
@ -4378,8 +4382,8 @@ var ZoteroPane = new function()
} }
}); });
this.viewPDF = function (itemID, openWindow) { this.viewPDF = async function (itemID, location) {
Zotero.Reader.open(itemID, null, openWindow); await this.viewAttachment(itemID, null, false, { location });
}; };

@ -1 +1 @@
Subproject commit 24012c75dcf6d7a30c17340b1999c8e106e111bf Subproject commit 0d2f9200260f3c2e72487373e3ad10d7e9d1d6aa