You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-16 00:14:34 +02:00
Plugins: Add support for joplin.workspace.filterEditorContextMenu to allow dynamically setting editor menu items depending on context
This commit is contained in:
@ -3,7 +3,7 @@ import eventManager from '../../../eventManager';
|
||||
import Setting from '../../../models/Setting';
|
||||
import { FolderEntity } from '../../database/types';
|
||||
import makeListener from '../utils/makeListener';
|
||||
import { Disposable } from './types';
|
||||
import { Disposable, MenuItem } from './types';
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
@ -15,6 +15,12 @@ import Note from '../../../models/Note';
|
||||
*/
|
||||
import Folder from '../../../models/Folder';
|
||||
|
||||
export interface EditContextMenuFilterObject {
|
||||
items: MenuItem[];
|
||||
}
|
||||
|
||||
type FilterHandler<T> = (object: T)=> Promise<void>;
|
||||
|
||||
enum ItemChangeEventType {
|
||||
Create = 1,
|
||||
Update = 2,
|
||||
@ -113,6 +119,14 @@ export default class JoplinWorkspace {
|
||||
return makeListener(eventManager, 'syncComplete', callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called just before the editor context menu is about to open. Allows
|
||||
* adding items to it.
|
||||
*/
|
||||
public filterEditorContextMenu(handler: FilterHandler<EditContextMenuFilterObject>) {
|
||||
eventManager.filterOn('editorContextMenu', handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the currently selected note
|
||||
*/
|
||||
@ -139,4 +153,5 @@ export default class JoplinWorkspace {
|
||||
public async selectedNoteIds(): Promise<string[]> {
|
||||
return this.store.getState().selectedNoteIds.slice();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -269,6 +269,17 @@ export interface MenuItem {
|
||||
*/
|
||||
commandName?: string;
|
||||
|
||||
/**
|
||||
* Arguments that should be passed to the command. They will be as rest
|
||||
* parameters.
|
||||
*/
|
||||
commandArgs?: any[];
|
||||
|
||||
/**
|
||||
* Set to "separator" to create a divider line
|
||||
*/
|
||||
type?: string;
|
||||
|
||||
/**
|
||||
* Accelerator associated with the menu item
|
||||
*/
|
||||
|
Reference in New Issue
Block a user