Skip to content

Commit

Permalink
[git] Group the context menu items per Git command eclipse-theia#8400
Browse files Browse the repository at this point in the history
Update packages/git/src/browser/git-contribution.ts
Co-authored-by: Vincent Fugnitto <[email protected]>

Signed-off-by: Dennis Hübner <[email protected]>
  • Loading branch information
dhuebner authored and kittaakos committed Apr 26, 2021
1 parent 88caf97 commit a8dec8d
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 9 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/browser/shell/tab-bar-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
100 changes: 91 additions & 9 deletions packages/git/src/browser/git-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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...'
Expand All @@ -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...'
Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a8dec8d

Please sign in to comment.