Add "Open PDF reader in new window" preference (#2868)
When enabled: - Double-clicking a PDF or choosing "Open PDF" opens a new window - Shift-double-clicking opens a new tab - "Open in New Window" locate option becomes "Open in New Tab" and has the reverse behavior
This commit is contained in:
parent
b6591dba5a
commit
a7b605f0cc
7 changed files with 60 additions and 30 deletions
|
@ -123,17 +123,17 @@ var Zotero_LocateMenu = new function() {
|
|||
});
|
||||
|
||||
function _addViewOption(selectedItems, optionName, optionObject, showIcons) {
|
||||
var menuitem = _createMenuItem(Zotero.getString("locate."+optionName+".label"),
|
||||
var menuitem = _createMenuItem(optionObject.label || Zotero.getString(`locate.${optionName}.label`),
|
||||
null, null);
|
||||
if(showIcons) {
|
||||
if (showIcons) {
|
||||
menuitem.setAttribute("class", "menuitem-iconic");
|
||||
menuitem.style.listStyleImage = "url('"+optionObject.icon+"')";
|
||||
menuitem.style.listStyleImage = `url('${optionObject.icon}')`;
|
||||
}
|
||||
menuitem.setAttribute("zotero-locate", "true");
|
||||
|
||||
menuitem.addEventListener("command", function(event) {
|
||||
menuitem.addEventListener("command", function (event) {
|
||||
optionObject.handleItems(selectedItems, event);
|
||||
}, false)
|
||||
}, false);
|
||||
return menuitem;
|
||||
}
|
||||
|
||||
|
@ -344,16 +344,30 @@ var Zotero_LocateMenu = new function() {
|
|||
* Should appear only when the item is a PDF, or a linked or attached file or web attachment is
|
||||
* a PDF
|
||||
*/
|
||||
function ViewPDF(inNewWindow) {
|
||||
function ViewPDF(alternateWindowBehavior) {
|
||||
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;
|
||||
// Don't show alternate-behavior option ("in New Window" when openReaderInNewWindow is false,
|
||||
// "in New Tab" when it's true) in toolbar Locate menu
|
||||
this.hideInToolbar = alternateWindowBehavior;
|
||||
|
||||
Object.defineProperty(this, 'label', {
|
||||
get() {
|
||||
if (alternateWindowBehavior) {
|
||||
return Zotero.getString(Zotero.Prefs.get('openReaderInNewWindow')
|
||||
? 'locate.pdfNewTab.label'
|
||||
: 'locate.pdfNewWindow.label');
|
||||
}
|
||||
else {
|
||||
return Zotero.getString('locate.pdf.label');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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")) {
|
||||
// Don't show alternate-behavior option when using an external PDF viewer
|
||||
if (alternateWindowBehavior && Zotero.Prefs.get("fileHandler.pdf")) {
|
||||
return false;
|
||||
}
|
||||
return _getFirstAttachmentWithMIMEType(item, this._mimeTypes).then((item) => !!item);
|
||||
|
@ -367,7 +381,7 @@ var Zotero_LocateMenu = new function() {
|
|||
}
|
||||
|
||||
ZoteroPane_Local.viewAttachment(attachments, event, false,
|
||||
{ forceOpenPDFInWindow: inNewWindow });
|
||||
{ forceAlternateWindowBehavior: alternateWindowBehavior });
|
||||
});
|
||||
|
||||
var _getFirstAttachmentWithMIMEType = Zotero.Promise.coroutine(function* (item, mimeTypes) {
|
||||
|
@ -384,7 +398,7 @@ var Zotero_LocateMenu = new function() {
|
|||
}
|
||||
|
||||
ViewOptions.pdf = new ViewPDF(false);
|
||||
ViewOptions.pdfNewWindow = new ViewPDF(true);
|
||||
ViewOptions.pdfAlternateWindowBehavior = new ViewPDF(true);
|
||||
|
||||
/**
|
||||
* "View Online" option
|
||||
|
|
|
@ -170,11 +170,13 @@ Zotero_Preferences.General = {
|
|||
var handler = Zotero.Prefs.get('fileHandler.pdf');
|
||||
var menulist = document.getElementById('fileHandler-pdf');
|
||||
var customMenuItem = document.getElementById('fileHandler-custom');
|
||||
var inNewWindowCheckbox = document.getElementById('open-reader-in-new-window');
|
||||
|
||||
// System default
|
||||
if (handler == 'system') {
|
||||
customMenuItem.hidden = true;
|
||||
menulist.selectedIndex = 1;
|
||||
inNewWindowCheckbox.disabled = true;
|
||||
}
|
||||
// Custom handler
|
||||
else if (handler) {
|
||||
|
@ -201,6 +203,7 @@ Zotero_Preferences.General = {
|
|||
}
|
||||
customMenuItem.hidden = false;
|
||||
menulist.selectedIndex = 2;
|
||||
inNewWindowCheckbox.disabled = true;
|
||||
|
||||
// There's almost certainly a better way to do this...
|
||||
// but why doesn't the icon just behave by default?
|
||||
|
@ -211,6 +214,7 @@ Zotero_Preferences.General = {
|
|||
let menuitem = document.getElementById('fileHandler-internal');
|
||||
menulist.selectedIndex = 0;
|
||||
customMenuItem.hidden = true;
|
||||
inNewWindowCheckbox.disabled = false;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -55,20 +55,26 @@
|
|||
oncommand="Zotero_Preferences.General.updateAutoRenameFilesUI()" native="true"/>
|
||||
</vbox>
|
||||
|
||||
<hbox align="center">
|
||||
<label value="&zotero.preferences.fileHandler.openPDFsUsing;" control="file-handler-pdf"/>
|
||||
<menulist id="fileHandler-pdf" class="fileHandler-menu" native="true">
|
||||
<menupopup>
|
||||
<menuitem id="fileHandler-internal"
|
||||
oncommand="Zotero_Preferences.General.setFileHandler('pdf', '')"/>
|
||||
<menuitem label="&zotero.preferences.fileHandler.systemDefault;"
|
||||
oncommand="Zotero_Preferences.General.setFileHandler('pdf', 'system')"/>
|
||||
<menuitem id="fileHandler-custom"/>
|
||||
<menuitem label="&zotero.preferences.custom;"
|
||||
oncommand="Zotero_Preferences.General.chooseFileHandler('pdf')"/>
|
||||
</menupopup>
|
||||
</menulist>
|
||||
</hbox>
|
||||
<vbox>
|
||||
<hbox align="center">
|
||||
<label value="&zotero.preferences.fileHandler.openPDFsUsing;" control="file-handler-pdf"/>
|
||||
<menulist id="fileHandler-pdf" class="fileHandler-menu" native="true">
|
||||
<menupopup>
|
||||
<menuitem id="fileHandler-internal"
|
||||
oncommand="Zotero_Preferences.General.setFileHandler('pdf', '')"/>
|
||||
<menuitem label="&zotero.preferences.fileHandler.systemDefault;"
|
||||
oncommand="Zotero_Preferences.General.setFileHandler('pdf', 'system')"/>
|
||||
<menuitem id="fileHandler-custom"/>
|
||||
<menuitem label="&zotero.preferences.custom;"
|
||||
oncommand="Zotero_Preferences.General.chooseFileHandler('pdf')"/>
|
||||
</menupopup>
|
||||
</menulist>
|
||||
</hbox>
|
||||
<checkbox id="open-reader-in-new-window" class="indented-pref"
|
||||
label="&zotero.preferences.fileHandler.openReaderInNewWindow;"
|
||||
preference="extensions.zotero.openReaderInNewWindow"
|
||||
native="true"/>
|
||||
</vbox>
|
||||
</groupbox>
|
||||
|
||||
<groupbox>
|
||||
|
|
|
@ -4446,13 +4446,17 @@ var ZoteroPane = new function()
|
|||
let pdfHandler = Zotero.Prefs.get("fileHandler.pdf");
|
||||
// Zotero PDF reader
|
||||
if (!pdfHandler) {
|
||||
let openInWindow = Zotero.Prefs.get('openReaderInNewWindow');
|
||||
let useAlternateWindowBehavior = event?.shiftKey || extraData?.forceAlternateWindowBehavior;
|
||||
if (useAlternateWindowBehavior) {
|
||||
openInWindow = !openInWindow;
|
||||
}
|
||||
await Zotero.Reader.open(
|
||||
itemID,
|
||||
extraData && extraData.location,
|
||||
{
|
||||
openInWindow: (event && event.shiftKey)
|
||||
|| (extraData && extraData.forceOpenPDFInWindow),
|
||||
allowDuplicate: event && event.shiftKey
|
||||
openInWindow,
|
||||
allowDuplicate: openInWindow
|
||||
}
|
||||
);
|
||||
return;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
<!ENTITY zotero.preferences.autoRenameFiles.renameLinked "Rename linked files">
|
||||
<!ENTITY zotero.preferences.fileHandler.openPDFsUsing "Open PDFs using">
|
||||
<!ENTITY zotero.preferences.fileHandler.systemDefault "System Default">
|
||||
<!ENTITY zotero.preferences.fileHandler.openReaderInNewWindow "Open PDFs in new windows instead of tabs">
|
||||
|
||||
<!ENTITY zotero.preferences.miscellaneous "Miscellaneous">
|
||||
<!ENTITY zotero.preferences.autoUpdate "Automatically check for updated translators and styles">
|
||||
|
|
|
@ -1220,6 +1220,7 @@ createParent.prompt = Enter a DOI, ISBN, PMID, arXiv ID, or ADS Bibcode to i
|
|||
locate.online.label = View Online
|
||||
locate.pdf.label = Open PDF
|
||||
locate.pdfNewWindow.label = Open PDF in New Window
|
||||
locate.pdfNewTab.label = Open PDF in New Tab
|
||||
locate.snapshot.label = View Snapshot
|
||||
locate.file.label = View File
|
||||
locate.externalViewer.label = Open in External Viewer
|
||||
|
|
|
@ -184,8 +184,8 @@ pref("extensions.zotero.purge.tags", false);
|
|||
// Zotero pane persistent data
|
||||
pref("extensions.zotero.pane.persist", "");
|
||||
|
||||
// Custom file handlers
|
||||
pref("extensions.zotero.fileHandler.pdf", "");
|
||||
pref("extensions.zotero.openReaderInNewWindow", false);
|
||||
|
||||
// File/URL opening executable if launch() fails
|
||||
pref("extensions.zotero.fallbackLauncher.unix", "/usr/bin/xdg-open");
|
||||
|
|
Loading…
Reference in a new issue