From a199b2aa53abbf93c246e528fd54359985ec4492 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Mon, 24 Apr 2017 11:47:03 +0200 Subject: [PATCH] :sparkles: merge git.open* commands --- extensions/git/package.json | 32 ++-------------------- extensions/git/src/commands.ts | 50 ++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 49 deletions(-) diff --git a/extensions/git/package.json b/extensions/git/package.json index 817bfa899dc..8db3b5bae93 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -63,24 +63,6 @@ "dark": "resources/icons/dark/open-file.svg" } }, - { - "command": "git.openChangeFromUri", - "title": "%command.openChange%", - "category": "Git", - "icon": { - "light": "resources/icons/light/open-change.svg", - "dark": "resources/icons/dark/open-change.svg" - } - }, - { - "command": "git.openFileFromUri", - "title": "%command.openFile%", - "category": "Git", - "icon": { - "light": "resources/icons/light/open-file.svg", - "dark": "resources/icons/dark/open-file.svg" - } - }, { "command": "git.stage", "title": "%command.stage%", @@ -244,20 +226,12 @@ "command": "git.refresh", "when": "config.git.enabled && scmProvider == git && gitState == idle" }, - { - "command": "git.openChange", - "when": "false" - }, { "command": "git.openFile", - "when": "false" - }, - { - "command": "git.openChangeFromUri", "when": "config.git.enabled && scmProvider == git && gitState == idle" }, { - "command": "git.openFileFromUri", + "command": "git.openChange", "when": "config.git.enabled && scmProvider == git && gitState == idle" }, { @@ -550,12 +524,12 @@ ], "editor/title": [ { - "command": "git.openFileFromUri", + "command": "git.openFile", "group": "navigation", "when": "config.git.enabled && scmProvider == git && isInDiffEditor && resourceScheme != extension" }, { - "command": "git.openChangeFromUri", + "command": "git.openChange", "group": "navigation", "when": "config.git.enabled && scmProvider == git && !isInDiffEditor && resourceScheme != extension" } diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 892f59756da..12cbbbf0bea 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -243,23 +243,44 @@ export class CommandCenter { } @command('git.openFile') - async openFile(resource?: Resource): Promise { - if (!(resource instanceof Resource)) { - // can happen when called from a keybinding - resource = this.getSCMResource(); + async openFile(arg?: Resource | Uri): Promise { + let uri: Uri | undefined; + + if (arg instanceof Uri) { + if (arg.scheme === 'git') { + uri = Uri.file(fromGitUri(arg).path); + } else if (arg.scheme === 'file') { + uri = arg; + } + } else { + let resource = arg; + + if (!(resource instanceof Resource)) { + // can happen when called from a keybinding + resource = this.getSCMResource(); + } + + if (resource) { + uri = resource.resourceUri; + } } - if (!resource) { + if (!uri) { return; } - return await commands.executeCommand('vscode.open', resource.resourceUri); + return await commands.executeCommand('vscode.open', uri); } @command('git.openChange') - async openChange(resource?: Resource): Promise { - if (!(resource instanceof Resource)) { - // can happen when called from a keybinding + async openChange(arg?: Resource | Uri): Promise { + let resource: Resource | undefined = undefined; + + if (arg instanceof Resource) { + resource = arg; + } else if (arg instanceof Uri) { + resource = this.getSCMResource(arg); + } else { resource = this.getSCMResource(); } @@ -291,17 +312,6 @@ export class CommandCenter { return await commands.executeCommand('vscode.open', uriToOpen); } - @command('git.openChangeFromUri') - async openChangeFromUri(uri?: Uri): Promise { - const resource = this.getSCMResource(uri); - - if (!resource) { - return; - } - - return await this._openResource(resource); - } - @command('git.stage') async stage(...resourceStates: SourceControlResourceState[]): Promise { if (resourceStates.length === 0) {