11import { isWebUri } from 'valid-url' ;
22
3- import { Disposable , commands , window , workspace , Uri } from 'vscode' ;
3+ import { Disposable , commands , window , workspace , Uri , MessageItem } from 'vscode' ;
44
55import { ErrorHandler } from '../util/errorhandler' ;
66import { TextDecorator } from '../util/textdecorator' ;
@@ -97,7 +97,6 @@ export class GitBlame {
9797
9898 async showMessage ( ) : Promise < void > {
9999 const commitInfo = await this . getCommitInfo ( ) ;
100- const commitToolUrl = this . getToolUrl ( commitInfo ) ;
101100 const messageFormat = Property . get ( Properties . InfoMessageFormat ) ;
102101 const normalizedTokens = TextDecorator . normalizeCommitInfoTokens (
103102 commitInfo
@@ -106,17 +105,34 @@ export class GitBlame {
106105 messageFormat ,
107106 normalizedTokens
108107 ) ;
109- const extraAction = commitToolUrl ? TITLE_VIEW_ONLINE : '' ;
108+ const extraActions = this . generateMessageActions ( commitInfo ) ;
110109
111110 this . updateView ( commitInfo ) ;
112111
113- const item = await window . showInformationMessage ( message , extraAction ) ;
112+ const actionedItem = await window . showInformationMessage ( message , ... extraActions ) ;
114113
115- if ( item === TITLE_VIEW_ONLINE ) {
116- commands . executeCommand ( 'vscode.open' , commitToolUrl ) ;
114+ if ( actionedItem ) {
115+ actionedItem . takeAction ( ) ;
117116 }
118117 }
119118
119+ private generateMessageActions ( commitInfo : GitCommitInfo ) : ActionableMessageItem [ ] {
120+ const commitToolUrl = this . getToolUrl ( commitInfo ) ;
121+ const extraActions :ActionableMessageItem [ ] = [ ] ;
122+
123+ if ( commitToolUrl ) {
124+ let viewOnlineAction = new ActionableMessageItem ( TITLE_VIEW_ONLINE ) ;
125+
126+ viewOnlineAction . setAction ( ( ) => {
127+ commands . executeCommand ( 'vscode.open' , commitToolUrl ) ;
128+ } ) ;
129+
130+ extraActions . push ( viewOnlineAction ) ;
131+ }
132+
133+ return extraActions ;
134+ }
135+
120136 async blameLink ( ) : Promise < void > {
121137 const commitInfo = await this . getCommitInfo ( ) ;
122138 const commitToolUrl = this . getToolUrl ( commitInfo ) ;
@@ -256,3 +272,25 @@ export class GitBlame {
256272 return hash . substr ( 0 , Property . get ( Properties . InternalHashLength ) ) ;
257273 }
258274}
275+
276+ /**
277+ * Helper class for window.showInformationMessage
278+ */
279+ class ActionableMessageItem implements MessageItem {
280+ public title : string ;
281+ private action : ( ) => void ;
282+
283+ constructor ( title ) {
284+ this . title = title ;
285+ }
286+
287+ setAction ( action ) {
288+ this . action = action ;
289+ }
290+
291+ takeAction ( ) {
292+ if ( this . action ) {
293+ this . action ( ) ;
294+ }
295+ }
296+ }
0 commit comments