@@ -9,9 +9,9 @@ import { localize } from 'vs/nls';
99import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility' ;
1010import { Action2 } from 'vs/platform/actions/common/actions' ;
1111import { AudioCue , IAudioCueService } from 'vs/platform/audioCues/browser/audioCueService' ;
12+ import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
1213import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
1314import { IQuickInputService , IQuickPickItem } from 'vs/platform/quickinput/common/quickInput' ;
14- import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences' ;
1515
1616export class ShowAudioCueHelp extends Action2 {
1717 static readonly ID = 'audioCues.help' ;
@@ -29,36 +29,45 @@ export class ShowAudioCueHelp extends Action2 {
2929
3030 override async run ( accessor : ServicesAccessor ) : Promise < void > {
3131 const audioCueService = accessor . get ( IAudioCueService ) ;
32- const quickPickService = accessor . get ( IQuickInputService ) ;
33- const preferencesService = accessor . get ( IPreferencesService ) ;
32+ const quickInputService = accessor . get ( IQuickInputService ) ;
33+ const configurationService = accessor . get ( IConfigurationService ) ;
3434 const accessibilityService = accessor . get ( IAccessibilityService ) ;
35-
35+ const userGestureCues = [ AudioCue . save , AudioCue . format ] ;
3636 const items : ( IQuickPickItem & { audioCue : AudioCue } ) [ ] = AudioCue . allAudioCues . map ( ( cue , idx ) => ( {
37- label : accessibilityService . isScreenReaderOptimized ( ) ?
38- `${ cue . name } ${ audioCueService . isCueEnabled ( cue ) ? '' : ' (' + localize ( 'disabled' , "Disabled" ) + ')' } `
39- : `${ audioCueService . isCueEnabled ( cue ) ? '$(check)' : ' ' } ${ cue . name } ` ,
37+ label : userGestureCues . includes ( cue ) ? `${ cue . name } (${ configurationService . getValue ( cue . settingsKey ) } )` : cue . name ,
4038 audioCue : cue ,
41- buttons : [ {
39+ buttons : userGestureCues . includes ( cue ) ? [ {
4240 iconClass : ThemeIcon . asClassName ( Codicon . settingsGear ) ,
4341 tooltip : localize ( 'audioCues.help.settings' , 'Enable/Disable Audio Cue' ) ,
44- } ] ,
42+ alwaysVisible : true
43+ } ] : [ ]
4544 } ) ) ;
46-
47- const quickPick = quickPickService . pick < IQuickPickItem & { audioCue : AudioCue } > (
48- items ,
49- {
50- activeItem : items [ 0 ] ,
51- onDidFocus : ( item ) => {
52- audioCueService . playSound ( item . audioCue . sound . getSound ( true ) , true ) ;
53- } ,
54- onDidTriggerItemButton : ( context ) => {
55- preferencesService . openSettings ( { query : context . item . audioCue . settingsKey } ) ;
56- } ,
57- placeHolder : localize ( 'audioCues.help.placeholder' , 'Select an audio cue to play' ) ,
45+ const qp = quickInputService . createQuickPick < IQuickPickItem & { audioCue : AudioCue } > ( ) ;
46+ qp . items = items ;
47+ qp . selectedItems = items . filter ( i => audioCueService . isCueEnabled ( i . audioCue ) ) ;
48+ qp . onDidAccept ( ( ) => {
49+ const enabledCues = qp . selectedItems . map ( i => i . audioCue ) ;
50+ const disabledCues = AudioCue . allAudioCues . filter ( cue => ! enabledCues . includes ( cue ) ) ;
51+ for ( const cue of enabledCues ) {
52+ if ( ! userGestureCues . includes ( cue ) ) {
53+ configurationService . updateValue ( cue . settingsKey , accessibilityService . isScreenReaderOptimized ( ) ? 'auto' : 'on' ) ;
54+ }
5855 }
59- ) ;
60-
61- await quickPick ;
56+ for ( const cue of disabledCues ) {
57+ if ( userGestureCues . includes ( cue ) ) {
58+ configurationService . updateValue ( cue . settingsKey , 'never' ) ;
59+ } else {
60+ configurationService . updateValue ( cue . settingsKey , 'off' ) ;
61+ }
62+ }
63+ qp . hide ( ) ;
64+ } ) ;
65+ qp . onDidChangeActive ( ( ) => {
66+ audioCueService . playSound ( qp . activeItems [ 0 ] . audioCue . sound . getSound ( true ) , true ) ;
67+ } ) ;
68+ qp . placeholder = localize ( 'audioCues.help.placeholder' , 'Select an audio cue to play and configure' ) ;
69+ qp . canSelectMany = true ;
70+ await qp . show ( ) ;
6271 }
6372}
6473
@@ -78,32 +87,40 @@ export class ShowAccessibilityAlertHelp extends Action2 {
7887
7988 override async run ( accessor : ServicesAccessor ) : Promise < void > {
8089 const audioCueService = accessor . get ( IAudioCueService ) ;
81- const quickPickService = accessor . get ( IQuickInputService ) ;
82- const preferencesService = accessor . get ( IPreferencesService ) ;
83- const accessibilityService = accessor . get ( IAccessibilityService ) ;
84-
85- const items : ( IQuickPickItem & { audioCue : AudioCue } ) [ ] = AudioCue . allAudioCues . filter ( c => ! ! c . alertMessage ) . map ( ( cue , idx ) => ( {
86- label : accessibilityService . isScreenReaderOptimized ( ) ?
87- `${ cue . name } ${ audioCueService . isAlertEnabled ( cue ) ? '' : ' (' + localize ( 'disabled' , "Disabled" ) + ')' } `
88- : `${ audioCueService . isAlertEnabled ( cue ) ? '$(check)' : ' ' } ${ cue . name } ` ,
90+ const quickInputService = accessor . get ( IQuickInputService ) ;
91+ const configurationService = accessor . get ( IConfigurationService ) ;
92+ const userGestureAlerts = [ AudioCue . save , AudioCue . format ] ;
93+ const items : ( IQuickPickItem & { audioCue : AudioCue } ) [ ] = AudioCue . allAudioCues . filter ( c => c . alertSettingsKey ) . map ( ( cue , idx ) => ( {
94+ label : userGestureAlerts . includes ( cue ) && cue . alertSettingsKey ? `${ cue . name } (${ configurationService . getValue ( cue . alertSettingsKey ) } )` : cue . name ,
8995 audioCue : cue ,
90- buttons : [ {
96+ buttons : userGestureAlerts . includes ( cue ) ? [ {
9197 iconClass : ThemeIcon . asClassName ( Codicon . settingsGear ) ,
92- tooltip : localize ( 'alerts.help.settings' , 'Enable/Disable Audio Cue' ) ,
93- } ] ,
98+ tooltip : localize ( 'alert.help.settings' , 'Enable/Disable Alert' ) ,
99+ alwaysVisible : true
100+ } ] : [ ]
94101 } ) ) ;
95-
96- const quickPick = quickPickService . pick < IQuickPickItem & { audioCue : AudioCue } > (
97- items ,
98- {
99- activeItem : items [ 0 ] ,
100- onDidTriggerItemButton : ( context ) => {
101- preferencesService . openSettings ( { query : context . item . audioCue . alertSettingsKey } ) ;
102- } ,
103- placeHolder : localize ( 'alerts.help.placeholder' , 'Inspect and configure the status of an alert' ) ,
102+ const qp = quickInputService . createQuickPick < IQuickPickItem & { audioCue : AudioCue } > ( ) ;
103+ qp . items = items ;
104+ qp . selectedItems = items . filter ( i => audioCueService . isAlertEnabled ( i . audioCue ) ) ;
105+ qp . onDidAccept ( ( ) => {
106+ const enabledAlerts = qp . selectedItems . map ( i => i . audioCue ) ;
107+ const disabledAlerts = AudioCue . allAudioCues . filter ( cue => ! enabledAlerts . includes ( cue ) ) ;
108+ for ( const cue of enabledAlerts ) {
109+ if ( ! userGestureAlerts . includes ( cue ) ) {
110+ configurationService . updateValue ( cue . alertSettingsKey ! , true ) ;
111+ }
104112 }
105- ) ;
106-
107- await quickPick ;
113+ for ( const cue of disabledAlerts ) {
114+ if ( userGestureAlerts . includes ( cue ) ) {
115+ configurationService . updateValue ( cue . alertSettingsKey ! , 'never' ) ;
116+ } else {
117+ configurationService . updateValue ( cue . alertSettingsKey ! , false ) ;
118+ }
119+ }
120+ qp . hide ( ) ;
121+ } ) ;
122+ qp . placeholder = localize ( 'alert.help.placeholder' , 'Select an alert to configure' ) ;
123+ qp . canSelectMany = true ;
124+ await qp . show ( ) ;
108125 }
109126}
0 commit comments