Rework note editor toolbar and related UI

This commit is contained in:
Martynas Bagdonas 2021-03-09 17:29:55 +02:00
parent 824f67cb36
commit 13cafe886e
6 changed files with 32 additions and 31 deletions

View file

@ -390,6 +390,7 @@
else {
noteEditor.hidden = true;
}
noteEditor.viewMode = 'library';
if (this.displayButton) {
selectButton.label = this.buttonCaption;

View file

@ -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,

View file

@ -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;
};

View file

@ -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);

View file

@ -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': {

@ -1 +1 @@
Subproject commit 28009d1773a69e87b6151ff189c5f806aab5320c
Subproject commit ed19f7d9ed1549d2674ca1545bc563928187b28b