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

Added support for custom menu node registration. #8404

Merged
merged 2 commits into from
Aug 24, 2020
Merged

Conversation

kittaakos
Copy link
Contributor

@kittaakos kittaakos commented Aug 19, 2020

Signed-off-by: Akos Kitta kittaakos@typefox.io

What it does

From now on, it's possible to register a custom menu node into the menu registry.

Added a placeholder example:
Screen Shot 2020-08-19 at 13 38 14

Screen Shot 2020-08-19 at 13 37 26

How to test

Check the sample apps.

Review checklist

Reminder for reviewers

@vince-fugnitto vince-fugnitto added enhancement issues that are enhancements to current functionality - nice to haves menus issues related to the menu labels Aug 20, 2020
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 functionality of the pull-request and it works well:

  • verified using the browser target
  • verified using the electron target
  • verified if there were any regressions with existing menus (sub-menus, action menus, context menus)

I also reviewed the code and do not have any comments, I'll however give @akosyakov a chance to review as well.

@akosyakov
Copy link
Member

I will review API changes tomorrow morning.

@kittaakos
Copy link
Contributor Author

I will review API changes tomorrow morning.

Sure. No hurry at all. It is not urgent for me. It can even wait until next week if you're busy.

const actionNode = new ActionMenuNode(item, this.commands);
return parent.addNode(actionNode);
}

registerMenuPlaceholder(menuPath: MenuPath, label: string, options?: SubMenuOptions): Disposable {
Copy link
Member

@akosyakov akosyakov Aug 21, 2020

Choose a reason for hiding this comment

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

Maybe we could add registerMenuNode(MenuPath, string, MenuNode) instead, it would allow downstreams do whatever they want and won't require us to add new APIs for different cases. I was trying to find other APIs having something like registerMenuPlaceholder, but could not. Chrome for instance creates a UI menu element assigns it a title and pushes in the parent menu first.

Copy link
Member

Choose a reason for hiding this comment

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

Rendering is abstract from MenuNode so such API is not feasible. Ok, let's go with registerMenuPlaceholder. Although meaning feels unclear to me. Maybe just a naming thing.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder also how hard is to the client to achieve such effect with registerMenuAction api. It seems to be one command which is always visible, but disabled and then many menu actions are reusing it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder also how hard is to the client

It's hard, as the menu items are always enabled in electron:

enabled: true, // https://github.com/eclipse-theia/theia/issues/446

Maybe we could add registerMenuNode(MenuPath, string, MenuNode) instead,

Let's give it a try. I did not want to introduce new APIs at all but add a groupLabel?: stirng to the SubMenuOptions. But there were cases it did not work. Let me check this once more.

Copy link
Member

@akosyakov akosyakov Aug 21, 2020

Choose a reason for hiding this comment

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

But sub menu and menu group are not the same? Maybe registerMenuGroup(subMenuPath, 'Recently Closed')? It can be then applied to any menu path, not only for submenus, to get effects like in Chrome for Recently Closed, for instance.

I think such naming also aligned with what we already have and provides explicit API to control menu groups' options.

@@ -78,15 +78,21 @@ export class MenuModelRegistry {
}
}

registerMenuAction(menuPath: MenuPath, item: MenuAction): Disposable {
const parent = this.findGroup(menuPath);
registerMenuAction(menuPath: MenuPath, item: MenuAction, options?: SubMenuOptions): Disposable {
Copy link
Member

@akosyakov akosyakov Aug 21, 2020

Choose a reason for hiding this comment

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

Why do we need to pass SubMenuOptions here? Clients should call registerSubmenu to configure the sub menu properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! That's a leftover and has to be removed.

@kittaakos kittaakos changed the title Added support for menu item placeholders. Added support for custom menu node registration. Aug 23, 2020
@kittaakos
Copy link
Contributor Author

Maybe we could add registerMenuNode(MenuPath, string, MenuNode) instead,

I implemented this and added an example. Please review.

Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

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

LGTM

return {
context: this.context,
contextKeyService: this.contextKeyService,
commandRegistry: this.commandRegistry,
keybindingRegistry: this.keybindingRegistry
keybindingRegistry: this.keybindingRegistry,
meneWidgetFactory: this
Copy link
Member

Choose a reason for hiding this comment

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

menu

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohh, thank you!

Akos Kitta added 2 commits August 24, 2020 10:08
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
`MenuModelRegistry#registerMenuNode`

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
@kittaakos kittaakos merged commit 9a07349 into master Aug 24, 2020
@kittaakos kittaakos deleted the menu-group-label branch September 15, 2020 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement issues that are enhancements to current functionality - nice to haves menus issues related to the menu
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants