Add "Open PDF in New Window" to context menu (#2490)

Also:

* Remove Locate tooltips
This commit is contained in:
Abe Jellinek 2022-04-11 14:53:40 -07:00 committed by GitHub
parent a5fc8b859c
commit 38f5551ee5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 22 deletions

View file

@ -423,7 +423,7 @@
label.classList.add("pointer");
// TODO: make getFieldValue non-private and use below instead
label.setAttribute("onclick", "Zotero.launchURL(this.nextSibling.firstChild ? this.nextSibling.firstChild.nodeValue : this.nextSibling.value)");
label.setAttribute("tooltiptext", Zotero.getString('locate.online.tooltip'));
label.setAttribute("tooltiptext", Zotero.getString('pane.item.viewOnline.tooltip'));
}
else if (fieldName == 'DOI' && val && typeof val == 'string') {
// Pull out DOI, in case there's a prefix
@ -438,7 +438,7 @@
.replace(/"/g, '%22');
label.classList.add("pointer");
label.setAttribute("onclick", "ZoteroPane_Local.loadURI('" + doi + "', event)");
label.setAttribute("tooltiptext", Zotero.getString('locate.online.tooltip'));
label.setAttribute("tooltiptext", Zotero.getString('pane.item.viewOnline.tooltip'));
valueElement.oncontextmenu = () => {
this._id('zotero-doi-menu').openPopup(valueElement);
};

View file

@ -45,7 +45,7 @@ var Zotero_LocateMenu = new function() {
var selectedItems = _getSelectedItems();
if(selectedItems.length) {
_addViewOptions(locateMenu, selectedItems, true, true);
_addViewOptions(locateMenu, selectedItems, true, true, true);
var availableEngines = _getAvailableLocateEngines(selectedItems);
// add engines that are available for selected items
@ -124,7 +124,7 @@ var Zotero_LocateMenu = new function() {
function _addViewOption(selectedItems, optionName, optionObject, showIcons) {
var menuitem = _createMenuItem(Zotero.getString("locate."+optionName+".label"),
null, Zotero.getString("locate."+optionName+".tooltip"));
null, null);
if(showIcons) {
menuitem.setAttribute("class", "menuitem-iconic");
menuitem.style.listStyleImage = "url('"+optionObject.icon+"')";
@ -143,14 +143,17 @@ var Zotero_LocateMenu = new function() {
* @param {Zotero.Item[]} selectedItems The items to create view options based upon
* @param {Boolean} showIcons Whether menu items should have associated icons
* @param {Boolean} addExtraOptions Whether to add options that start with "_" below the separator
* @param {Boolean} isToolbarMenu Whether the menu being populated is displayed in the toolbar
* (and not the item tree context menu)
*/
var _addViewOptions = Zotero.Promise.coroutine(function* (locateMenu, selectedItems, showIcons, addExtraOptions) {
var _addViewOptions = Zotero.Promise.coroutine(function* (locateMenu, selectedItems, showIcons, addExtraOptions, isToolbarMenu) {
var optionsToShow = {};
// check which view options are available
for (let item of selectedItems) {
for(var viewOption in ViewOptions) {
if(!optionsToShow[viewOption]) {
if (!optionsToShow[viewOption]
&& (!isToolbarMenu || !ViewOptions[viewOption].hideInToolbar)) {
optionsToShow[viewOption] = yield ViewOptions[viewOption].canHandleItem(item);
}
}
@ -336,16 +339,23 @@ var Zotero_LocateMenu = new function() {
var ViewOptions = {};
/**
* "View PDF" option
* "Open PDF" option
*
* Should appear only when the item is a PDF, or a linked or attached file or web attachment is
* a PDF
*/
ViewOptions.pdf = new function() {
function ViewPDF(inNewWindow) {
this.icon = "chrome://zotero/skin/treeitem-attachment-pdf.png";
this._mimeTypes = ["application/pdf"];
// Don't show "Open PDF in New Window" in toolbar Locate menu
this.hideInToolbar = inNewWindow;
this.canHandleItem = function (item) {
this.canHandleItem = async function (item) {
// Don't show "Open PDF in New Window" when using an external PDF viewer
if (inNewWindow && Zotero.Prefs.get("fileHandler.pdf")) {
return false;
}
return _getFirstAttachmentWithMIMEType(item, this._mimeTypes).then((item) => !!item);
}
@ -356,7 +366,8 @@ var Zotero_LocateMenu = new function() {
if(attachment) attachments.push(attachment.id);
}
ZoteroPane_Local.viewAttachment(attachments, event);
ZoteroPane_Local.viewAttachment(attachments, event, false,
{ forceOpenPDFInWindow: inNewWindow });
});
var _getFirstAttachmentWithMIMEType = Zotero.Promise.coroutine(function* (item, mimeTypes) {
@ -370,7 +381,10 @@ var Zotero_LocateMenu = new function() {
}
return false;
});
};
}
ViewOptions.pdf = new ViewPDF(false);
ViewOptions.pdfNewWindow = new ViewPDF(true);
/**
* "View Online" option
@ -441,7 +455,7 @@ var Zotero_LocateMenu = new function() {
* "View File" option
*
* Should appear only when an item or a linked or attached file or web attachment does not
* satisfy the conditions for "View PDF" or "View Snapshot"
* satisfy the conditions for "Open PDF" or "View Snapshot"
*/
ViewOptions.file = new function() {
this.icon = "chrome://zotero/skin/treeitem-attachment-file.png";

View file

@ -4261,7 +4261,10 @@ var ZoteroPane = new function()
await Zotero.Reader.open(
itemID,
extraData && extraData.location,
{ openInWindow: event && event.shiftKey }
{
openInWindow: (event && event.shiftKey)
|| (extraData && extraData.forceOpenPDFInWindow)
}
);
return;
}

View file

@ -431,6 +431,7 @@ pane.item.related.count.zero = %S related:
pane.item.related.count.singular = %S related:
pane.item.related.count.plural = %S related:
pane.item.parentItem = Parent Item:
pane.item.viewOnline.tooltip = Go to this item online
pane.context.noParent = No parent item
pane.context.itemNotes = Item Notes
@ -1208,21 +1209,14 @@ lookup.failureTooMany.description = Too many identifiers. Please enter one ident
createParent.prompt = Enter a DOI, ISBN, PMID, arXiv ID, or ADS Bibcode to identify this file
locate.online.label = View Online
locate.online.tooltip = Go to this item online
locate.pdf.label = View PDF
locate.pdf.tooltip = Open PDF using the selected viewer
locate.pdf.label = Open PDF
locate.pdfNewWindow.label = Open PDF in New Window
locate.snapshot.label = View Snapshot
locate.snapshot.tooltip = View and annotate the snapshot for this item
locate.file.label = View File
locate.file.tooltip = Open file using the selected viewer
locate.externalViewer.label = Open in External Viewer
locate.externalViewer.tooltip = Open file in another application
locate.internalViewer.label = Open in Internal Viewer
locate.internalViewer.tooltip = Open file in this application
locate.showFile.label = Show File
locate.showFile.tooltip = Open the directory in which this file resides
locate.libraryLookup.label = Library Lookup
locate.libraryLookup.tooltip = Look up this item using the selected OpenURL resolver
locate.manageLocateEngines = Manage Lookup Engines…
locate.locateEngineDescription = Lookup engines help you find resources in your %S library on the web. Engines enabled in this list appear in the Locate drop-down in the toolbar.