1+ /*---------------------------------------------------------------------------------------------
2+ * Copyright (c) Microsoft Corporation. All rights reserved.
3+ * Licensed under the MIT License. See License.txt in the project root for license information.
4+ *--------------------------------------------------------------------------------------------*/
5+
6+ import * as vscode from 'vscode' ;
7+ import { Resource } from '../common/resources' ;
8+ import { IPullRequestModel , IPullRequestManager } from '../github/interface' ;
9+ import { FileChangeNode } from './treeNodes/fileChangeNode' ;
10+ import { DescriptionNode } from './treeNodes/descriptionNode' ;
11+ import { TreeNode } from './treeNodes/treeNode' ;
12+ import { FilesCategoryNode } from './treeNodes/filesCategoryNode' ;
13+ import { CommitsNode } from './treeNodes/commitsCategoryNode' ;
14+ import { Comment } from '../common/comment' ;
15+
16+ export class PullRequestChangesTreeDataProvider extends vscode . Disposable implements vscode . TreeDataProvider < TreeNode > {
17+ private _onDidChangeTreeData = new vscode . EventEmitter < FileChangeNode | DescriptionNode > ( ) ;
18+ readonly onDidChangeTreeData = this . _onDidChangeTreeData . event ;
19+
20+ private _localFileChanges : FileChangeNode [ ] = [ ] ;
21+ private _comments : Comment [ ] = [ ] ;
22+ private _pullrequest : IPullRequestModel = null ;
23+ private _pullRequestManager : IPullRequestManager ;
24+
25+ constructor ( private context : vscode . ExtensionContext ) {
26+ super ( ( ) => this . dispose ( ) ) ;
27+ this . context . subscriptions . push ( vscode . window . registerTreeDataProvider < TreeNode > ( 'prStatus' , this ) ) ;
28+ }
29+
30+ async showPullRequestFileChanges ( pullRequestManager : IPullRequestManager , pullrequest : IPullRequestModel , fileChanges : FileChangeNode [ ] , comments : Comment [ ] ) {
31+ this . _pullRequestManager = pullRequestManager ;
32+ this . _pullrequest = pullrequest ;
33+ this . _comments = comments ;
34+
35+ await vscode . commands . executeCommand (
36+ 'setContext' ,
37+ 'github:inReviewMode' ,
38+ true
39+ ) ;
40+
41+ this . _localFileChanges = fileChanges ;
42+ this . _onDidChangeTreeData . fire ( ) ;
43+ }
44+
45+ async hide ( ) {
46+ await vscode . commands . executeCommand (
47+ 'setContext' ,
48+ 'github:inReviewMode' ,
49+ false
50+ ) ;
51+ }
52+
53+ getTreeItem ( element : TreeNode ) : vscode . TreeItem | Thenable < vscode . TreeItem > {
54+ return element . getTreeItem ( ) ;
55+ }
56+
57+ getChildren ( element ?: FileChangeNode ) : vscode . ProviderResult < TreeNode [ ] > {
58+ if ( ! element ) {
59+ const descriptionNode = new DescriptionNode ( 'Description' ,
60+ {
61+ light : Resource . icons . light . Description ,
62+ dark : Resource . icons . dark . Description
63+ } , this . _pullrequest ) ;
64+ const filesCategoryNode = new FilesCategoryNode ( this . _localFileChanges ) ;
65+ const commitsCategoryNode = new CommitsNode ( this . _pullRequestManager , this . _pullrequest , this . _comments ) ;
66+ return [ descriptionNode , filesCategoryNode , commitsCategoryNode ] ;
67+ } else {
68+ return element . getChildren ( ) ;
69+ }
70+ }
71+ }
0 commit comments