From 13cafe886ec5bcf073fc460648077966ba69ba38 Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Tue, 9 Mar 2021 17:29:55 +0200 Subject: [PATCH] Rework note editor toolbar and related UI --- .../content/zotero/bindings/attachmentbox.xml | 1 + chrome/content/zotero/bindings/noteeditor.xml | 1 + chrome/content/zotero/itemPane.js | 3 +- chrome/content/zotero/note.js | 1 + chrome/content/zotero/xpcom/editorInstance.js | 55 +++++++++---------- note-editor | 2 +- 6 files changed, 32 insertions(+), 31 deletions(-) diff --git a/chrome/content/zotero/bindings/attachmentbox.xml b/chrome/content/zotero/bindings/attachmentbox.xml index 917c99e2a6..2a25c1ae7c 100644 --- a/chrome/content/zotero/bindings/attachmentbox.xml +++ b/chrome/content/zotero/bindings/attachmentbox.xml @@ -390,6 +390,7 @@ else { noteEditor.hidden = true; } + noteEditor.viewMode = 'library'; if (this.displayButton) { selectButton.label = this.buttonCaption; diff --git a/chrome/content/zotero/bindings/noteeditor.xml b/chrome/content/zotero/bindings/noteeditor.xml index 36ad879fbc..d51afa8b0c 100644 --- a/chrome/content/zotero/bindings/noteeditor.xml +++ b/chrome/content/zotero/bindings/noteeditor.xml @@ -102,6 +102,7 @@ iframeWindow: document.getAnonymousElementByAttribute(this, 'anonid', 'editor-view').contentWindow, popup: document.getAnonymousElementByAttribute(this, 'anonid', 'editor-menu'), onNavigate: this._navigateHandler, + viewMode: this.viewMode, readOnly: !this.editable, disableUI: this.mode == 'merge', onReturn: this._returnHandler, diff --git a/chrome/content/zotero/itemPane.js b/chrome/content/zotero/itemPane.js index 7103353c76..1193667ae7 100644 --- a/chrome/content/zotero/itemPane.js +++ b/chrome/content/zotero/itemPane.js @@ -290,11 +290,12 @@ var ZoteroItemPane = new function() { else { var noteEditor = document.getElementById('zotero-note-editor'); noteEditor.mode = editable ? 'edit' : 'view'; + noteEditor.viewMode = 'library'; noteEditor.parent = null; noteEditor.item = item; } - document.getElementById('zotero-view-note-button').hidden = !editable; + document.getElementById('zotero-view-note-button').hidden = !editable || type != 'group' && Zotero.isPDFBuild; document.getElementById('zotero-item-pane-content').selectedIndex = 2; }; diff --git a/chrome/content/zotero/note.js b/chrome/content/zotero/note.js index 120df37099..3901d57b15 100644 --- a/chrome/content/zotero/note.js +++ b/chrome/content/zotero/note.js @@ -66,6 +66,7 @@ async function onLoad() { noteEditor = document.getElementById('zotero-note-editor'); } noteEditor.mode = 'edit'; + noteEditor.viewMode = 'window'; // Set font size from pref Zotero.setFontSize(noteEditor); diff --git a/chrome/content/zotero/xpcom/editorInstance.js b/chrome/content/zotero/xpcom/editorInstance.js index 5651505d00..5e0af78846 100644 --- a/chrome/content/zotero/xpcom/editorInstance.js +++ b/chrome/content/zotero/xpcom/editorInstance.js @@ -47,6 +47,7 @@ class EditorInstance { Zotero.Notes.registerEditorInstance(this); this.onNavigate = options.onNavigate; this._item = options.item; + this._viewMode = options.viewMode; this._readOnly = options.readOnly; this._disableUI = options.disableUI; this._onReturn = options.onReturn; @@ -82,7 +83,9 @@ class EditorInstance { this._postMessage({ action: 'init', value: this._state || this._item.note, + viewMode: this._viewMode, readOnly: this._readOnly, + unsaved: !this._item.id, disableUI: this._disableUI, enableReturnButton: !!this._onReturn, placeholder: options.placeholder, @@ -179,6 +182,17 @@ class EditorInstance { this._postMessage({ action: 'updateFont', font: this._getFont() }); } + _showInLibrary(ids) { + if (!Array.isArray(ids)) { + ids = [ids]; + } + let win = Zotero.getMainWindow(); + if (win) { + win.ZoteroPane.selectItems(ids); + win.Zotero_Tabs.select('zotero-pane'); + win.focus(); + } + } /** * @param {Zotero.Item[]} annotations @@ -355,15 +369,7 @@ class EditorInstance { await Zotero.Reader.open(attachments[0].id, { pageLabel: citationItem.locator }); } else { - let zp = Zotero.getActiveZoteroPane(); - if (zp) { - zp.selectItems([item.id]); - let win = Zotero.getMainWindow(); - if (win) { - win.focus(); - win.Zotero_Tabs.select('zotero-pane'); - } - } + this._showInLibrary(item.id); } return; } @@ -376,14 +382,9 @@ class EditorInstance { items.push(item); } } - let zp = Zotero.getActiveZoteroPane(); - if (zp && items.length) { - zp.selectItems(items.map(item => item.id)); - let win = Zotero.getMainWindow(); - if (win) { - win.focus(); - win.Zotero_Tabs.select('zotero-pane'); - } + + if (items.length) { + this._showInLibrary(items.map(item => item.id)); } return; } @@ -395,19 +396,15 @@ class EditorInstance { } return; } - case 'showInLibrary': { - let { uri } = message; + case 'showNote': { + this._showInLibrary(this._item.id); + return; + } + case 'openWindow': { + // TODO: Can we can avoid creating empty note just to open it in a new window? + await this._ensureNoteCreated(); let zp = Zotero.getActiveZoteroPane(); - if (zp) { - let item = await Zotero.URI.getURIItem(uri); - if (item) { - zp.selectItems([item.id]); - let win = Zotero.getMainWindow(); - if (win) { - win.focus(); - } - } - } + zp.openNoteWindow(this._item.id); return; } case 'openBackup': { diff --git a/note-editor b/note-editor index 28009d1773..ed19f7d9ed 160000 --- a/note-editor +++ b/note-editor @@ -1 +1 @@ -Subproject commit 28009d1773a69e87b6151ff189c5f806aab5320c +Subproject commit ed19f7d9ed1549d2674ca1545bc563928187b28b