Crash Zotero on note-saving error
Closes #1277, Crash note if not saving properly
This commit is contained in:
		
					parent
					
						
							
								18c62be6a4
							
						
					
				
			
			
				commit
				
					
						8215ba7a1d
					
				
			
		
					 4 changed files with 36 additions and 13 deletions
				
			
		| 
						 | 
					@ -65,6 +65,11 @@
 | 
				
			||||||
					switch (val) {
 | 
										switch (val) {
 | 
				
			||||||
						case 'view':
 | 
											case 'view':
 | 
				
			||||||
						case 'merge':
 | 
											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;
 | 
												break;
 | 
				
			||||||
						
 | 
											
 | 
				
			||||||
						case 'edit':
 | 
											case 'edit':
 | 
				
			||||||
| 
						 | 
					@ -243,9 +248,9 @@
 | 
				
			||||||
			</method>
 | 
								</method>
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			<method name="save">
 | 
								<method name="save">
 | 
				
			||||||
				<body>
 | 
									<body><![CDATA[
 | 
				
			||||||
					<![CDATA[
 | 
										return Zotero.spawn(function* () {
 | 
				
			||||||
						return Zotero.spawn(function* () {
 | 
											try {
 | 
				
			||||||
							if (this._mode == 'view') {
 | 
												if (this._mode == 'view') {
 | 
				
			||||||
								Zotero.debug("Not saving read-only note");
 | 
													Zotero.debug("Not saving read-only note");
 | 
				
			||||||
								return;
 | 
													return;
 | 
				
			||||||
| 
						 | 
					@ -262,10 +267,6 @@
 | 
				
			||||||
							if (this.item) {
 | 
												if (this.item) {
 | 
				
			||||||
								// If note field doesn't match item, abort save and run error handler
 | 
													// If note field doesn't match item, abort save and run error handler
 | 
				
			||||||
								if (noteField.getAttribute('itemID') != this.item.id) {
 | 
													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");
 | 
														throw new Error("Note field doesn't match current item");
 | 
				
			||||||
								}
 | 
													}
 | 
				
			||||||
								
 | 
													
 | 
				
			||||||
| 
						 | 
					@ -298,10 +299,21 @@
 | 
				
			||||||
								}
 | 
													}
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
							
 | 
												
 | 
				
			||||||
							this.item = yield Zotero.Items.getAsync(id);
 | 
												this.item = item;
 | 
				
			||||||
						}.bind(this));
 | 
											}
 | 
				
			||||||
					]]>
 | 
											catch (e) {
 | 
				
			||||||
				</body>
 | 
												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>
 | 
								</method>
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			<!-- Used to insert a tab manually -->
 | 
								<!-- Used to insert a tab manually -->
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -113,7 +113,7 @@
 | 
				
			||||||
				-->
 | 
									-->
 | 
				
			||||||
				<zoteronoteeditor id="zotero-note-editor" flex="1" notitle="1"
 | 
									<zoteronoteeditor id="zotero-note-editor" flex="1" notitle="1"
 | 
				
			||||||
					previousfocus="zotero-items-tree"
 | 
										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'));"/>
 | 
									<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>
 | 
								</groupbox>
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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()
 | 
					function onUnload()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if(noteEditor && noteEditor.value)
 | 
						if(noteEditor && noteEditor.value)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,5 +23,5 @@
 | 
				
			||||||
	</keyset>
 | 
						</keyset>
 | 
				
			||||||
	<command id="cmd_close" oncommand="window.close();"/>
 | 
						<command id="cmd_close" oncommand="window.close();"/>
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	<zoteronoteeditor id="zotero-note-editor" flex="1"/>
 | 
						<zoteronoteeditor id="zotero-note-editor" flex="1" onerror="onError()"/>
 | 
				
			||||||
</window>
 | 
					</window>
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue