提交 3faded62 编写于 作者: J Joao Moreno

commit, open, drag optional methods

上级 08e73a51
......@@ -31,7 +31,7 @@
}
},
{
"command": "git.open-change",
"command": "git.open",
"title": "Open Change",
"category": "Git"
},
......
......@@ -16,8 +16,8 @@ function refresh(model: Model): () => void {
};
}
function openChange(...args: any[]): void {
console.log('openChange', args);
function open(...args: any[]): void {
console.log('open', args);
}
function stage(resource: SCMResource): void {
......@@ -43,7 +43,7 @@ export function registerCommands(model: Model): Disposable {
commands.registerCommand('git.stage-all', stageAll),
commands.registerCommand('git.unstage', unstage),
commands.registerCommand('git.unstage-all', unstageAll),
commands.registerCommand('git.open-change', openChange)
commands.registerCommand('git.open', open)
];
return Disposable.from(...disposables);
......
......@@ -155,6 +155,18 @@ export class GitSCMProvider implements SCMProvider {
model.update(true);
}
commit(message: string): void {
console.log('commit', message);
}
open(resource: SCMResource): void {
console.log('open', resource);
}
drag(resource: SCMResource, resourceGroup: SCMResourceGroup): void {
console.log('drag', resource, resourceGroup);
}
getOriginalResource(uri: Uri): Uri | undefined {
if (uri.scheme !== 'file') {
return void 0;
......
......@@ -109,13 +109,13 @@ declare module 'vscode' {
export interface SCMProvider {
readonly label: string;
readonly commitCommand?: string;
readonly clickCommand?: string;
readonly dragCommand?: string;
readonly resources: SCMResourceGroup[];
readonly onDidChange: Event<SCMResourceGroup[]>;
getOriginalResource?(uri: Uri, token: CancellationToken): ProviderResult<Uri>;
commit?(message: string, token: CancellationToken): ProviderResult<void>;
open?(resource: SCMResource, token: CancellationToken): ProviderResult<void>;
drag?(resource: SCMResource, resourceGroup: SCMResourceGroup, token: CancellationToken): ProviderResult<void>;
}
export namespace scm {
......
......@@ -230,9 +230,9 @@ export abstract class MainProcessExtensionServiceShape {
export interface SCMProviderFeatures {
label: string;
commitCommand?: string;
clickCommand?: string;
dragCommand?: string;
supportsCommit: boolean;
supportsOpen: boolean;
supportsDrag: boolean;
supportsOriginalResource: boolean;
}
......@@ -377,6 +377,9 @@ export abstract class ExtHostTerminalServiceShape {
}
export abstract class ExtHostSCMShape {
$commit(id: string, message: string): TPromise<void> { throw ni(); }
$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(); }
}
......
......@@ -23,6 +23,13 @@ function getIconPath(decorations: vscode.SCMResourceThemableDecorations) {
}
}
export interface Cache {
[groupId: string]: {
resourceGroup: vscode.SCMResourceGroup,
resources: { [uri: string]: vscode.SCMResource }
};
}
export class ExtHostSCM {
private _proxy: MainThreadSCMShape;
......@@ -34,6 +41,8 @@ export class ExtHostSCM {
private _activeProvider: vscode.SCMProvider;
get activeProvider(): vscode.SCMProvider | undefined { return this._activeProvider; }
private cache: Cache = Object.create(null);
constructor(threadService: IThreadService) {
this._proxy = threadService.get(MainContext.MainThreadSCM);
}
......@@ -48,15 +57,19 @@ export class ExtHostSCM {
this._proxy.$register(id, {
label: provider.label,
commitCommand: provider.commitCommand,
clickCommand: provider.clickCommand,
dragCommand: provider.dragCommand,
supportsCommit: !!provider.commit,
supportsOpen: !!provider.open,
supportsDrag: !!provider.drag,
supportsOriginalResource: !!provider.getOriginalResource
});
const onDidChange = debounceEvent(provider.onDidChange, (l, e) => e, 200);
const onDidChangeListener = onDidChange(resourceGroups => {
this.cache = Object.create(null);
const rawResourceGroups = resourceGroups.map(g => {
const resources: { [id: string]: vscode.SCMResource; } = Object.create(null);
const rawResources = g.resources.map(r => {
const uri = r.uri.toString();
const iconPath = getIconPath(r.decorations);
......@@ -73,9 +86,13 @@ export class ExtHostSCM {
}
const strikeThrough = r.decorations && !!r.decorations.strikeThrough;
resources[uri] = r;
return [uri, icons, strikeThrough] as SCMRawResource;
});
this.cache[g.id] = { resourceGroup: g, resources };
return [g.id, g.label, rawResources] as SCMRawResourceGroup;
});
......@@ -89,6 +106,52 @@ export class ExtHostSCM {
});
}
$commit(id: string, message: string): TPromise<void> {
const provider = this._providers[id];
if (!provider) {
return TPromise.as(null);
}
return asWinJsPromise(token => provider.commit(message, token));
}
$open(id: string, resourceGroupId: string, uri: string): TPromise<void> {
const provider = this._providers[id];
if (!provider) {
return TPromise.as(null);
}
const resourceGroup = this.cache[resourceGroupId];
const resource = resourceGroup && resourceGroup.resources[uri];
if (!resource) {
return TPromise.as(null);
}
return asWinJsPromise(token => provider.open(resource, token));
}
$drag(id: string, fromResourceGroupId: string, fromUri: string, toResourceGroupId: string): TPromise<void> {
const provider = this._providers[id];
if (!provider) {
return TPromise.as(null);
}
const fromResourceGroup = this.cache[fromResourceGroupId];
const resource = fromResourceGroup && fromResourceGroup.resources[fromUri];
const toResourceGroup = this.cache[toResourceGroupId];
const resourceGroup = toResourceGroup && toResourceGroup.resourceGroup;
if (!resource || !resourceGroup) {
return TPromise.as(null);
}
return asWinJsPromise(token => provider.drag(resource, resourceGroup, token));
}
$getOriginalResource(id: string, uri: URI): TPromise<URI> {
const provider = this._providers[id];
......
......@@ -39,33 +39,27 @@ class MainThreadSCMProvider implements ISCMProvider {
}
commit(message: string): TPromise<void> {
const id = this.features.commitCommand;
if (!id) {
if (!this.features.supportsCommit) {
return TPromise.as(null);
}
return this.commandService.executeCommand<void>(id, message);
return this.proxy.$commit(this.id, message);
}
open(uri: ISCMResource): TPromise<void> {
const id = this.features.clickCommand;
if (!id) {
open(resource: ISCMResource): TPromise<void> {
if (!this.features.supportsOpen) {
return TPromise.as(null);
}
return this.commandService.executeCommand<void>(id, uri);
return this.proxy.$open(this.id, resource.resourceGroupId, resource.uri.toString());
}
drag(from: ISCMResource, to: ISCMResource): TPromise<void> {
const id = this.features.dragCommand;
if (!id) {
drag(from: ISCMResource, to: ISCMResourceGroup): TPromise<void> {
if (!this.features.supportsDrag) {
return TPromise.as(null);
}
return this.commandService.executeCommand<void>(id, from, to);
return this.proxy.$drag(this.id, from.resourceGroupId, from.uri.toString(), to.id);
}
getOriginalResource(uri: URI): TPromise<URI> {
......
......@@ -43,7 +43,7 @@ export interface ISCMProvider extends IDisposable {
commit(message: string): TPromise<void>;
open(uri: ISCMResource): TPromise<void>;
drag(from: ISCMResource, to: ISCMResource): TPromise<void>;
drag(from: ISCMResource, to: ISCMResourceGroup): TPromise<void>;
getOriginalResource(uri: URI): TPromise<URI>;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册