How to disable Menu/Sub menu items via my custom Extensions

I have my own extensions and i would like to remove/disable menu/sub menu items on the top panel from my extension.
Like from the File menu, i want to disable one of the sub menu item from my extension. How would i do that?
Or is there any configurable options can be done from package.json file?

[original thread by asvinwin123]

You can unregister menu items by command ids. Look at APIs of MenuRegistry

In order to find a command ID you can search Theia code base using command label.

[asvinwin123]

Thank you

[asvinwin123]

May i know how to enable/disable the toolbar items?

please file an isee, there is no way to unregister right now

should be quick to fix, we need unregiterItem by an id here: https://github.com/theia-ide/theia/blob/fa15670e79ccb8478b4b54b59b943df1dfddd7df/packages/core/src/browser/shell/tab-bar-toolbar.tsx#L353

[asvinwin123]

Thank you. let me check

[asvinwin123]

Is there a way to remove submenu?

It does not look like that. Could you file an issue?

Maybe @thegecko can help. I know you managed to unregister some menus.

Submenu should not appear if it is empty. You can try to unregister all its commands.

[Rob Moran]

You can register an extension which removes menus and commands like this:
import { injectable } from ‘inversify’;
import { CommandRegistry } from ‘@theia/core’;
import { CommandContribution, MenuContribution, MenuModelRegistry } from ‘@theia/core/lib/common’;
import { CommonCommands } from ‘@theia/core/lib/browser’;

@injectable()
export class RemovalContribution implements CommandContribution, MenuContribution {

public registerCommands(commandRegistry: CommandRegistry): void {
    // Help
    commandRegistry.unregisterCommand(CommonCommands.ABOUT_COMMAND);
}

public registerMenus(menus: MenuModelRegistry): void {
    // Help
    menus.unregisterMenuAction(CommonCommands.ABOUT_COMMAND);
}

}

[Rob Moran]

As long as you import the command IDs, it guarantees the dependency tree is correct and it removes items after they have been added

[asvinwin123]

I tried unregister all items under the submenu. Still submenu appears.

ok, then we either need new unregisterSubmenu method, do what @kittaakos suggested in another thread

[asvinwin123]

@anton-kosyakov Thank you

[Rob Moran]

You can unregister entire menus like this:
menus.unregisterMenuAction(DebugMenus.DEBUG.slice(-1)[0]);

[Rob Moran]

Which removes the entirety of DEBUG