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 'zotero.preferences.launchNonNativeFiles', Zotero.appName
); );
} }
var menuitem = document.getElementById('fileHandler-internal');
menuitem.setAttribute('label', Zotero.appName);
this.updateAutoRenameFilesUI(); this.updateAutoRenameFilesUI();
this._updateFileHandlerUI(); this._updateFileHandlerUI();
@ -88,6 +90,16 @@ Zotero_Preferences.General = {
var handler = Zotero.Prefs.get('fileHandler.pdf'); var handler = Zotero.Prefs.get('fileHandler.pdf');
var menulist = document.getElementById('fileHandler-pdf'); var menulist = document.getElementById('fileHandler-pdf');
var customMenuItem = document.getElementById('fileHandler-custom'); 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) { if (handler) {
let icon; let icon;
try { try {
@ -113,11 +125,12 @@ Zotero_Preferences.General = {
customMenuItem.className = ''; customMenuItem.className = '';
} }
customMenuItem.hidden = false; customMenuItem.hidden = false;
menulist.selectedIndex = 0; menulist.selectedIndex = 1;
} }
// System default
else { else {
customMenuItem.hidden = true; 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-copyChildLinks" name="extensions.zotero.groups.copyChildLinks" type="bool"/>
<preference id="pref-groups-copyTags" name="extensions.zotero.groups.copyTags" 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> </preferences>
<groupbox id="zotero-prefpane-file-handling-groupbox"> <groupbox id="zotero-prefpane-file-handling-groupbox">
@ -67,6 +68,9 @@
<label value="&zotero.preferences.fileHandler.openPDFsUsing;" control="file-handler-pdf"/> <label value="&zotero.preferences.fileHandler.openPDFsUsing;" control="file-handler-pdf"/>
<menulist id="fileHandler-pdf" class="fileHandler-menu"> <menulist id="fileHandler-pdf" class="fileHandler-menu">
<menupopup> <menupopup>
<menuitem id="fileHandler-internal"
oncommand="Zotero_Preferences.General.setFileHandler('pdf', 'zotero')"
hidden="true"/>
<menuitem id="fileHandler-custom"/> <menuitem id="fileHandler-custom"/>
<menuitem label="&zotero.preferences.fileHandler.systemDefault;" <menuitem label="&zotero.preferences.fileHandler.systemDefault;"
oncommand="Zotero_Preferences.General.setFileHandler('pdf', false)"/> oncommand="Zotero_Preferences.General.setFileHandler('pdf', false)"/>
@ -75,6 +79,9 @@
</menupopup> </menupopup>
</menulist> </menulist>
</hbox> </hbox>
<checkbox
label="Use Zotero PDF reader for My Library (beta)"
preference="pref-useInternalPDFReader"/>
</groupbox> </groupbox>
<groupbox id="zotero-prefpane-miscellaneous-groupbox"> <groupbox id="zotero-prefpane-miscellaneous-groupbox">

View file

@ -26,7 +26,34 @@
/* eslint-disable array-element-newline */ /* eslint-disable array-element-newline */
Zotero.OpenPDF = { 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 handler = Zotero.Prefs.get("fileHandler.pdf");
var opened = false; var opened = false;

View file

@ -73,6 +73,11 @@ Zotero.Prefs = new function(){
this.clear('firstRunGuidanceShown.saveIcon'); this.clear('firstRunGuidanceShown.saveIcon');
this.clear('firstRunGuidanceShown.saveButton'); this.clear('firstRunGuidanceShown.saveButton');
break; 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); this.set('prefVersion', toVersion);

View file

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

View file

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

View file

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