diff --git a/packages/app-cli/tests/support/plugins/register_command/api/types.ts b/packages/app-cli/tests/support/plugins/register_command/api/types.ts index f81bc10384..af2ccb25ee 100644 --- a/packages/app-cli/tests/support/plugins/register_command/api/types.ts +++ b/packages/app-cli/tests/support/plugins/register_command/api/types.ts @@ -208,6 +208,13 @@ export enum MenuItemLocation { * @deprecated Do not use - same as NoteListContextMenu */ Context = 'context', + + /** + * The context menu that appears when right-clicking on the note + * list, or when multiple notes are selected. Any command triggered from + * this location will receive a `noteIds` array with the list of notes that + * were right-clicked or selected. + */ NoteListContextMenu = 'noteListContextMenu', EditorContextMenu = 'editorContextMenu', } diff --git a/packages/app-cli/tests/support/plugins/register_command/src/index.ts b/packages/app-cli/tests/support/plugins/register_command/src/index.ts index 276081ca5f..404709a518 100644 --- a/packages/app-cli/tests/support/plugins/register_command/src/index.ts +++ b/packages/app-cli/tests/support/plugins/register_command/src/index.ts @@ -21,6 +21,20 @@ joplin.plugins.register({ }, }); + await joplin.commands.register({ + name: 'contextMenuCommandExample', + label: 'My Context Menu command', + execute: async (noteIds:string[]) => { + const notes = []; + for (const noteId of noteIds) { + notes.push(await joplin.data.get(['notes', noteId])); + } + + const noteTitles = notes.map((note:any) => note.title); + alert('The following notes will be processed:\n\n' + noteTitles.join(', ')); + }, + }); + // Commands that return a result and take argument can only be used // programmatically, so it's not necessary to set a label and icon. await joplin.commands.register({ @@ -40,6 +54,8 @@ joplin.plugins.register({ await joplin.views.menuItems.create('myMenuItem1', 'testCommand1', MenuItemLocation.Tools, { accelerator: 'CmdOrCtrl+Alt+Shift+B' }); await joplin.views.menuItems.create('myMenuItem2', 'testCommand2', MenuItemLocation.Tools); + await joplin.views.menuItems.create('contextMenuItem1', 'contextMenuCommandExample', MenuItemLocation.NoteListContextMenu); + console.info('Running command with arguments...'); const result = await joplin.commands.execute('commandWithResult', 'abcd', 123); console.info('Result was: ' + result); diff --git a/packages/app-desktop/gui/utils/NoteListUtils.ts b/packages/app-desktop/gui/utils/NoteListUtils.ts index 21dd33b6ca..92d46b378b 100644 --- a/packages/app-desktop/gui/utils/NoteListUtils.ts +++ b/packages/app-desktop/gui/utils/NoteListUtils.ts @@ -186,7 +186,7 @@ export default class NoteListUtils { if (location !== MenuItemLocation.Context && location !== MenuItemLocation.NoteListContextMenu) continue; menu.append( - new MenuItem(menuUtils.commandToStatefulMenuItem(info.view.commandName)) + new MenuItem(menuUtils.commandToStatefulMenuItem(info.view.commandName, noteIds)) ); }