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

💥 scm input onDidAccept

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