From 2ce712df703cc972ef701068ffb5a35ede82b5ba Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Mon, 30 May 2011 05:25:13 +0000 Subject: [PATCH] Show an error when a user attempts to use an invalid style --- chrome/content/zotero/xpcom/integration.js | 30 ++++++++++++-------- chrome/locale/en-US/zotero/zotero.properties | 1 + 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index a1b7eed508..412060b2b7 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -665,7 +665,6 @@ Zotero.Integration.Document = function(app, doc) { Zotero.Integration.Document.prototype._createNewSession = function(data) { data.sessionID = Zotero.randomString(); var session = Zotero.Integration.sessions[data.sessionID] = new Zotero.Integration.Session(); - session.setData(data); return session; } @@ -684,7 +683,9 @@ Zotero.Integration.Document.prototype._getSession = function(require, dontRunSet throw new Zotero.Integration.DisplayException("mustInsertCitation"); } else { // Set doc prefs if no data string yet - this._session = this._createNewSession(new Zotero.Integration.DocumentData()); + var data = new Zotero.Integration.DocumentData(); + this._session = this._createNewSession(data); + this._session.setData(data); if(dontRunSetDocPrefs) return false; Zotero.Integration.activate(); @@ -715,14 +716,19 @@ Zotero.Integration.Document.prototype._getSession = function(require, dontRunSet this._session = Zotero.Integration.sessions[data.sessionID]; } else { this._session = this._createNewSession(data); - - // make sure style is defined - if(!this._session.style) { - Zotero.Integration.activate(); - try { - this._session.setDocPrefs(this._app.primaryFieldType, this._app.secondaryFieldType); - } finally { - this._doc.activate(); + try { + this._session.setData(data); + } catch(e) { + // make sure style is defined + if(e instanceof Zotero.Integration.DisplayException && e.name === "invalidStyle") { + Zotero.Integration.activate(); + try { + this._session.setDocPrefs(this._app.primaryFieldType, this._app.secondaryFieldType); + } finally { + this._doc.activate(); + } + } else { + throw e; } } this._doc.setDocumentData(this._session.data.serializeXML()); @@ -1278,9 +1284,9 @@ Zotero.Integration.Session.prototype.setData = function(data) { this.styleClass = getStyle.class; this.dateModified = new Object(); } catch(e) { - Zotero.debug(e) + Zotero.logError(e); data.style.styleID = undefined; - return false; + throw new Zotero.Integration.DisplayException("invalidStyle"); } return true; diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties index 7cb1a5a500..583b972cb1 100644 --- a/chrome/locale/en-US/zotero/zotero.properties +++ b/chrome/locale/en-US/zotero/zotero.properties @@ -587,6 +587,7 @@ integration.error.cannotInsertHere = Zotero fields cannot be inserted here. integration.error.notInCitation = You must place the cursor in a Zotero citation to edit it. integration.error.noBibliography = The current bibliographic style does not define a bibliography. If you wish to add a bibliography, please choose another style. 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 http://zotero.org/support/dev/citation_styles. Alternatively, try selecting another style. integration.replace = Replace this Zotero field? integration.missingItem.single = This item no longer exists in your Zotero database. Do you want to select a substitute item?