Skip to content

Commit

Permalink
scm: install additional scm providers
Browse files Browse the repository at this point in the history
fixes #25696
  • Loading branch information
isidorn committed May 18, 2017
1 parent 258bde4 commit d38e245
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
14 changes: 13 additions & 1 deletion src/vs/workbench/parts/scm/electron-browser/scm.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { VIEWLET_ID } from 'vs/workbench/parts/scm/common/scm';
import { IWorkbenchActionRegistry, Extensions as WorkbenchActionExtensions } from 'vs/workbench/common/actionRegistry';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IExtensionsViewlet, VIEWLET_ID as EXTENSIONS_VIEWLET_ID } from 'vs/workbench/parts/extensions/common/extensions';
import { ISCMService } from 'vs/workbench/services/scm/common/scm';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
Expand All @@ -41,7 +42,8 @@ export class SwitchProvider extends Action {
id = SwitchProvider.ID,
label = SwitchProvider.LABEL,
@ISCMService private scmService: ISCMService,
@IQuickOpenService private quickOpenService: IQuickOpenService
@IQuickOpenService private quickOpenService: IQuickOpenService,
@IViewletService private viewletService: IViewletService
) {
super('scm.switchprovider', 'Switch SCM Provider', '', true);
}
Expand All @@ -51,6 +53,16 @@ export class SwitchProvider extends Action {
label: provider.label,
run: () => this.scmService.activeProvider = provider
}));
picks.push({
label: localize('installAdditionalSCMProviders', "Install Additional SCM Providers..."), run: () => {
this.viewletService.openViewlet(EXTENSIONS_VIEWLET_ID, true).then(viewlet => viewlet as IExtensionsViewlet)
.then(viewlet => {
viewlet.search('category:"SCM Providers" @sort:installs');
viewlet.focus();
});
return this.scmService.activeProvider;
}
});

return this.quickOpenService.pick(picks);
}
Expand Down
32 changes: 26 additions & 6 deletions src/vs/workbench/parts/scm/electron-browser/scmMenus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { IAction, Action } from 'vs/base/common/actions';
import { fillInActions } from 'vs/platform/actions/browser/menuItemActionItem';
import { ContextSubMenu } from 'vs/platform/contextview/browser/contextView';
import { Separator } from 'vs/base/browser/ui/actionbar/actionbar';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IExtensionsViewlet, VIEWLET_ID as EXTENSIONS_VIEWLET_ID } from 'vs/workbench/parts/extensions/common/extensions';
import { ISCMService, ISCMProvider, ISCMResource, ISCMResourceGroup } from 'vs/workbench/services/scm/common/scm';
import { getSCMResourceContextKey } from './scmUtil';

Expand All @@ -38,6 +40,21 @@ class SwitchProviderAction extends Action {
}
}

class InstallAdditionalSCMProviders extends Action {

constructor(private viewletService: IViewletService) {
super('scm.installAdditionalSCMProviders', localize('installAdditionalSCMProviders', "Install Additional SCM Providers..."), '', true);
}

run(): TPromise<void> {
return this.viewletService.openViewlet(EXTENSIONS_VIEWLET_ID, true).then(viewlet => viewlet as IExtensionsViewlet)
.then(viewlet => {
viewlet.search('category:"SCM Providers" @sort:installs');
viewlet.focus();
});
}
}

export class SCMMenus implements IDisposable {

private disposables: IDisposable[] = [];
Expand All @@ -52,7 +69,8 @@ export class SCMMenus implements IDisposable {
constructor(
@IContextKeyService private contextKeyService: IContextKeyService,
@ISCMService private scmService: ISCMService,
@IMenuService private menuService: IMenuService
@IMenuService private menuService: IMenuService,
@IViewletService private viewletService: IViewletService
) {
this.setActiveProvider(this.scmService.activeProvider);
this.scmService.onDidChangeProvider(this.setActiveProvider, this, this.disposables);
Expand Down Expand Up @@ -92,22 +110,24 @@ export class SCMMenus implements IDisposable {
}

getTitleSecondaryActions(): IAction[] {
const providerSwitchActions = this.scmService.providers
const providerSwitchActions: IAction[] = this.scmService.providers
.map(p => new SwitchProviderAction(p, this.scmService));

let result = [];

if (this.titleSecondaryActions.length > 0) {
result = result.concat(this.titleSecondaryActions);
}
if (providerSwitchActions.length > 0) {
providerSwitchActions.push(new Separator());
}
providerSwitchActions.push(new InstallAdditionalSCMProviders(this.viewletService));

if (result.length > 0 && providerSwitchActions.length > 0) {
if (result.length > 0) {
result.push(new Separator());
}

if (providerSwitchActions.length > 0) {
result.push(new ContextSubMenu(localize('switch provider', "Switch SCM Provider..."), providerSwitchActions));
}
result.push(new ContextSubMenu(localize('switch provider', "Switch SCM Provider..."), providerSwitchActions));

return result;
}
Expand Down

0 comments on commit d38e245

Please sign in to comment.