diff --git a/chrome/content/zotero/itemPane.js b/chrome/content/zotero/itemPane.js index 1d12df393..789755a93 100644 --- a/chrome/content/zotero/itemPane.js +++ b/chrome/content/zotero/itemPane.js @@ -222,6 +222,58 @@ var ZoteroItemPane = new function() { }); + this.onNoteSelected = function (item, editable) { + // If an external note window is open for this item, don't show the editor + if (ZoteroPane.findNoteWindow(item.id)) { + this.showNoteWindowMessage(); + return; + } + + var noteEditor = document.getElementById('zotero-note-editor'); + noteEditor.mode = editable ? 'edit' : 'view'; + + noteEditor.parent = null; + noteEditor.item = item; + + // If loading new or different note, disable undo while we repopulate the text field + // so Undo doesn't end up clearing the field. This also ensures that Undo doesn't + // undo content from another note into the current one. + var clearUndo = noteEditor.item ? noteEditor.item.id != item.id : false; + if (clearUndo) { + noteEditor.clearUndo(); + } + + document.getElementById('zotero-view-note-button').hidden = !editable; + document.getElementById('zotero-item-pane-content').selectedIndex = 2; + }; + + + this.showNoteWindowMessage = function () { + ZoteroPane.setItemPaneMessage(Zotero.getString('pane.item.notes.editingInWindow')); + }; + + + /** + * Select the parent item and open the note editor + */ + this.openNoteWindow = async function () { + var noteEditor = document.getElementById('zotero-note-editor'); + var item = noteEditor.item; + // We don't want to show the note in two places, since it causes unnecessary UI updates + // and can result in weird bugs where note content gets lost. + // + // If this is a child note, select the parent + if (item.parentID) { + await ZoteroPane.selectItem(item.parentID); + } + // Otherwise, hide note and replace with a message that we're editing externally + else { + this.showNoteWindowMessage(); + } + ZoteroPane.openNoteWindow(item.id); + }; + + this.addNote = function (popup) { ZoteroPane_Local.newNote(popup, _lastItem.key); } diff --git a/chrome/content/zotero/itemPane.xul b/chrome/content/zotero/itemPane.xul index 8f40a346b..6bc6a5678 100644 --- a/chrome/content/zotero/itemPane.xul +++ b/chrome/content/zotero/itemPane.xul @@ -114,7 +114,9 @@ -