@@ -34,7 +34,7 @@ import { ConfigureLanguageBasedSettingsAction } from 'vs/workbench/contrib/prefe
34
34
import { SettingsEditorContribution } from 'vs/workbench/contrib/preferences/browser/preferencesEditor' ;
35
35
import { preferencesOpenSettingsIcon } from 'vs/workbench/contrib/preferences/browser/preferencesIcons' ;
36
36
import { SettingsEditor2 , SettingsFocusContext } from 'vs/workbench/contrib/preferences/browser/settingsEditor2' ;
37
- import { CONTEXT_KEYBINDINGS_EDITOR , CONTEXT_KEYBINDINGS_SEARCH_FOCUS , CONTEXT_KEYBINDING_FOCUS , CONTEXT_SETTINGS_EDITOR , CONTEXT_SETTINGS_EDITOR_IN_USER_TAB , CONTEXT_SETTINGS_JSON_EDITOR , CONTEXT_SETTINGS_ROW_FOCUS , CONTEXT_SETTINGS_SEARCH_FOCUS , CONTEXT_TOC_ROW_FOCUS , CONTEXT_WHEN_FOCUS , KEYBINDINGS_EDITOR_COMMAND_ACCEPT_WHEN , KEYBINDINGS_EDITOR_COMMAND_ADD , KEYBINDINGS_EDITOR_COMMAND_CLEAR_SEARCH_HISTORY , KEYBINDINGS_EDITOR_COMMAND_CLEAR_SEARCH_RESULTS , KEYBINDINGS_EDITOR_COMMAND_COPY , KEYBINDINGS_EDITOR_COMMAND_COPY_COMMAND , KEYBINDINGS_EDITOR_COMMAND_COPY_COMMAND_TITLE , KEYBINDINGS_EDITOR_COMMAND_DEFINE , KEYBINDINGS_EDITOR_COMMAND_DEFINE_WHEN , KEYBINDINGS_EDITOR_COMMAND_FOCUS_KEYBINDINGS , KEYBINDINGS_EDITOR_COMMAND_RECORD_SEARCH_KEYS , KEYBINDINGS_EDITOR_COMMAND_REJECT_WHEN , KEYBINDINGS_EDITOR_COMMAND_REMOVE , KEYBINDINGS_EDITOR_COMMAND_RESET , KEYBINDINGS_EDITOR_COMMAND_SEARCH , KEYBINDINGS_EDITOR_COMMAND_SHOW_SIMILAR , KEYBINDINGS_EDITOR_COMMAND_SORTBY_PRECEDENCE , KEYBINDINGS_EDITOR_SHOW_DEFAULT_KEYBINDINGS , KEYBINDINGS_EDITOR_SHOW_EXTENSION_KEYBINDINGS , KEYBINDINGS_EDITOR_SHOW_USER_KEYBINDINGS , REQUIRE_TRUSTED_WORKSPACE_SETTING_TAG , SETTINGS_EDITOR_COMMAND_CLEAR_SEARCH_RESULTS , SETTINGS_EDITOR_COMMAND_SHOW_CONTEXT_MENU } from 'vs/workbench/contrib/preferences/common/preferences' ;
37
+ import { CONTEXT_KEYBINDINGS_EDITOR , CONTEXT_KEYBINDINGS_SEARCH_FOCUS , CONTEXT_KEYBINDING_FOCUS , CONTEXT_SETTINGS_EDITOR , CONTEXT_SETTINGS_JSON_EDITOR , CONTEXT_SETTINGS_ROW_FOCUS , CONTEXT_SETTINGS_SEARCH_FOCUS , CONTEXT_TOC_ROW_FOCUS , CONTEXT_WHEN_FOCUS , KEYBINDINGS_EDITOR_COMMAND_ACCEPT_WHEN , KEYBINDINGS_EDITOR_COMMAND_ADD , KEYBINDINGS_EDITOR_COMMAND_CLEAR_SEARCH_HISTORY , KEYBINDINGS_EDITOR_COMMAND_CLEAR_SEARCH_RESULTS , KEYBINDINGS_EDITOR_COMMAND_COPY , KEYBINDINGS_EDITOR_COMMAND_COPY_COMMAND , KEYBINDINGS_EDITOR_COMMAND_COPY_COMMAND_TITLE , KEYBINDINGS_EDITOR_COMMAND_DEFINE , KEYBINDINGS_EDITOR_COMMAND_DEFINE_WHEN , KEYBINDINGS_EDITOR_COMMAND_FOCUS_KEYBINDINGS , KEYBINDINGS_EDITOR_COMMAND_RECORD_SEARCH_KEYS , KEYBINDINGS_EDITOR_COMMAND_REJECT_WHEN , KEYBINDINGS_EDITOR_COMMAND_REMOVE , KEYBINDINGS_EDITOR_COMMAND_RESET , KEYBINDINGS_EDITOR_COMMAND_SEARCH , KEYBINDINGS_EDITOR_COMMAND_SHOW_SIMILAR , KEYBINDINGS_EDITOR_COMMAND_SORTBY_PRECEDENCE , KEYBINDINGS_EDITOR_SHOW_DEFAULT_KEYBINDINGS , KEYBINDINGS_EDITOR_SHOW_EXTENSION_KEYBINDINGS , KEYBINDINGS_EDITOR_SHOW_USER_KEYBINDINGS , REQUIRE_TRUSTED_WORKSPACE_SETTING_TAG , SETTINGS_EDITOR_COMMAND_CLEAR_SEARCH_RESULTS , SETTINGS_EDITOR_COMMAND_SHOW_CONTEXT_MENU } from 'vs/workbench/contrib/preferences/common/preferences' ;
38
38
import { PreferencesContribution } from 'vs/workbench/contrib/preferences/common/preferencesContribution' ;
39
39
import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
40
40
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService' ;
@@ -57,8 +57,6 @@ const SETTINGS_EDITOR_COMMAND_FOCUS_CONTROL = 'settings.action.focusSettingContr
57
57
const SETTINGS_EDITOR_COMMAND_FOCUS_UP = 'settings.action.focusLevelUp' ;
58
58
59
59
const SETTINGS_EDITOR_COMMAND_SWITCH_TO_JSON = 'settings.switchToJSON' ;
60
- const SETTINGS_EDITOR_COMMAND_SWITCH_TO_APPLICATION_JSON = 'settings.switchToApplicationJSON' ;
61
- const SETTINGS_EDITOR_COMMAND_SWITCH_TO_CURRENT_PROFILE_JSON = 'settings.switchToCurrentProfileJSON' ;
62
60
const SETTINGS_EDITOR_COMMAND_FILTER_ONLINE = 'settings.filterByOnline' ;
63
61
const SETTINGS_EDITOR_COMMAND_FILTER_UNTRUSTED = 'settings.filterUntrusted' ;
64
62
@@ -122,7 +120,7 @@ Registry.as<IEditorFactoryRegistry>(EditorExtensions.EditorFactory).registerEdit
122
120
123
121
const OPEN_USER_SETTINGS_UI_TITLE = { value : nls . localize ( 'openSettings2' , "Open Settings (UI)" ) , original : 'Open Settings (UI)' } ;
124
122
const OPEN_USER_SETTINGS_JSON_TITLE = { value : nls . localize ( 'openUserSettingsJson' , "Open User Settings (JSON)" ) , original : 'Open User Settings (JSON)' } ;
125
- const OPEN_CURRENT_PROFILE_SETTINGS_JSON_TITLE = { value : nls . localize ( 'openCurrentProfileSettingsJson ' , "Open Current Profile Settings (JSON)" ) , original : 'Open Current Profile Settings (JSON)' } ;
123
+ const OPEN_APPLICATION_SETTINGS_JSON_TITLE = { value : nls . localize ( 'openApplicationSettingsJson ' , "Open Application Settings (JSON)" ) , original : 'Open Application Settings (JSON)' } ;
126
124
const category = { value : nls . localize ( 'preferences' , "Preferences" ) , original : 'Preferences' } ;
127
125
128
126
interface IOpenSettingsActionOptions {
@@ -209,30 +207,27 @@ class PreferencesActionsContribution extends Disposable implements IWorkbenchCon
209
207
}
210
208
} ) ;
211
209
212
- const that = this ;
213
- const registerOpenSettingsJsonCommandDisposable = this . _register ( new MutableDisposable ( ) ) ;
214
- const registerOpenSettingsJsonCommand = ( ) => {
215
- registerOpenSettingsJsonCommandDisposable . value = registerAction2 ( class extends Action2 {
216
- constructor ( ) {
217
- super ( {
218
- id : 'workbench.action.openSettingsJson' ,
219
- title : that . userDataProfileService . currentProfile . isDefault ? OPEN_USER_SETTINGS_JSON_TITLE : OPEN_CURRENT_PROFILE_SETTINGS_JSON_TITLE ,
220
- category,
221
- f1 : true ,
222
- } ) ;
223
- }
224
- run ( accessor : ServicesAccessor , args : IOpenSettingsActionOptions ) {
225
- args = sanitizeOpenSettingsArgs ( args ) ;
226
- return accessor . get ( IPreferencesService ) . openSettings ( { jsonEditor : true , ...args } ) ;
227
- }
228
- } ) ;
229
- } ;
210
+ registerAction2 ( class extends Action2 {
211
+ constructor ( ) {
212
+ super ( {
213
+ id : 'workbench.action.openSettingsJson' ,
214
+ title : OPEN_USER_SETTINGS_JSON_TITLE ,
215
+ category,
216
+ f1 : true ,
217
+ } ) ;
218
+ }
219
+ run ( accessor : ServicesAccessor , args : IOpenSettingsActionOptions ) {
220
+ args = sanitizeOpenSettingsArgs ( args ) ;
221
+ return accessor . get ( IPreferencesService ) . openSettings ( { jsonEditor : true , ...args } ) ;
222
+ }
223
+ } ) ;
230
224
225
+ const that = this ;
231
226
registerAction2 ( class extends Action2 {
232
227
constructor ( ) {
233
228
super ( {
234
229
id : 'workbench.action.openApplicationSettingsJson' ,
235
- title : OPEN_USER_SETTINGS_JSON_TITLE ,
230
+ title : OPEN_APPLICATION_SETTINGS_JSON_TITLE ,
236
231
category,
237
232
menu : {
238
233
id : MenuId . CommandPalette ,
@@ -276,13 +271,11 @@ class PreferencesActionsContribution extends Disposable implements IWorkbenchCon
276
271
} ) ;
277
272
278
273
const registerOpenUserSettingsEditorFromJsonActionDisposable = this . _register ( new MutableDisposable ( ) ) ;
274
+ const openUserSettingsEditorWhen = ContextKeyExpr . and (
275
+ ContextKeyExpr . or ( ResourceContextKey . Resource . isEqualTo ( this . userDataProfileService . currentProfile . settingsResource . toString ( ) ) ,
276
+ ResourceContextKey . Resource . isEqualTo ( this . userDataProfilesService . defaultProfile . settingsResource . toString ( ) ) ) ,
277
+ ContextKeyExpr . not ( 'isInDiffEditor' ) ) ;
279
278
const registerOpenUserSettingsEditorFromJsonAction = ( ) => {
280
- let when = ContextKeyExpr . and ( ResourceContextKey . Resource . isEqualTo ( this . userDataProfileService . currentProfile . settingsResource . toString ( ) ) , ContextKeyExpr . not ( 'isInDiffEditor' ) ) ;
281
- if ( ! this . userDataProfileService . currentProfile . isDefault ) {
282
- // If the default profile is not active, also show the action when we're in the
283
- // default profile JSON file, which contains the application-scoped settings.
284
- when = ContextKeyExpr . or ( when , ContextKeyExpr . and ( ResourceContextKey . Resource . isEqualTo ( this . userDataProfilesService . defaultProfile . settingsResource . toString ( ) ) , ContextKeyExpr . not ( 'isInDiffEditor' ) ) ) ;
285
- }
286
279
registerOpenUserSettingsEditorFromJsonActionDisposable . value = registerAction2 ( class extends Action2 {
287
280
constructor ( ) {
288
281
super ( {
@@ -291,7 +284,7 @@ class PreferencesActionsContribution extends Disposable implements IWorkbenchCon
291
284
icon : preferencesOpenSettingsIcon ,
292
285
menu : [ {
293
286
id : MenuId . EditorTitle ,
294
- when,
287
+ when : openUserSettingsEditorWhen ,
295
288
group : 'navigation' ,
296
289
order : 1
297
290
} ]
@@ -304,93 +297,35 @@ class PreferencesActionsContribution extends Disposable implements IWorkbenchCon
304
297
} ) ;
305
298
} ;
306
299
307
- const openJsonFromSettingsEditorDisposableStore = this . _register ( new DisposableStore ( ) ) ;
308
- const registerOpenJsonFromSettingsEditorAction = ( ) => {
309
- openJsonFromSettingsEditorDisposableStore . clear ( ) ;
310
- if ( ! this . userDataProfileService . currentProfile . isDefault ) {
311
- // When the default profile is not active, the action for the User tab needs a dropdown
312
- // because User tab settings in that case are actually saved in two separate files.
313
- const submenuId = MenuId . for ( 'PreferencesSubMenu' ) ;
314
- openJsonFromSettingsEditorDisposableStore . add ( registerAction2 ( class extends Action2 {
315
- constructor ( ) {
316
- super ( {
317
- id : SETTINGS_EDITOR_COMMAND_SWITCH_TO_CURRENT_PROFILE_JSON ,
318
- title : OPEN_CURRENT_PROFILE_SETTINGS_JSON_TITLE ,
319
- menu : [ { id : submenuId , order : 1 } ]
320
- } ) ;
321
- }
322
- run ( accessor : ServicesAccessor ) {
323
- const editorPane = accessor . get ( IEditorService ) . activeEditorPane ;
324
- if ( editorPane instanceof SettingsEditor2 ) {
325
- return editorPane . switchToSettingsFile ( ) ;
326
- }
327
- return null ;
328
- }
329
- } ) ) ;
330
- openJsonFromSettingsEditorDisposableStore . add ( registerAction2 ( class extends Action2 {
331
- constructor ( ) {
332
- super ( {
333
- id : SETTINGS_EDITOR_COMMAND_SWITCH_TO_APPLICATION_JSON ,
334
- title : OPEN_USER_SETTINGS_JSON_TITLE ,
335
- menu : [ { id : submenuId , order : 2 } ]
336
- } ) ;
337
- }
338
- run ( accessor : ServicesAccessor ) {
339
- const editorPane = accessor . get ( IEditorService ) . activeEditorPane ;
340
- if ( editorPane instanceof SettingsEditor2 ) {
341
- return editorPane . switchToApplicationSettingsFile ( ) ;
342
- }
343
- return null ;
344
- }
345
- } ) ) ;
346
- openJsonFromSettingsEditorDisposableStore . add ( MenuRegistry . appendMenuItem ( MenuId . EditorTitle , {
300
+ const openSettingsJsonWhen = ContextKeyExpr . and ( CONTEXT_SETTINGS_EDITOR , CONTEXT_SETTINGS_JSON_EDITOR . toNegated ( ) ) ;
301
+ registerAction2 ( class extends Action2 {
302
+ constructor ( ) {
303
+ super ( {
304
+ id : SETTINGS_EDITOR_COMMAND_SWITCH_TO_JSON ,
347
305
title : { value : nls . localize ( 'openSettingsJson' , "Open Settings (JSON)" ) , original : 'Open Settings (JSON)' } ,
348
- submenu : submenuId ,
349
306
icon : preferencesOpenSettingsIcon ,
350
- when : ContextKeyExpr . and ( CONTEXT_SETTINGS_EDITOR , CONTEXT_SETTINGS_EDITOR_IN_USER_TAB , CONTEXT_SETTINGS_JSON_EDITOR . toNegated ( ) ) ,
351
- group : 'navigation' ,
352
- order : 1
353
- } ) ) ;
354
- }
355
-
356
- let openSettingsJsonWhen = ContextKeyExpr . and ( CONTEXT_SETTINGS_EDITOR , CONTEXT_SETTINGS_JSON_EDITOR . toNegated ( ) ) ;
357
- if ( ! this . userDataProfileService . currentProfile . isDefault ) {
358
- // If we're not in the default profile, we already created the action for the User tab above,
359
- // so we want to make sure the user is not in the User tab for this more general action.
360
- openSettingsJsonWhen = ContextKeyExpr . and ( openSettingsJsonWhen , CONTEXT_SETTINGS_EDITOR_IN_USER_TAB . toNegated ( ) ) ;
307
+ menu : [ {
308
+ id : MenuId . EditorTitle ,
309
+ when : openSettingsJsonWhen ,
310
+ group : 'navigation' ,
311
+ order : 1
312
+ } ]
313
+ } ) ;
361
314
}
362
- openJsonFromSettingsEditorDisposableStore . add ( registerAction2 ( class extends Action2 {
363
- constructor ( ) {
364
- super ( {
365
- id : SETTINGS_EDITOR_COMMAND_SWITCH_TO_JSON ,
366
- title : { value : nls . localize ( 'openSettingsJson' , "Open Settings (JSON)" ) , original : 'Open Settings (JSON)' } ,
367
- icon : preferencesOpenSettingsIcon ,
368
- menu : [ {
369
- id : MenuId . EditorTitle ,
370
- when : openSettingsJsonWhen ,
371
- group : 'navigation' ,
372
- order : 1
373
- } ]
374
- } ) ;
375
- }
376
- run ( accessor : ServicesAccessor ) {
377
- const editorPane = accessor . get ( IEditorService ) . activeEditorPane ;
378
- if ( editorPane instanceof SettingsEditor2 ) {
379
- return editorPane . switchToSettingsFile ( ) ;
380
- }
381
- return null ;
315
+ run ( accessor : ServicesAccessor ) {
316
+ const editorPane = accessor . get ( IEditorService ) . activeEditorPane ;
317
+ if ( editorPane instanceof SettingsEditor2 ) {
318
+ return editorPane . switchToSettingsFile ( ) ;
382
319
}
383
- } ) ) ;
384
- } ;
320
+ return null ;
321
+ }
322
+ } ) ;
385
323
386
324
registerOpenUserSettingsEditorFromJsonAction ( ) ;
387
- registerOpenJsonFromSettingsEditorAction ( ) ;
388
- registerOpenSettingsJsonCommand ( ) ;
389
325
390
326
this . _register ( this . userDataProfileService . onDidChangeCurrentProfile ( ( ) => {
327
+ // Force the action to check the context again.
391
328
registerOpenUserSettingsEditorFromJsonAction ( ) ;
392
- registerOpenJsonFromSettingsEditorAction ( ) ;
393
- registerOpenSettingsJsonCommand ( ) ;
394
329
} ) ) ;
395
330
396
331
registerAction2 ( class extends Action2 {
0 commit comments