hello,I wanna disable and enable items in menu dynamic,how to achive it

hello,I wanna disable and enable items in menu dynamic,how to achive it.

@Gnails menu items are tied to commands. In order to display menu items dynamically as enabled/disabled the command will need to include a corresponding isEnabled:

For example, in this case we use a service to enable the command (and subsequently the menu item) when at least 1 workspace roots is present:

commands.registerCommand(SearchInWorkspaceCommands.OPEN_SIW_WIDGET, {
    isEnabled: () => this.workspaceService.tryGetRoots().length > 0,
    execute: async () => {
        const widget = await this.openView({ activate: true });
        widget.updateSearchTerm(this.getSearchTerm());
    }
});

If you need to completely remove menu items then you can unregister them: How to disable Menu/Sub menu items via my custom Extensions

it works,thanks

Is there any method to achieve multi-level submenu?

@Gnails you can take a look at the example under @theia/api-samples for menu (you can use the same idea of nested menu paths to create even more levels if necessary):

In this example we create a submenu:

ok :grinning: