Skip to content

Migrate menubar action registrations out of menubar.contribution.ts #54510

Closed

Description

With the new menubar implementation, all menubar actions can be contributed via the MenuRegistry. Currently, all actions for the menubar are registered in a single file menubar.contribution.ts; however, it would be nice to have these registered and owned by the area owners from which they originate.

When moving your command registration to the appropriate location, you may also opt to add a precondition to the command so that it is enabled dynamically. I have chosen the debug actions as an example a08526a. Isidor Nikolic (@isidorn) I have not moved the registrations, only used them to demonstrate the use of precondition for the menu entries.

Here is an inline example:

MenuRegistry.appendMenuItem(MenuId.MenubarDebugMenu, {
	group: '3_step',
	command: {
		id: 'workbench.action.debug.continue',
		title: nls.localize({ key: 'miContinue', comment: ['&& denotes a mnemonic'] }, "&&Continue"),
		precondition: ContextKeyExpr.has('inDebugMode')
	},
	order: 4
});

There is also a when clause on the menu entry that hides the entry if the condition is not met; however, we are not currently recommending this approach for the menubar unless you are swapping two entries that are mutually exclusive.

@Microsoft/vscode please review the menubar entries for ones that you can own and move the corresponding registration into a more appropriate location. You can then add a precondition if it applies. Please ping me if you have any questions.

Activity

  1. bpasero commented on Jul 18, 2018

    @bpasero
    Contributor

    Linking #991 which is the original issue. One thing to emphasize is that we should try hard to set a precondition on most menu items to make sure the enablement is proper. If a context key does not exist yet for a particular menu item, it should be added 👍

  2. isidorn commented on Jul 19, 2018

    @isidorn

    SteVen Batten (@sbatten) nice work.
    I have moved the Debug menu contribution via 0738ae2
    Benjamin Pasero (@bpasero) I can also move the View menu but not sure where to put it. How about it main.contribution? I can also create a new file view.contribution

    SteVen Batten (@sbatten) the ugly part now is that we have double the registration both in menu.contribution.ts and in menus.ts. When will we be able to drop menus.ts and rely solely on the new way of registering menu items?

  3. isidorn commented on Jul 19, 2018

    @isidorn

    I have updated the checkboxes in the original comment such that we have some owners per menu item.
    Benjamin Pasero (@bpasero) I will move the file, view and window menus in appropriate places. Just do a code review once you are back
    SteVen Batten (@sbatten) please tryout my changes on windows. For window menu I will wait until this new way of registration is supported on the mac.

  4. dbaeumer commented on Jul 20, 2018

    @dbaeumer
    Member

    Done for tasks. Isidor Nikolic (@isidorn) thanks for your help.

  5. alexdima commented on Jul 25, 2018

    @alexdima
    Member

    SteVen Batten (@sbatten) I tried to use precondition to control the enablement of Undo and Redo. One of the problems that came up is that the menubar menu entries are evaluated in the global context.

    But in the workbench you can have multiple editors opened, some of which can undo and some of which cannot.

    I have noticed that the menubar will refocus on the previously focused element when invoking the action, so if focus is in editor1, and then the Edit menu is opened, and Undo picked, focus is correctly brought back to editor1 before the command is invoked.

    I think we could support high fidelity disablement/enablement of these commands if the menu items precondition would be evaluated in the context of the previous focused element. You can find the context associated with a particular element via IContextKeyService.getContext(previousFocusedElement).

  6. sandy081 commented on Jul 25, 2018

    @sandy081
    Member

    Thanks Isidor Nikolic (@isidorn) for adopting Open View... action.

  7. locked and limited conversation to collaborators on Sep 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

debt

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions