From 42e69dbf97e1f14339ea2020224844407a339394 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sun, 29 Jan 2012 16:39:27 -0500 Subject: [PATCH] Don't break integration if QuickFormat dialog is closed with close box (only affects Linux) --- .../content/zotero/integration/quickFormat.js | 27 +++++++++++++++---- .../zotero/integration/quickFormat.xul | 3 ++- chrome/content/zotero/xpcom/integration.js | 2 +- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/chrome/content/zotero/integration/quickFormat.js b/chrome/content/zotero/integration/quickFormat.js index 1491ac0bb..3bf9e9a3a 100644 --- a/chrome/content/zotero/integration/quickFormat.js +++ b/chrome/content/zotero/integration/quickFormat.js @@ -29,7 +29,7 @@ var Zotero_QuickFormat = new function () { showEditor, referencePanel, referenceBox, referenceHeight = 0, separatorHeight = 0, currentLocator, currentLocatorLabel, currentSearchTime, dragging, panel, panelPrefix, panelSuffix, panelSuppressAuthor, panelLocatorLabel, panelLocator, panelInfo, - panelRefersToBubble, panelFrameHeight = 0; + panelRefersToBubble, panelFrameHeight = 0, accepted = false; // A variable that contains the timeout object for the latest onKeyPress event var eventTimeout = null; @@ -918,9 +918,25 @@ var Zotero_QuickFormat = new function () { * Accepts current selection and adds citation */ function _accept() { - _updateCitationObject(); - document.getElementById("quick-format-deck").selectedIndex = 1; - io.accept(_onProgress); + if(accepted) return; + accepted = true; + try { + _updateCitationObject(); + document.getElementById("quick-format-deck").selectedIndex = 1; + io.accept(_onProgress); + } catch(e) { + Zotero.debug(e); + } + } + + /** + * Handles windows closed with the close box + */ + this.onUnload = function() { + if(accepted) return; + accepted = true; + io.citation.citationItems = []; + io.accept(); } /** @@ -928,7 +944,8 @@ var Zotero_QuickFormat = new function () { */ this.onKeyPress = function(event) { var keyCode = event.keyCode; - if(keyCode === event.DOM_VK_ESCAPE) { + if(keyCode === event.DOM_VK_ESCAPE && !accepted) { + accepted = true; io.citation.citationItems = []; io.accept(); } diff --git a/chrome/content/zotero/integration/quickFormat.xul b/chrome/content/zotero/integration/quickFormat.xul index b82478f9d..f0452c3b4 100644 --- a/chrome/content/zotero/integration/quickFormat.xul +++ b/chrome/content/zotero/integration/quickFormat.xul @@ -37,7 +37,8 @@ xmlns:html="http://www.w3.org/1999/xhtml" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" persist="screenX screenY" - onkeypress="Zotero_QuickFormat.onKeyPress(event)"> + onkeypress="Zotero_QuickFormat.onKeyPress(event)" + onunload="Zotero_QuickFormat.onUnload()">