提交 e06a8382 编写于 作者: J Joao Moreno

🎨 fix scm api based on @jrieken's recommendations

上级 b0557082
......@@ -15,6 +15,7 @@ import { GitContentProvider } from './contentProvider';
import { AutoFetcher } from './autofetch';
import { MergeDecorator } from './merge';
import { Askpass } from './askpass';
import { filterEvent } from './util';
import TelemetryReporter from 'vscode-extension-telemetry';
import * as nls from 'vscode-nls';
......@@ -76,8 +77,12 @@ async function init(context: ExtensionContext, disposables: Disposable[]): Promi
}
}
scm.inputBox.onDidAccept(commandCenter.commitWithInput, commandCenter, disposables);
scm.inputBox.value = await model.getCommitTemplate();
filterEvent(scm.onDidAcceptInputValue, () => scm.activeProvider === provider)
(commandCenter.commitWithInput, commandCenter, disposables);
if (scm.activeProvider === provider) {
scm.inputBox.value = await model.getCommitTemplate();
}
}
export function activate(context: ExtensionContext): any {
......
......@@ -5,7 +5,7 @@
'use strict';
import { scm, Uri, Disposable, SCMProvider, SCMResourceGroup, Event, ProviderResult, workspace } from 'vscode';
import { scm, Uri, Disposable, SCMProvider, SCMResourceGroup, Event, workspace } from 'vscode';
import { Model, Resource, State } from './model';
import { CommandCenter } from './commands';
import { mapEvent } from './util';
......@@ -17,8 +17,8 @@ export class GitSCMProvider implements SCMProvider {
get contextKey(): string { return 'git'; }
get resources(): SCMResourceGroup[] { return this.model.resources; }
get onDidChange(): Event<SCMResourceGroup[]> {
return mapEvent(this.model.onDidChange, () => this.model.resources);
get onDidChange(): Event<this> {
return mapEvent(this.model.onDidChange, () => this);
}
get label(): string { return 'Git'; }
......@@ -46,11 +46,11 @@ export class GitSCMProvider implements SCMProvider {
scm.registerSCMProvider(this);
}
open(resource: Resource): ProviderResult<void> {
return this.commandCenter.open(resource);
open(resource: Resource): void {
this.commandCenter.open(resource);
}
getOriginalResource(uri: Uri): Uri | undefined {
provideOriginalResource(uri: Uri): Uri | undefined {
if (uri.scheme !== 'file') {
return;
}
......
......@@ -674,8 +674,8 @@ declare module 'vscode' {
}
/**
* An SCM provider is able to provide [SCM resources](#SCMResource) to Code,
* notify of changes in them and interact with Code in several SCM related ways.
* An SCM provider is able to provide [SCM resources](#SCMResource) to the editor,
* notify of changes in them and interact with the editor in several SCM related ways.
*/
export interface SCMProvider {
......@@ -713,7 +713,7 @@ declare module 'vscode' {
* - [count](#SCMProvider.count)
* - [state](#SCMProvider.state)
*/
readonly onDidChange?: Event<SCMResourceGroup[]>;
readonly onDidChange?: Event<SCMProvider>;
/**
* Provide a [uri](#Uri) to the original resource of any given resource uri.
......@@ -722,7 +722,7 @@ declare module 'vscode' {
* @param token A cancellation token.
* @return A thenable that resolves to uri of the matching original resource.
*/
getOriginalResource?(uri: Uri, token: CancellationToken): ProviderResult<Uri>;
provideOriginalResource?(uri: Uri, token: CancellationToken): ProviderResult<Uri>;
/**
* Open a specific [SCM resource](#SCMResource). Called when SCM resources
......@@ -732,7 +732,7 @@ declare module 'vscode' {
* @param token A cancellation token.
* @return A thenable which resolves when the resource is open.
*/
open?(resource: SCMResource, token: CancellationToken): ProviderResult<void>;
open?(resource: SCMResource): void;
}
/**
......@@ -744,19 +744,14 @@ declare module 'vscode' {
* Setter and getter for the contents of the input box.
*/
value: string;
}
/**
* An [event](#Event) which fires when the input box value has changed.
*/
readonly onDidChange: Event<string>;
export namespace scm {
/**
* An [event](#Event) which fires when the user has accepted the changes.
* The currently active [SCM provider](#SCMProvider).
*/
readonly onDidAccept: Event<string>;
}
export namespace scm {
export let activeProvider: SCMProvider | undefined;
/**
* An [event](#Event) which fires when the active [SCM provider](#SCMProvider)
......@@ -765,19 +760,18 @@ declare module 'vscode' {
export const onDidChangeActiveProvider: Event<SCMProvider>;
/**
* The currently active [SCM provider](#SCMProvider).
* The [input box](#SCMInputBox) in the SCM view.
*/
export let activeProvider: SCMProvider | undefined;
export const inputBox: SCMInputBox;
/**
* The [input box](#SCMInputBox) in the SCM view.
* An [event](#Event) which fires when the user has accepted the changes.
*/
export const inputBox: SCMInputBox;
export const onDidAcceptInputValue: Event<SCMInputBox>;
/**
* Registers an [SCM provider](#SCMProvider).
*
* @param id The provider's id.
* @return A disposable which unregisters the provider.
*/
export function registerSCMProvider(provider: SCMProvider): Disposable;
......
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { Emitter } from 'vs/base/common/event';
import { Emitter, mapEvent } from 'vs/base/common/event';
import { TrieMap } from 'vs/base/common/map';
import { score } from 'vs/editor/common/modes/languageSelector';
import * as Platform from 'vs/base/common/platform';
......@@ -451,6 +451,11 @@ export function createApiFactory(initData: IInitData, threadService: IThreadServ
return extHostSCM.onDidChangeActiveProvider;
}
@proposed(extension)
get onDidAcceptInputValue() {
return mapEvent(extHostSCM.inputBox.onDidAccept, () => extHostSCM.inputBox);
}
@proposed(extension)
get inputBox() {
return extHostSCM.inputBox;
......
......@@ -24,7 +24,7 @@ function getIconPath(decorations: vscode.SCMResourceThemableDecorations) {
return undefined;
}
class ExtHostSCMInputBox {
export class ExtHostSCMInputBox {
private _value: string = '';
......@@ -84,7 +84,7 @@ export class ExtHostSCM {
get activeProvider(): vscode.SCMProvider | undefined { return this._activeProvider; }
private _inputBox: ExtHostSCMInputBox;
get inputBox(): vscode.SCMInputBox { return this._inputBox; }
get inputBox(): ExtHostSCMInputBox { return this._inputBox; }
constructor(threadService: IThreadService) {
this._proxy = threadService.get(MainContext.MainThreadSCM);
......@@ -100,15 +100,15 @@ export class ExtHostSCM {
label: provider.label,
contextKey: provider.contextKey,
supportsOpen: !!provider.open,
supportsOriginalResource: !!provider.getOriginalResource
supportsOriginalResource: !!provider.provideOriginalResource
});
const onDidChange = debounceEvent(provider.onDidChange || createEmptyEvent(), (l, e) => e, 100);
const onDidChangeListener = onDidChange(resourceGroups => {
const onDidChange = debounceEvent(provider.onDidChange || createEmptyEvent<vscode.SCMProvider>(), (l, e) => e, 100);
const onDidChangeListener = onDidChange(scmProvider => {
const cache = new Map<string, vscode.SCMResource>();
this._cache.set(handle, cache);
const rawResourceGroups = resourceGroups.map(g => {
const rawResourceGroups = scmProvider.resources.map(g => {
const rawResources = g.resources.map(r => {
const uri = r.uri.toString();
cache.set(uri, r);
......@@ -164,7 +164,8 @@ export class ExtHostSCM {
return TPromise.as(null);
}
return asWinJsPromise(token => provider.open(resource, token));
provider.open(resource);
return TPromise.as(null);
}
$getOriginalResource(handle: number, uri: URI): TPromise<URI> {
......@@ -174,7 +175,7 @@ export class ExtHostSCM {
return TPromise.as(null);
}
return asWinJsPromise(token => provider.getOriginalResource(uri, token));
return asWinJsPromise(token => provider.provideOriginalResource(uri, token));
}
$onInputBoxValueChange(value: string): TPromise<void> {
......
......@@ -7,6 +7,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 { onUnexpectedError } from 'vs/base/common/errors';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
import { ISCMService, ISCMProvider, ISCMResource, ISCMResourceGroup } from 'vs/workbench/services/scm/common/scm';
......@@ -45,12 +46,13 @@ class MainThreadSCMProvider implements ISCMProvider {
this.disposables.push(scmService.registerSCMProvider(this));
}
open(resource: ISCMResource): TPromise<void> {
open(resource: ISCMResource): void {
if (!this.features.supportsOpen) {
return TPromise.as(null);
return;
}
return this.proxy.$open(this.handle, resource.uri.toString());
this.proxy.$open(this.handle, resource.uri.toString())
.done(null, onUnexpectedError);
}
getOriginalResource(uri: URI): TPromise<URI> {
......
......@@ -45,7 +45,7 @@ export interface ISCMProvider extends IDisposable {
readonly count?: number;
readonly stateContextKey?: string;
open(uri: ISCMResource): TPromise<void>;
open(uri: ISCMResource): void;
getOriginalResource(uri: URI): TPromise<URI>;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册