4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
6
import * as vscode from 'vscode' ;
7
+ import { GitApiImpl } from '../api/api1' ;
8
+ import { commands , contexts } from '../common/executeCommands' ;
7
9
import Logger , { PR_TREE } from '../common/logger' ;
8
10
import { FILE_LIST_LAYOUT } from '../common/settingKeys' ;
9
11
import { FolderRepositoryManager , SETTINGS_NAMESPACE } from '../github/folderRepositoryManager' ;
10
12
import { PullRequestModel } from '../github/pullRequestModel' ;
13
+ import { RepositoriesManager } from '../github/repositoriesManager' ;
11
14
import { ReviewModel } from './reviewModel' ;
12
15
import { DescriptionNode } from './treeNodes/descriptionNode' ;
13
16
import { GitFileChangeNode } from './treeNodes/fileChangeNode' ;
@@ -26,7 +29,7 @@ export class PullRequestChangesTreeDataProvider extends vscode.Disposable implem
26
29
return this . _view ;
27
30
}
28
31
29
- constructor ( private _context : vscode . ExtensionContext ) {
32
+ constructor ( private _context : vscode . ExtensionContext , private _git : GitApiImpl , private _reposManager : RepositoriesManager ) {
30
33
super ( ( ) => this . dispose ( ) ) ;
31
34
this . _view = vscode . window . createTreeView ( 'prStatus:github' , {
32
35
treeDataProvider : this ,
@@ -92,29 +95,41 @@ export class PullRequestChangesTreeDataProvider extends vscode.Disposable implem
92
95
this . _pullRequestManagerMap . set ( pullRequestManager , node ) ;
93
96
this . updateViewTitle ( ) ;
94
97
95
- await vscode . commands . executeCommand ( 'setContext' , 'github:inReviewMode' , true ) ;
98
+ await this . setReviewModeContexts ( ) ;
96
99
this . _onDidChangeTreeData . fire ( ) ;
97
100
98
101
if ( shouldReveal ) {
99
102
this . reveal ( node ) ;
100
103
}
101
104
}
102
105
106
+ private async setReviewModeContexts ( ) {
107
+ await commands . setContext ( contexts . IN_REVIEW_MODE , this . _pullRequestManagerMap . size > 0 ) ;
108
+
109
+ const rootUrisNotInReviewMode : string [ ] = [ ] ;
110
+ const rootUrisInReviewMode : string [ ] = [ ] ;
111
+ this . _git . repositories . forEach ( repo => {
112
+ const folderManager = this . _reposManager . getManagerForFile ( repo . rootUri ) ;
113
+ if ( folderManager && ! this . _pullRequestManagerMap . has ( folderManager ) ) {
114
+ rootUrisNotInReviewMode . push ( repo . rootUri . toString ( ) ) ;
115
+ } else if ( folderManager ) {
116
+ rootUrisInReviewMode . push ( repo . rootUri . toString ( ) ) ;
117
+ }
118
+ } ) ;
119
+ await commands . setContext ( contexts . REPOS_NOT_IN_REVIEW_MODE , rootUrisNotInReviewMode ) ;
120
+ await commands . setContext ( contexts . REPOS_IN_REVIEW_MODE , rootUrisInReviewMode ) ;
121
+ }
122
+
103
123
async removePrFromView ( pullRequestManager : FolderRepositoryManager ) {
104
124
const oldPR = this . _pullRequestManagerMap . has ( pullRequestManager ) ? this . _pullRequestManagerMap . get ( pullRequestManager ) : undefined ;
105
125
Logger . appendLine ( `Removing PR #${ oldPR ?. pullRequestModel . number } from tree` , PR_TREE ) ;
106
126
107
127
oldPR ?. dispose ( ) ;
108
128
this . _pullRequestManagerMap . delete ( pullRequestManager ) ;
109
129
this . updateViewTitle ( ) ;
110
- if ( this . _pullRequestManagerMap . size === 0 ) {
111
- this . hide ( ) ;
112
- }
113
- this . _onDidChangeTreeData . fire ( ) ;
114
- }
115
130
116
- async hide ( ) {
117
- await vscode . commands . executeCommand ( 'setContext' , 'github:inReviewMode' , false ) ;
131
+ await this . setReviewModeContexts ( ) ;
132
+ this . _onDidChangeTreeData . fire ( ) ;
118
133
}
119
134
120
135
getTreeItem ( element : TreeNode ) : vscode . TreeItem | Thenable < vscode . TreeItem > {
0 commit comments