scm: hide input box model from extension host

This commit is contained in:
Joao Moreno
2017-02-03 17:20:26 +01:00
parent d7382f0d55
commit 3eddf71678
11 changed files with 107 additions and 50 deletions

View File

@@ -424,6 +424,11 @@ export function createApiFactory(initData: IInitData, threadService: IThreadServ
return extHostSCM.onDidChangeActiveProvider;
}
@proposed(extension)
get inputBox() {
return extHostSCM.inputBox;
}
@proposed(extension)
getResourceFromURI(uri) {
return extHostSCM.getResourceFromURI(uri);

View File

@@ -259,6 +259,7 @@ export abstract class MainThreadSCMShape {
$register(id: string, features: SCMProviderFeatures): void { throw ni(); }
$unregister(id: string): void { throw ni(); }
$onChange(id: string, resources: SCMRawResourceGroup[], count: number | undefined): void { throw ni(); }
$setInputBoxValue(value: string): void { throw ni(); }
}
// -- extension host
@@ -394,6 +395,7 @@ export abstract class ExtHostSCMShape {
$open(id: string, resourceGroupId: string, uri: string): TPromise<void> { throw ni(); }
$drag(id: string, fromResourceGroupId: string, fromUri: string, toResourceGroupId: string): TPromise<void> { throw ni(); }
$getOriginalResource(id: string, uri: URI): TPromise<URI> { throw ni(); }
$onInputBoxValueChange(value: string): TPromise<void> { throw ni(); }
}
// --- proxy identifiers

View File

@@ -33,6 +33,39 @@ export interface Cache {
};
}
class ExtHostSCMInputBox {
private _value: string = '';
get value(): string {
return this._value;
}
set value(value: string) {
this._proxy.$setInputBoxValue(value);
this.updateValue(value);
}
private _onDidChange = new Emitter<string>();
get onDidChange(): Event<string> {
return this._onDidChange.event;
}
constructor(private _proxy: MainThreadSCMShape) {
// noop
}
$onInputBoxValueChange(value: string): void {
this.updateValue(value);
}
private updateValue(value: string): void {
this._value = value;
this._onDidChange.fire(value);
}
}
export class ExtHostSCM {
private _proxy: MainThreadSCMShape;
@@ -44,10 +77,14 @@ export class ExtHostSCM {
private _activeProvider: vscode.SCMProvider;
get activeProvider(): vscode.SCMProvider | undefined { return this._activeProvider; }
private _inputBox: ExtHostSCMInputBox;
get inputBox(): vscode.SCMInputBox { return this._inputBox; }
private cache: Cache = Object.create(null);
constructor(threadService: IThreadService) {
this._proxy = threadService.get(MainContext.MainThreadSCM);
this._inputBox = new ExtHostSCMInputBox(this._proxy);
}
getResourceFromURI(uri: vscode.Uri): vscode.SCMResource | vscode.SCMResourceGroup | undefined {
@@ -209,4 +246,9 @@ export class ExtHostSCM {
return asWinJsPromise(token => provider.getOriginalResource(uri, token));
}
$onInputBoxValueChange(value: string): TPromise<void> {
this._inputBox.$onInputBoxValueChange(value);
return TPromise.as(null);
}
}

View File

@@ -110,13 +110,19 @@ export class MainThreadSCM extends MainThreadSCMShape {
private proxy: ExtHostSCMShape;
private providers: { [id: string]: MainThreadSCMProvider; } = Object.create(null);
private inputBoxListener: IDisposable;
constructor(
@IThreadService threadService: IThreadService,
@IInstantiationService private instantiationService: IInstantiationService
@IInstantiationService private instantiationService: IInstantiationService,
@ISCMService private scmService: ISCMService
) {
super();
this.proxy = threadService.get(ExtHostContext.ExtHostSCM);
this.inputBoxListener = this.scmService.inputBoxModel.onDidChangeContent(e => {
this.proxy.$onInputBoxValueChange(this.scmService.inputBoxModel.getValue());
});
}
$register(id: string, features: SCMProviderFeatures): void {
@@ -144,10 +150,15 @@ export class MainThreadSCM extends MainThreadSCMShape {
provider.$onChange(rawResourceGroups, count);
}
$setInputBoxValue(value: string): void {
this.scmService.inputBoxModel.setValue(value);
}
dispose(): void {
Object.keys(this.providers)
.forEach(id => this.providers[id].dispose());
this.providers = Object.create(null);
this.inputBoxListener = dispose(this.inputBoxListener);
}
}