diff --git a/src/vs/workbench/api/node/mainThreadSCM.ts b/src/vs/workbench/api/node/mainThreadSCM.ts index b6572f01934..76f7f976ea1 100644 --- a/src/vs/workbench/api/node/mainThreadSCM.ts +++ b/src/vs/workbench/api/node/mainThreadSCM.ts @@ -24,7 +24,7 @@ class MainThreadSCMResourceGroup implements ISCMResourceGroup { public provider: ISCMProvider, public features: SCMGroupFeatures, public label: string, - public contextKey: string, + public id: string, public resources: ISCMResource[] ) { } @@ -76,7 +76,7 @@ class MainThreadSCMProvider implements ISCMProvider { get handle(): number { return this._handle; } get label(): string { return this._label; } - get contextKey(): string { return this._id; } + get id(): string { return this._id; } get commitTemplate(): string | undefined { return this.features.commitTemplate; } get acceptInputCommand(): Command | undefined { return this.features.acceptInputCommand; } diff --git a/src/vs/workbench/parts/scm/electron-browser/scm.contribution.ts b/src/vs/workbench/parts/scm/electron-browser/scm.contribution.ts index 64e62f8cd3c..b372695a4bd 100644 --- a/src/vs/workbench/parts/scm/electron-browser/scm.contribution.ts +++ b/src/vs/workbench/parts/scm/electron-browser/scm.contribution.ts @@ -33,7 +33,6 @@ class OpenSCMViewletAction extends ToggleViewletAction { } } -// TODO@Joao export class SwitchProvider extends Action { static readonly ID = 'scm.switch'; diff --git a/src/vs/workbench/parts/scm/electron-browser/scmUtil.ts b/src/vs/workbench/parts/scm/electron-browser/scmUtil.ts index 2032354475f..3970c0b7883 100644 --- a/src/vs/workbench/parts/scm/electron-browser/scmUtil.ts +++ b/src/vs/workbench/parts/scm/electron-browser/scmUtil.ts @@ -12,5 +12,5 @@ export function isSCMResource(element: ISCMResourceGroup | ISCMResource): elemen } export function getSCMResourceContextKey(resource: ISCMResourceGroup | ISCMResource): string { - return isSCMResource(resource) ? resource.resourceGroup.contextKey : resource.contextKey; + return isSCMResource(resource) ? resource.resourceGroup.id : resource.id; } \ No newline at end of file diff --git a/src/vs/workbench/parts/scm/electron-browser/scmViewlet.ts b/src/vs/workbench/parts/scm/electron-browser/scmViewlet.ts index 6c5c5c1a3ab..375539eef35 100644 --- a/src/vs/workbench/parts/scm/electron-browser/scmViewlet.ts +++ b/src/vs/workbench/parts/scm/electron-browser/scmViewlet.ts @@ -60,16 +60,14 @@ class SCMMenuItemActionItem extends MenuItemActionItem { } } -// TODO@Joao -// Rename contextKey to something else function identityProvider(r: ISCMResourceGroup | ISCMResource): string { if (isSCMResource(r)) { const group = r.resourceGroup; const provider = group.provider; - return `${provider.contextKey}/${group.contextKey}/${r.sourceUri.toString()}`; + return `${provider.id}/${group.id}/${r.sourceUri.toString()}`; } else { const provider = r.provider; - return `${provider.contextKey}/${r.contextKey}`; + return `${provider.id}/${r.id}`; } } diff --git a/src/vs/workbench/services/scm/common/scm.ts b/src/vs/workbench/services/scm/common/scm.ts index 30fa58366bb..e6eaaf95c34 100644 --- a/src/vs/workbench/services/scm/common/scm.ts +++ b/src/vs/workbench/services/scm/common/scm.ts @@ -17,6 +17,7 @@ export interface IBaselineResourceProvider { } export const ISCMService = createDecorator('scm'); +export const DefaultSCMProviderIdStorageKey = 'settings.workspace.scm.defaultProviderId'; export interface ISCMResourceDecorations { icon?: URI; @@ -34,13 +35,13 @@ export interface ISCMResource { export interface ISCMResourceGroup { readonly provider: ISCMProvider; readonly label: string; - readonly contextKey?: string; + readonly id: string; readonly resources: ISCMResource[]; } export interface ISCMProvider extends IDisposable { readonly label: string; - readonly contextKey?: string; + readonly id: string; readonly resources: ISCMResourceGroup[]; readonly onDidChange: Event; readonly count?: number; diff --git a/src/vs/workbench/services/scm/common/scmService.ts b/src/vs/workbench/services/scm/common/scmService.ts index 8a146558a0e..f05e8810711 100644 --- a/src/vs/workbench/services/scm/common/scmService.ts +++ b/src/vs/workbench/services/scm/common/scmService.ts @@ -10,7 +10,8 @@ import Event, { Emitter } from 'vs/base/common/event'; import { memoize } from 'vs/base/common/decorators'; import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey'; import { IStatusbarService, StatusbarAlignment as MainThreadStatusBarAlignment } from 'vs/platform/statusbar/common/statusbar'; -import { ISCMService, ISCMProvider, ISCMInput } from './scm'; +import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; +import { ISCMService, ISCMProvider, ISCMInput, DefaultSCMProviderIdStorageKey } from './scm'; class SCMInput implements ISCMInput { @@ -44,6 +45,28 @@ export class SCMService implements ISCMService { } set activeProvider(provider: ISCMProvider | undefined) { + this.setActiveSCMProdiver(provider); + this.storageService.store(DefaultSCMProviderIdStorageKey, provider.id, StorageScope.WORKSPACE); + } + + private _providers: ISCMProvider[] = []; + get providers(): ISCMProvider[] { return [...this._providers]; } + + private _onDidChangeProvider = new Emitter(); + get onDidChangeProvider(): Event { return this._onDidChangeProvider.event; } + + @memoize + get input(): ISCMInput { return new SCMInput(); } + + constructor( + @IContextKeyService contextKeyService: IContextKeyService, + @IStorageService private storageService: IStorageService, + @IStatusbarService private statusbarService: IStatusbarService + ) { + this.activeProviderContextKey = contextKeyService.createKey('scmProvider', void 0); + } + + private setActiveSCMProdiver(provider: ISCMProvider): void { this.activeProviderDisposable.dispose(); if (!provider) { @@ -59,31 +82,17 @@ export class SCMService implements ISCMService { this.activeProviderDisposable = provider.onDidChange(() => this.onDidProviderChange(provider)); this.onDidProviderChange(provider); - this.activeProviderContextKey.set(provider ? provider.contextKey : void 0); + this.activeProviderContextKey.set(provider ? provider.id : void 0); this._onDidChangeProvider.fire(provider); } - private _providers: ISCMProvider[] = []; - get providers(): ISCMProvider[] { return [...this._providers]; } - - private _onDidChangeProvider = new Emitter(); - get onDidChangeProvider(): Event { return this._onDidChangeProvider.event; } - - @memoize - get input(): ISCMInput { return new SCMInput(); } - - constructor( - @IContextKeyService contextKeyService: IContextKeyService, - @IStatusbarService private statusbarService: IStatusbarService - ) { - this.activeProviderContextKey = contextKeyService.createKey('scmProvider', void 0); - } - registerSCMProvider(provider: ISCMProvider): IDisposable { - this._providers = [provider, ...this._providers]; + this._providers.push(provider); - if (this._providers.length === 1) { - this.activeProvider = provider; + const defaultProviderId = this.storageService.get(DefaultSCMProviderIdStorageKey, StorageScope.WORKSPACE); + + if (this._providers.length === 1 || defaultProviderId === provider.id) { + this.setActiveSCMProdiver(provider); } return toDisposable(() => {