mirror of https://github.com/laurent22/joplin.git
Plugins: Provides selected notes when triggering a command from the note list context menu
parent
d953f6bcab
commit
4ac2409318
|
@ -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',
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue