@@ -45,74 +45,74 @@ export class GitGraphView {
4545 }
4646 } , null , this . disposables ) ;
4747
48- this . panel . webview . onDidReceiveMessage ( async ( message : RequestMessage ) => {
48+ this . panel . webview . onDidReceiveMessage ( async ( msg : RequestMessage ) => {
4949 if ( this . dataSource === null ) return ;
50- switch ( message . command ) {
51- case 'loadBranches' :
52- this . sendMessage ( {
53- command : 'loadBranches' ,
54- data : await this . dataSource . getBranches ( message . data . showRemoteBranches )
55- } ) ;
56- return ;
57- case 'loadCommits' :
50+ switch ( msg . command ) {
51+ case 'addTag' :
5852 this . sendMessage ( {
59- command : 'loadCommits ' ,
60- data : await this . dataSource . getCommits ( message . data . branch , message . data . maxCommits , message . data . showRemoteBranches , message . data . currentBranch )
53+ command : 'addTag ' ,
54+ status : await this . dataSource . addTag ( msg . tagName , msg . commitHash )
6155 } ) ;
6256 return ;
63- case 'addTag ' :
57+ case 'checkoutBranch ' :
6458 this . sendMessage ( {
65- command : 'addTag ' ,
66- data : await this . dataSource . addTag ( message . data . tagName , message . data . commitHash )
59+ command : 'checkoutBranch ' ,
60+ status : await this . dataSource . checkoutBranch ( msg . branchName , msg . remoteBranch )
6761 } ) ;
6862 return ;
69- case 'deleteTag ' :
63+ case 'commitDetails ' :
7064 this . sendMessage ( {
71- command : 'deleteTag ' ,
72- data : await this . dataSource . deleteTag ( message . data )
65+ command : 'commitDetails ' ,
66+ commitDetails : await this . dataSource . commitDetails ( msg . commitHash )
7367 } ) ;
7468 return ;
7569 case 'copyCommitHashToClipboard' :
76- this . copyCommitHashToClipboard ( message . data ) ;
70+ this . copyCommitHashToClipboard ( msg . commitHash ) ;
7771 return ;
7872 case 'createBranch' :
7973 this . sendMessage ( {
8074 command : 'createBranch' ,
81- data : await this . dataSource . createBranch ( message . data . branchName , message . data . commitHash )
75+ status : await this . dataSource . createBranch ( msg . branchName , msg . commitHash )
8276 } ) ;
8377 return ;
84- case 'checkoutBranch ' :
78+ case 'deleteBranch ' :
8579 this . sendMessage ( {
86- command : 'checkoutBranch ' ,
87- data : await this . dataSource . checkoutBranch ( message . data . branchName , message . data . remoteBranch )
80+ command : 'deleteBranch ' ,
81+ status : await this . dataSource . deleteBranch ( msg . branchName , msg . forceDelete )
8882 } ) ;
8983 return ;
90- case 'deleteBranch ' :
84+ case 'deleteTag ' :
9185 this . sendMessage ( {
92- command : 'deleteBranch' ,
93- data : await this . dataSource . deleteBranch ( message . data . branchName , message . data . forceDelete )
86+ command : 'deleteTag' ,
87+ status : await this . dataSource . deleteTag ( msg . tagName )
88+ } ) ;
89+ return ;
90+ case 'loadBranches' :
91+ this . sendMessage ( {
92+ command : 'loadBranches' ,
93+ branches : await this . dataSource . getBranches ( msg . showRemoteBranches )
94+ } ) ;
95+ return ;
96+ case 'loadCommits' :
97+ this . sendMessage ( {
98+ command : 'loadCommits' ,
99+ ... await this . dataSource . getCommits ( msg . branchName , msg . maxCommits , msg . showRemoteBranches , msg . currentBranch )
94100 } ) ;
95101 return ;
96102 case 'renameBranch' :
97103 this . sendMessage ( {
98104 command : 'renameBranch' ,
99- data : await this . dataSource . renameBranch ( message . data . oldName , message . data . newName )
105+ status : await this . dataSource . renameBranch ( msg . oldName , msg . newName )
100106 } ) ;
101107 return ;
102108 case 'resetToCommit' :
103109 this . sendMessage ( {
104110 command : 'resetToCommit' ,
105- data : await this . dataSource . resetToCommit ( message . data . commitHash , message . data . resetMode )
106- } ) ;
107- return ;
108- case 'commitDetails' :
109- this . sendMessage ( {
110- command : 'commitDetails' ,
111- data : await this . dataSource . commitDetails ( message . data )
111+ status : await this . dataSource . resetToCommit ( msg . commitHash , msg . resetMode )
112112 } ) ;
113113 return ;
114114 case 'viewDiff' :
115- this . viewDiff ( message . data . commitHash , message . data . oldFilePath , message . data . newFilePath , message . data . type ) ;
115+ this . viewDiff ( msg . commitHash , msg . oldFilePath , msg . newFilePath , msg . type ) ;
116116 return ;
117117 }
118118 } , null , this . disposables ) ;
@@ -135,11 +135,8 @@ export class GitGraphView {
135135
136136 private async getHtmlForWebview ( ) {
137137 const config = new Config ( ) ;
138- const jsPathOnDisk = vscode . Uri . file ( path . join ( this . extensionPath , 'media' , 'main.min.js' ) ) ;
139- const jsUri = jsPathOnDisk . with ( { scheme : 'vscode-resource' } ) ;
140- const cssPathOnDisk = vscode . Uri . file ( path . join ( this . extensionPath , 'media' , 'main.css' ) ) ;
141- const cssUri = cssPathOnDisk . with ( { scheme : 'vscode-resource' } ) ;
142- const isRepo = this . dataSource !== null && await this . dataSource . isGitRepository ( ) ;
138+ const jsUri = vscode . Uri . file ( path . join ( this . extensionPath , 'media' , 'main.min.js' ) ) . with ( { scheme : 'vscode-resource' } ) ;
139+ const cssUri = vscode . Uri . file ( path . join ( this . extensionPath , 'media' , 'main.css' ) ) . with ( { scheme : 'vscode-resource' } ) ;
143140 const nonce = getNonce ( ) ;
144141
145142 let settings : GitGraphViewSettings = {
@@ -151,23 +148,13 @@ export class GitGraphView {
151148 loadMoreCommits : config . loadMoreCommits ( )
152149 } ;
153150
154- let colourStyles = '' ;
151+ let colourStyles = '' , body ;
155152 for ( let i = 0 ; i < settings . graphColours . length ; i ++ ) {
156153 colourStyles += '.colour' + i + ' { background-color:' + settings . graphColours [ i ] + '; } ' ;
157154 }
158155
159- let html = `<!DOCTYPE html>
160- <html lang="en">
161- <head>
162- <meta charset="UTF-8">
163- <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src vscode-resource: 'nonce-${ nonce } '; script-src vscode-resource: 'nonce-${ nonce } ';">
164- <meta name="viewport" content="width=device-width, initial-scale=1.0">
165- <link rel="stylesheet" type="text/css" href="${ cssUri } ">
166- <title>Git Graph</title>
167- <style nonce="${ nonce } ">${ colourStyles } </style>
168- </head>` ;
169- if ( isRepo ) {
170- html += `<body>
156+ if ( this . dataSource !== null && await this . dataSource . isGitRepository ( ) ) {
157+ body = `<body>
171158 <div id="controls">
172159 <span class="unselectable">Branch: </span><select id="branchSelect"></select>
173160 <label><input type="checkbox" id="showRemoteBranchesCheckbox" value="1" checked>Show Remote Branches</label>
@@ -182,20 +169,31 @@ export class GitGraphView {
182169 <script src="${ jsUri } "></script>
183170 </body>` ;
184171 } else {
185- html + = `<body class="notGitRepository"><h1>Git Graph</h1><p>The current workspace is not a Git Repository, unable to show Git Graph.</p></body>` ;
172+ body = `<body class="notGitRepository"><h1>Git Graph</h1><p>The current workspace is not a Git Repository, unable to show Git Graph.</p></body>` ;
186173 }
187- html += `</html>` ;
188- return html ;
174+
175+ return `<!DOCTYPE html>
176+ <html lang="en">
177+ <head>
178+ <meta charset="UTF-8">
179+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src vscode-resource: 'nonce-${ nonce } '; script-src vscode-resource: 'nonce-${ nonce } ';">
180+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
181+ <link rel="stylesheet" type="text/css" href="${ cssUri } ">
182+ <title>Git Graph</title>
183+ <style nonce="${ nonce } ">${ colourStyles } </style>
184+ </head>
185+ ${ body }
186+ </html>` ;
189187 }
190188
191189 private sendMessage ( msg : ResponseMessage ) {
192190 this . panel . webview . postMessage ( msg ) ;
193191 }
194192
195- private copyCommitHashToClipboard ( str : string ) {
196- vscode . env . clipboard . writeText ( str ) . then (
197- ( ) => this . sendMessage ( { command : 'copyCommitHashToClipboard' , data : true } ) ,
198- ( ) => this . sendMessage ( { command : 'copyCommitHashToClipboard' , data : false } )
193+ private copyCommitHashToClipboard ( commitHash : string ) {
194+ vscode . env . clipboard . writeText ( commitHash ) . then (
195+ ( ) => this . sendMessage ( { command : 'copyCommitHashToClipboard' , success : true } ) ,
196+ ( ) => this . sendMessage ( { command : 'copyCommitHashToClipboard' , success : false } )
199197 ) ;
200198 }
201199
@@ -204,7 +202,7 @@ export class GitGraphView {
204202 let pathComponents = newFilePath . split ( '/' ) ;
205203 let title = pathComponents [ pathComponents . length - 1 ] + ' (' + ( type === 'A' ? 'Added in ' + abbrevHash : type === 'D' ? 'Deleted in ' + abbrevHash : abbrevCommit ( commitHash ) + '^ ↔ ' + abbrevCommit ( commitHash ) ) + ')' ;
206204 vscode . commands . executeCommand ( 'vscode.diff' , encodeDiffDocUri ( oldFilePath , commitHash + '^' ) , encodeDiffDocUri ( newFilePath , commitHash ) , title , { preview : true } ) ;
207- this . sendMessage ( { command : 'viewDiff' , data : true } ) ;
205+ this . sendMessage ( { command : 'viewDiff' , success : true } ) ;
208206 }
209207}
210208
0 commit comments