mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Merge from master
This commit is contained in:
@@ -2,37 +2,37 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as nls from 'vs/nls';
|
||||
import { ResolvedKeybinding, Keybinding } from 'vs/base/common/keyCodes';
|
||||
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
import { KeybindingResolver, IResolveResult } from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import { IKeybindingEvent, IKeybindingService, IKeyboardEvent } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { IContextKeyService, IContextKeyServiceTarget } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
import * as arrays from 'vs/base/common/arrays';
|
||||
import { IntervalTimer } from 'vs/base/common/async';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import { KeyCode, Keybinding, ResolvedKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
import { IContextKeyService, IContextKeyServiceTarget } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IKeybindingEvent, IKeybindingService, IKeyboardEvent } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { IResolveResult, KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
|
||||
interface CurrentChord {
|
||||
keypress: string;
|
||||
label: string;
|
||||
label: string | null;
|
||||
}
|
||||
|
||||
export abstract class AbstractKeybindingService extends Disposable implements IKeybindingService {
|
||||
public _serviceBrand: any;
|
||||
|
||||
private _currentChord: CurrentChord;
|
||||
private _currentChord: CurrentChord | null;
|
||||
private _currentChordChecker: IntervalTimer;
|
||||
private _currentChordStatusMessage: IDisposable;
|
||||
private _currentChordStatusMessage: IDisposable | null;
|
||||
protected _onDidUpdateKeybindings: Emitter<IKeybindingEvent>;
|
||||
|
||||
private _contextKeyService: IContextKeyService;
|
||||
private _statusService: IStatusbarService;
|
||||
private _statusService: IStatusbarService | undefined;
|
||||
private _notificationService: INotificationService;
|
||||
protected _commandService: ICommandService;
|
||||
protected _telemetryService: ITelemetryService;
|
||||
@@ -88,10 +88,12 @@ export abstract class AbstractKeybindingService extends Disposable implements IK
|
||||
}
|
||||
|
||||
public lookupKeybindings(commandId: string): ResolvedKeybinding[] {
|
||||
return this._getResolver().lookupKeybindings(commandId).map(item => item.resolvedKeybinding);
|
||||
return arrays.coalesce(
|
||||
this._getResolver().lookupKeybindings(commandId).map(item => item.resolvedKeybinding)
|
||||
);
|
||||
}
|
||||
|
||||
public lookupKeybinding(commandId: string): ResolvedKeybinding {
|
||||
public lookupKeybinding(commandId: string): ResolvedKeybinding | null {
|
||||
let result = this._getResolver().lookupPrimaryKeybinding(commandId);
|
||||
if (!result) {
|
||||
return null;
|
||||
@@ -99,7 +101,7 @@ export abstract class AbstractKeybindingService extends Disposable implements IK
|
||||
return result.resolvedKeybinding;
|
||||
}
|
||||
|
||||
public softDispatch(e: IKeyboardEvent, target: IContextKeyServiceTarget): IResolveResult {
|
||||
public softDispatch(e: IKeyboardEvent, target: IContextKeyServiceTarget): IResolveResult | null {
|
||||
const keybinding = this.resolveKeyboardEvent(e);
|
||||
if (keybinding.isChord()) {
|
||||
console.warn('Unexpected keyboard event mapped to a chord');
|
||||
@@ -116,7 +118,7 @@ export abstract class AbstractKeybindingService extends Disposable implements IK
|
||||
return this._getResolver().resolve(contextValue, currentChord, firstPart);
|
||||
}
|
||||
|
||||
private _enterChordMode(firstPart: string, keypressLabel: string): void {
|
||||
private _enterChordMode(firstPart: string, keypressLabel: string | null): void {
|
||||
this._currentChord = {
|
||||
keypress: firstPart,
|
||||
label: keypressLabel
|
||||
@@ -156,7 +158,7 @@ export abstract class AbstractKeybindingService extends Disposable implements IK
|
||||
const keybinding = this.resolveKeyboardEvent(e);
|
||||
if (keybinding.isChord()) {
|
||||
console.warn('Unexpected keyboard event mapped to a chord');
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
const [firstPart,] = keybinding.getDispatchParts();
|
||||
if (firstPart === null) {
|
||||
@@ -189,9 +191,9 @@ export abstract class AbstractKeybindingService extends Disposable implements IK
|
||||
shouldPreventDefault = true;
|
||||
}
|
||||
if (typeof resolveResult.commandArgs === 'undefined') {
|
||||
this._commandService.executeCommand(resolveResult.commandId).done(undefined, err => this._notificationService.warn(err));
|
||||
this._commandService.executeCommand(resolveResult.commandId).then(undefined, err => this._notificationService.warn(err));
|
||||
} else {
|
||||
this._commandService.executeCommand(resolveResult.commandId, resolveResult.commandArgs).done(undefined, err => this._notificationService.warn(err));
|
||||
this._commandService.executeCommand(resolveResult.commandId, resolveResult.commandArgs).then(undefined, err => this._notificationService.warn(err));
|
||||
}
|
||||
/* __GDPR__
|
||||
"workbenchActionExecuted" : {
|
||||
@@ -204,4 +206,18 @@ export abstract class AbstractKeybindingService extends Disposable implements IK
|
||||
|
||||
return shouldPreventDefault;
|
||||
}
|
||||
|
||||
mightProducePrintableCharacter(event: IKeyboardEvent): boolean {
|
||||
if (event.ctrlKey || event.metaKey) {
|
||||
// ignore ctrl/cmd-combination but not shift/alt-combinatios
|
||||
return false;
|
||||
}
|
||||
// weak check for certain ranges. this is properly implemented in a subclass
|
||||
// with access to the KeyboardMapperFactory.
|
||||
if ((event.keyCode >= KeyCode.KEY_A && event.keyCode <= KeyCode.KEY_Z)
|
||||
|| (event.keyCode >= KeyCode.KEY_0 && event.keyCode <= KeyCode.KEY_9)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { ResolvedKeybinding, Keybinding, KeyCode } from 'vs/base/common/keyCodes';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { KeyCode, Keybinding, ResolvedKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { IContextKeyServiceTarget } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IResolveResult } from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
|
||||
export interface IUserFriendlyKeybinding {
|
||||
key: string;
|
||||
@@ -18,7 +17,7 @@ export interface IUserFriendlyKeybinding {
|
||||
when?: string;
|
||||
}
|
||||
|
||||
export enum KeybindingSource {
|
||||
export const enum KeybindingSource {
|
||||
Default = 1,
|
||||
User
|
||||
}
|
||||
@@ -56,7 +55,7 @@ export interface IKeybindingService {
|
||||
/**
|
||||
* Resolve and dispatch `keyboardEvent`, but do not invoke the command or change inner state.
|
||||
*/
|
||||
softDispatch(keyboardEvent: IKeyboardEvent, target: IContextKeyServiceTarget): IResolveResult;
|
||||
softDispatch(keyboardEvent: IKeyboardEvent, target: IContextKeyServiceTarget): IResolveResult | null;
|
||||
|
||||
/**
|
||||
* Look up keybindings for a command.
|
||||
@@ -68,7 +67,7 @@ export interface IKeybindingService {
|
||||
* Look up the preferred (last defined) keybinding for a command.
|
||||
* @returns The preferred keybinding or null if the command is not bound.
|
||||
*/
|
||||
lookupKeybinding(commandId: string): ResolvedKeybinding;
|
||||
lookupKeybinding(commandId: string): ResolvedKeybinding | null;
|
||||
|
||||
getDefaultKeybindingsContent(): string;
|
||||
|
||||
@@ -77,5 +76,11 @@ export interface IKeybindingService {
|
||||
getKeybindings(): ResolvedKeybindingItem[];
|
||||
|
||||
customKeybindingsCount(): number;
|
||||
|
||||
/**
|
||||
* Will the given key event produce a character that's rendered on screen, e.g. in a
|
||||
* text box. *Note* that the results of this function can be incorrect.
|
||||
*/
|
||||
mightProducePrintableCharacter(event: IKeyboardEvent): boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,16 +2,16 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
|
||||
import { ContextKeyExpr, IContext, ContextKeyAndExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
|
||||
import { isNonEmptyArray } from 'vs/base/common/arrays';
|
||||
import { MenuRegistry } from 'vs/platform/actions/common/actions';
|
||||
import { CommandsRegistry, ICommandHandlerDescription } from 'vs/platform/commands/common/commands';
|
||||
import { ContextKeyAndExpr, ContextKeyExpr, IContext } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
|
||||
|
||||
export interface IResolveResult {
|
||||
enterChord: boolean;
|
||||
commandId: string;
|
||||
commandId: string | null;
|
||||
commandArgs: any;
|
||||
bubble: boolean;
|
||||
}
|
||||
@@ -29,7 +29,9 @@ export class KeybindingResolver {
|
||||
this._defaultBoundCommands = new Map<string, boolean>();
|
||||
for (let i = 0, len = defaultKeybindings.length; i < len; i++) {
|
||||
const command = defaultKeybindings[i].command;
|
||||
this._defaultBoundCommands.set(command, true);
|
||||
if (command) {
|
||||
this._defaultBoundCommands.set(command, true);
|
||||
}
|
||||
}
|
||||
|
||||
this._map = new Map<string, ResolvedKeybindingItem[]>();
|
||||
@@ -47,7 +49,7 @@ export class KeybindingResolver {
|
||||
}
|
||||
}
|
||||
|
||||
private static _isTargetedForRemoval(defaultKb: ResolvedKeybindingItem, keypressFirstPart: string, keypressChordPart: string, command: string, when: ContextKeyExpr): boolean {
|
||||
private static _isTargetedForRemoval(defaultKb: ResolvedKeybindingItem, keypressFirstPart: string | null, keypressChordPart: string | null, command: string, when: ContextKeyExpr | null): boolean {
|
||||
if (defaultKb.command !== command) {
|
||||
return false;
|
||||
}
|
||||
@@ -147,6 +149,9 @@ export class KeybindingResolver {
|
||||
}
|
||||
|
||||
private _removeFromLookupMap(item: ResolvedKeybindingItem): void {
|
||||
if (!item.command) {
|
||||
return;
|
||||
}
|
||||
let arr = this._lookupMap.get(item.command);
|
||||
if (typeof arr === 'undefined') {
|
||||
return;
|
||||
@@ -163,7 +168,7 @@ export class KeybindingResolver {
|
||||
* Returns true if it is provable `a` implies `b`.
|
||||
* **Precondition**: Assumes `a` and `b` are normalized!
|
||||
*/
|
||||
public static whenIsEntirelyIncluded(a: ContextKeyExpr, b: ContextKeyExpr): boolean {
|
||||
public static whenIsEntirelyIncluded(a: ContextKeyExpr | null, b: ContextKeyExpr | null): boolean {
|
||||
if (!b) {
|
||||
return true;
|
||||
}
|
||||
@@ -220,7 +225,7 @@ export class KeybindingResolver {
|
||||
return result;
|
||||
}
|
||||
|
||||
public lookupPrimaryKeybinding(commandId: string): ResolvedKeybindingItem {
|
||||
public lookupPrimaryKeybinding(commandId: string): ResolvedKeybindingItem | null {
|
||||
let items = this._lookupMap.get(commandId);
|
||||
if (typeof items === 'undefined' || items.length === 0) {
|
||||
return null;
|
||||
@@ -229,8 +234,8 @@ export class KeybindingResolver {
|
||||
return items[items.length - 1];
|
||||
}
|
||||
|
||||
public resolve(context: IContext, currentChord: string, keypress: string): IResolveResult {
|
||||
let lookupMap: ResolvedKeybindingItem[] = null;
|
||||
public resolve(context: IContext, currentChord: string | null, keypress: string): IResolveResult | null {
|
||||
let lookupMap: ResolvedKeybindingItem[] | null = null;
|
||||
|
||||
if (currentChord !== null) {
|
||||
// Fetch all chord bindings for `currentChord`
|
||||
@@ -280,7 +285,7 @@ export class KeybindingResolver {
|
||||
};
|
||||
}
|
||||
|
||||
private _findCommand(context: IContext, matches: ResolvedKeybindingItem[]): ResolvedKeybindingItem {
|
||||
private _findCommand(context: IContext, matches: ResolvedKeybindingItem[]): ResolvedKeybindingItem | null {
|
||||
for (let i = matches.length - 1; i >= 0; i--) {
|
||||
let k = matches[i];
|
||||
|
||||
@@ -294,7 +299,7 @@ export class KeybindingResolver {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static contextMatchesRules(context: IContext, rules: ContextKeyExpr): boolean {
|
||||
public static contextMatchesRules(context: IContext, rules: ContextKeyExpr | null): boolean {
|
||||
if (!rules) {
|
||||
return true;
|
||||
}
|
||||
@@ -302,21 +307,31 @@ export class KeybindingResolver {
|
||||
}
|
||||
|
||||
public static getAllUnboundCommands(boundCommands: Map<string, boolean>): string[] {
|
||||
const commands = CommandsRegistry.getCommands();
|
||||
const unboundCommands: string[] = [];
|
||||
|
||||
for (let id in commands) {
|
||||
if (id[0] === '_' || id.indexOf('vscode.') === 0) { // private command
|
||||
continue;
|
||||
const seenMap: Map<string, boolean> = new Map<string, boolean>();
|
||||
const addCommand = id => {
|
||||
if (seenMap.has(id)) {
|
||||
return;
|
||||
}
|
||||
if (typeof commands[id].description === 'object'
|
||||
&& !isFalsyOrEmpty((<ICommandHandlerDescription>commands[id].description).args)) { // command with args
|
||||
continue;
|
||||
seenMap.set(id);
|
||||
if (id[0] === '_' || id.indexOf('vscode.') === 0) { // private command
|
||||
return;
|
||||
}
|
||||
if (boundCommands.get(id) === true) {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
const command = CommandsRegistry.getCommand(id);
|
||||
if (command && typeof command.description === 'object'
|
||||
&& isNonEmptyArray((<ICommandHandlerDescription>command.description).args)) { // command with args
|
||||
return;
|
||||
}
|
||||
unboundCommands.push(id);
|
||||
};
|
||||
for (const id in MenuRegistry.getCommands()) {
|
||||
addCommand(id);
|
||||
}
|
||||
for (const id in CommandsRegistry.getCommands()) {
|
||||
addCommand(id);
|
||||
}
|
||||
|
||||
return unboundCommands;
|
||||
|
||||
@@ -2,19 +2,18 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { SimpleKeybinding, KeyCode, KeybindingType, createKeybinding, Keybinding } from 'vs/base/common/keyCodes';
|
||||
import { KeyCode, Keybinding, KeybindingType, SimpleKeybinding, createKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { OS, OperatingSystem } from 'vs/base/common/platform';
|
||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { CommandsRegistry, ICommandHandler, ICommandHandlerDescription } from 'vs/platform/commands/common/commands';
|
||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
|
||||
export interface IKeybindingItem {
|
||||
keybinding: Keybinding;
|
||||
command: string;
|
||||
commandArgs?: any;
|
||||
when: ContextKeyExpr;
|
||||
when: ContextKeyExpr | null | undefined;
|
||||
weight1: number;
|
||||
weight2: number;
|
||||
}
|
||||
@@ -39,17 +38,17 @@ export interface IKeybindings {
|
||||
export interface IKeybindingRule extends IKeybindings {
|
||||
id: string;
|
||||
weight: number;
|
||||
when: ContextKeyExpr;
|
||||
when: ContextKeyExpr | null | undefined;
|
||||
}
|
||||
|
||||
export interface IKeybindingRule2 {
|
||||
primary: Keybinding;
|
||||
win?: { primary: Keybinding; };
|
||||
linux?: { primary: Keybinding; };
|
||||
mac?: { primary: Keybinding; };
|
||||
primary: Keybinding | null;
|
||||
win?: { primary: Keybinding | null; } | null;
|
||||
linux?: { primary: Keybinding | null; } | null;
|
||||
mac?: { primary: Keybinding | null; } | null;
|
||||
id: string;
|
||||
weight: number;
|
||||
when: ContextKeyExpr;
|
||||
when: ContextKeyExpr | null;
|
||||
}
|
||||
|
||||
export const enum KeybindingRuleSource {
|
||||
@@ -67,7 +66,7 @@ export const enum KeybindingWeight {
|
||||
|
||||
export interface ICommandAndKeybindingRule extends IKeybindingRule {
|
||||
handler: ICommandHandler;
|
||||
description?: ICommandHandlerDescription;
|
||||
description?: ICommandHandlerDescription | null;
|
||||
}
|
||||
|
||||
export interface IKeybindingsRegistry {
|
||||
@@ -111,7 +110,7 @@ class KeybindingsRegistryImpl implements IKeybindingsRegistry {
|
||||
/**
|
||||
* Take current platform into account and reduce to primary & secondary.
|
||||
*/
|
||||
private static bindToCurrentPlatform2(kb: IKeybindingRule2): { primary?: Keybinding; } {
|
||||
private static bindToCurrentPlatform2(kb: IKeybindingRule2): { primary?: Keybinding | null; } {
|
||||
if (OS === OperatingSystem.Windows) {
|
||||
if (kb && kb.win) {
|
||||
return kb.win;
|
||||
@@ -133,13 +132,19 @@ class KeybindingsRegistryImpl implements IKeybindingsRegistry {
|
||||
let actualKb = KeybindingsRegistryImpl.bindToCurrentPlatform(rule);
|
||||
|
||||
if (actualKb && actualKb.primary) {
|
||||
this._registerDefaultKeybinding(createKeybinding(actualKb.primary, OS), rule.id, rule.weight, 0, rule.when, source);
|
||||
const kk = createKeybinding(actualKb.primary, OS);
|
||||
if (kk) {
|
||||
this._registerDefaultKeybinding(kk, rule.id, rule.weight, 0, rule.when, source);
|
||||
}
|
||||
}
|
||||
|
||||
if (actualKb && Array.isArray(actualKb.secondary)) {
|
||||
for (let i = 0, len = actualKb.secondary.length; i < len; i++) {
|
||||
const k = actualKb.secondary[i];
|
||||
this._registerDefaultKeybinding(createKeybinding(k, OS), rule.id, rule.weight, -i - 1, rule.when, source);
|
||||
const kk = createKeybinding(k, OS);
|
||||
if (kk) {
|
||||
this._registerDefaultKeybinding(kk, rule.id, rule.weight, -i - 1, rule.when, source);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -191,7 +196,7 @@ class KeybindingsRegistryImpl implements IKeybindingsRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
private _registerDefaultKeybinding(keybinding: Keybinding, commandId: string, weight1: number, weight2: number, when: ContextKeyExpr, source: KeybindingRuleSource): void {
|
||||
private _registerDefaultKeybinding(keybinding: Keybinding, commandId: string, weight1: number, weight2: number, when: ContextKeyExpr | null | undefined, source: KeybindingRuleSource): void {
|
||||
if (source === KeybindingRuleSource.Core && OS === OperatingSystem.Windows) {
|
||||
if (keybinding.type === KeybindingType.Chord) {
|
||||
this._assertNoCtrlAlt(keybinding.firstPart, commandId);
|
||||
|
||||
@@ -2,25 +2,24 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { CharCode } from 'vs/base/common/charCode';
|
||||
import { ResolvedKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { CharCode } from 'vs/base/common/charCode';
|
||||
|
||||
export class ResolvedKeybindingItem {
|
||||
_resolvedKeybindingItemBrand: void;
|
||||
|
||||
public readonly resolvedKeybinding: ResolvedKeybinding;
|
||||
public readonly keypressFirstPart: string;
|
||||
public readonly keypressChordPart: string;
|
||||
public readonly resolvedKeybinding: ResolvedKeybinding | null;
|
||||
public readonly keypressFirstPart: string | null;
|
||||
public readonly keypressChordPart: string | null;
|
||||
public readonly bubble: boolean;
|
||||
public readonly command: string;
|
||||
public readonly command: string | null;
|
||||
public readonly commandArgs: any;
|
||||
public readonly when: ContextKeyExpr;
|
||||
public readonly when: ContextKeyExpr | null;
|
||||
public readonly isDefault: boolean;
|
||||
|
||||
constructor(resolvedKeybinding: ResolvedKeybinding, command: string, commandArgs: any, when: ContextKeyExpr, isDefault: boolean) {
|
||||
constructor(resolvedKeybinding: ResolvedKeybinding | null, command: string | null, commandArgs: any, when: ContextKeyExpr | null, isDefault: boolean) {
|
||||
this.resolvedKeybinding = resolvedKeybinding;
|
||||
if (resolvedKeybinding) {
|
||||
let [keypressFirstPart, keypressChordPart] = resolvedKeybinding.getDispatchParts();
|
||||
@@ -31,7 +30,7 @@ export class ResolvedKeybindingItem {
|
||||
this.keypressChordPart = null;
|
||||
}
|
||||
this.bubble = (command ? command.charCodeAt(0) === CharCode.Caret : false);
|
||||
this.command = this.bubble ? command.substr(1) : command;
|
||||
this.command = this.bubble ? command!.substr(1) : command;
|
||||
this.commandArgs = commandArgs;
|
||||
this.when = when;
|
||||
this.isDefault = isDefault;
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { ResolvedKeybinding, ResolvedKeybindingPart, KeyCode, KeyCodeUtils, Keybinding, KeybindingType, SimpleKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { UILabelProvider, AriaLabelProvider, ElectronAcceleratorLabelProvider, UserSettingsLabelProvider } from 'vs/base/common/keybindingLabels';
|
||||
import { KeyCode, KeyCodeUtils, Keybinding, KeybindingType, ResolvedKeybinding, ResolvedKeybindingPart, SimpleKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { AriaLabelProvider, ElectronAcceleratorLabelProvider, UILabelProvider, UserSettingsLabelProvider } from 'vs/base/common/keybindingLabels';
|
||||
import { OperatingSystem } from 'vs/base/common/platform';
|
||||
|
||||
/**
|
||||
@@ -15,12 +14,12 @@ export class USLayoutResolvedKeybinding extends ResolvedKeybinding {
|
||||
|
||||
private readonly _os: OperatingSystem;
|
||||
private readonly _firstPart: SimpleKeybinding;
|
||||
private readonly _chordPart: SimpleKeybinding;
|
||||
private readonly _chordPart: SimpleKeybinding | null;
|
||||
|
||||
constructor(actual: Keybinding, OS: OperatingSystem) {
|
||||
super();
|
||||
this._os = OS;
|
||||
if (actual === null) {
|
||||
if (!actual) {
|
||||
throw new Error(`Invalid USLayoutResolvedKeybinding`);
|
||||
} else if (actual.type === KeybindingType.Chord) {
|
||||
this._firstPart = actual.firstPart;
|
||||
@@ -47,7 +46,7 @@ export class USLayoutResolvedKeybinding extends ResolvedKeybinding {
|
||||
return KeyCodeUtils.toString(keyCode);
|
||||
}
|
||||
|
||||
private _getUILabelForKeybinding(keybinding: SimpleKeybinding): string {
|
||||
private _getUILabelForKeybinding(keybinding: SimpleKeybinding | null): string | null {
|
||||
if (!keybinding) {
|
||||
return null;
|
||||
}
|
||||
@@ -57,13 +56,13 @@ export class USLayoutResolvedKeybinding extends ResolvedKeybinding {
|
||||
return this._keyCodeToUILabel(keybinding.keyCode);
|
||||
}
|
||||
|
||||
public getLabel(): string {
|
||||
public getLabel(): string | null {
|
||||
let firstPart = this._getUILabelForKeybinding(this._firstPart);
|
||||
let chordPart = this._getUILabelForKeybinding(this._chordPart);
|
||||
return UILabelProvider.toLabel(this._firstPart, firstPart, this._chordPart, chordPart, this._os);
|
||||
}
|
||||
|
||||
private _getAriaLabelForKeybinding(keybinding: SimpleKeybinding): string {
|
||||
private _getAriaLabelForKeybinding(keybinding: SimpleKeybinding | null): string | null {
|
||||
if (!keybinding) {
|
||||
return null;
|
||||
}
|
||||
@@ -73,13 +72,13 @@ export class USLayoutResolvedKeybinding extends ResolvedKeybinding {
|
||||
return KeyCodeUtils.toString(keybinding.keyCode);
|
||||
}
|
||||
|
||||
public getAriaLabel(): string {
|
||||
public getAriaLabel(): string | null {
|
||||
let firstPart = this._getAriaLabelForKeybinding(this._firstPart);
|
||||
let chordPart = this._getAriaLabelForKeybinding(this._chordPart);
|
||||
return AriaLabelProvider.toLabel(this._firstPart, firstPart, this._chordPart, chordPart, this._os);
|
||||
}
|
||||
|
||||
private _keyCodeToElectronAccelerator(keyCode: KeyCode): string {
|
||||
private _keyCodeToElectronAccelerator(keyCode: KeyCode): string | null {
|
||||
if (keyCode >= KeyCode.NUMPAD_0 && keyCode <= KeyCode.NUMPAD_DIVIDE) {
|
||||
// Electron cannot handle numpad keys
|
||||
return null;
|
||||
@@ -99,7 +98,7 @@ export class USLayoutResolvedKeybinding extends ResolvedKeybinding {
|
||||
return KeyCodeUtils.toString(keyCode);
|
||||
}
|
||||
|
||||
private _getElectronAcceleratorLabelForKeybinding(keybinding: SimpleKeybinding): string {
|
||||
private _getElectronAcceleratorLabelForKeybinding(keybinding: SimpleKeybinding | null): string | null {
|
||||
if (!keybinding) {
|
||||
return null;
|
||||
}
|
||||
@@ -109,7 +108,7 @@ export class USLayoutResolvedKeybinding extends ResolvedKeybinding {
|
||||
return this._keyCodeToElectronAccelerator(keybinding.keyCode);
|
||||
}
|
||||
|
||||
public getElectronAccelerator(): string {
|
||||
public getElectronAccelerator(): string | null {
|
||||
if (this._chordPart !== null) {
|
||||
// Electron cannot handle chords
|
||||
return null;
|
||||
@@ -119,7 +118,7 @@ export class USLayoutResolvedKeybinding extends ResolvedKeybinding {
|
||||
return ElectronAcceleratorLabelProvider.toLabel(this._firstPart, firstPart, null, null, this._os);
|
||||
}
|
||||
|
||||
private _getUserSettingsLabelForKeybinding(keybinding: SimpleKeybinding): string {
|
||||
private _getUserSettingsLabelForKeybinding(keybinding: SimpleKeybinding | null): string | null {
|
||||
if (!keybinding) {
|
||||
return null;
|
||||
}
|
||||
@@ -129,7 +128,7 @@ export class USLayoutResolvedKeybinding extends ResolvedKeybinding {
|
||||
return KeyCodeUtils.toUserSettingsUS(keybinding.keyCode);
|
||||
}
|
||||
|
||||
public getUserSettingsLabel(): string {
|
||||
public getUserSettingsLabel(): string | null {
|
||||
let firstPart = this._getUserSettingsLabelForKeybinding(this._firstPart);
|
||||
let chordPart = this._getUserSettingsLabelForKeybinding(this._chordPart);
|
||||
let result = UserSettingsLabelProvider.toLabel(this._firstPart, firstPart, this._chordPart, chordPart, this._os);
|
||||
@@ -144,18 +143,14 @@ export class USLayoutResolvedKeybinding extends ResolvedKeybinding {
|
||||
return (this._chordPart ? true : false);
|
||||
}
|
||||
|
||||
public getParts(): [ResolvedKeybindingPart, ResolvedKeybindingPart] {
|
||||
public getParts(): [ResolvedKeybindingPart, ResolvedKeybindingPart | null] {
|
||||
return [
|
||||
this._toResolvedKeybindingPart(this._firstPart),
|
||||
this._toResolvedKeybindingPart(this._chordPart)
|
||||
this._chordPart ? this._toResolvedKeybindingPart(this._chordPart) : null
|
||||
];
|
||||
}
|
||||
|
||||
private _toResolvedKeybindingPart(keybinding: SimpleKeybinding): ResolvedKeybindingPart {
|
||||
if (!keybinding) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ResolvedKeybindingPart(
|
||||
keybinding.ctrlKey,
|
||||
keybinding.shiftKey,
|
||||
@@ -166,13 +161,13 @@ export class USLayoutResolvedKeybinding extends ResolvedKeybinding {
|
||||
);
|
||||
}
|
||||
|
||||
public getDispatchParts(): [string, string] {
|
||||
public getDispatchParts(): [string | null, string | null] {
|
||||
let firstPart = this._firstPart ? USLayoutResolvedKeybinding.getDispatchStr(this._firstPart) : null;
|
||||
let chordPart = this._chordPart ? USLayoutResolvedKeybinding.getDispatchStr(this._chordPart) : null;
|
||||
return [firstPart, chordPart];
|
||||
}
|
||||
|
||||
public static getDispatchStr(keybinding: SimpleKeybinding): string {
|
||||
public static getDispatchStr(keybinding: SimpleKeybinding): string | null {
|
||||
if (keybinding.isModifierKey()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2,24 +2,21 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { ResolvedKeybinding, KeyCode, KeyMod, KeyChord, Keybinding, createKeybinding, createSimpleKeybinding, SimpleKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { AbstractKeybindingService } from 'vs/platform/keybinding/common/abstractKeybindingService';
|
||||
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
|
||||
import { KeyChord, KeyCode, KeyMod, Keybinding, ResolvedKeybinding, SimpleKeybinding, createKeybinding, createSimpleKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { OS } from 'vs/base/common/platform';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import { IContext, ContextKeyExpr, IContextKeyService, IContextKeyServiceTarget } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
|
||||
import { OS } from 'vs/base/common/platform';
|
||||
import { ContextKeyExpr, IContext, IContextKeyService, IContextKeyServiceTarget } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { AbstractKeybindingService } from 'vs/platform/keybinding/common/abstractKeybindingService';
|
||||
import { IKeyboardEvent } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
|
||||
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
|
||||
import { INotification, INotificationService, IPromptChoice, IPromptOptions, NoOpNotification } from 'vs/platform/notification/common/notification';
|
||||
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
|
||||
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
|
||||
import { INotificationService, NoOpNotification, INotification, IPromptChoice } from 'vs/platform/notification/common/notification';
|
||||
|
||||
function createContext(ctx: any) {
|
||||
return {
|
||||
@@ -86,11 +83,11 @@ suite('AbstractKeybindingService', () => {
|
||||
}
|
||||
|
||||
let createTestKeybindingService: (items: ResolvedKeybindingItem[], contextValue?: any) => TestKeybindingService = null;
|
||||
let currentContextValue: IContext = null;
|
||||
let currentContextValue: IContext | null = null;
|
||||
let executeCommandCalls: { commandId: string; args: any[]; }[] = null;
|
||||
let showMessageCalls: { sev: Severity, message: any; }[] = null;
|
||||
let statusMessageCalls: string[] = null;
|
||||
let statusMessageCallsDisposed: string[] = null;
|
||||
let statusMessageCalls: string[] | null = null;
|
||||
let statusMessageCallsDisposed: string[] | null = null;
|
||||
|
||||
setup(() => {
|
||||
executeCommandCalls = [];
|
||||
@@ -116,12 +113,12 @@ suite('AbstractKeybindingService', () => {
|
||||
let commandService: ICommandService = {
|
||||
_serviceBrand: undefined,
|
||||
onWillExecuteCommand: () => ({ dispose: () => { } }),
|
||||
executeCommand: (commandId: string, ...args: any[]): TPromise<any> => {
|
||||
executeCommand: (commandId: string, ...args: any[]): Promise<any> => {
|
||||
executeCommandCalls.push({
|
||||
commandId: commandId,
|
||||
args: args
|
||||
});
|
||||
return TPromise.as(void 0);
|
||||
return Promise.resolve(void 0);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -143,7 +140,7 @@ suite('AbstractKeybindingService', () => {
|
||||
showMessageCalls.push({ sev: Severity.Error, message });
|
||||
return new NoOpNotification();
|
||||
},
|
||||
prompt(severity: Severity, message: string, choices: IPromptChoice[], onCancel?: () => void) {
|
||||
prompt(severity: Severity, message: string, choices: IPromptChoice[], options?: IPromptOptions) {
|
||||
throw new Error('not implemented');
|
||||
}
|
||||
};
|
||||
@@ -176,7 +173,7 @@ suite('AbstractKeybindingService', () => {
|
||||
statusMessageCallsDisposed = null;
|
||||
});
|
||||
|
||||
function kbItem(keybinding: number, command: string, when: ContextKeyExpr = null): ResolvedKeybindingItem {
|
||||
function kbItem(keybinding: number, command: string, when: ContextKeyExpr | null = null): ResolvedKeybindingItem {
|
||||
const resolvedKeybinding = (keybinding !== 0 ? new USLayoutResolvedKeybinding(createKeybinding(keybinding, OS), OS) : null);
|
||||
return new ResolvedKeybindingItem(
|
||||
resolvedKeybinding,
|
||||
|
||||
@@ -2,12 +2,10 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { KeyCode, KeyMod, KeyChord, createKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
|
||||
import { KeyChord, KeyCode, KeyMod, createKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { OperatingSystem } from 'vs/base/common/platform';
|
||||
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
|
||||
|
||||
suite('KeybindingLabels', () => {
|
||||
|
||||
|
||||
@@ -2,15 +2,13 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { KeyCode, KeyMod, KeyChord, createKeybinding, KeybindingType, SimpleKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import { KeyChord, KeyCode, KeyMod, KeybindingType, SimpleKeybinding, createKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { OS } from 'vs/base/common/platform';
|
||||
import { ContextKeyAndExpr, ContextKeyExpr, IContext } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
|
||||
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
|
||||
import { OS } from 'vs/base/common/platform';
|
||||
|
||||
function createContext(ctx: any) {
|
||||
return {
|
||||
@@ -192,7 +190,7 @@ suite('KeybindingResolver', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
test('contextIsEntirelyIncluded', function () {
|
||||
test('contextIsEntirelyIncluded', () => {
|
||||
let assertIsIncluded = (a: ContextKeyExpr[], b: ContextKeyExpr[]) => {
|
||||
let tmpA = new ContextKeyAndExpr(a).normalize();
|
||||
let tmpB = new ContextKeyAndExpr(b).normalize();
|
||||
|
||||
@@ -2,27 +2,26 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { ResolvedKeybinding, Keybinding, SimpleKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { IKeybindingService, IKeybindingEvent, IKeyboardEvent } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { IContextKey, IContextKeyService, IContextKeyServiceTarget, ContextKeyExpr, IContextKeyChangeEvent } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IResolveResult } from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
|
||||
import { Keybinding, ResolvedKeybinding, SimpleKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { OS } from 'vs/base/common/platform';
|
||||
import { ContextKeyExpr, IContextKey, IContextKeyChangeEvent, IContextKeyService, IContextKeyServiceTarget } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IKeybindingEvent, IKeybindingService, IKeyboardEvent } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { IResolveResult } from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
|
||||
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
|
||||
|
||||
class MockKeybindingContextKey<T> implements IContextKey<T> {
|
||||
private _defaultValue: T;
|
||||
private _value: T;
|
||||
private _defaultValue: T | undefined;
|
||||
private _value: T | undefined;
|
||||
|
||||
constructor(defaultValue: T) {
|
||||
constructor(defaultValue: T | undefined) {
|
||||
this._defaultValue = defaultValue;
|
||||
this._value = this._defaultValue;
|
||||
}
|
||||
|
||||
public set(value: T): void {
|
||||
public set(value: T | undefined): void {
|
||||
this._value = value;
|
||||
}
|
||||
|
||||
@@ -30,7 +29,7 @@ class MockKeybindingContextKey<T> implements IContextKey<T> {
|
||||
this._value = this._defaultValue;
|
||||
}
|
||||
|
||||
public get(): T {
|
||||
public get(): T | undefined {
|
||||
return this._value;
|
||||
}
|
||||
}
|
||||
@@ -43,7 +42,7 @@ export class MockContextKeyService implements IContextKeyService {
|
||||
public dispose(): void {
|
||||
//
|
||||
}
|
||||
public createKey<T>(key: string, defaultValue: T): IContextKey<T> {
|
||||
public createKey<T>(key: string, defaultValue: T | undefined): IContextKey<T> {
|
||||
let ret = new MockKeybindingContextKey(defaultValue);
|
||||
this._keys.set(key, ret);
|
||||
return ret;
|
||||
@@ -75,7 +74,7 @@ export class MockKeybindingService implements IKeybindingService {
|
||||
}
|
||||
|
||||
public getDefaultKeybindingsContent(): string {
|
||||
return null;
|
||||
return '';
|
||||
}
|
||||
|
||||
public getDefaultKeybindings(): ResolvedKeybindingItem[] {
|
||||
@@ -109,7 +108,7 @@ export class MockKeybindingService implements IKeybindingService {
|
||||
return [];
|
||||
}
|
||||
|
||||
public lookupKeybinding(commandId: string): ResolvedKeybinding {
|
||||
public lookupKeybinding(commandId: string): ResolvedKeybinding | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -117,11 +116,15 @@ export class MockKeybindingService implements IKeybindingService {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public softDispatch(keybinding: IKeyboardEvent, target: IContextKeyServiceTarget): IResolveResult {
|
||||
public softDispatch(keybinding: IKeyboardEvent, target: IContextKeyServiceTarget): IResolveResult | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
dispatchEvent(e: IKeyboardEvent, target: IContextKeyServiceTarget): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
mightProducePrintableCharacter(e: IKeyboardEvent): boolean {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user