mirror of https://github.com/laurent22/joplin.git
Plugins: Add support for enabledConditions when creating menu item from command
parent
0a54854f54
commit
9260b2a9ab
|
@ -12,6 +12,7 @@ interface MenuItem {
|
|||
click: Function;
|
||||
role?: any;
|
||||
accelerator?: string;
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
interface MenuItems {
|
||||
|
@ -78,6 +79,7 @@ export default class MenuUtils {
|
|||
id: command.declaration.name,
|
||||
label: this.service.label(commandName),
|
||||
click: () => onClick(command.declaration.name),
|
||||
enabled: true,
|
||||
};
|
||||
|
||||
if (command.declaration.role) item.role = command.declaration.role;
|
||||
|
@ -132,10 +134,13 @@ export default class MenuUtils {
|
|||
public pluginContextMenuItems(plugins: PluginStates, location: MenuItemLocation): MenuItem[] {
|
||||
const output: MenuItem[] = [];
|
||||
const pluginViewInfos = pluginUtils.viewInfosByType(plugins, 'menuItem');
|
||||
const whenClauseContext = this.service.currentWhenClauseContext();
|
||||
|
||||
for (const info of pluginViewInfos) {
|
||||
if (info.view.location !== location) continue;
|
||||
output.push(this.commandToStatefulMenuItem(info.view.commandName));
|
||||
const menuItem = this.commandToStatefulMenuItem(info.view.commandName);
|
||||
menuItem.enabled = this.service.isEnabled(info.view.commandName, whenClauseContext);
|
||||
output.push(menuItem);
|
||||
}
|
||||
|
||||
if (output.length) output.splice(0, 0, { type: 'separator' } as any);
|
||||
|
|
Loading…
Reference in New Issue