Skip to content

Commit

Permalink
Prompt if style in document is not from official source
Browse files Browse the repository at this point in the history
  • Loading branch information
adomasven committed Apr 12, 2017
1 parent 02c43c3 commit 3e69da7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
5 changes: 1 addition & 4 deletions chrome/content/zotero/bibliography.js
Expand Up @@ -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

Expand Down
15 changes: 10 additions & 5 deletions chrome/content/zotero/xpcom/integration.js
Expand Up @@ -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());
Expand Down Expand Up @@ -2081,18 +2091,13 @@ 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");
this.styleClass = getStyle.class;
this.dateModified = new Object();
} catch (e) {
Zotero.logError(e);
data.style.styleID = undefined;
throw new Zotero.Exception.Alert("integration.error.invalidStyle");
}

Expand Down
1 change: 1 addition & 0 deletions chrome/locale/en-US/zotero/zotero.properties
Expand Up @@ -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?
Expand Down

0 comments on commit 3e69da7

Please sign in to comment.