提交 1bac8550 编写于 作者: S SteVen Batten

improve keybinding handling in dialogs

上级 c61e5d90
...@@ -20,6 +20,7 @@ export interface IDialogOptions { ...@@ -20,6 +20,7 @@ export interface IDialogOptions {
cancelId?: number; cancelId?: number;
detail?: string; detail?: string;
type?: 'none' | 'info' | 'error' | 'question' | 'warning' | 'pending'; type?: 'none' | 'info' | 'error' | 'question' | 'warning' | 'pending';
keyEventProcessor?: (event: StandardKeyboardEvent) => void;
} }
export interface IDialogStyles extends IButtonStyles { export interface IDialogStyles extends IButtonStyles {
...@@ -103,19 +104,26 @@ export class Dialog extends Disposable { ...@@ -103,19 +104,26 @@ export class Dialog extends Disposable {
return; return;
} }
let eventHandled = false;
if (this.buttonGroup) { if (this.buttonGroup) {
if (evt.equals(KeyMod.Shift | KeyCode.Tab) || evt.equals(KeyCode.LeftArrow)) { if (evt.equals(KeyMod.Shift | KeyCode.Tab) || evt.equals(KeyCode.LeftArrow)) {
focusedButton = focusedButton + this.buttonGroup.buttons.length - 1; focusedButton = focusedButton + this.buttonGroup.buttons.length - 1;
focusedButton = focusedButton % this.buttonGroup.buttons.length; focusedButton = focusedButton % this.buttonGroup.buttons.length;
this.buttonGroup.buttons[focusedButton].focus(); this.buttonGroup.buttons[focusedButton].focus();
eventHandled = true;
} else if (evt.equals(KeyCode.Tab) || evt.equals(KeyCode.RightArrow)) { } else if (evt.equals(KeyCode.Tab) || evt.equals(KeyCode.RightArrow)) {
focusedButton++; focusedButton++;
focusedButton = focusedButton % this.buttonGroup.buttons.length; focusedButton = focusedButton % this.buttonGroup.buttons.length;
this.buttonGroup.buttons[focusedButton].focus(); this.buttonGroup.buttons[focusedButton].focus();
eventHandled = true;
} }
} }
if (eventHandled) {
EventHelper.stop(e, true); EventHelper.stop(e, true);
} else if (this.options.keyEventProcessor) {
this.options.keyEventProcessor(evt);
}
})); }));
this._register(domEvent(window, 'keyup', true)((e: KeyboardEvent) => { this._register(domEvent(window, 'keyup', true)((e: KeyboardEvent) => {
......
...@@ -13,6 +13,8 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; ...@@ -13,6 +13,8 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IThemeService } from 'vs/platform/theme/common/themeService'; import { IThemeService } from 'vs/platform/theme/common/themeService';
import { attachDialogStyler } from 'vs/platform/theme/common/styler'; import { attachDialogStyler } from 'vs/platform/theme/common/styler';
import { dispose, IDisposable } from 'vs/base/common/lifecycle'; import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { EventHelper } from 'vs/base/browser/dom';
export class DialogService implements IDialogService { export class DialogService implements IDialogService {
_serviceBrand: any; _serviceBrand: any;
...@@ -76,7 +78,10 @@ export class DialogService implements IDialogService { ...@@ -76,7 +78,10 @@ export class DialogService implements IDialogService {
{ {
detail: options ? options.detail : undefined, detail: options ? options.detail : undefined,
cancelId: options ? options.cancelId : undefined, cancelId: options ? options.cancelId : undefined,
type: this.getDialogType(severity) type: this.getDialogType(severity),
keyEventProcessor: (event: StandardKeyboardEvent) => {
EventHelper.stop(event, true);
}
}); });
dialogDisposables.push(dialog); dialogDisposables.push(dialog);
......
...@@ -20,6 +20,9 @@ import { ILayoutService } from 'vs/platform/layout/browser/layoutService'; ...@@ -20,6 +20,9 @@ import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
import { Dialog } from 'vs/base/browser/ui/dialog/dialog'; import { Dialog } from 'vs/base/browser/ui/dialog/dialog';
import { attachDialogStyler } from 'vs/platform/theme/common/styler'; import { attachDialogStyler } from 'vs/platform/theme/common/styler';
import { IThemeService } from 'vs/platform/theme/common/themeService'; import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { EventHelper } from 'vs/base/browser/dom';
export class ProgressService2 implements IProgressService2 { export class ProgressService2 implements IProgressService2 {
...@@ -34,7 +37,8 @@ export class ProgressService2 implements IProgressService2 { ...@@ -34,7 +37,8 @@ export class ProgressService2 implements IProgressService2 {
@INotificationService private readonly _notificationService: INotificationService, @INotificationService private readonly _notificationService: INotificationService,
@IStatusbarService private readonly _statusbarService: IStatusbarService, @IStatusbarService private readonly _statusbarService: IStatusbarService,
@ILayoutService private readonly _layoutService: ILayoutService, @ILayoutService private readonly _layoutService: ILayoutService,
@IThemeService private readonly _themeService: IThemeService @IThemeService private readonly _themeService: IThemeService,
@IKeybindingService private readonly _keybindingService: IKeybindingService
) { } ) { }
withProgress<R = unknown>(options: IProgressOptions, task: (progress: IProgress<IProgressStep>) => Promise<R>, onDidCancel?: () => void): Promise<R> { withProgress<R = unknown>(options: IProgressOptions, task: (progress: IProgress<IProgressStep>) => Promise<R>, onDidCancel?: () => void): Promise<R> {
...@@ -276,6 +280,10 @@ export class ProgressService2 implements IProgressService2 { ...@@ -276,6 +280,10 @@ export class ProgressService2 implements IProgressService2 {
private _withDialogProgress<P extends Promise<R>, R = unknown>(options: IProgressOptions, task: (progress: IProgress<{ message?: string, increment?: number }>) => P, onDidCancel?: () => void): P { private _withDialogProgress<P extends Promise<R>, R = unknown>(options: IProgressOptions, task: (progress: IProgress<{ message?: string, increment?: number }>) => P, onDidCancel?: () => void): P {
const disposables: IDisposable[] = []; const disposables: IDisposable[] = [];
const allowableCommands = [
'workbench.action.quit',
'workbench.action.reloadWindow'
];
let dialog: Dialog; let dialog: Dialog;
...@@ -284,7 +292,17 @@ export class ProgressService2 implements IProgressService2 { ...@@ -284,7 +292,17 @@ export class ProgressService2 implements IProgressService2 {
this._layoutService.container, this._layoutService.container,
message, message,
[options.cancellable ? localize('cancel', "Cancel") : localize('dismiss', "Dismiss")], [options.cancellable ? localize('cancel', "Cancel") : localize('dismiss', "Dismiss")],
{ type: 'pending' } {
type: 'pending',
keyEventProcessor: (event: StandardKeyboardEvent) => {
const resolved = this._keybindingService.softDispatch(event, this._layoutService.container);
if (resolved && resolved.commandId) {
if (allowableCommands.indexOf(resolved.commandId) === -1) {
EventHelper.stop(event, true);
}
}
}
}
); );
disposables.push(dialog); disposables.push(dialog);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册