From 3e69da7e4c12f7a0e2b5f35ac5bfdf6b7eed4e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Wed, 12 Apr 2017 11:47:57 +0300 Subject: [PATCH] Prompt if style in document is not from official source --- chrome/content/zotero/bibliography.js | 5 +---- chrome/content/zotero/xpcom/integration.js | 15 ++++++++++----- chrome/locale/en-US/zotero/zotero.properties | 1 + 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/chrome/content/zotero/bibliography.js b/chrome/content/zotero/bibliography.js index 13c591a548..5e198255fe 100644 --- a/chrome/content/zotero/bibliography.js +++ b/chrome/content/zotero/bibliography.js @@ -67,11 +67,8 @@ var Zotero_File_Interface_Bibliography = new function() { _io.style = Zotero.Prefs.get("export.lastStyle"); } - // Initialize styles and try to load the style, attempting a download + // Initialize styles yield Zotero.Styles.init(); - if (!Zotero.Styles.get(_io.style)) { - yield Zotero.Styles.install({url: _io.style}, data.style.styleID, true); - } // add styles to list diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index f03266baa9..226117f359 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -1027,6 +1027,16 @@ Zotero.Integration.Document.prototype._getSession = Zotero.Promise.coroutine(fun } catch(e) { // make sure style is defined if(e instanceof Zotero.Exception.Alert && e.name === "integration.error.invalidStyle") { + if (data.style.styleID) { + let displayError = Zotero.getString("integration.error.styleMissing", data.style.styleID); + if (/^https?:\/\/(www\.)?(zotero\.org|citationstyles\.org)/.test(data.style.styleID) || + me._doc.displayAlert(displayError, DIALOG_ICON_WARNING, DIALOG_BUTTONS_YES_NO)) { + + yield Zotero.Styles.install({url: data.style.styleID}, data.style.styleID, true); + yield this._session.setData(data, true); + return Zotero.Promise.resolve(this._session); + } + } return this._session.setDocPrefs(this._doc, this._app.primaryFieldType, this._app.secondaryFieldType).then(function(status) { me._doc.setDocumentData(me._session.data.serializeXML()); @@ -2081,10 +2091,6 @@ Zotero.Integration.Session.prototype.setData = Zotero.Promise.coroutine(function try { yield Zotero.Styles.init(); var getStyle = Zotero.Styles.get(data.style.styleID); - if (!getStyle) { - yield Zotero.Styles.install({url: data.style.styleID}, data.style.styleID, true); - getStyle = Zotero.Styles.get(data.style.styleID); - } data.style.hasBibliography = getStyle.hasBibliography; this.style = getStyle.getCiteProc(data.style.locale, data.prefs.automaticJournalAbbreviations); this.style.setOutputFormat("rtf"); @@ -2092,7 +2098,6 @@ Zotero.Integration.Session.prototype.setData = Zotero.Promise.coroutine(function this.dateModified = new Object(); } catch (e) { Zotero.logError(e); - data.style.styleID = undefined; throw new Zotero.Exception.Alert("integration.error.invalidStyle"); } diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties index 896dc86a50..c3452564b0 100644 --- a/chrome/locale/en-US/zotero/zotero.properties +++ b/chrome/locale/en-US/zotero/zotero.properties @@ -818,6 +818,7 @@ integration.error.noBibliography = The current bibliographic style does not def integration.error.deletePipe = The pipe that Zotero uses to communicate with the word processor could not be initialized. Would you like Zotero to attempt to correct this error? You will be prompted for your password. integration.error.invalidStyle = The style you have selected does not appear to be valid. If you have created this style yourself, please ensure that it passes validation as described at https://github.com/citation-style-language/styles/wiki/Validation. Alternatively, try selecting another style. integration.error.fieldTypeMismatch = Zotero cannot update this document because it was created by a different word processing application with an incompatible field encoding. In order to make a document compatible with both Word and LibreOffice, open the document in the word processor with which it was originally created and switch the field type to Bookmarks in the Zotero Document Preferences. +integration.error.styleMissing = The citation style used in this document is missing. Would you like to install it from %S? integration.replace = Replace this Zotero field? integration.missingItem.single = The highlighted citation no longer exists in your Zotero database. Do you want to select a substitute item?