提交 79aa19e9 编写于 作者: J Joao Moreno

💥 scm input onDidAccept

上级 ee9982da
......@@ -76,6 +76,7 @@ async function init(context: ExtensionContext, disposables: Disposable[]): Promi
}
}
scm.inputBox.onDidAccept(commandCenter.commitWithInput, commandCenter, disposables);
scm.inputBox.value = await model.getCommitTemplate();
}
......
......@@ -50,10 +50,6 @@ export class GitSCMProvider implements SCMProvider {
return this.commandCenter.open(resource);
}
acceptChanges(): ProviderResult<void> {
return this.commandCenter.commitWithInput();
}
getOriginalResource(uri: Uri): Uri | undefined {
if (uri.scheme !== 'file') {
return;
......
......@@ -733,9 +733,6 @@ declare module 'vscode' {
* @return A thenable which resolves when the resource is open.
*/
open?(resource: SCMResource, token: CancellationToken): ProviderResult<void>;
// TODO@joao: move to SCMInput?
acceptChanges?(token: CancellationToken): ProviderResult<void>;
}
/**
......@@ -752,6 +749,11 @@ declare module 'vscode' {
* An [event](#Event) which fires when the input box value has changed.
*/
readonly onDidChange: Event<string>;
/**
* An [event](#Event) which fires when the user has accepted the changes.
*/
readonly onDidAccept: Event<string>;
}
export namespace scm {
......
......@@ -253,7 +253,6 @@ export abstract class MainProcessExtensionServiceShape {
export interface SCMProviderFeatures {
label: string;
supportsOpen: boolean;
supportsAcceptChanges: boolean;
supportsOriginalResource: boolean;
}
......@@ -419,9 +418,9 @@ export abstract class ExtHostTerminalServiceShape {
export abstract class ExtHostSCMShape {
$open(id: string, uri: string): TPromise<void> { throw ni(); }
$acceptChanges(id: string): TPromise<void> { throw ni(); }
$getOriginalResource(id: string, uri: URI): TPromise<URI> { throw ni(); }
$onInputBoxValueChange(value: string): TPromise<void> { throw ni(); }
$onInputBoxAcceptChanges(): TPromise<void> { throw ni(); }
}
export abstract class ExtHostTaskShape {
......
......@@ -49,6 +49,12 @@ class ExtHostSCMInputBox {
return this._onDidChange.event;
}
private _onDidAccept = new Emitter<string>();
get onDidAccept(): Event<string> {
return this._onDidAccept.event;
}
constructor(private _proxy: MainThreadSCMShape) {
// noop
}
......@@ -57,6 +63,10 @@ class ExtHostSCMInputBox {
this.updateValue(value);
}
$onInputBoxAcceptChanges(): void {
this._onDidAccept.fire(this._value);
}
private updateValue(value: string): void {
this._value = value;
this._onDidChange.fire(value);
......@@ -97,7 +107,6 @@ export class ExtHostSCM {
this._proxy.$register(providerId, {
label: provider.label,
supportsOpen: !!provider.open,
supportsAcceptChanges: !!provider.acceptChanges,
supportsOriginalResource: !!provider.getOriginalResource
});
......@@ -158,16 +167,6 @@ export class ExtHostSCM {
return asWinJsPromise(token => provider.open(resource, token));
}
$acceptChanges(providerId: string): TPromise<void> {
const provider = this._providers[providerId];
if (!provider) {
return TPromise.as(null);
}
return asWinJsPromise(token => provider.acceptChanges(token));
}
$getOriginalResource(id: string, uri: URI): TPromise<URI> {
const provider = this._providers[id];
......@@ -182,4 +181,9 @@ export class ExtHostSCM {
this._inputBox.$onInputBoxValueChange(value);
return TPromise.as(null);
}
$onInputBoxAcceptChanges(): TPromise<void> {
this._inputBox.$onInputBoxAcceptChanges();
return TPromise.as(null);
}
}
......@@ -52,14 +52,6 @@ class MainThreadSCMProvider implements ISCMProvider {
return this.proxy.$open(this.id, resource.uri.toString());
}
acceptChanges(): TPromise<void> {
if (!this.features.supportsAcceptChanges) {
return TPromise.as(null);
}
return this.proxy.$acceptChanges(this.id);
}
getOriginalResource(uri: URI): TPromise<URI> {
if (!this.features.supportsOriginalResource) {
return TPromise.as(null);
......@@ -116,7 +108,7 @@ export class MainThreadSCM extends MainThreadSCMShape {
private proxy: ExtHostSCMShape;
private providers: { [id: string]: MainThreadSCMProvider; } = Object.create(null);
private inputBoxListener: IDisposable;
private inputBoxListeners: IDisposable[] = [];
constructor(
@IThreadService threadService: IThreadService,
......@@ -126,9 +118,8 @@ export class MainThreadSCM extends MainThreadSCMShape {
super();
this.proxy = threadService.get(ExtHostContext.ExtHostSCM);
this.inputBoxListener = this.scmService.input.onDidChange(value => {
this.proxy.$onInputBoxValueChange(value);
});
this.scmService.input.onDidChange(this.proxy.$onInputBoxValueChange, this.proxy, this.inputBoxListeners);
this.scmService.input.onDidAccept(this.proxy.$onInputBoxAcceptChanges, this.proxy, this.inputBoxListeners);
}
$register(id: string, features: SCMProviderFeatures): void {
......@@ -165,6 +156,6 @@ export class MainThreadSCM extends MainThreadSCMShape {
.forEach(id => this.providers[id].dispose());
this.providers = Object.create(null);
this.inputBoxListener = dispose(this.inputBoxListener);
this.inputBoxListeners = dispose(this.inputBoxListeners);
}
}
......@@ -257,7 +257,7 @@ export class SCMViewlet extends Viewlet {
chain(domEvent(this.inputBox.inputElement, 'keydown'))
.map(e => new StandardKeyboardEvent(e))
.filter(e => e.equals(KeyMod.CtrlCmd | KeyCode.Enter) || e.equals(KeyMod.CtrlCmd | KeyCode.KEY_S))
.on(this.acceptChanges, this, this.disposables);
.on(this.scmService.input.acceptChanges, this.scmService.input, this.disposables);
this.listContainer = append(root, $('.scm-status.show-file-icons'));
const delegate = new Delegate();
......@@ -334,10 +334,6 @@ export class SCMViewlet extends Viewlet {
this.scmService.activeProvider.open(e);
}
private acceptChanges(): void {
this.scmService.activeProvider.acceptChanges();
}
getActions(): IAction[] {
return this.menus.getTitleActions();
}
......
......@@ -46,13 +46,14 @@ export interface ISCMProvider extends IDisposable {
readonly state?: string;
open(uri: ISCMResource): TPromise<void>;
acceptChanges(): TPromise<void>;
getOriginalResource(uri: URI): TPromise<URI>;
}
export interface ISCMInput {
value: string;
readonly onDidChange: Event<string>;
readonly onDidAccept: Event<string>;
acceptChanges(): void;
}
export interface ISCMService {
......
......@@ -26,6 +26,13 @@ class SCMInput implements ISCMInput {
private _onDidChange = new Emitter<string>();
get onDidChange(): Event<string> { return this._onDidChange.event; }
private _onDidAccept = new Emitter<string>();
get onDidAccept(): Event<string> { return this._onDidAccept.event; }
acceptChanges(): void {
this._onDidAccept.fire(this._value);
}
}
export class SCMService implements ISCMService {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册