From a8dec8d798342631f2ab3a84bec4b8fdc4621d61 Mon Sep 17 00:00:00 2001 From: Dennis Huebner Date: Fri, 26 Mar 2021 14:30:22 +0000 Subject: [PATCH] [git] Group the context menu items per Git command #8400 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update packages/git/src/browser/git-contribution.ts Co-authored-by: Vincent Fugnitto Signed-off-by: Dennis Hübner --- .../src/browser/shell/tab-bar-toolbar.tsx | 2 + packages/git/src/browser/git-contribution.ts | 100 ++++++++++++++++-- 2 files changed, 93 insertions(+), 9 deletions(-) diff --git a/packages/core/src/browser/shell/tab-bar-toolbar.tsx b/packages/core/src/browser/shell/tab-bar-toolbar.tsx index 9b67a757c26de..b49b37e830d5a 100644 --- a/packages/core/src/browser/shell/tab-bar-toolbar.tsx +++ b/packages/core/src/browser/shell/tab-bar-toolbar.tsx @@ -179,9 +179,11 @@ export class TabBarToolbar extends ReactWidget { const paths: string[] = []; for (let i = 0; i < split.length - 1; i += 2) { paths.push(split[i], split[i + 1]); + // TODO order is missing, items sorting will be alphabetic toDisposeOnHide.push(this.menus.registerSubmenu([...menuPath, ...paths], split[i + 1])); } } + // TODO order is missing, items sorting will be alphabetic toDisposeOnHide.push(this.menus.registerMenuAction([...menuPath, ...item.group!.split('/')], { label: item.tooltip, commandId: item.id, diff --git a/packages/git/src/browser/git-contribution.ts b/packages/git/src/browser/git-contribution.ts index be587fdbf7999..e86b839b43fe6 100644 --- a/packages/git/src/browser/git-contribution.ts +++ b/packages/git/src/browser/git-contribution.ts @@ -61,6 +61,10 @@ export namespace GIT_COMMANDS { id: 'git.pull.default', label: 'Git: Pull' }; + export const PULL_DEFAULT_FAVORITE = { + id: PULL_DEFAULT.id + '.favorite', + label: PULL_DEFAULT.label + }; export const PULL = { id: 'git.pull', label: 'Git: Pull from...' @@ -69,6 +73,10 @@ export namespace GIT_COMMANDS { id: 'git.push.default', label: 'Git: Push' }; + export const PUSH_DEFAULT_FAVORITE = { + id: PUSH_DEFAULT.id + '.favorite', + label: PUSH_DEFAULT.label + }; export const PUSH = { id: 'git.push', label: 'Git: Push to...' @@ -204,7 +212,32 @@ export namespace GIT_COMMANDS { category: 'Git' }; } +export namespace GIT_MENUS { + // Top level Groups + export const FAV_GROUP = '2_favorites'; + export const COMMANDS_GROUP = '3_commands'; + export const SUBMENU_COMMIT = { + group: COMMANDS_GROUP, + label: 'Commit', + menuGroups: ['1_commit'], + }; + export const SUBMENU_CHANGES = { + group: COMMANDS_GROUP, + label: 'Changes', + menuGroups: ['1_changes'] + }; + export const SUBMENU_PULL_PUSH = { + group: COMMANDS_GROUP, + label: 'Pull, Push', + menuGroups: ['2_pull', '3_push', '4_fetch'] + }; + export const SUBMENU_STASH = { + group: COMMANDS_GROUP, + label: 'Stash', + menuGroups: ['1_stash'] + }; +} @injectable() export class GitContribution implements CommandContribution, MenuContribution, TabBarToolbarContribution, ColorContribution { @@ -339,6 +372,10 @@ export class GitContribution implements CommandContribution, MenuContribution, T execute: () => this.withProgress(() => this.quickOpenService.performDefaultGitAction(GitAction.PULL)), isEnabled: () => !!this.repositoryTracker.selectedRepository }); + registry.registerCommand(GIT_COMMANDS.PULL_DEFAULT_FAVORITE, { + execute: () => registry.executeCommand(GIT_COMMANDS.PULL_DEFAULT.id), + isEnabled: () => !!this.repositoryTracker.selectedRepository + }); registry.registerCommand(GIT_COMMANDS.PULL, { execute: () => this.withProgress(() => this.quickOpenService.pull()), isEnabled: () => !!this.repositoryTracker.selectedRepository @@ -347,6 +384,10 @@ export class GitContribution implements CommandContribution, MenuContribution, T execute: () => this.withProgress(() => this.quickOpenService.performDefaultGitAction(GitAction.PUSH)), isEnabled: () => !!this.repositoryTracker.selectedRepository }); + registry.registerCommand(GIT_COMMANDS.PUSH_DEFAULT_FAVORITE, { + execute: () => registry.executeCommand(GIT_COMMANDS.PUSH_DEFAULT.id), + isEnabled: () => !!this.repositoryTracker.selectedRepository + }); registry.registerCommand(GIT_COMMANDS.PUSH, { execute: () => this.withProgress(() => this.quickOpenService.push()), isEnabled: () => !!this.repositoryTracker.selectedRepository @@ -568,56 +609,97 @@ export class GitContribution implements CommandContribution, MenuContribution, T command: GIT_COMMANDS.COMMIT_ADD_SIGN_OFF.id, tooltip: GIT_COMMANDS.COMMIT_ADD_SIGN_OFF.label }); + + // Favorites menu group + [GIT_COMMANDS.PULL_DEFAULT_FAVORITE, GIT_COMMANDS.PUSH_DEFAULT_FAVORITE].forEach((command, index) => + registerItem({ + id: command.id + '_fav', + command: command.id, + tooltip: command.label.slice('Git: '.length), + group: GIT_MENUS.FAV_GROUP, + priority: 100 - index + }) + ); + registerItem({ id: GIT_COMMANDS.COMMIT_AMEND.id, command: GIT_COMMANDS.COMMIT_AMEND.id, tooltip: 'Commit (Amend)', - group: '1_input' + group: this.asSubMenuItemOf(GIT_MENUS.SUBMENU_COMMIT) }); registerItem({ id: GIT_COMMANDS.COMMIT_SIGN_OFF.id, command: GIT_COMMANDS.COMMIT_SIGN_OFF.id, tooltip: 'Commit (Signed Off)', - group: '1_input' + group: this.asSubMenuItemOf(GIT_MENUS.SUBMENU_COMMIT) }); - [GIT_COMMANDS.FETCH, GIT_COMMANDS.PULL_DEFAULT, GIT_COMMANDS.PULL, GIT_COMMANDS.PUSH_DEFAULT, GIT_COMMANDS.PUSH, GIT_COMMANDS.MERGE].forEach(command => + [GIT_COMMANDS.PULL_DEFAULT, GIT_COMMANDS.PULL].forEach(command => + registerItem({ + id: command.id, + command: command.id, + tooltip: command.label.slice('Git: '.length), + group: this.asSubMenuItemOf(GIT_MENUS.SUBMENU_PULL_PUSH) + }) + ); + [GIT_COMMANDS.PUSH_DEFAULT, GIT_COMMANDS.PUSH].forEach(command => registerItem({ id: command.id, command: command.id, tooltip: command.label.slice('Git: '.length), - group: '2_other' + group: this.asSubMenuItemOf(GIT_MENUS.SUBMENU_PULL_PUSH, 1) }) ); + registerItem({ + id: GIT_COMMANDS.FETCH.id, + command: GIT_COMMANDS.FETCH.id, + tooltip: GIT_COMMANDS.FETCH.label.slice('Git: '.length), + group: this.asSubMenuItemOf(GIT_MENUS.SUBMENU_PULL_PUSH, 2) + }); + [ GIT_COMMANDS.STASH, GIT_COMMANDS.APPLY_STASH, GIT_COMMANDS.APPLY_LATEST_STASH, GIT_COMMANDS.POP_STASH, GIT_COMMANDS.POP_LATEST_STASH, GIT_COMMANDS.DROP_STASH - ].forEach(command => + ].forEach((command, index) => registerItem({ id: command.id, command: command.id, tooltip: command.label, - group: '3_other' + group: this.asSubMenuItemOf(GIT_MENUS.SUBMENU_STASH), + priority: 100 - index }) ); registerItem({ id: GIT_COMMANDS.STAGE_ALL.id, command: GIT_COMMANDS.STAGE_ALL.id, tooltip: 'Stage All Changes', - group: '3_batch' + group: this.asSubMenuItemOf(GIT_MENUS.SUBMENU_CHANGES), + priority: 30 }); registerItem({ id: GIT_COMMANDS.UNSTAGE_ALL.id, command: GIT_COMMANDS.UNSTAGE_ALL.id, tooltip: 'Unstage All Changes', - group: '3_batch' + group: this.asSubMenuItemOf(GIT_MENUS.SUBMENU_CHANGES), + priority: 20 }); registerItem({ id: GIT_COMMANDS.DISCARD_ALL.id, command: GIT_COMMANDS.DISCARD_ALL.id, tooltip: 'Discard All Changes', - group: '3_batch' + group: this.asSubMenuItemOf(GIT_MENUS.SUBMENU_CHANGES), + priority: 10 }); + registerItem({ + id: GIT_COMMANDS.MERGE.id, + command: GIT_COMMANDS.MERGE.id, + tooltip: GIT_COMMANDS.MERGE.label.slice('Git: '.length), + group: GIT_MENUS.COMMANDS_GROUP + }); + } + + protected asSubMenuItemOf(submenu: { group: string; label: string; menuGroups: string[]; }, groupIdx: number = 0): string { + return submenu.group + '/' + submenu.label + '/' + submenu.menuGroups[groupIdx]; } protected hasConflicts(changes: GitFileChange[]): boolean {