diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index b05bb0735d692f5ca4a582ebf2a42c8130f9095b..bd13a07e96d87ff10401c862c9255ac41561b1b8 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -5447,7 +5447,10 @@ declare module 'vscode' { export namespace scm { /** - * The [input box](#SourceControlInputBox) in the Source Control viewlet. + * The [input box](#SourceControlInputBox) for the last source control + * created by the extension. + * + * @deprecated Use [SourceControl.inputBox](#SourceControl.inputBox) instead */ export const inputBox: SourceControlInputBox; diff --git a/src/vs/workbench/api/electron-browser/mainThreadSCM.ts b/src/vs/workbench/api/electron-browser/mainThreadSCM.ts index 685f6242f9cb6fb058bb684f444fc690424a310b..d9119994320ca88422adf3036da47b6310c8246e 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadSCM.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadSCM.ts @@ -9,7 +9,7 @@ import { TPromise } from 'vs/base/common/winjs.base'; import URI from 'vs/base/common/uri'; import Event, { Emitter } from 'vs/base/common/event'; import { assign } from 'vs/base/common/objects'; -import { IDisposable, dispose } from 'vs/base/common/lifecycle'; +import { IDisposable, dispose, combinedDisposable } from 'vs/base/common/lifecycle'; import { ISCMService, ISCMProvider, ISCMResource, ISCMResourceGroup, ISCMResourceDecorations } from 'vs/workbench/services/scm/common/scm'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { ICommandService } from 'vs/platform/commands/common/commands'; @@ -231,9 +231,6 @@ export class MainThreadSCM implements MainThreadSCMShape { @ICommandService private commandService: ICommandService ) { this._proxy = extHostContext.get(ExtHostContext.ExtHostSCM); - - this.scmService.onDidChangeProvider(this.onDidChangeProvider, this, this._disposables); - this.scmService.input.onDidChange(this._proxy.$onInputBoxValueChange, this._proxy, this._disposables); } dispose(): void { @@ -251,7 +248,10 @@ export class MainThreadSCM implements MainThreadSCMShape { $registerSourceControl(handle: number, id: string, label: string): void { const provider = new MainThreadSCMProvider(this._proxy, handle, id, label, this.scmService, this.commandService); this._sourceControls[handle] = provider; - this._sourceControlDisposables[handle] = this.scmService.registerSCMProvider(provider); + + const providerDisposable = this.scmService.registerSCMProvider(provider); + const inputDisposable = this.scmService.input.onDidChange(value => this._proxy.$onInputBoxValueChange(handle, value)); + this._sourceControlDisposables[handle] = combinedDisposable([providerDisposable, inputDisposable]); } $updateSourceControl(handle: number, features: SCMProviderFeatures): void { @@ -331,9 +331,4 @@ export class MainThreadSCM implements MainThreadSCMShape { $setInputBoxValue(value: string): void { this.scmService.input.value = value; } - - private onDidChangeProvider(provider: ISCMProvider): void { - const handle = Object.keys(this._sourceControls).filter(handle => this._sourceControls[handle] === provider)[0]; - this._proxy.$onActiveSourceControlChange(handle && parseInt(handle)); - } } diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index 76658ed41a1da4ee2a6d1980ef1f76e94205225c..49ab193559e28e80b31b62be2e6c04506700563a 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -472,7 +472,7 @@ export function createApiFactory( // namespace: scm const scm: typeof vscode.scm = { get inputBox() { - return extHostSCM.inputBox; + return extHostSCM.getLastInputBox(extension); }, createSourceControl(id: string, label: string) { telemetryService.publicLog('registerSCMProvider', { @@ -481,7 +481,7 @@ export function createApiFactory( providerLabel: label }); - return extHostSCM.createSourceControl(id, label); + return extHostSCM.createSourceControl(extension, id, label); } }; diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 6e9b29c06ac950012f97cadd659ba4bbe75703a7..31490f5317e6d0221e08da8f93c82e076b5682f9 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -508,9 +508,7 @@ export interface ExtHostTerminalServiceShape { export interface ExtHostSCMShape { $provideOriginalResource(sourceControlHandle: number, uri: URI): TPromise; - $onActiveSourceControlChange(sourceControlHandle: number): TPromise; - $onInputBoxValueChange(value: string): TPromise; - $onInputBoxAcceptChanges(): TPromise; + $onInputBoxValueChange(sourceControlHandle: number, value: string): TPromise; } export interface ExtHostTaskShape { diff --git a/src/vs/workbench/api/node/extHostSCM.ts b/src/vs/workbench/api/node/extHostSCM.ts index 059ce5e86fe6060318a8c780f13dd5e588c6dae2..16b1c4ef6da106eaa7a80bf04f568d83193439f3 100644 --- a/src/vs/workbench/api/node/extHostSCM.ts +++ b/src/vs/workbench/api/node/extHostSCM.ts @@ -8,6 +8,7 @@ import URI from 'vs/base/common/uri'; import { TPromise } from 'vs/base/common/winjs.base'; import Event, { Emitter } from 'vs/base/common/event'; import { asWinJsPromise } from 'vs/base/common/async'; +import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'; import { ExtHostCommands, CommandsConverter } from 'vs/workbench/api/node/extHostCommands'; import { MainContext, MainThreadSCMShape, SCMRawResource, IMainContext } from './extHost.protocol'; import * as vscode from 'vscode'; @@ -42,12 +43,6 @@ export class ExtHostSCMInputBox { return this._onDidChange.event; } - private _onDidAccept = new Emitter(); - - get onDidAccept(): Event { - return this._onDidAccept.event; - } - constructor(private _proxy: MainThreadSCMShape) { // noop } @@ -56,10 +51,6 @@ export class ExtHostSCMInputBox { this.updateValue(value); } - $onInputBoxAcceptChanges(): void { - this._onDidAccept.fire(this._value); - } - private updateValue(value: string): void { this._value = value; this._onDidChange.fire(value); @@ -171,6 +162,9 @@ class ExtHostSourceControl implements vscode.SourceControl { return this._label; } + private _inputBox: ExtHostSCMInputBox; + get inputBox(): ExtHostSCMInputBox { return this._inputBox; } + private _count: number | undefined = undefined; get count(): number | undefined { @@ -238,6 +232,7 @@ class ExtHostSourceControl implements vscode.SourceControl { private _id: string, private _label: string, ) { + this._inputBox = new ExtHostSCMInputBox(this._proxy); this._proxy.$registerSourceControl(this._handle, _id, _label); } @@ -266,22 +261,16 @@ export class ExtHostSCM { private _proxy: MainThreadSCMShape; private _sourceControls: Map = new Map(); + private _sourceControlsByExtension: Map = new Map(); private _onDidChangeActiveProvider = new Emitter(); get onDidChangeActiveProvider(): Event { return this._onDidChangeActiveProvider.event; } - private _activeProvider: vscode.SourceControl | undefined; - get activeProvider(): vscode.SourceControl | undefined { return this._activeProvider; } - - private _inputBox: ExtHostSCMInputBox; - get inputBox(): ExtHostSCMInputBox { return this._inputBox; } - constructor( mainContext: IMainContext, private _commands: ExtHostCommands ) { this._proxy = mainContext.get(MainContext.MainThreadSCM); - this._inputBox = new ExtHostSCMInputBox(this._proxy); _commands.registerArgumentProcessor({ processArgument: arg => { @@ -322,14 +311,27 @@ export class ExtHostSCM { }); } - createSourceControl(id: string, label: string): vscode.SourceControl { + createSourceControl(extension: IExtensionDescription, id: string, label: string): vscode.SourceControl { const handle = ExtHostSCM._handlePool++; const sourceControl = new ExtHostSourceControl(this._proxy, this._commands.converter, id, label); this._sourceControls.set(handle, sourceControl); + const sourceControls = this._sourceControlsByExtension.get(extension.id) || []; + sourceControls.push(sourceControl); + this._sourceControlsByExtension.set(extension.id, sourceControls); + return sourceControl; } + // Deprecated + getLastInputBox(extension: IExtensionDescription): ExtHostSCMInputBox { + const sourceControls = this._sourceControlsByExtension.get(extension.id); + const sourceControl = sourceControls && sourceControls[sourceControls.length - 1]; + const inputBox = sourceControl && sourceControl.inputBox; + + return inputBox; + } + $provideOriginalResource(sourceControlHandle: number, uri: URI): TPromise { const sourceControl = this._sourceControls.get(sourceControlHandle); @@ -343,18 +345,14 @@ export class ExtHostSCM { }); } - $onActiveSourceControlChange(handle: number): TPromise { - this._activeProvider = this._sourceControls.get(handle); - return TPromise.as(null); - } + $onInputBoxValueChange(sourceControlHandle: number, value: string): TPromise { + const sourceControl = this._sourceControls.get(sourceControlHandle); - $onInputBoxValueChange(value: string): TPromise { - this._inputBox.$onInputBoxValueChange(value); - return TPromise.as(null); - } + if (!sourceControl || !sourceControl.quickDiffProvider) { + return TPromise.as(null); + } - $onInputBoxAcceptChanges(): TPromise { - this._inputBox.$onInputBoxAcceptChanges(); + sourceControl.inputBox.$onInputBoxValueChange(value); return TPromise.as(null); } }