Merge pull request #195585 from microsoft/merogge/saved

add saved alert, audio cue
This commit is contained in:
Megan Rogge 2023-10-13 13:21:51 -07:00 committed by GitHub
commit ab51ad15e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 100 additions and 25 deletions

View file

@ -5,33 +5,55 @@
import { Disposable } from 'vs/base/common/lifecycle'; import { Disposable } from 'vs/base/common/lifecycle';
import { localize } from 'vs/nls'; import { localize } from 'vs/nls';
import { IAccessibilityService, IAccessibleNotificationService } from 'vs/platform/accessibility/common/accessibility'; import { AccessibleNotificationEvent, IAccessibilityService, IAccessibleNotificationService } from 'vs/platform/accessibility/common/accessibility';
import { AudioCue, IAudioCueService } from 'vs/platform/audioCues/browser/audioCueService'; import { AudioCue, IAudioCueService, Sound } from 'vs/platform/audioCues/browser/audioCueService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
export class AccessibleNotificationService extends Disposable implements IAccessibleNotificationService { export class AccessibleNotificationService extends Disposable implements IAccessibleNotificationService {
declare readonly _serviceBrand: undefined; declare readonly _serviceBrand: undefined;
private _events: Map<AccessibleNotificationEvent, { audioCue: AudioCue; alertMessage: string }> = new Map();
constructor( constructor(
@IAudioCueService private readonly _audioCueService: IAudioCueService, @IAudioCueService private readonly _audioCueService: IAudioCueService,
@IConfigurationService private readonly _configurationService: IConfigurationService, @IConfigurationService private readonly _configurationService: IConfigurationService,
@IAccessibilityService private readonly _accessibilityService: IAccessibilityService) { @IAccessibilityService private readonly _accessibilityService: IAccessibilityService) {
super(); super();
this._events.set(AccessibleNotificationEvent.Clear, { audioCue: AudioCue.clear, alertMessage: localize('cleared', "Cleared") });
this._events.set(AccessibleNotificationEvent.Save, { audioCue: AudioCue.save, alertMessage: localize('saved', "Saved") });
} }
notifyCleared(): void { notify(event: AccessibleNotificationEvent): void {
const audioCueValue = this._configurationService.getValue(AudioCue.clear.settingsKey); const { audioCue, alertMessage } = this._events.get(event)!;
const audioCueValue = this._configurationService.getValue(audioCue.settingsKey);
if (audioCueValue === 'on' || audioCueValue === 'auto' && this._accessibilityService.isScreenReaderOptimized()) { if (audioCueValue === 'on' || audioCueValue === 'auto' && this._accessibilityService.isScreenReaderOptimized()) {
this._audioCueService.playAudioCue(AudioCue.clear); this._audioCueService.playAudioCue(audioCue);
} else { } else {
alert(localize('cleared', "Cleared")); this._accessibilityService.alert(alertMessage);
} }
} }
notifySaved(userGesture: boolean): void {
const { audioCue, alertMessage } = this._events.get(AccessibleNotificationEvent.Save)!;
const alertSetting: NotificationSetting = this._configurationService.getValue('accessibility.alert.save');
if (this._shouldNotify(alertSetting, userGesture)) {
this._accessibilityService.alert(alertMessage);
}
const audioCueSetting: NotificationSetting = this._configurationService.getValue(audioCue.settingsKey);
if (this._shouldNotify(audioCueSetting, userGesture)) {
// Play sound bypasses the usual audio cue checks IE screen reader optimized, auto, etc.
this._audioCueService.playSound(Sound.save, true);
}
}
private _shouldNotify(settingValue: NotificationSetting, userGesture: boolean): boolean {
return settingValue === 'always' || settingValue === 'userGesture' && userGesture;
}
} }
type NotificationSetting = 'never' | 'always' | 'userGesture';
export class TestAccessibleNotificationService extends Disposable implements IAccessibleNotificationService { export class TestAccessibleNotificationService extends Disposable implements IAccessibleNotificationService {
declare readonly _serviceBrand: undefined; declare readonly _serviceBrand: undefined;
notifyCleared(): void { } notify(event: AccessibleNotificationEvent): void { }
notifySaved(userGesture: boolean): void { }
} }

View file

@ -55,6 +55,12 @@ export const IAccessibleNotificationService = createDecorator<IAccessibleNotific
*/ */
export interface IAccessibleNotificationService { export interface IAccessibleNotificationService {
readonly _serviceBrand: undefined; readonly _serviceBrand: undefined;
notifyCleared(): void; notify(event: AccessibleNotificationEvent): void;
notifySaved(userGesture: boolean): void;
} }
export const enum AccessibleNotificationEvent {
Clear = 'clear',
Save = 'save',
Format = 'format'
}

View file

@ -255,6 +255,7 @@ export class Sound {
public static readonly chatResponseReceived3 = Sound.register({ fileName: 'chatResponseReceived3.mp3' }); public static readonly chatResponseReceived3 = Sound.register({ fileName: 'chatResponseReceived3.mp3' });
public static readonly chatResponseReceived4 = Sound.register({ fileName: 'chatResponseReceived4.mp3' }); public static readonly chatResponseReceived4 = Sound.register({ fileName: 'chatResponseReceived4.mp3' });
public static readonly clear = Sound.register({ fileName: 'clear.mp3' }); public static readonly clear = Sound.register({ fileName: 'clear.mp3' });
public static readonly save = Sound.register({ fileName: 'save.mp3' });
private constructor(public readonly fileName: string) { } private constructor(public readonly fileName: string) { }
} }
@ -426,6 +427,12 @@ export class AudioCue {
settingsKey: 'audioCues.clear' settingsKey: 'audioCues.clear'
}); });
public static readonly save = AudioCue.register({
name: localize('audioCues.save', 'Save'),
sound: Sound.save,
settingsKey: 'audioCues.save'
});
private constructor( private constructor(
public readonly sound: SoundSource, public readonly sound: SoundSource,
public readonly name: string, public readonly name: string,

Binary file not shown.

View file

@ -14,6 +14,7 @@ import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editor
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService'; import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
import { IWorkingCopy, WorkingCopyCapabilities } from 'vs/workbench/services/workingCopy/common/workingCopy'; import { IWorkingCopy, WorkingCopyCapabilities } from 'vs/workbench/services/workingCopy/common/workingCopy';
import { ILogService } from 'vs/platform/log/common/log'; import { ILogService } from 'vs/platform/log/common/log';
import { IAccessibleNotificationService } from 'vs/platform/accessibility/common/accessibility';
export class EditorAutoSave extends Disposable implements IWorkbenchContribution { export class EditorAutoSave extends Disposable implements IWorkbenchContribution {
@ -32,7 +33,8 @@ export class EditorAutoSave extends Disposable implements IWorkbenchContribution
@IEditorService private readonly editorService: IEditorService, @IEditorService private readonly editorService: IEditorService,
@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService, @IEditorGroupsService private readonly editorGroupService: IEditorGroupsService,
@IWorkingCopyService private readonly workingCopyService: IWorkingCopyService, @IWorkingCopyService private readonly workingCopyService: IWorkingCopyService,
@ILogService private readonly logService: ILogService @ILogService private readonly logService: ILogService,
@IAccessibleNotificationService private readonly _accessibleNotificationService: IAccessibleNotificationService
) { ) {
super(); super();
@ -196,7 +198,7 @@ export class EditorAutoSave extends Disposable implements IWorkbenchContribution
// Save if dirty // Save if dirty
if (workingCopy.isDirty()) { if (workingCopy.isDirty()) {
this.logService.trace(`[editor auto save] running auto save`, workingCopy.resource.toString(), workingCopy.typeId); this.logService.trace(`[editor auto save] running auto save`, workingCopy.resource.toString(), workingCopy.typeId);
this._accessibleNotificationService.notifySaved(false);
workingCopy.save({ reason: SaveReason.AUTO }); workingCopy.save({ reason: SaveReason.AUTO });
} }
}, this.autoSaveAfterDelay); }, this.autoSaveAfterDelay);

View file

@ -47,6 +47,10 @@ export const enum AccessibilityVerbositySettingId {
Comments = 'accessibility.verbosity.comments' Comments = 'accessibility.verbosity.comments'
} }
export const enum AccessibilityAlertSettingId {
Save = 'accessibility.alert.save'
}
export const enum AccessibleViewProviderId { export const enum AccessibleViewProviderId {
Terminal = 'terminal', Terminal = 'terminal',
TerminalHelp = 'terminal-help', TerminalHelp = 'terminal-help',
@ -117,7 +121,19 @@ const configuration: IConfigurationNode = {
[AccessibilityVerbositySettingId.Comments]: { [AccessibilityVerbositySettingId.Comments]: {
description: localize('verbosity.comments', 'Provide information about actions that can be taken in the comment widget or in a file which contains comments.'), description: localize('verbosity.comments', 'Provide information about actions that can be taken in the comment widget or in a file which contains comments.'),
...baseProperty ...baseProperty
} },
[AccessibilityAlertSettingId.Save]: {
'markdownDescription': localize('alert.save', "When in screen reader mode, alerts when a file is saved. Also see {0}", '`#audioCues.save#`'),
'type': 'string',
'enum': ['userGesture', 'always', 'never'],
'default': 'never',
'enumDescriptions': [
localize('alert.save.userGesture', "Alerts when a file is saved via user gesture."),
localize('alert.save.always', "Alerts whenever is a file is saved, including auto save."),
localize('alert.save.never', "Never alerts.")
],
tags: ['accessibility']
},
} }
}; };

View file

@ -137,6 +137,18 @@ Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).regis
...audioCueFeatureBase, ...audioCueFeatureBase,
default: 'off' default: 'off'
}, },
'audioCues.save': {
'markdownDescription': localize('audioCues.save', "Plays a sound when a file is saved. Also see {0}", '`#accessibility.alert.save#`'),
'type': 'string',
'enum': ['userGesture', 'always', 'never'],
'default': 'never',
'enumDescriptions': [
localize('audioCues.enabled.userGesture', "Plays the audio cue when a user explicitly saves a file."),
localize('audioCues.enabled.always', "Plays the audio cue whenever a file is saved, including auto save."),
localize('audioCues.enabled.never', "Never plays the audio cue.")
],
tags: ['accessibility']
},
}, },
}); });

View file

@ -7,7 +7,7 @@ import { Codicon } from 'vs/base/common/codicons';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions'; import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { localize } from 'vs/nls'; import { localize } from 'vs/nls';
import { IAccessibleNotificationService } from 'vs/platform/accessibility/common/accessibility'; import { AccessibleNotificationEvent, IAccessibleNotificationService } from 'vs/platform/accessibility/common/accessibility';
import { Action2, IAction2Options, MenuId, registerAction2 } from 'vs/platform/actions/common/actions'; import { Action2, IAction2Options, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
@ -118,5 +118,5 @@ export function getClearAction(viewId: string, providerId: string) {
} }
function announceChatCleared(accessor: ServicesAccessor): void { function announceChatCleared(accessor: ServicesAccessor): void {
accessor.get(IAccessibleNotificationService).notifyCleared(); accessor.get(IAccessibleNotificationService).notify(AccessibleNotificationEvent.Clear);
} }

View file

@ -69,7 +69,7 @@ import { Variable } from 'vs/workbench/contrib/debug/common/debugModel';
import { ReplEvaluationResult, ReplGroup } from 'vs/workbench/contrib/debug/common/replModel'; import { ReplEvaluationResult, ReplGroup } from 'vs/workbench/contrib/debug/common/replModel';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { registerNavigableContainer } from 'vs/workbench/browser/actions/widgetNavigationCommands'; import { registerNavigableContainer } from 'vs/workbench/browser/actions/widgetNavigationCommands';
import { IAccessibleNotificationService } from 'vs/platform/accessibility/common/accessibility'; import { AccessibleNotificationEvent, IAccessibleNotificationService } from 'vs/platform/accessibility/common/accessibility';
const $ = dom.$; const $ = dom.$;
@ -978,7 +978,7 @@ registerAction2(class extends ViewAction<Repl> {
runInView(_accessor: ServicesAccessor, view: Repl): void { runInView(_accessor: ServicesAccessor, view: Repl): void {
const accessibleNotificationService = _accessor.get(IAccessibleNotificationService); const accessibleNotificationService = _accessor.get(IAccessibleNotificationService);
view.clearRepl(); view.clearRepl();
accessibleNotificationService.notifyCleared(); accessibleNotificationService.notify(AccessibleNotificationEvent.Clear);
} }
}); });

View file

@ -23,6 +23,8 @@ import { DEFAULT_EDITOR_ASSOCIATION } from 'vs/workbench/common/editor';
import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace'; import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
import { TestContextService } from 'vs/workbench/test/common/workbenchTestServices'; import { TestContextService } from 'vs/workbench/test/common/workbenchTestServices';
import { UriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentityService'; import { UriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentityService';
import { IAccessibleNotificationService } from 'vs/platform/accessibility/common/accessibility';
import { TestAccessibleNotificationService } from 'vs/platform/accessibility/browser/accessibleNotificationService';
suite('EditorAutoSave', () => { suite('EditorAutoSave', () => {
@ -42,7 +44,7 @@ suite('EditorAutoSave', () => {
const configurationService = new TestConfigurationService(); const configurationService = new TestConfigurationService();
configurationService.setUserConfiguration('files', autoSaveConfig); configurationService.setUserConfiguration('files', autoSaveConfig);
instantiationService.stub(IConfigurationService, configurationService); instantiationService.stub(IConfigurationService, configurationService);
instantiationService.stub(IAccessibleNotificationService, disposables.add(new TestAccessibleNotificationService()));
instantiationService.stub(IFilesConfigurationService, disposables.add(new TestFilesConfigurationService( instantiationService.stub(IFilesConfigurationService, disposables.add(new TestFilesConfigurationService(
<IContextKeyService>instantiationService.createInstance(MockContextKeyService), <IContextKeyService>instantiationService.createInstance(MockContextKeyService),
configurationService, configurationService,

View file

@ -28,7 +28,7 @@ import { registerIcon } from 'vs/platform/theme/common/iconRegistry';
import { Categories } from 'vs/platform/action/common/actionCommonCategories'; import { Categories } from 'vs/platform/action/common/actionCommonCategories';
import { Disposable, dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle'; import { Disposable, dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService'; import { IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
import { IAccessibleNotificationService } from 'vs/platform/accessibility/common/accessibility'; import { AccessibleNotificationEvent, IAccessibleNotificationService } from 'vs/platform/accessibility/common/accessibility';
// Register Service // Register Service
registerSingleton(IOutputService, OutputService, InstantiationType.Delayed); registerSingleton(IOutputService, OutputService, InstantiationType.Delayed);
@ -225,7 +225,7 @@ class OutputContribution extends Disposable implements IWorkbenchContribution {
const activeChannel = outputService.getActiveChannel(); const activeChannel = outputService.getActiveChannel();
if (activeChannel) { if (activeChannel) {
activeChannel.clear(); activeChannel.clear();
accessibleNotificationService.notifyCleared(); accessibleNotificationService.notify(AccessibleNotificationEvent.Clear);
} }
} }
})); }));

View file

@ -43,7 +43,7 @@ import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService
import { debounce } from 'vs/base/common/decorators'; import { debounce } from 'vs/base/common/decorators';
import { MouseWheelClassifier } from 'vs/base/browser/ui/scrollbar/scrollableElement'; import { MouseWheelClassifier } from 'vs/base/browser/ui/scrollbar/scrollableElement';
import { IMouseWheelEvent, StandardWheelEvent } from 'vs/base/browser/mouseEvent'; import { IMouseWheelEvent, StandardWheelEvent } from 'vs/base/browser/mouseEvent';
import { IAccessibleNotificationService } from 'vs/platform/accessibility/common/accessibility'; import { AccessibleNotificationEvent, IAccessibleNotificationService } from 'vs/platform/accessibility/common/accessibility';
const enum RenderConstants { const enum RenderConstants {
/** /**
@ -590,7 +590,7 @@ export class XtermTerminal extends Disposable implements IXtermTerminal, IDetach
// the prompt being written // the prompt being written
this._capabilities.get(TerminalCapability.CommandDetection)?.handlePromptStart(); this._capabilities.get(TerminalCapability.CommandDetection)?.handlePromptStart();
this._capabilities.get(TerminalCapability.CommandDetection)?.handleCommandStart(); this._capabilities.get(TerminalCapability.CommandDetection)?.handleCommandStart();
this._accessibleNotificationService.notifyCleared(); this._accessibleNotificationService.notify(AccessibleNotificationEvent.Clear);
} }
hasSelection(): boolean { hasSelection(): boolean {

View file

@ -33,6 +33,7 @@ import { IWorkspaceTrustRequestService, WorkspaceTrustUriResponse } from 'vs/pla
import { IHostService } from 'vs/workbench/services/host/browser/host'; import { IHostService } from 'vs/workbench/services/host/browser/host';
import { findGroup } from 'vs/workbench/services/editor/common/editorGroupFinder'; import { findGroup } from 'vs/workbench/services/editor/common/editorGroupFinder';
import { ITextEditorService } from 'vs/workbench/services/textfile/common/textEditorService'; import { ITextEditorService } from 'vs/workbench/services/textfile/common/textEditorService';
import { IAccessibleNotificationService } from 'vs/platform/accessibility/common/accessibility';
export class EditorService extends Disposable implements EditorServiceImpl { export class EditorService extends Disposable implements EditorServiceImpl {
@ -70,7 +71,8 @@ export class EditorService extends Disposable implements EditorServiceImpl {
@IEditorResolverService private readonly editorResolverService: IEditorResolverService, @IEditorResolverService private readonly editorResolverService: IEditorResolverService,
@IWorkspaceTrustRequestService private readonly workspaceTrustRequestService: IWorkspaceTrustRequestService, @IWorkspaceTrustRequestService private readonly workspaceTrustRequestService: IWorkspaceTrustRequestService,
@IHostService private readonly hostService: IHostService, @IHostService private readonly hostService: IHostService,
@ITextEditorService private readonly textEditorService: ITextEditorService @ITextEditorService private readonly textEditorService: ITextEditorService,
@IAccessibleNotificationService private readonly accessibleNotificationService: IAccessibleNotificationService
) { ) {
super(); super();
@ -972,9 +974,12 @@ export class EditorService extends Disposable implements EditorServiceImpl {
} }
} }
} }
const success = saveResults.every(result => !!result);
if (success) {
this.accessibleNotificationService.notifySaved(options?.reason === SaveReason.EXPLICIT);
}
return { return {
success: saveResults.every(result => !!result), success,
editors: coalesce(saveResults) editors: coalesce(saveResults)
}; };
} }

View file

@ -73,7 +73,7 @@ import { IHostService } from 'vs/workbench/services/host/browser/host';
import { IWorkingCopyService, WorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService'; import { IWorkingCopyService, WorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
import { IWorkingCopy, IWorkingCopyBackupMeta, IWorkingCopyIdentifier } from 'vs/workbench/services/workingCopy/common/workingCopy'; import { IWorkingCopy, IWorkingCopyBackupMeta, IWorkingCopyIdentifier } from 'vs/workbench/services/workingCopy/common/workingCopy';
import { IFilesConfigurationService, FilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService'; import { IFilesConfigurationService, FilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility'; import { IAccessibilityService, IAccessibleNotificationService } from 'vs/platform/accessibility/common/accessibility';
import { BrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService'; import { BrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService';
import { BrowserTextFileService } from 'vs/workbench/services/textfile/browser/browserTextFileService'; import { BrowserTextFileService } from 'vs/workbench/services/textfile/browser/browserTextFileService';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
@ -166,6 +166,7 @@ import { IHoverOptions, IHoverService, IHoverWidget } from 'vs/workbench/service
import { IRemoteExtensionsScannerService } from 'vs/platform/remote/common/remoteExtensionsScanner'; import { IRemoteExtensionsScannerService } from 'vs/platform/remote/common/remoteExtensionsScanner';
import { IRemoteSocketFactoryService, RemoteSocketFactoryService } from 'vs/platform/remote/common/remoteSocketFactoryService'; import { IRemoteSocketFactoryService, RemoteSocketFactoryService } from 'vs/platform/remote/common/remoteSocketFactoryService';
import { EditorParts } from 'vs/workbench/browser/parts/editor/editorParts'; import { EditorParts } from 'vs/workbench/browser/parts/editor/editorParts';
import { TestAccessibleNotificationService } from 'vs/platform/accessibility/browser/accessibleNotificationService';
export function createFileEditorInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput { export function createFileEditorInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput {
return instantiationService.createInstance(FileEditorInput, resource, undefined, undefined, undefined, undefined, undefined, undefined); return instantiationService.createInstance(FileEditorInput, resource, undefined, undefined, undefined, undefined, undefined, undefined);
@ -274,6 +275,8 @@ export function workbenchInstantiationService(
instantiationService.stub(IDialogService, new TestDialogService()); instantiationService.stub(IDialogService, new TestDialogService());
const accessibilityService = new TestAccessibilityService(); const accessibilityService = new TestAccessibilityService();
instantiationService.stub(IAccessibilityService, accessibilityService); instantiationService.stub(IAccessibilityService, accessibilityService);
const accessibleNotificationService = disposables.add(new TestAccessibleNotificationService());
instantiationService.stub(IAccessibleNotificationService, accessibleNotificationService);
instantiationService.stub(IFileDialogService, instantiationService.createInstance(TestFileDialogService)); instantiationService.stub(IFileDialogService, instantiationService.createInstance(TestFileDialogService));
instantiationService.stub(ILanguageService, disposables.add(instantiationService.createInstance(LanguageService))); instantiationService.stub(ILanguageService, disposables.add(instantiationService.createInstance(LanguageService)));
instantiationService.stub(ILanguageFeaturesService, new LanguageFeaturesService()); instantiationService.stub(ILanguageFeaturesService, new LanguageFeaturesService());