Adding widgets under new menu entry

Hi I have created several widget extensions and all of them appear under View in menu bar, however I am trying to put few of my extensions under Custom submenu.
I already took a look at below thread, though it did help me to understand how to add new entry and submenu, the examples had built in command id which was used easily, but in my case I need to add the extension ids.
How to add a new main menu on top?

I tried this by creating a menu bar extension which creates a submenu, and at the same path I try to add the action, but register.MenuAddAction was called in resptective widget extensions, this did add the submenu but the action below never pops up.
Could you please provide me your insights here?
Thanks in Advance
Nandish

@Nandish thank you for the discussion, I believe it should be quite easy.

In your MenuContribution you can create the menu-path you need, and build the menu as you see fit. In order to add the widgets you can register their toggleCommandId to the same menu path.

The toggleCommandId comes from ViewContributionOptions.

Alternatively you can register commands for your views which open them, and register those to your top-level menu.

@vince-fugnitto, thanks for your response, my code looks like this,

const MyMenuPath = […MAIN_MENU_BAR, ‘MyMenu’];
@injectable()
export class MyMenuContribution implements MenuContribution {

constructor(
    @inject(MyViewContribution) private readonly viewContribution: MyViewContribution
) {}

registerMenus(menus: MenuModelRegistry): void {
    menus.registerSubmenu(MyMenuPath , 'MyMenu',{order: '6'});
    menus.registerMenuAction(MyMenuPath , {
        commandId: this.viewContribution.toggleCommandId,
        label:"My view",
        order: '1'
    });
}

}
Note MyViewContribution is the extension which I am trying to display under MyMenu, however I do not see the action under My Menu, I can see My Menu at the top of menubar. Could you please let me know what am I doing wrong, in terms of registering menu action.

I do not get any error message.
Kind Regards

Hi, @vince-fugnitto, I could figure it out, I was not getting the correct CommandId at my menu contribution.
However, I get my widget name under my menu entry, would it be possible to have an alias for this, for example: label: MyExtensionWidget widget, instead of displaying this can I display, MyWidget1 under MyMenu and open MyExtensionWidget widget when clicked on MyWidget1?

Kind Regards

@Nandish glad you were able to figure it out :+1:

You can take a look at the API when registering menus, but basically you can specify a custom label if you do not want to use the one attached to your commandId.


For example:

The command is registered with Close All Tabs but the menu entry uses a custom label of Close All.

Thanks a lot for quick response, I shall take a look at the git hub links.
Thanks once again.