Add temporary prefs checkbox to use internal PDF reader

And use when opening PDFs in My Library from items list and
zotero://open-pdf

This also adds "Zotero" to the main PDF reader pref, which will be the
real way to set this, but that option is hidden for now so that group
library items will still open with the configured reader.
This commit is contained in:
Dan Stillman 2021-02-10 03:24:42 -05:00
parent 04c64fe9fc
commit f0816cc8fb
7 changed files with 64 additions and 7 deletions

View file

@ -38,6 +38,8 @@ Zotero_Preferences.General = {
'zotero.preferences.launchNonNativeFiles', Zotero.appName
);
}
var menuitem = document.getElementById('fileHandler-internal');
menuitem.setAttribute('label', Zotero.appName);
this.updateAutoRenameFilesUI();
this._updateFileHandlerUI();
@ -88,6 +90,16 @@ Zotero_Preferences.General = {
var handler = Zotero.Prefs.get('fileHandler.pdf');
var menulist = document.getElementById('fileHandler-pdf');
var customMenuItem = document.getElementById('fileHandler-custom');
// TEMP: Use separate checkbox for now
/*if (handler == 'zotero') {
let menuitem = document.getElementById('fileHandler-internal');
menulist.selectedIndex = 0;
customMenuItem.hidden = true;
return;
}*/
// Custom handler
if (handler) {
let icon;
try {
@ -113,11 +125,12 @@ Zotero_Preferences.General = {
customMenuItem.className = '';
}
customMenuItem.hidden = false;
menulist.selectedIndex = 0;
menulist.selectedIndex = 1;
}
// System default
else {
customMenuItem.hidden = true;
menulist.selectedIndex = 1;
menulist.selectedIndex = 2;
}
},

View file

@ -45,6 +45,7 @@
<preference id="pref-groups-copyChildLinks" name="extensions.zotero.groups.copyChildLinks" type="bool"/>
<preference id="pref-groups-copyTags" name="extensions.zotero.groups.copyTags" type="bool"/>
<preference id="pref-useInternalPDFReader" name="extensions.zotero.beta.useInternalPDFReader" type="bool"/>
</preferences>
<groupbox id="zotero-prefpane-file-handling-groupbox">
@ -67,6 +68,9 @@
<label value="&zotero.preferences.fileHandler.openPDFsUsing;" control="file-handler-pdf"/>
<menulist id="fileHandler-pdf" class="fileHandler-menu">
<menupopup>
<menuitem id="fileHandler-internal"
oncommand="Zotero_Preferences.General.setFileHandler('pdf', 'zotero')"
hidden="true"/>
<menuitem id="fileHandler-custom"/>
<menuitem label="&zotero.preferences.fileHandler.systemDefault;"
oncommand="Zotero_Preferences.General.setFileHandler('pdf', false)"/>
@ -75,6 +79,9 @@
</menupopup>
</menulist>
</hbox>
<checkbox
label="Use Zotero PDF reader for My Library (beta)"
preference="pref-useInternalPDFReader"/>
</groupbox>
<groupbox id="zotero-prefpane-miscellaneous-groupbox">

View file

@ -26,7 +26,34 @@
/* eslint-disable array-element-newline */
Zotero.OpenPDF = {
openToPage: async function (path, page) {
openToPage: async function (pathOrItem, page) {
var path;
if (pathOrItem == 'string') {
Zotero.logError("Zotero.OpenPDF.openToPage() now takes a Zotero.Item rather than a path "
+ "-- please update your code");
path = pathOrItem;
}
else {
let item = pathOrItem;
let library = Zotero.Libraries.get(item.libraryID);
if (library.libraryType == 'user' && Zotero.Prefs.get('beta.useInternalPDFReader')) {
let location = {
position: {
pageIndex: page - 1,
rects: [[0, 0, 0, 0]]
}
};
await Zotero.Reader.open(item.id, location);
return true;
}
path = await item.getFilePathAsync();
if (!path) {
Zotero.warn(`${path} not found`);
return false;
}
}
var handler = Zotero.Prefs.get("fileHandler.pdf");
var opened = false;

View file

@ -73,6 +73,11 @@ Zotero.Prefs = new function(){
this.clear('firstRunGuidanceShown.saveIcon');
this.clear('firstRunGuidanceShown.saveButton');
break;
// TEMP: Uncomment and set toVersion above to 3 when adding to prefs drop-down
//case 3:
// this.clear('fileHandler.pdf');
// break;
}
}
this.set('prefVersion', toVersion);

View file

@ -4095,9 +4095,13 @@ var ZoteroPane = new function()
}
// Custom PDF handler
if (contentType === 'application/pdf') {
this.viewPDF(itemID, event.shiftKey);
// TODO: Still leave an option to use an external PDF viewer
return;
let item = await Zotero.Items.getAsync(itemID);
let library = Zotero.Libraries.get(item.libraryID);
// TEMP
if (library.libraryType == 'user' && Zotero.Prefs.get('beta.useInternalPDFReader')) {
this.viewPDF(itemID, event && event.shiftKey);
return;
}
let pdfHandler = Zotero.Prefs.get("fileHandler.pdf");
if (pdfHandler) {
if (await OS.File.exists(pdfHandler)) {

View file

@ -1182,7 +1182,7 @@ function ZoteroProtocolHandler() {
var opened = false;
if (page) {
try {
opened = await Zotero.OpenPDF.openToPage(path, page);
opened = await Zotero.OpenPDF.openToPage(item, page);
}
catch (e) {
Zotero.logError(e);

View file

@ -178,6 +178,7 @@ pref("extensions.zotero.pane.persist", "");
// Custom file handlers
pref("extensions.zotero.fileHandler.pdf", "");
pref("extensions.zotero.beta.useInternalPDFReader", true);
// File/URL opening executable if launch() fails
pref("extensions.zotero.fallbackLauncher.unix", "/usr/bin/xdg-open");