From dcfaa5521e25c29f2218bd7e1b8666e66df4dd70 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 11 Dec 2017 02:23:15 -0500 Subject: [PATCH] Don't show note in right-hand pane when editing in separate window - When a child note is opened in a separate window, the parent window is selected. (This used to work but was broken in 5.0.) - When a top-level note is opened (via double-click), the right-hand pane changes to show "Editing in separate window". - If a note that's currently open in a separate window is clicked on, the right-hand pane shows "Editing in a separate window". - If a note window is closed and the item is selected, the note editor reappears in the right-hand pane after the note is saved. This will avoid unnecessary UI updates and data loss bugs from the two notes getting out of sync (and is just generally cleaner). Also: - General cleanup of note display code --- chrome/content/zotero/itemPane.js | 52 +++++++++++++ chrome/content/zotero/itemPane.xul | 4 +- chrome/content/zotero/note.js | 72 +++++++++--------- chrome/content/zotero/note.xul | 1 - chrome/content/zotero/zoteroPane.js | 79 +++++++++----------- chrome/locale/en-US/zotero/zotero.properties | 1 + 6 files changed, 126 insertions(+), 83 deletions(-) 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 @@ -