Skip to content

Handled Menu Item Contributions to ShowInMenu do not evaluate Visible-When Expression #3969

@r-mennig

Description

@r-mennig

Handled Menu Items contributed to the "ShowIn"-Menu do not evaluate Visible-When Expressions. Because of this problem, entries in the "ShowIn"-Menu can be disabled, but cannot be made invisible.

Steps to reproduce

Reproducing this problem inside the workspace requires additional PDE bundles (in order to create and modify a new E4 model fragment).

Since this is a E4 problem, the easiest reproduction I found for this is by modifying the "org.eclipse.e4.ui.examples.e4editor" test bundle and adding this bundle to my run configuration:

  1. Open the E4 fragment editor for /org.eclipse.e4.ui.examples.e4editor/fragment.e4xmi
  2. Add a new menu contribution with parent-ID org.eclipse.ui.menus.showInMenu
  3. Add a new handled menu item with a matching command and handler and connect them to each other
  4. Add a imperative expression for the menu item
  5. Create a new handler class which implements (at)Evaluate, (at)CanExecute and (at)Execute as follows (both the handled menu item and the imperative expression must point to this class):
Image
  1. Add the "org.eclipse.e4.ui.examples.e4editor" bundle to a run configuration and start the application
  2. Inside the runtime application, create a new project and open the "ShowIn"-menu (via the context menu) -> The problem occurs: The added menu item is show as disabled although the imperative expression we've added for this item should make it invisible (since the "Evaluate" method of our handler always returns false)
Image

For comparison: Change the parent-ID of the handled menu item to "popup" and restart the application -> The item is now an invisible entry in the popup menu (can be tested via breakpoints or by changing the "Evaluate" method to return true).

Note: I've tried fixing this issue as a PR but stopped, since it looks like fixing this would require a bigger change in the way the "ShowIn"-Menu is filled. As far as I can tell the root cause for this problem seems to be inside org.eclipse.ui.internal.ShowInMenu.fillMenu(IMenuManager). Here, the handled menu items get converted to CommandContributionItem without considering if a visibleWhen-Expression is present on the item.

Image

Community

  • I understand reporting an issue to this OSS project does not mandate anyone to fix it. Other contributors may consider the issue, or not, at their own convenience. The most efficient way to get it fixed is that I fix it myself and contribute it back as a good quality patch to the project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions