From 2082b68dd3f6fc5ea8cfe2a35275e96010818371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Wed, 14 Dec 2022 16:20:04 +0200 Subject: [PATCH] Add a prompt to import Mendeley DB if mendeley citation found in doc --- chrome/content/zotero/import/importWizard.js | 4 ++ chrome/content/zotero/xpcom/integration.js | 39 ++++++++++++++++++-- chrome/locale/en-US/zotero/zotero.properties | 4 ++ components/zotero-service.js | 1 + defaults/preferences/zotero.js | 1 + 5 files changed, 45 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/import/importWizard.js b/chrome/content/zotero/import/importWizard.js index 04a4706bf3..87da262dbc 100644 --- a/chrome/content/zotero/import/importWizard.js +++ b/chrome/content/zotero/import/importWizard.js @@ -49,6 +49,10 @@ var Zotero_Import_Wizard = { document.getElementById('create-collection-checkbox').removeAttribute('checked'); } } + + if (args && args.pageID) { + this._wizard.goTo(args.pageID); + } if (args && args.mendeleyCode && Zotero.Prefs.get("import.mendeleyUseOAuth")) { this._mendeleyCode = args.mendeleyCode; diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index d6c634cede..006adf5733 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -2632,11 +2632,42 @@ Zotero.Integration.URIMap.prototype.getZoteroItemForURIs = async function (uris) replacer = await Zotero.Relations.getByPredicateAndObject( 'item', 'mendeleyDB:documentUUID', m[1] ); - if (replacer.length && !replacer[0].deleted) { - zoteroItem = replacer[0]; - break; + if (replacer.length) { + if (!replacer[0].deleted) { + zoteroItem = replacer[0]; + break; + } } - } + // If not blocked by user having pressed skip in this session, + // or user having checked the checkbox to not be prompted about this, + // or user having imported their library with the new version of importer + else if (!(this.session.dontPromptForMendeley + || Zotero.Prefs.get('integration.dontPromptMendeleyImport') + || await Zotero.DB.valueQueryAsync("SELECT value FROM settings WHERE setting='mendeleyImport' AND key='version'") + )) { + // Prompt user to (re)import their mendeley database which might make us recognize + // these items + let checkbox = {}; + let result = Zotero.Prompt.confirm({ + title: Zotero.getString('integration.mendeleyImport.title'), + text: Zotero.getString('integration.mendeleyImport.description', [Zotero.appName]), + button0: Zotero.getString('integration.mendeleyImport.openImporter'), + button1: Zotero.getString('general.skip'), + checkLabel: Zotero.getString('general.dontAskAgain'), + checkbox + }); + if (result === 0) { + setTimeout(() => Zotero.getMainWindow().Zotero_File_Interface.showImportWizard({ pageID: 'mendeley-online-explanation' })); + throw new Zotero.Exception.UserCancelled("Importing mendeley citations"); + } + else { + this.session.dontPromptForMendeley = true; + } + if (checkbox.value) { + Zotero.Prefs.set('integration.dontPromptMendeleyImport', true); + } + } + }; } diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties index 9eeaec0634..3344d6a670 100644 --- a/chrome/locale/en-US/zotero/zotero.properties +++ b/chrome/locale/en-US/zotero/zotero.properties @@ -74,6 +74,7 @@ general.tryLater = Try Later general.showDirectory = Show Directory general.showInLibrary = Show in Library general.continue = Continue +general.skip = Skip general.copy = Copy general.copyToClipboard = Copy to Clipboard general.cancel = Cancel @@ -990,6 +991,9 @@ integration.exportDocument.description1 = Zotero will convert citations in the d integration.exportDocument.description2 = You should make a backup of the document before proceeding. integration.importInstructions = The Zotero citations in this document have been converted to a format that can be safely transferred between word processors. Open this document in a supported word processor and press Refresh in the Zotero plugin to continue working with the citations. integration.upgradeTemplate = The %S plugin for %S is outdated. Reinstall the plugin from Preferences → Cite → Word Processors. +integration.mendeleyImport.title = Missing Mendeley Data +integration.mendeleyImport.description = %1$S detected that the document you are citing with contains Mendeley citations. %1$S will be able to manage these citations if you import your Mendeley database. +integration.mendeleyImport.openImporter = Open Mendeley Importer... styles.install.title = Install Style styles.install.unexpectedError = An unexpected error occurred while installing "%1$S" diff --git a/components/zotero-service.js b/components/zotero-service.js index 3f26c9a105..6032cc205f 100644 --- a/components/zotero-service.js +++ b/components/zotero-service.js @@ -53,6 +53,7 @@ const xpcomFilesAll = [ 'mimeTypeHandler', 'pdfWorker/manager', 'ipc', + 'prompt', 'profile', 'progressWindow', 'proxy', diff --git a/defaults/preferences/zotero.js b/defaults/preferences/zotero.js index 2a300aabed..e4b8e86cb1 100644 --- a/defaults/preferences/zotero.js +++ b/defaults/preferences/zotero.js @@ -137,6 +137,7 @@ pref("extensions.zotero.integration.autoRegenerate", -1); // -1 = ask; 0 = no; 1 pref("extensions.zotero.integration.useClassicAddCitationDialog", false); pref("extensions.zotero.integration.keepAddCitationDialogRaised", false); pref("extensions.zotero.integration.upgradeTemplateDelayedOn", 0); +pref("extensions.zotero.integration.dontPromptMendeleyImport", false); // Connector settings pref("extensions.zotero.httpServer.enabled", false); // TODO enabled for testing only