Add notes list context menu

Fixes #1979
This commit is contained in:
Martynas Bagdonas 2021-03-06 00:42:12 +02:00
parent a1206e8901
commit 6e49da1452
4 changed files with 47 additions and 6 deletions

View file

@ -28,9 +28,9 @@ import cx from 'classnames';
const MAX_ALL_NOTES = 7;
const NoteRow = ({ title, body, date, onClick, parentItemType, parentTitle }) => {
const NoteRow = ({ title, body, date, onClick, onContextMenu, parentItemType, parentTitle }) => {
return (
<div className={cx('note-row', { 'standalone-note-row': !parentItemType })} onClick={onClick}>
<div className={cx('note-row', { 'standalone-note-row': !parentItemType })} onClick={onClick} onContextMenu={onContextMenu}>
<div className="inner">
{ parentItemType
? <div className="parent-line">
@ -51,7 +51,7 @@ const NoteRow = ({ title, body, date, onClick, parentItemType, parentTitle }) =>
);
};
const NotesList = forwardRef(({ onClick, onAddChildButtonDown, onAddStandaloneButtonDown }, ref) => {
const NotesList = forwardRef(({ onClick, onContextMenu, onAddChildButtonDown, onAddStandaloneButtonDown }, ref) => {
const [notes, setNotes] = useState([]);
const [expanded, setExpanded] = useState(false);
const [hasParent, setHasParent] = useState(true);
@ -71,7 +71,8 @@ const NotesList = forwardRef(({ onClick, onAddChildButtonDown, onAddStandaloneBu
<button onMouseDown={onAddChildButtonDown}>+</button>
</div>
{!childNotes.length && <div className="empty-row">{Zotero.getString('pane.context.noNotes')}</div>}
{childNotes.map(note => <NoteRow key={note.id} {...note} onClick={() => onClick(note.id)}/>)}
{childNotes.map(note => <NoteRow key={note.id} {...note}
onClick={() => onClick(note.id)} onContextMenu={(event) => onContextMenu(note.id, event)}/>)}
</section>}
<section>
<div className="header-row">
@ -79,7 +80,9 @@ const NotesList = forwardRef(({ onClick, onAddChildButtonDown, onAddStandaloneBu
<button onMouseDown={onAddStandaloneButtonDown}>+</button>
</div>
{!allNotes.length && <div className="empty-row">{Zotero.getString('pane.context.noNotes')}</div>}
{(expanded ? allNotes : allNotes.slice(0, MAX_ALL_NOTES)).map(note => <NoteRow key={note.id} {...note} onClick={() => onClick(note.id)}/>)}
{(expanded ? allNotes : allNotes.slice(0, MAX_ALL_NOTES))
.map(note => <NoteRow key={note.id} {...note}
onClick={() => onClick(note.id)} onContextMenu={(event) => onContextMenu(note.id, event)}/>)}
{!expanded && allNotes.length > MAX_ALL_NOTES
&& <div className="more-row" onClick={handleClickMore}>{
Zotero.getString('general.numMore', Zotero.Utilities.numberFormat([allNotes.length - MAX_ALL_NOTES], 0))

View file

@ -23,7 +23,7 @@
***** END LICENSE BLOCK *****
*/
// TODO: Fix import/require related isues that might be
// TODO: Fix import/require related issues that might be
// related with `require` not reusing the context
var React = require('react');
var ReactDOM = require('react-dom');
@ -537,6 +537,31 @@ var ZoteroContextPane = new function () {
updateFromCache: () => _updateNotesList(true)
};
function _handleListPopupClick(id, event) {
switch (event.originalTarget.id) {
case 'context-pane-list-show-in-library':
ZoteroPane_Local.selectItem(id);
Zotero_Tabs.select('zotero-pane');
break;
case 'context-pane-list-edit-in-window':
ZoteroPane_Local.openNoteWindow(id);
break;
case 'context-pane-list-delete':
var ps = Components.classes['@mozilla.org/embedcomp/prompt-service;1']
.getService(Components.interfaces.nsIPromptService);
if (ps.confirm(null, '', Zotero.getString('pane.item.notes.delete.confirm'))) {
Zotero.Items.trashTx(id);
context.cachedNotes = context.cachedNotes.filter(x => x.id != id);
_updateNotesList(true);
}
break;
default:
}
}
function _handleAddChildNotePopupClick(event) {
switch (event.originalTarget.id) {
case 'context-pane-add-child-note':
@ -571,6 +596,11 @@ var ZoteroContextPane = new function () {
onClick={(id) => {
_setPinnedNote(id);
}}
onContextMenu={(id, event) => {
var popup = document.getElementById('context-pane-list-popup');
popup.onclick = (event) => _handleListPopupClick(id, event);
popup.openPopupAtScreen(event.screenX, event.screenY);
}}
onAddChildButtonDown={(event) => {
var popup = document.getElementById('context-pane-add-child-note-button-popup');
popup.onclick = _handleAddChildNotePopupClick;

View file

@ -643,6 +643,13 @@
<menuitem id="context-pane-add-standalone-note" label="&zotero.context.addStandaloneNote;"/>
<menuitem id="context-pane-add-standalone-note-from-annotations" label="&zotero.context.addStandaloneNoteFromAnnotations;"/>
</menupopup>
<menupopup id="context-pane-list-popup">
<menuitem id="context-pane-list-show-in-library" label="&zotero.items.menu.showInLibrary;"/>
<menuitem id="context-pane-list-edit-in-window" label="&zotero.context.editInWindow;"/>
<menuseparator/>
<menuitem id="context-pane-list-delete" label="&zotero.general.delete;"/>
</menupopup>
</popupset>
</hbox>

View file

@ -333,3 +333,4 @@
<!ENTITY zotero.context.addChildNoteFromAnnotations "Add Item Note from Annotations">
<!ENTITY zotero.context.addStandaloneNote "Add Standalone Note">
<!ENTITY zotero.context.addStandaloneNoteFromAnnotations "Add Standalone Note from Annotations">
<!ENTITY zotero.context.editInWindow "Edit in a Separate Window">