Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

electron: update rendering of menu items #7869

Merged
merged 1 commit into from
May 26, 2020
Merged

Conversation

vince-fugnitto
Copy link
Member

@vince-fugnitto vince-fugnitto commented May 23, 2020

What it does

The following pull-request updates the rendering of electron context-menu items based on a command's isEnabled. In electron, menu items cannot be disabled (grayed-out) like the browser so we must rely on hiding elements instead of disabling them. With this change, menu items in electron are not rendered if their isEnabled is not true.

For example, language-server commands (monaco) are always populated in electron menus which does not make sense since such commands (ex: 'go to definition') do not make sense when they are no-op. Omitting the rendering of these items also aligns with the menu behavior visible from vscode.

Master:

Screen Shot 2020-05-22 at 8 51 10 PM

Pull Request:

Screen Shot 2020-05-22 at 9 34 04 PM

How to test

  1. execute the command Reset Workbench Layout
  2. verify that the main-menu successfully displays the menu items (electron: update rendering of menu items #7869 (comment))
  3. open a typescript file and trigger the context-menu
    (language feature menu items should be available)
  4. open a markdown, image, textfile and trigger the context-menu
    (language feature menu items should not be available)

Review checklist

Reminder for reviewers

Signed-off-by: vince-fugnitto vincent.fugnitto@ericsson.com

@vince-fugnitto vince-fugnitto added electron issues related to the electron target menus issues related to the menu labels May 23, 2020
@vince-fugnitto vince-fugnitto self-assigned this May 23, 2020
@vince-fugnitto vince-fugnitto changed the title electron: render menu items based on 'isEnabled' electron: update rendering of menu items May 23, 2020
@kittaakos
Copy link
Contributor

kittaakos commented May 25, 2020

Two remarks:

  • VS Code always shows application menu items even if they are not enabled. I assume, if we do this for the context menu, we will do the same for the app menu; do we want to diverge from VS Code's behavior?
  • If we decide to hide not enabled items, we have to adjust this code too.

@kittaakos
Copy link
Contributor

There is another side-effect of this PR, we do not show non-enabled menu items on start, so for instance, the Selection menu will contain only Select All. Since we do not support dynamic menu items in electron, the Selection menu content won't ever get updated unless the window has a blur then focus event:

Screen Shot 2020-05-25 at 13 06 50

Screen Shot 2020-05-25 at 13 10 43

I tend to not accept this PR with the current state. I prefer to see the menu items even if they're NOOP than not seeing them.

@vince-fugnitto
Copy link
Member Author

Thank you for your feedback @kittaakos!

  • VS Code always shows application menu items even if they are not enabled. I assume, if we do this for the context menu, we will do the same for the app menu; do we want to diverge from VS Code's behavior?

We will need to find a solution which does not affect the main-menu, but rather only the context-menu (due to the dynamic menu issue). In VS Code, the context-menu only displays enabled menu items, it will not display no-op menu items (similarly to this pull-request).

  • If we decide to hide not enabled items, we have to adjust this code too.

The idea is to hide context-menu items only.

I tend to not accept this PR with the current state. I prefer to see the menu items even if they're NOOP than not seeing them.

I agree, I'll need to dive deeper to see if it's possible only to modify the context-menu and not the main-menu.

There is another side-effect of this PR, we do not show non-enabled menu items on start, so for instance, the Selection menu will contain only Select All.

I wasn't able to reproduce this issue with my changes, do you have the steps to reproduce?

@kittaakos
Copy link
Contributor

do you have the steps to reproduce?

You can try resetting the workbench layout.

@akosyakov akosyakov requested review from spoenemann and kittaakos May 25, 2020 13:42
@kittaakos
Copy link
Contributor

In VS Code, the context-menu only displays enabled menu items

The idea is to hide context-menu items only.

Do you want to align the browser behavior with electron? AFAIK, we disable but show the context menu items in browser env.

@vince-fugnitto
Copy link
Member Author

In VS Code, the context-menu only displays enabled menu items

The idea is to hide context-menu items only.

Do you want to align the browser behavior with electron? AFAIK, we disable but show the context menu items in browser env.

@kittaakos I was only planning on updating the electron target to hide disabled menu items (similarly to vscode) and not update the browser which does not have this limitation. In the browser, disabled menu items are properly decorated (grayed-out).

@kittaakos
Copy link
Contributor

@kittaakos I was only planning on updating the electron target to hide disabled menu items (similarly to vscode) and not update the browser which does not have this limitation. In the browser, disabled menu items are properly decorated (grayed-out).

👍 I am fine with it, I just wanted to know what to verify once it's ready.

@vince-fugnitto vince-fugnitto force-pushed the vf/electron-menus branch 2 times, most recently from f1776cf to c1514fc Compare May 25, 2020 17:26
@vince-fugnitto
Copy link
Member Author

@kittaakos I modified the code to only affect context-menus and not the main-menu.
The behavior is now aligned with vscode (hiding disabled menu items from the context-menu).

Copy link
Contributor

@spoenemann spoenemann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

This commit updates the logic of rendering menu items with the
electron target to be based on a command being `enabled`. Since
electron does not support graying-out items (enable), we must rely
on hiding these items from the menus since they are no-op when
executed.

Signed-off-by: vince-fugnitto <vincent.fugnitto@ericsson.com>
@vince-fugnitto
Copy link
Member Author

@kittaakos @akosyakov thank you for the feedback, I've updated and retested the code based on your feedback :)

@kittaakos kittaakos self-requested a review May 26, 2020 12:45
Copy link
Contributor

@kittaakos kittaakos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have checked it with the electron example; it worked as expected. Thank you! 👍

@vince-fugnitto vince-fugnitto merged commit 6c1f835 into master May 26, 2020
@vince-fugnitto vince-fugnitto deleted the vf/electron-menus branch May 26, 2020 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
electron issues related to the electron target menus issues related to the menu
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants