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

Expanding Submenus contribution support #9371

Merged
merged 1 commit into from
May 18, 2021

Conversation

EstherPerelman
Copy link
Contributor

@EstherPerelman EstherPerelman commented Apr 18, 2021

Signed-off-by: Esther Perelman Esther.Perelman@sap.com

What it does

Enabling contribute submenus not only for "scm/title" menus, But also for all other available contribution menus

How to test

Contribute submenus in any extension package.json following this syntax
Duplicates and cycle submenus are prevented.

For the next code in Package.json:

 "contributes": {
 ...
    "submenus": [
      {
        "id": "ep.custosubmenu1",
        "label": "custom submenu 1"
      },
      {
        "id": "ep.custosubmenu2",
        "label": "custom submenu 2"
      }
    ],
    "menus": {
      "ep.custosubmenu1": [
        {
          "command": "git.publish"
        },
        {
          "submenu": "ep.custosubmenu2"
        }
      ],
      "ep.custosubmenu2": [
        {
          "command": "git.sync",
          "group": "0_ep"
        },
        {
          "submenu": "ep.custosubmenu1"
        }
      ],
      "explorer/context": [
        {
          "command": "git.sync"
        },
        {
          "submenu": "ep.custosubmenu1"
        }
      ],
      "editor/title": [
        {
          "submenu": "ep.custosubmenu1"
        },
        {
          "submenu": "ep.custosubmenu1"
        }
      ]
    }
  },

The result is:
ezgif com-gif-maker

Review checklist

Reminder for reviewers

@EstherPerelman EstherPerelman marked this pull request as draft April 18, 2021 15:50
@EstherPerelman EstherPerelman marked this pull request as ready for review April 19, 2021 15:50
@EstherPerelman
Copy link
Contributor Author

EstherPerelman commented Apr 19, 2021

@vince-fugnitto @kittaakos @akosyakov , Anyone else...
Can you review please?

@EstherPerelman EstherPerelman changed the title Expand support in Submenus contribution Expanding Submenus contribution support Apr 20, 2021
@colin-grant-work colin-grant-work self-requested a review April 21, 2021 22:18
@colin-grant-work
Copy link
Contributor

I will take a look tomorrow morning.

@colin-grant-work
Copy link
Contributor

@EstherPerelman, I'm reading over the code now. In your PR description, you say

For the next code in Package.json:

Do you have a plugin with which to test the code, or should it be possible to copy that code into any plugin's package.json and see the results?

Copy link
Contributor

@colin-grant-work colin-grant-work left a comment

Choose a reason for hiding this comment

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

I believe this is working well. I've confirmed that the JSON manifest provided produces the menus that it should. I have some questions about the code and some suggestions for how it might be made more legible. Let me know what you think of those ideas.

@EstherPerelman
Copy link
Contributor Author

@EstherPerelman, I'm reading over the code now. In your PR description, you say

For the next code in Package.json:

Do you have a plugin with which to test the code, or should it be possible to copy that code into any plugin's package.json and see the results?

Thank you for reviewing, It is possible to copy this code to any plugin's package.json,
I will go over the conversations as soon as possible, Thank's

@EstherPerelman EstherPerelman force-pushed the Submenus branch 2 times, most recently from 37fda8f to 16b3e36 Compare April 27, 2021 08:51
@EstherPerelman
Copy link
Contributor Author

@colin-grant-work I've updated code, Can you check if everything is OK?
Thanks.

Copy link
Contributor

@colin-grant-work colin-grant-work left a comment

Choose a reason for hiding this comment

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

Thanks for the changes. I'm now getting all of the items I expect, but there are some odd ordering effects. For example, the manifest I gave above to non-cyclical menu duplication now gives the following menus:

image

All of the menu items are present, but Custom Submenu 3 now appears before the other two items in custom submenu 1 even though it is listed after both of them. Are the items being sorted alphabetically (with capital letters preceding lower-case letters), and is that intentional?

There's also an odd effect that is likely beyond the scope of this PR where selecting certain submenus causes a flicker effect where items are highlighted from the menu root out to the leaf, and it can cause a failure when hovering a new submenu as focus is returned to the root menu and lost at the leaf.

weird-flickers

You can see a couple of instances in that GIF where the focus is lost. It happened more frequently, but it's so brief that the GIF doesn't capture them all. The behavior occurs on master as well (for example in the Sample Menu > Sample sub menu in the example application in the electron version), so I don't believe it's a problem with this code.

@EstherPerelman
Copy link
Contributor Author

EstherPerelman commented Apr 28, 2021

All of the menu items are present, but Custom Submenu 3 now appears before the other two items in custom submenu 1 even though it is listed after both of them. Are the items being sorted alphabetically (with capital letters preceding lower-case letters), and is that intentional?

Yes it is sorted, Look at this

Copy link
Contributor

@colin-grant-work colin-grant-work left a comment

Choose a reason for hiding this comment

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

This looks good to me. Thanks @EstherPerelman!

@vince-fugnitto vince-fugnitto added menus issues related to the menu vscode issues related to VSCode compatibility labels Apr 28, 2021
@EstherPerelman EstherPerelman marked this pull request as draft April 28, 2021 20:35
Comment on lines +162 to +166
const parentSubmenusIds = new Set<string>();

return menus.reduce((children: MenuTree[], menuItem) => {
if (menuItem.submenu) {
if (parentSubmenusIds.has(menuItem.submenu)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @colin-grant-work I updated the code because parentSubmenusIds declaration was inside the reduce
so it didn't work as excepted, I found by chance that the menu was duplicated...

menus.forEach(menu => {
if (group) {
// Adding previous group to the start of current menu group.
menu.group = `${group}/${menu.group || '_'}`;
Copy link
Contributor Author

@EstherPerelman EstherPerelman Apr 29, 2021

Choose a reason for hiding this comment

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

Also updated default value for group from '' to '_' (If there's no group the item should be at the end of the menu list - compared with VSCode)

@EstherPerelman EstherPerelman marked this pull request as ready for review April 29, 2021 08:01
@amiramw
Copy link
Member

amiramw commented May 6, 2021

Any objection to merging this one? I see it is approved by @colin-grant-work

@amiramw
Copy link
Member

amiramw commented May 11, 2021

we will merge it this week if there's no objection

@amiramw
Copy link
Member

amiramw commented May 13, 2021

Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

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

I verified the changes with the vscode-builtin-git plugin, as well as the contributes.menus described in the pull-request description and it seems to work as intended.

I also verified if there were any regressions with the different contributions points:

const tree: MenuTree[] = [];

Object.keys(allMenus).forEach(location => {
// Don't build menus tree for a submenu decleration at root.
Copy link
Member

Choose a reason for hiding this comment

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

typo: decleration > declaration

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @vince-fugnitto, Fixed it.

Signed-off-by: Esther Perelman <Esther.Perelman@sap.com>
@vince-fugnitto
Copy link
Member

The changes should allow us to easily support new menu contribution points such as #9387 👍

@EstherPerelman
Copy link
Contributor Author

I verified the changes with the vscode-builtin-git plugin, as well as the contributes.menus described in the pull-request description and it seems to work as intended.

I also verified if there were any regressions with the different contributions points:

Thanks for testing & verifying, Is that says you approve this PR?

@vince-fugnitto
Copy link
Member

Thanks for testing & verifying, Is that says you approve this PR?

Since Red Hat initially implemented the menu-contribution-handler I wanted to give them the opportunity to test, but so far there hasn't been a review. Functionality the code seems to work well, but I have not done a thorough review code-wise. @RomanNikitenko @tsmaeder @vinokurig

Copy link
Contributor

@vinokurig vinokurig left a comment

Choose a reason for hiding this comment

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

Tested according to the provided steps and with the vscode git plugin, works as expected.

@amiramw amiramw merged commit 36d6e04 into eclipse-theia:master May 18, 2021
@vince-fugnitto vince-fugnitto added this to the 1.14.0 milestone May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
menus issues related to the menu vscode issues related to VSCode compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants