@@ -4,53 +4,91 @@ import * as vscode from 'vscode';
4
4
import { FileStatus } from '../../bitbucket/model' ;
5
5
import { Commands } from '../../commands' ;
6
6
import { configuration } from '../../config/configuration' ;
7
- import { Resources } from '../../resources' ;
8
7
import { DiffViewArgs } from '../pullrequest/diffViewHelper' ;
9
- import { PullRequestContextValue } from '../pullrequest/pullRequestNode' ;
10
8
import { AbstractBaseNode } from './abstractBaseNode' ;
11
9
10
+ export class FileDecorationProvider implements vscode . FileDecorationProvider {
11
+ private _onDidChangeFileDecorations = new vscode . EventEmitter < vscode . Uri [ ] > ( ) ;
12
+ readonly onDidChangeFileDecorations = this . _onDidChangeFileDecorations . event ;
13
+
14
+ provideFileDecoration (
15
+ uri : vscode . Uri ,
16
+ _token : vscode . CancellationToken ,
17
+ ) : vscode . ProviderResult < vscode . FileDecoration > {
18
+ try {
19
+ const params = JSON . parse ( uri . query ) ;
20
+ const status = params . status as FileStatus ;
21
+ const hasComments = params . hasComments ;
22
+ if ( status ) {
23
+ return {
24
+ badge : hasComments ? `💬${ status } ` : status ,
25
+ color : this . getColor ( status ) ,
26
+ tooltip : hasComments ? `File has comments` : undefined ,
27
+ propagate : false ,
28
+ } ;
29
+ }
30
+ } catch ( e ) {
31
+ console . error ( 'Error in provideFileDecoration:' , e ) ;
32
+ }
33
+ return undefined ;
34
+ }
35
+
36
+ private getColor ( status : FileStatus ) : vscode . ThemeColor {
37
+ switch ( status ) {
38
+ case FileStatus . MODIFIED :
39
+ return new vscode . ThemeColor ( 'gitDecoration.modifiedResourceForeground' ) ;
40
+ case FileStatus . ADDED :
41
+ return new vscode . ThemeColor ( 'gitDecoration.addedResourceForeground' ) ;
42
+ case FileStatus . DELETED :
43
+ return new vscode . ThemeColor ( 'gitDecoration.deletedResourceForeground' ) ;
44
+ case FileStatus . RENAMED :
45
+ return new vscode . ThemeColor ( 'gitDecoration.renamedResourceForeground' ) ;
46
+ case FileStatus . CONFLICT :
47
+ return new vscode . ThemeColor ( 'gitDecoration.conflictingResourceForeground' ) ;
48
+ case FileStatus . COPIED :
49
+ return new vscode . ThemeColor ( 'gitDecoration.addedResourceForeground' ) ;
50
+ default :
51
+ return new vscode . ThemeColor ( 'gitDecoration.modifiedResourceForeground' ) ;
52
+ }
53
+ }
54
+ }
55
+
12
56
export class PullRequestFilesNode extends AbstractBaseNode {
13
57
constructor ( private diffViewData : DiffViewArgs ) {
14
58
super ( ) ;
15
59
}
16
60
61
+ createFileChangeUri ( fileName : string , status : FileStatus , prUrl : string , hasComments : boolean ) : vscode . Uri {
62
+ return vscode . Uri . parse ( `${ prUrl } /${ fileName } ` ) . with ( {
63
+ scheme : 'pullRequest' ,
64
+ query : JSON . stringify ( {
65
+ status : status ,
66
+ hasComments : hasComments ,
67
+ } ) ,
68
+ } ) ;
69
+ }
70
+
17
71
async getTreeItem ( ) : Promise < vscode . TreeItem > {
18
72
const itemData = this . diffViewData . fileDisplayData ;
19
73
let fileDisplayString = itemData . fileDisplayName ;
20
74
if ( configuration . get < boolean > ( 'bitbucket.explorer.nestFilesEnabled' ) ) {
21
75
fileDisplayString = path . basename ( itemData . fileDisplayName ) ;
22
76
}
23
- const item = new vscode . TreeItem (
24
- `${ itemData . numberOfComments > 0 ? '💬 ' : '' } ${ fileDisplayString } ` ,
25
- vscode . TreeItemCollapsibleState . None ,
26
- ) ;
77
+ const item = new vscode . TreeItem ( fileDisplayString , vscode . TreeItemCollapsibleState . None ) ;
27
78
item . tooltip = itemData . fileDisplayName ;
28
79
item . command = {
29
80
command : Commands . ViewDiff ,
30
81
title : 'Diff file' ,
31
82
arguments : this . diffViewData . diffArgs ,
32
83
} ;
33
84
34
- item . contextValue = PullRequestContextValue ;
35
- item . resourceUri = vscode . Uri . parse ( `${ itemData . prUrl } #chg-${ itemData . fileDisplayName } ` ) ;
36
- switch ( itemData . fileDiffStatus ) {
37
- case FileStatus . ADDED :
38
- item . iconPath = Resources . icons . get ( 'add-circle' ) ;
39
- break ;
40
- case FileStatus . DELETED :
41
- item . iconPath = Resources . icons . get ( 'delete' ) ;
42
- break ;
43
- case FileStatus . CONFLICT :
44
- item . iconPath = Resources . icons . get ( 'warning' ) ;
45
- break ;
46
- default :
47
- item . iconPath = Resources . icons . get ( 'edit' ) ;
48
- break ;
49
- }
50
-
51
- if ( this . diffViewData . fileDisplayData . isConflicted ) {
52
- item . iconPath = Resources . icons . get ( 'warning' ) ;
53
- }
85
+ item . resourceUri = this . createFileChangeUri (
86
+ itemData . fileDisplayName ,
87
+ itemData . fileDiffStatus ,
88
+ itemData . prUrl ,
89
+ itemData . numberOfComments > 0 ,
90
+ ) ;
91
+ item . iconPath = undefined ;
54
92
55
93
return item ;
56
94
}
0 commit comments