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

Remove the old menu implementation #54826

Merged
merged 9 commits into from
Jul 25, 2018
Merged

Remove the old menu implementation #54826

merged 9 commits into from
Jul 25, 2018

Conversation

sbatten
Copy link
Member

@sbatten sbatten commented Jul 22, 2018

This removes the old menubar implementation to allow macOS and the native menubar experience to take advantage of the new menubar registration. Please test the new branch and review.

@sbatten sbatten requested a review from isidorn July 22, 2018 18:13
@isidorn isidorn added this to the July 2018 milestone Jul 23, 2018
@isidorn
Copy link
Contributor

isidorn commented Jul 23, 2018

@sbatten thanks for the PR. Before I test the new branch could you clarify something:

  • Why is there still a file menus.ts, isn't the idea to get rid of this file and the old registration?
  • There are some conflicts with master, can you please resolve those
  • Since now the native menu takes advantage of the new menu bar registration - is it possible to dynamicly enable / disable actions in the native bar (as we can currently do in custom menu)?

I can test this in great detail, but for the review I only did a birds eye perspective review (comments lnline). @bpasero would be better for the more detailed review (if needed next week once he comes back from vacation)

@@ -70,7 +57,8 @@ export class Menubar {
// this.nativeTabMenuItems = [];

this.menuUpdater = new RunOnceScheduler(() => this.doUpdateMenu(), 0);
this.keybindingsResolver = instantiationService.createInstance(KeybindingsResolver);
// this.keybindingsResolver = instantiationService.createInstance(KeybindingsResolver);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this commented line still needed, same for line 104

@@ -277,6 +252,15 @@ export class Menubar {
menubar.append(gotoMenuItem);
}

// Terminal
Copy link
Contributor

Choose a reason for hiding this comment

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

It does not feel right that this component is aware of the terminal menu.
Couldn't this be done fully from the terminal.contribution? What is missing for that?

Copy link
Member Author

Choose a reason for hiding this comment

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

do you specifically mean for terminal, tasks and preferences? or are you referring to every top-level menu?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the nicest would be that every top level menu item is registered outside and that we do not reference them manually here

@@ -290,8 +274,8 @@ export class Menubar {
const taskMenu = new Menu();
const taskMenuItem = new MenuItem({ label: this.mnemonicLabel(nls.localize({ key: 'mTask', comment: ['&& denotes a mnemonic'] }, "&&Tasks")), submenu: taskMenu });

if (this.shouldDrawMenu('Task')) {
this.setMenuById(taskMenu, 'Task');
if (this.shouldDrawMenu('Tasks')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as for Terminal above.
Also for Preferences below.

this.setMenu(submenu, item.submenu.items);
menu.append(submenuItem);
} else if (isMenubarMenuItemAction(item)) {
if (item.id === 'workbench.action.openRecent') {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would leave a TODO here since it feels a bit hacky how we are inserting recent menu items

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea, we do this on both sides for the custom and native menubar experience. maybe we should discuss with a joh a way to do this better with the MenuRegistry in the future

Copy link
Contributor

Choose a reason for hiding this comment

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

Would you like me to create a debt item so we do not forget about this
fyi @jrieken

Copy link
Member

Choose a reason for hiding this comment

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

what's that about? dynamically computed menu entries?

private nativeTabMenuItems: Electron.MenuItem[];

private menubarMenus: IMenubarData = {};

private keybindings: { [commandId: string]: IKeybinding };
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use a Map<string, IKeybinding>

this.setMenu(menu, this.menubarMenus[menuId].items);
}

private insertRecentMenuItems(menu: Electron.Menu) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels like it deos not belong in this file. this hsould be contributed by the filesActions.contributions imho

Copy link
Member Author

Choose a reason for hiding this comment

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

same as above?

export interface IMenubarKeybinding {
id: string;
label: string;
isNative: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is isNative read and what is the purpose

Copy link
Member Author

Choose a reason for hiding this comment

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

It is used in menubar.ts under electron-main. I was accidentally using IKeybinding still in that file which is now fixed so it should be easier to find.

if (isMacintosh && isWindows) {
this.menubarService.updateMenubar(this.windowService.getCurrentWindowId(), this.getMenubarMenus());
}
this.menubarService.updateMenubar(this.windowService.getCurrentWindowId(), this.getMenubarMenus());
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not really see a point of a private method called just once that has a one line call. Just my 2 cents from the birds eye perspective

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason is primarily for symmetry. Where this is called we call either custom or native and the custom one is super long. I could make less functions and more if statements to achieve the same level of readability or just add a comment and remove the private function

Copy link
Contributor

Choose a reason for hiding this comment

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

Whatever you prefer :)

},
order: 1
});
if (!isMacintosh) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use when clauses instead of the ugly if brackets,

Copy link
Member Author

Choose a reason for hiding this comment

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

I would like to do that. I tried but I didn't see platform context keys, but I may have missed them. Are you aware?

Copy link
Contributor

Choose a reason for hiding this comment

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

I checked and there is none at the moment.
But I would add it somewhere in this file
I would call it platform and it would be windows|linux|macintosh

But we do not have to do it for this PR, we can tackle later. Would you like me to create an issue so we do not forget about it?
fyi @bpasero

Copy link
Member

Choose a reason for hiding this comment

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

@isidorn @sbatten this just landed via #54894

Copy link
Contributor

Choose a reason for hiding this comment

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

@bpasero nice. @sbatten can you look into using this context keys so we do not have the ugly if clauses.

Copy link
Member Author

Choose a reason for hiding this comment

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

@isidorn isidorn removed this from the July 2018 milestone Jul 23, 2018
@sbatten
Copy link
Member Author

sbatten commented Jul 23, 2018

In response to your initial comment: I will remove the menus.ts and possibly keyboard.ts as they are no longer used. Yes, the native menus will get the same dynamic enablement features as the custom menus with this change. @bpasero had discussed that this change was desired to get some coverage in insiders and recommended you as the reviewer, but good testing on our part before merging is necessary.

@isidorn
Copy link
Contributor

isidorn commented Jul 23, 2018

@sbatten great, just ping me once all those files are removed and I will test this out on mac.
In my view we should create a test plan item complexity 4 for this on all three platforms. In the endgame week we can decide if we want to ship this or not (in case of too many issues)

@isidorn
Copy link
Contributor

isidorn commented Jul 24, 2018

Tried it out on mac, here are the issues

  1. Error on startup
    screen shot 2018-07-24 at 12 53 08

  2. Preferences menu is top level (also in Code-Insiders as it should so it is duplicated)

screen shot 2018-07-24 at 12 54 55

Apart from that seems to work fine. Let me know if you want me to try it out on other platforms.

@isidorn
Copy link
Contributor

isidorn commented Jul 24, 2018

Thinking about going forward and what we do for this milestone my recommendation is to have some setting for windows, like workbench.customMenu which would be by default false and only temporary there.
So for all platforms we would release the new registration, but the new windows visuals would be under a setting for one milestone. I am leaning towards this protective approach since people are very passionate about menus and this is playing it safe.

This flag does not have to be a part of this PR but something to keep in mind.

Also let me know if I can help in any way.
fyi @dbaeumer @joaomoreno who self hosted

@sbatten
Copy link
Member Author

sbatten commented Jul 25, 2018

@isidorn fixed issues, please merge if ok, thanks for the review

@isidorn
Copy link
Contributor

isidorn commented Jul 25, 2018

Looks great, nice work! I have resolved some conflicts and am merging.

@isidorn isidorn merged commit d63937a into master Jul 25, 2018
@isidorn isidorn deleted the sbatten/removeOldMenu branch July 25, 2018 08:39
@isidorn isidorn added this to the July 2018 milestone Jul 25, 2018
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants