@@ -3,11 +3,12 @@ import * as vscode from 'vscode';
33import { AvatarManager } from './avatarManager' ;
44import { getConfig } from './config' ;
55import { DataSource } from './dataSource' ;
6+ import { DiffDocProvider , decodeDiffDocUri } from './diffDocProvider' ;
67import { CodeReviewData , CodeReviews , ExtensionState } from './extensionState' ;
78import { GitGraphView } from './gitGraphView' ;
89import { Logger } from './logger' ;
910import { RepoManager } from './repoManager' ;
10- import { GitExecutable , UNABLE_TO_FIND_GIT_MSG , abbrevCommit , abbrevText , copyToClipboard , getExtensionVersion , getPathFromUri , getRelativeTimeDiff , getRepoName , isPathInWorkspace , resolveToSymbolicPath , showErrorMessage , showInformationMessage } from './utils' ;
11+ import { GitExecutable , UNABLE_TO_FIND_GIT_MSG , abbrevCommit , abbrevText , copyToClipboard , doesVersionMeetRequirement , getExtensionVersion , getPathFromUri , getRelativeTimeDiff , getRepoName , isPathInWorkspace , openFile , resolveToSymbolicPath , showErrorMessage , showInformationMessage } from './utils' ;
1112import { Disposable } from './utils/disposable' ;
1213import { Event } from './utils/event' ;
1314
@@ -44,6 +45,7 @@ export class CommandManager extends Disposable {
4445 this . repoManager = repoManager ;
4546 this . gitExecutable = gitExecutable ;
4647
48+ // Register Extension Commands
4749 this . registerCommand ( 'git-graph.view' , ( arg ) => this . view ( arg ) ) ;
4850 this . registerCommand ( 'git-graph.addGitRepository' , ( ) => this . addGitRepository ( ) ) ;
4951 this . registerCommand ( 'git-graph.removeGitRepository' , ( ) => this . removeGitRepository ( ) ) ;
@@ -53,12 +55,20 @@ export class CommandManager extends Disposable {
5355 this . registerCommand ( 'git-graph.endSpecificWorkspaceCodeReview' , ( ) => this . endSpecificWorkspaceCodeReview ( ) ) ;
5456 this . registerCommand ( 'git-graph.resumeWorkspaceCodeReview' , ( ) => this . resumeWorkspaceCodeReview ( ) ) ;
5557 this . registerCommand ( 'git-graph.version' , ( ) => this . version ( ) ) ;
58+ this . registerCommand ( 'git-graph.openFile' , ( arg ) => this . openFile ( arg ) ) ;
5659
5760 this . registerDisposable (
5861 onDidChangeGitExecutable ( ( gitExecutable ) => {
5962 this . gitExecutable = gitExecutable ;
6063 } )
6164 ) ;
65+
66+ // Register Extension Contexts
67+ try {
68+ this . registerContext ( 'git-graph:codiconsSupported' , doesVersionMeetRequirement ( vscode . version , '1.42.0' ) ) ;
69+ } catch ( _ ) {
70+ this . logger . logError ( 'Unable to set Visual Studio Code Context "git-graph:codiconsSupported"' ) ;
71+ }
6272 }
6373
6474 /**
@@ -72,6 +82,18 @@ export class CommandManager extends Disposable {
7282 ) ;
7383 }
7484
85+ /**
86+ * Register a context with Visual Studio Code.
87+ * @param key The Context Key.
88+ * @param value The Context Value.
89+ */
90+ private registerContext ( key : string , value : any ) {
91+ return vscode . commands . executeCommand ( 'setContext' , key , value ) . then (
92+ ( ) => this . logger . log ( 'Successfully set Visual Studio Code Context "' + key + '" to "' + JSON . stringify ( value ) + '"' ) ,
93+ ( ) => this . logger . logError ( 'Failed to set Visual Studio Code Context "' + key + '" to "' + JSON . stringify ( value ) + '"' )
94+ ) ;
95+ }
96+
7597
7698 /* Commands */
7799
@@ -292,6 +314,26 @@ export class CommandManager extends Disposable {
292314 }
293315 }
294316
317+ /**
318+ * Opens a file in Visual Studio Code, based on a Git Graph URI (from the Diff View).
319+ * The method run when the `git-graph.openFile` command is invoked.
320+ * @param arg The Git Graph URI.
321+ */
322+ private openFile ( arg ?: vscode . Uri ) {
323+ const uri = arg || vscode . window . activeTextEditor ?. document . uri ;
324+ if ( typeof uri === 'object' && uri . scheme === DiffDocProvider . scheme ) {
325+ // A Git Graph URI has been provided
326+ const request = decodeDiffDocUri ( uri ) ;
327+ return openFile ( request . repo , request . filePath , vscode . ViewColumn . Active ) . then ( ( errorInfo ) => {
328+ if ( errorInfo !== null ) {
329+ return showErrorMessage ( 'Unable to Open File: ' + errorInfo ) ;
330+ }
331+ } ) ;
332+ } else {
333+ return showErrorMessage ( 'Unable to Open File: The command was not called with the required arguments.' ) ;
334+ }
335+ }
336+
295337
296338 /* Helper Methods */
297339
0 commit comments