From 8fe4b6f8f835ba8cc1cd0c69a7496b5750c1f4d3 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Wed, 23 Mar 2011 06:05:34 +0000 Subject: [PATCH] Show corrupt field error message if getCode fails --- chrome/content/zotero/xpcom/integration.js | 56 ++++++++++++++-------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index fbc066f4b..232f8b2ee 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -687,6 +687,35 @@ Zotero.Integration.Document.prototype._addField = function(note) { return field; } +/** + * Shows an error if a field code is corrupted + * @param {Exception} e The exception thrown + * @param {Field} field The Zotero field object + * @param {Integer} i The field index + */ +Zotero.Integration.Document.prototype._showCorruptFieldError = function(e, field, i) { + var msg = Zotero.getString("integration.corruptField")+'\n\n'+ + Zotero.getString('integration.corruptField.description'); + field.select(); + var result = this._doc.displayAlert(msg, + Components.interfaces.zoteroIntegrationDocument.DIALOG_ICON_CAUTION, + Components.interfaces.zoteroIntegrationDocument.DIALOG_BUTTONS_YES_NO_CANCEL); + + if(result == 0) { + throw e; + } else if(result == 1) { // No + this._removeCodeFields.push(i); + } else { + // Display reselect edit citation dialog + var added = this._session.editCitation(i, field.getNoteIndex()); + if(added) { + this._doc.activate(); + } else { + throw new Zotero.Integration.UserCancelledException(); + } + } +} + /** * Loads existing citations and bibliographies out of a document, and creates or edits fields */ @@ -707,7 +736,11 @@ Zotero.Integration.Document.prototype._updateSession = function(newField, editFi if(editField && field.equals(editField)) { editFieldIndex = i; } else { - var fieldCode = field.getCode(); + try { + var fieldCode = field.getCode(); + } catch(e) { + this._showCorruptFieldError(e, field, i); + } if(fieldCode.substr(0, ITEM_CODE.length) == ITEM_CODE) { var noteIndex = (this._session.styleClass == "note" ? field.getNoteIndex() : 0); @@ -752,26 +785,7 @@ Zotero.Integration.Document.prototype._updateSession = function(newField, editFi } } } else if(e instanceof Zotero.Integration.CorruptFieldException) { - var msg = Zotero.getString("integration.corruptField")+'\n\n'+ - Zotero.getString('integration.corruptField.description'); - field.select(); - var result = this._doc.displayAlert(msg, - Components.interfaces.zoteroIntegrationDocument.DIALOG_ICON_CAUTION, - Components.interfaces.zoteroIntegrationDocument.DIALOG_BUTTONS_YES_NO_CANCEL); - - if(result == 0) { - throw e; - } else if(result == 1) { // No - this._removeCodeFields.push(i); - } else { - // Display reselect edit citation dialog - var added = this._session.editCitation(i, field.getNoteIndex()); - if(added) { - this._doc.activate(); - } else { - throw new Zotero.Integration.UserCancelledException(); - } - } + this._showCorruptFieldError(e, field, i); } else { throw e; }