Theia: How do I unregister subMenu?

Created on 5 Feb 2019  路  9Comments  路  Source: eclipse-theia/theia

I would like to hide certain Menu Options such as Files, Selection in Theia. I found out that there is currently an API(#2951) that allows unregistering some of the menuActions but not subMenu. This leaves the subMenu to be rendered but no existing options are shown.

Is there a way to remove the subMenu altogether?

question

All 9 comments

@duemaster, you can subclass the CommonFrontendContribution class, override the registerMenus method, then register the menus you need and finally rebid the contribution.

You may want to customize WorkspaceFrontendContribution class too. See here.

Can you please give some more details here @kittaakos ?

If I subclass CommonFrontendContribution, change the registerMenus method to add the default menus, they get added twice since the method in both my class and default CommonFrontendContribution gets executed. If I unbind CommonFrontendContribution in my extension, then I don't get a workable editor at all.

@bezidejni Could you try unbind and bind the CommonFrontEndContribution to your custom exension?

@duemaster That actually seems to work, thanks!

But I still don't know how to remove the subMenu. In this case I could stop some default menus generated in CommonFrontendContribution from getting created, but for example the "Go" menu gets created in menu.ts. Does that mean I'd have to extend EditorMenuContribution as well to stop those menus from getting created or is there an easier way?

@duemaster to unregister submenu:

MenuModelRegistry.unregisterMenuAction(submenuId, menuPath)

for instance:

MenuModelRegistry.unregisterMenuAction(CommonMenus.HELP[CommonMenus.HELP.length - 1], CommonMenus.MAIN_MENU_BAR)
MenuModelRegistry.unregisterMenuAction(CommonMenus.HELP[CommonMenus.HELP.length - 1], CommonMenus.MAIN_MENU_BAR)

@akosyakov In which file should I write the above code to disable or hide the sub menu.

@akosyakov do you mean implementing this through an extension?

Override the CommandContribution in the contribution.ts and bind it in the frontend-module.ts?

@squidwarddab1111 yes, your extension should provide a class implementing this interface and bind it in the extension frontend module

Was this page helpful?
0 / 5 - 0 ratings