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 enabledConditions when creating menu item from command
This commit is contained in:
@ -12,6 +12,7 @@ interface MenuItem {
|
|||||||
click: Function;
|
click: Function;
|
||||||
role?: any;
|
role?: any;
|
||||||
accelerator?: string;
|
accelerator?: string;
|
||||||
|
enabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MenuItems {
|
interface MenuItems {
|
||||||
@ -78,6 +79,7 @@ export default class MenuUtils {
|
|||||||
id: command.declaration.name,
|
id: command.declaration.name,
|
||||||
label: this.service.label(commandName),
|
label: this.service.label(commandName),
|
||||||
click: () => onClick(command.declaration.name),
|
click: () => onClick(command.declaration.name),
|
||||||
|
enabled: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (command.declaration.role) item.role = command.declaration.role;
|
if (command.declaration.role) item.role = command.declaration.role;
|
||||||
@ -132,10 +134,13 @@ export default class MenuUtils {
|
|||||||
public pluginContextMenuItems(plugins: PluginStates, location: MenuItemLocation): MenuItem[] {
|
public pluginContextMenuItems(plugins: PluginStates, location: MenuItemLocation): MenuItem[] {
|
||||||
const output: MenuItem[] = [];
|
const output: MenuItem[] = [];
|
||||||
const pluginViewInfos = pluginUtils.viewInfosByType(plugins, 'menuItem');
|
const pluginViewInfos = pluginUtils.viewInfosByType(plugins, 'menuItem');
|
||||||
|
const whenClauseContext = this.service.currentWhenClauseContext();
|
||||||
|
|
||||||
for (const info of pluginViewInfos) {
|
for (const info of pluginViewInfos) {
|
||||||
if (info.view.location !== location) continue;
|
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);
|
if (output.length) output.splice(0, 0, { type: 'separator' } as any);
|
||||||
|
Reference in New Issue
Block a user