www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 8215ba7a1d5c850e8e2382f56e8af8d6b32b2df9
parent 18c62be6a49a3e17b8dd251319fedbfbac5d996b
Author: Dan Stillman <dstillman@zotero.org>
Date:   Fri, 15 Sep 2017 00:46:04 -0400

Crash Zotero on note-saving error

Closes #1277, Crash note if not saving properly

Diffstat:
Mchrome/content/zotero/bindings/noteeditor.xml | 34+++++++++++++++++++++++-----------
Mchrome/content/zotero/itemPane.xul | 2+-
Mchrome/content/zotero/note.js | 11+++++++++++
Mchrome/content/zotero/note.xul | 2+-
4 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/chrome/content/zotero/bindings/noteeditor.xml b/chrome/content/zotero/bindings/noteeditor.xml @@ -65,6 +65,11 @@ switch (val) { case 'view': case 'merge': + // If there's an existing editor, mark it as read-only. This allows for + // disabling an existing editable note (e.g., if there's a save error). + if (this.noteField) { + this.noteField.onInit(ed => ed.setMode('readonly')); + } break; case 'edit': @@ -243,9 +248,9 @@ </method> <method name="save"> - <body> - <![CDATA[ - return Zotero.spawn(function* () { + <body><![CDATA[ + return Zotero.spawn(function* () { + try { if (this._mode == 'view') { Zotero.debug("Not saving read-only note"); return; @@ -262,10 +267,6 @@ if (this.item) { // If note field doesn't match item, abort save and run error handler if (noteField.getAttribute('itemID') != this.item.id) { - if (this.hasAttribute('onerror')) { - let fn = new Function("", this.getAttribute('onerror')); - fn.call(this) - } throw new Error("Note field doesn't match current item"); } @@ -298,10 +299,21 @@ } } - this.item = yield Zotero.Items.getAsync(id); - }.bind(this)); - ]]> - </body> + this.item = item; + } + catch (e) { + Zotero.logError(e); + + if (this.hasAttribute('onerror')) { + let fn = new Function("", this.getAttribute('onerror')); + fn.call(this) + } + if (this.onError) { + this.onError(e); + } + } + }.bind(this)); + ]]></body> </method> <!-- Used to insert a tab manually --> diff --git a/chrome/content/zotero/itemPane.xul b/chrome/content/zotero/itemPane.xul @@ -113,7 +113,7 @@ --> <zoteronoteeditor id="zotero-note-editor" flex="1" notitle="1" previousfocus="zotero-items-tree" - onerror="ZoteroPane.displayErrorMessage()"/> + onerror="ZoteroPane.displayErrorMessage(); this.mode = 'view'"/> <button id="zotero-view-note-button" label="&zotero.notes.separate;" oncommand="ZoteroPane_Local.openNoteWindow(this.getAttribute('noteID')); if(this.hasAttribute('sourceID')) ZoteroPane_Local.selectItem(this.getAttribute('sourceID'));"/> </groupbox> diff --git a/chrome/content/zotero/note.js b/chrome/content/zotero/note.js @@ -75,6 +75,17 @@ function onLoad() { }); } +// If there's an error saving a note, close the window and crash the app +function onError() { + try { + window.opener.ZoteroPane.displayErrorMessage(); + } + catch (e) { + Zotero.logError(e); + } + window.close(); +} + function onUnload() { if(noteEditor && noteEditor.value) diff --git a/chrome/content/zotero/note.xul b/chrome/content/zotero/note.xul @@ -23,5 +23,5 @@ </keyset> <command id="cmd_close" oncommand="window.close();"/> - <zoteronoteeditor id="zotero-note-editor" flex="1"/> + <zoteronoteeditor id="zotero-note-editor" flex="1" onerror="onError()"/> </window> \ No newline at end of file