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

commit, open, drag optional methods

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