55
66import * as vscode from 'vscode' ;
77import { AuthenticationError } from '../../common/authentication' ;
8- import { PR_SETTINGS_NAMESPACE , QUERIES } from '../../common/settingKeys' ;
98import { ITelemetry } from '../../common/telemetry' ;
109import { formatError } from '../../common/utils' ;
1110import { FolderRepositoryManager , ItemsResponseResult } from '../../github/folderRepositoryManager' ;
@@ -27,19 +26,6 @@ export enum PRCategoryActionType {
2726 ConfigureRemotes ,
2827}
2928
30- interface QueryInspect {
31- key : string ;
32- defaultValue ?: { label : string ; query : string } [ ] ;
33- globalValue ?: { label : string ; query : string } [ ] ;
34- workspaceValue ?: { label : string ; query : string } [ ] ;
35- workspaceFolderValue ?: { label : string ; query : string } [ ] ;
36- defaultLanguageValue ?: { label : string ; query : string } [ ] ;
37- globalLanguageValue ?: { label : string ; query : string } [ ] ;
38- workspaceLanguageValue ?: { label : string ; query : string } [ ] ;
39- workspaceFolderLanguageValue ?: { label : string ; query : string } [ ] ;
40- languageIds ?: string [ ]
41- }
42-
4329export class PRCategoryActionNode extends TreeNode implements vscode . TreeItem {
4430 public collapsibleState : vscode . TreeItemCollapsibleState ;
4531 public iconPath ?: { light : string | vscode . Uri ; dark : string | vscode . Uri } ;
@@ -167,81 +153,6 @@ export class CategoryTreeNode extends TreeNode implements vscode.TreeItem {
167153 }
168154 }
169155
170- private async addNewQuery ( config : vscode . WorkspaceConfiguration , inspect : QueryInspect | undefined , startingValue : string ) {
171- const inputBox = vscode . window . createInputBox ( ) ;
172- inputBox . title = vscode . l10n . t ( 'Enter the title of the new query' ) ;
173- inputBox . placeholder = vscode . l10n . t ( 'Title' ) ;
174- inputBox . step = 1 ;
175- inputBox . totalSteps = 2 ;
176- inputBox . show ( ) ;
177- let title : string | undefined ;
178- inputBox . onDidAccept ( async ( ) => {
179- inputBox . validationMessage = '' ;
180- if ( inputBox . step === 1 ) {
181- if ( ! inputBox . value ) {
182- inputBox . validationMessage = vscode . l10n . t ( 'Title is required' ) ;
183- return ;
184- }
185-
186- title = inputBox . value ;
187- inputBox . value = startingValue ;
188- inputBox . title = vscode . l10n . t ( 'Enter the GitHub search query' ) ;
189- inputBox . step ++ ;
190- } else {
191- if ( ! inputBox . value ) {
192- inputBox . validationMessage = vscode . l10n . t ( 'Query is required' ) ;
193- return ;
194- }
195- inputBox . busy = true ;
196- if ( inputBox . value && title ) {
197- if ( inspect ?. workspaceValue ) {
198- inspect . workspaceValue . push ( { label : title , query : inputBox . value } ) ;
199- await config . update ( QUERIES , inspect . workspaceValue , vscode . ConfigurationTarget . Workspace ) ;
200- } else {
201- const value = config . get < { label : string ; query : string } [ ] > ( QUERIES ) ;
202- value ?. push ( { label : title , query : inputBox . value } ) ;
203- await config . update ( QUERIES , value , vscode . ConfigurationTarget . Global ) ;
204- }
205- }
206- inputBox . dispose ( ) ;
207- }
208- } ) ;
209- inputBox . onDidHide ( ( ) => inputBox . dispose ( ) ) ;
210- }
211-
212- private updateQuery ( queries : { label : string ; query : string } [ ] , queryToUpdate : { label : string ; query : string } ) {
213- for ( const query of queries ) {
214- if ( query . label === queryToUpdate . label ) {
215- query . query = queryToUpdate . query ;
216- return ;
217- }
218- }
219- }
220-
221- private async openSettings ( config : vscode . WorkspaceConfiguration , inspect : QueryInspect | undefined ) {
222- let command : string ;
223- if ( inspect ?. workspaceValue ) {
224- command = 'workbench.action.openWorkspaceSettingsFile' ;
225- } else {
226- const value = config . get < { label : string ; query : string } [ ] > ( QUERIES ) ;
227- if ( inspect ?. defaultValue && JSON . stringify ( inspect ?. defaultValue ) === JSON . stringify ( value ) ) {
228- await config . update ( QUERIES , inspect . defaultValue , vscode . ConfigurationTarget . Global ) ;
229- }
230- command = 'workbench.action.openSettingsJson' ;
231- }
232- await vscode . commands . executeCommand ( command ) ;
233- const editor = vscode . window . activeTextEditor ;
234- if ( editor ) {
235- const text = editor . document . getText ( ) ;
236- const search = text . search ( this . label ! ) ;
237- if ( search >= 0 ) {
238- const position = editor . document . positionAt ( search ) ;
239- editor . revealRange ( new vscode . Range ( position , position ) ) ;
240- editor . selection = new vscode . Selection ( position , position ) ;
241- }
242- }
243- }
244-
245156 public async expandPullRequest ( pullRequest : PullRequestModel , retry : boolean = true ) : Promise < boolean > {
246157 if ( ! this . children && retry ) {
247158 await this . getChildren ( ) ;
@@ -265,41 +176,6 @@ export class CategoryTreeNode extends TreeNode implements vscode.TreeItem {
265176 return false ;
266177 }
267178
268- async editQuery ( ) {
269- const config = vscode . workspace . getConfiguration ( PR_SETTINGS_NAMESPACE ) ;
270- const inspect = config . inspect < { label : string ; query : string } [ ] > ( QUERIES ) ;
271-
272- const inputBox = vscode . window . createQuickPick ( ) ;
273- inputBox . title = vscode . l10n . t ( 'Edit Pull Request Query "{0}"' , this . label ?? '' ) ;
274- inputBox . value = this . _categoryQuery ?? '' ;
275- inputBox . items = [ { iconPath : new vscode . ThemeIcon ( 'pencil' ) , label : vscode . l10n . t ( 'Save edits' ) , alwaysShow : true } , { iconPath : new vscode . ThemeIcon ( 'add' ) , label : vscode . l10n . t ( 'Add new query' ) , alwaysShow : true } , { iconPath : new vscode . ThemeIcon ( 'settings' ) , label : vscode . l10n . t ( 'Edit in settings.json' ) , alwaysShow : true } ] ;
276- inputBox . activeItems = [ ] ;
277- inputBox . selectedItems = [ ] ;
278- inputBox . onDidAccept ( async ( ) => {
279- inputBox . busy = true ;
280- if ( inputBox . selectedItems [ 0 ] === inputBox . items [ 0 ] ) {
281- const newQuery = inputBox . value ;
282- if ( newQuery !== this . _categoryQuery && this . label ) {
283- if ( inspect ?. workspaceValue ) {
284- this . updateQuery ( inspect . workspaceValue , { label : this . label , query : newQuery } ) ;
285- await config . update ( QUERIES , inspect . workspaceValue , vscode . ConfigurationTarget . Workspace ) ;
286- } else {
287- const value = config . get < { label : string ; query : string } [ ] > ( QUERIES ) ?? inspect ! . defaultValue ! ;
288- this . updateQuery ( value , { label : this . label , query : newQuery } ) ;
289- await config . update ( QUERIES , value , vscode . ConfigurationTarget . Global ) ;
290- }
291- }
292- } else if ( inputBox . selectedItems [ 0 ] === inputBox . items [ 1 ] ) {
293- this . addNewQuery ( config , inspect , inputBox . value ) ;
294- } else if ( inputBox . selectedItems [ 0 ] === inputBox . items [ 2 ] ) {
295- this . openSettings ( config , inspect ) ;
296- }
297- inputBox . dispose ( ) ;
298- } ) ;
299- inputBox . onDidHide ( ( ) => inputBox . dispose ( ) ) ;
300- inputBox . show ( ) ;
301- }
302-
303179 override async getChildren ( ) : Promise < TreeNode [ ] > {
304180 await super . getChildren ( ) ;
305181 const isFirstLoad = ! this . _firstLoad ;
0 commit comments