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

fixup! Add Scm component and bind Git to it #5256

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions packages/core/src/common/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ export interface Command {
* A category of this command.
*/
category?: string;

// tslint:disable-next-line:no-any
props?: { [key: string]: any }
}

export namespace Command {
Expand Down
68 changes: 53 additions & 15 deletions packages/git/src/browser/git-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ export namespace GIT_COMMANDS {
id: 'git.stage.all',
label: 'Stage All Changes',
iconClass: 'fa fa-plus',
category: 'inline',
props: { ['group']: 'inline' }
};
export const UNSTAGE = {
id: 'git.unstage',
Expand All @@ -179,8 +177,6 @@ export namespace GIT_COMMANDS {
id: 'git.unstage.all',
iconClass: 'fa fa-minus',
label: 'Unstage All',
category: 'inline',
props: { ['group']: 'inline' }
};
export const DISCARD = {
id: 'git.discard',
Expand All @@ -191,8 +187,6 @@ export namespace GIT_COMMANDS {
id: 'git.discard.all',
iconClass: 'fa fa-undo',
label: 'Discard All Changes',
category: 'inline',
props: { ['group']: 'inline' }
};
export const STASH = {
id: 'git.stash',
Expand Down Expand Up @@ -824,7 +818,7 @@ export class GitContribution implements
const { upstreamBranch, aheadBehind } = status;
if (upstreamBranch) {
return {
text: '$(refresh)' + (aheadBehind ? ` ${aheadBehind.behind} $(arrow-down) ${aheadBehind.ahead} $(arrow-up)` : ''),
text: '$(refresh)' + (aheadBehind && (aheadBehind.ahead + aheadBehind.behind) > 0 ? ` ${aheadBehind.behind}↓ ${aheadBehind.ahead}` : ''),
command: GIT_COMMANDS.SYNC.id,
tooltip: 'Synchronize Changes'
};
Expand All @@ -837,20 +831,64 @@ export class GitContribution implements
}

registerScmTitleCommands(registry: ScmTitleCommandRegistry): void {
registry.registerCommand({ command: GIT_COMMANDS.REFRESH.id });
registry.registerCommand({ command: GIT_COMMANDS.COMMIT_ADD_SIGN_OFF.id });
registry.registerItem({ command: GIT_COMMANDS.REFRESH.id, group: 'navigation' });
registry.registerItem({ command: GIT_COMMANDS.COMMIT_ADD_SIGN_OFF.id, group: 'navigation'});
}

registerScmResourceCommands(registry: ScmResourceCommandRegistry): void {
registry.registerCommands('Changes', [GIT_COMMANDS.OPEN_CHANGED_FILE.id, GIT_COMMANDS.DISCARD.id, GIT_COMMANDS.STAGE.id]);
registry.registerCommands('Staged changes', [GIT_COMMANDS.OPEN_CHANGED_FILE.id, GIT_COMMANDS.UNSTAGE.id]);
registry.registerCommands('Merged Changes', [GIT_COMMANDS.OPEN_CHANGED_FILE.id, GIT_COMMANDS.DISCARD.id, GIT_COMMANDS.STAGE.id]);
registry.registerItems('Changes', [
{
command: GIT_COMMANDS.OPEN_CHANGED_FILE.id,
group: 'navigation'
},
{
command: GIT_COMMANDS.DISCARD.id,
group: 'navigation'
},
{
command: GIT_COMMANDS.STAGE.id,
group: 'navigation'
}
]);
registry.registerItems('Staged changes', [
{
command: GIT_COMMANDS.OPEN_CHANGED_FILE.id,
group: 'navigation'
},
{
command: GIT_COMMANDS.UNSTAGE.id,
group: 'navigation'
}
]);
registry.registerItems('Merged Changes', [
{
command: GIT_COMMANDS.OPEN_CHANGED_FILE.id,
group: 'navigation'
},
{
command: GIT_COMMANDS.DISCARD.id,
group: 'navigation'
},
{
command: GIT_COMMANDS.STAGE.id,
group: 'navigation'
}
]);
}

registerScmGroupCommands(registry: ScmGroupCommandRegistry): void {
registry.registerCommands('Changes', [GIT_COMMANDS.DISCARD_ALL.id, GIT_COMMANDS.STAGE_ALL.id]);
registry.registerCommands('Staged changes', [GIT_COMMANDS.UNSTAGE_ALL.id]);
registry.registerCommands('Merged Changes', [GIT_COMMANDS.STAGE_ALL.id]);
registry.registerItems('Changes', [
{
command: GIT_COMMANDS.DISCARD_ALL.id,
group: 'inline'
},
{
command: GIT_COMMANDS.STAGE_ALL.id,
group: 'inline'
}
]);
registry.registerItems('Staged changes', [{ command: GIT_COMMANDS.UNSTAGE_ALL.id, group: 'inline' }]);
registry.registerItems('Merged Changes', [{ command: GIT_COMMANDS.STAGE_ALL.id, group: 'inline' }]);
}
}
export interface GitOpenFileOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class MenusContributionPointHandler {
execute: () => this.commands.executeCommand(menuAction.command)
});

this.scmTitleCommandRegistry.registerCommand({ command: id, when: menuAction.when });
this.scmTitleCommandRegistry.registerItem({ command: id, when: menuAction.when, group: menuAction.group });

if (menuAction.group && menuAction.group !== 'navigation') {
const action: MenuAction = { commandId: id };
Expand All @@ -137,7 +137,6 @@ export class MenusContributionPointHandler {
command.iconClass = pluginCommand.iconClass;
command.category = pluginCommand.category;
command.label = pluginCommand.label;
command.props = { ['group']: menuAction.group };
});
}

Expand All @@ -157,15 +156,14 @@ export class MenusContributionPointHandler {
if (action.group !== 'inline') {
this.menuRegistry.registerMenuAction(['scm-group-context-menu_' + group], { commandId: id });
} else {
this.scmGroupCommandRegistry.registerCommand(group, id);
this.scmGroupCommandRegistry.registerItem(group, { command: id, group: action.group });
}
}

this.onDidRegisterCommand(action.command, pluginCommand => {
command.iconClass = pluginCommand.iconClass;
command.category = pluginCommand.category;
command.label = pluginCommand.label;
command.props = { ['group']: action.group };
});
}

Expand All @@ -183,7 +181,7 @@ export class MenusContributionPointHandler {
group = group.substring(0, group.indexOf(' &&'));
}
if (action.group && action.group.startsWith('inline')) {
this.scmResourceCommandRegistry.registerCommand(group, id);
this.scmResourceCommandRegistry.registerItem(group, {command: id, group: 'inline'});
} else {
this.menuRegistry.registerMenuAction(['scm-resource-context-menu_' + group], { commandId: id });
}
Expand All @@ -193,7 +191,6 @@ export class MenusContributionPointHandler {
command.iconClass = pluginCommand.iconClass;
command.category = pluginCommand.category;
command.label = pluginCommand.label;
command.props = { ['group']: action.group };
});
}

Expand Down
35 changes: 20 additions & 15 deletions packages/scm/src/browser/scm-group-command-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ export interface ScmGroupCommandContribution {
registerScmGroupCommands(registry: ScmGroupCommandRegistry): void;
}

export interface ScmGroupItem {
command: string;
group?: string;
}

@injectable()
export class ScmGroupCommandRegistry implements FrontendApplicationContribution {
private commands: Map<string, string[]> = new Map();
private items: Map<string, ScmGroupItem[]> = new Map();

@inject(ContributionProvider)
@named(ScmGroupCommandContribution)
Expand All @@ -39,27 +44,27 @@ export class ScmGroupCommandRegistry implements FrontendApplicationContribution
}
}

registerCommands(groupId: string, commands: string[]): void {
const savedCommands = this.commands.get(groupId);
if (savedCommands) {
commands.forEach(command => savedCommands.push(command));
this.commands.set(groupId, savedCommands);
registerItems(groupId: string, items: ScmGroupItem[]): void {
const savedItems = this.items.get(groupId);
if (savedItems) {
items.forEach(item => savedItems.push(item));
this.items.set(groupId, savedItems);
} else {
this.commands.set(groupId, commands);
this.items.set(groupId, items);
}
}

registerCommand(groupId: string, command: string): void {
const commands = this.commands.get(groupId);
if (commands) {
commands.push(command);
this.commands.set(groupId, commands);
registerItem(groupId: string, item: ScmGroupItem): void {
const items = this.items.get(groupId);
if (items) {
items.push(item);
this.items.set(groupId, items);
} else {
this.commands.set(groupId, [command]);
this.items.set(groupId, [item]);
}
}

getCommands(groupId: string): string[] | undefined {
return this.commands.get(groupId);
getItems(groupId: string): ScmGroupItem[] | undefined {
return this.items.get(groupId);
}
}
35 changes: 20 additions & 15 deletions packages/scm/src/browser/scm-resource-command-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ export interface ScmResourceCommandContribution {
registerScmResourceCommands(registry: ScmResourceCommandRegistry): void;
}

export interface ScmResourceItem {
command: string;
group?: string;
}

@injectable()
export class ScmResourceCommandRegistry implements FrontendApplicationContribution {
private commands: Map<string, string[]> = new Map();
private items: Map<string, ScmResourceItem[]> = new Map();

@inject(ContributionProvider)
@named(ScmResourceCommandContribution)
Expand All @@ -38,27 +43,27 @@ export class ScmResourceCommandRegistry implements FrontendApplicationContributi
}
}

registerCommands(groupId: string, commands: string[]): void {
const savedCommands = this.commands.get(groupId);
if (savedCommands) {
commands.forEach(command => savedCommands.push(command));
this.commands.set(groupId, savedCommands);
registerItems(groupId: string, items: ScmResourceItem[]): void {
const savedItems = this.items.get(groupId);
if (savedItems) {
items.forEach(item => savedItems.push(item));
this.items.set(groupId, savedItems);
} else {
this.commands.set(groupId, commands);
this.items.set(groupId, items);
}
}

registerCommand(groupId: string, command: string): void {
const commands = this.commands.get(groupId);
if (commands) {
commands.push(command);
this.commands.set(groupId, commands);
registerItem(groupId: string, item: ScmResourceItem): void {
const items = this.items.get(groupId);
if (items) {
items.push(item);
this.items.set(groupId, items);
} else {
this.commands.set(groupId, [command]);
this.items.set(groupId, [item]);
}
}

getCommands(groupId: string): string[] | undefined {
return this.commands.get(groupId);
getItems(groupId: string): ScmResourceItem[] | undefined {
return this.items.get(groupId);
}
}
5 changes: 3 additions & 2 deletions packages/scm/src/browser/scm-title-command-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface ScmTitleCommandsContribution {
export interface ScmTitleItem {
command: string;
when?: string;
group?: string;
}

@injectable()
Expand All @@ -42,11 +43,11 @@ export class ScmTitleCommandRegistry implements FrontendApplicationContribution
}
}

registerCommand(item: ScmTitleItem): void {
registerItem(item: ScmTitleItem): void {
this.items.push(item);
}

getCommands(): ScmTitleItem[] {
getItems(): ScmTitleItem[] {
return this.items;
}
}
Loading