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

[git] Group the context menu items per Git command #8400 #9324

Merged
merged 1 commit into from
Apr 26, 2021

Conversation

dhuebner
Copy link
Member

@dhuebner dhuebner commented Apr 9, 2021

What it does

Groups menu items in git toolbar menu into sub-menus

How to test

Open Source Control view, open toolbar menu. Grouped menu should be shown:
Bildschirmfoto 2021-04-09 um 15 20 57

Review checklist

Reminder for reviewers

@kittaakos
Copy link
Contributor

Super. Thank you for the patch. Could you please add groups for Pull/Push and keep the order from VS Code?

VS Code:
Screen Shot 2021-04-12 at 09 15 50

Theia:
Screen Shot 2021-04-12 at 09 15 59

@dhuebner
Copy link
Member Author

@kittaakos
I'm not sure how to define groups in submenus, I need to try it out

@vince-fugnitto vince-fugnitto added git issues related to git ui/ux issues related to user interface / user experience labels Apr 12, 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 have noticed the following logs with the changes:

image

@@ -204,7 +204,32 @@ export namespace GIT_COMMANDS {
category: 'Git'
};
}
export namespace GIT_MENUS {
// Main menu groups
Copy link
Member

Choose a reason for hiding this comment

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

The following comment may be misleading, the main menu is the top-level menu.
We can likely omit the comment entirely.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, you are right. I will remove it

packages/git/src/browser/git-contribution.ts Outdated Show resolved Hide resolved
@dhuebner
Copy link
Member Author

I have noticed the following logs with the changes:

image

@vince-fugnitto
I didn't noticed that :(

This is probably because we have PULL and PUSH in favorites group and as submenu entry. Would it be fine to just create the entries with different command id's or is there a way to reference the same command in different menu items?

@vince-fugnitto
Copy link
Member

@dhuebner

The error happens when we attempt to register the same command id multiple times:

/**
* Register the given command and handler if present.
*
* Throw if a command is already registered for the given command identifier.
*/
registerCommand(command: Command, handler?: CommandHandler): Disposable {
if (this._commands[command.id]) {
console.warn(`A command ${command.id} is already registered.`);
return Disposable.NULL;
}

This happens when we call registerItem:

const registerItem = (item: Mutable<TabBarToolbarItem>) => {
const commandId = item.command;
const id = '__git.tabbar.toolbar.' + commandId;
const command = this.commands.getCommand(commandId);
this.commands.registerCommand({ id, iconClass: command && command.iconClass }, {

One solution might need to register a new command which wraps the existing, and is used in the submenu, but there might be others:

export const PULL_DEFAULT_SUBMENU = {
  id: 'git.pull.default.submenu',
};
registry.registerCommand(GIT_COMMANDS.PULL_DEFAULT_SUBMENU, {
  execute: () => registry.executeCommand(GIT_COMMANDS.PULL_DEFAULT.id),
  isEnabled: () => !!this.repositoryTracker.selectedRepository
});

@dhuebner
Copy link
Member Author

@kittaakos
Groups are added to the submenu:

Bildschirmfoto 2021-04-16 um 15 44 41

Unfortunately priorities are lost due to missing order property during renderMoreContextMenu in tab-bar-toolbar.tsx, I added TODO comments.

@vince-fugnitto
I also registered the favorites menu entries (Pull/Push) with new ids like you suggested.

@kittaakos
Copy link
Contributor

Theia:
Screen Shot 2021-04-23 at 08 06 42

VS Code:
Screen Shot 2021-04-23 at 08 07 10

Besides some ordering differences, the Changes menu groups are in sync 👍. Why did you re-declare the Stage All Changes in the Pull, Push submenu? Is it a bug or feature?

Theia:
Screen Shot 2021-04-23 at 08 06 47

VS Code:
Screen Shot 2021-04-23 at 08 11 54

@dhuebner
Copy link
Member Author

@kittaakos
Thanks for your feedback. I fixed the Fetch command label (Stage All Changes -> Fetch...) and also moved Merge... from favorites to command group.
Bildschirmfoto 2021-04-23 um 08 53 21

Regarding the order, I see any chance to do it properly because of alphabetical sorting due to missing SubMenuOptions here: https://github.com/eclipse-theia/theia/pull/9324/files#diff-07529f987e23173e43dafbf57a0b4b625978849167b48205fc30d3f806feec01

Missing order leads to the alphabetical sorting here: https://github.com/eclipse-theia/theia/blob/master/packages/core/src/common/menu.ts#L341

...because the sorting string is the MenuItem label

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 verified it on Gitpod, and it worked:

  • there were no warnings in the console due to the duplicate command registration,
  • all menu items were there, and
  • the Git commands I have tried ran successfully.

Thank you, @dhuebner 👍

@vince-fugnitto, could you please check if you're happy with the merge?

examples/README.md Outdated Show resolved Hide resolved
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 confirmed that the menu is correctly populated and organized when testing 👍

@kittaakos
Copy link
Contributor

@dhuebner, can you please squash your commits? Thank you!

Update packages/git/src/browser/git-contribution.ts
Co-authored-by: Vincent Fugnitto <[email protected]>

Signed-off-by: Dennis Hübner <[email protected]>
@dhuebner
Copy link
Member Author

@kittaakos
Done!

@kittaakos kittaakos merged commit a8dec8d into eclipse-theia:master Apr 26, 2021
@vince-fugnitto vince-fugnitto added this to the 1.13.0 milestone Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
git issues related to git ui/ux issues related to user interface / user experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants