mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-30 18:46:00 +01:00
Extract NormalizedKeybindingItem to its own file
This commit is contained in:
@@ -12,7 +12,7 @@ import { IConfigurationService, IConfigurationServiceEvent, IConfigurationValue,
|
||||
import { IEditor, IEditorInput, IEditorOptions, IEditorService, IResourceInput, Position } from 'vs/platform/editor/common/editor';
|
||||
import { ICommandService, ICommand, ICommandEvent, ICommandHandler, CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
import { SimpleResolvedKeybinding, AbstractKeybindingService } from 'vs/platform/keybinding/common/abstractKeybindingService';
|
||||
import { KeybindingResolver, NormalizedKeybindingItem } from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import { IKeybindingEvent, IKeybindingItem, KeybindingSource } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IConfirmation, IMessageService } from 'vs/platform/message/common/message';
|
||||
@@ -32,6 +32,7 @@ import { MenuId, IMenu, IMenuService } from 'vs/platform/actions/common/actions'
|
||||
import { Menu } from 'vs/platform/actions/common/menu';
|
||||
import { ITelemetryService, ITelemetryExperiments, ITelemetryInfo } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { ResolvedKeybinding, Keybinding } from 'vs/base/common/keyCodes';
|
||||
import { NormalizedKeybindingItem } from 'vs/platform/keybinding/common/normalizedKeybindingItem';
|
||||
|
||||
export class SimpleEditor implements IEditor {
|
||||
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { createKeybinding, Keybinding } from 'vs/base/common/keyCodes';
|
||||
import { Keybinding } from 'vs/base/common/keyCodes';
|
||||
import { ISimplifiedPlatform, KeybindingLabels } from 'vs/platform/keybinding/common/keybindingLabels';
|
||||
import * as platform from 'vs/base/common/platform';
|
||||
import { IKeybindingItem, IUserFriendlyKeybinding } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { CharCode } from "vs/base/common/charCode";
|
||||
import { NormalizedKeybindingItem } from 'vs/platform/keybinding/common/normalizedKeybindingItem';
|
||||
|
||||
export interface IResolveResult {
|
||||
enterChord: boolean;
|
||||
@@ -30,52 +30,6 @@ interface IChordsMap {
|
||||
[keypress: string]: ICommandMap;
|
||||
}
|
||||
|
||||
export class NormalizedKeybindingItem {
|
||||
_normalizedKeybindingItemBrand: void;
|
||||
|
||||
public readonly keybinding: Keybinding;
|
||||
public readonly keypressFirstPart: string;
|
||||
public readonly keypressChordPart: string;
|
||||
public readonly bubble: boolean;
|
||||
public readonly command: string;
|
||||
public readonly commandArgs: any;
|
||||
public readonly when: ContextKeyExpr;
|
||||
public readonly isDefault: boolean;
|
||||
|
||||
public static fromKeybindingItem(source: IKeybindingItem, isDefault: boolean): NormalizedKeybindingItem {
|
||||
let when: ContextKeyExpr = null;
|
||||
if (source.when) {
|
||||
when = source.when.normalize();
|
||||
}
|
||||
let keybinding: Keybinding = null;
|
||||
if (source.keybinding !== 0) {
|
||||
keybinding = createKeybinding(source.keybinding);
|
||||
}
|
||||
return new NormalizedKeybindingItem(keybinding, source.command, source.commandArgs, when, isDefault);
|
||||
}
|
||||
|
||||
constructor(keybinding: Keybinding, command: string, commandArgs: any, when: ContextKeyExpr, isDefault: boolean) {
|
||||
this.keybinding = keybinding;
|
||||
|
||||
if (keybinding === null) {
|
||||
this.keypressFirstPart = null;
|
||||
this.keypressChordPart = null;
|
||||
} else if (keybinding.isChord()) {
|
||||
this.keypressFirstPart = keybinding.extractFirstPart().value.toString();
|
||||
this.keypressChordPart = keybinding.extractChordPart().value.toString();
|
||||
} else {
|
||||
this.keypressFirstPart = keybinding.value.toString();
|
||||
this.keypressChordPart = null;
|
||||
}
|
||||
|
||||
this.bubble = (command ? command.charCodeAt(0) === CharCode.Caret : false);
|
||||
this.command = this.bubble ? command.substr(1) : command;
|
||||
this.commandArgs = commandArgs;
|
||||
this.when = when;
|
||||
this.isDefault = isDefault;
|
||||
}
|
||||
}
|
||||
|
||||
export class KeybindingResolver {
|
||||
private readonly _defaultKeybindings: NormalizedKeybindingItem[];
|
||||
private readonly _shouldWarnOnConflict: boolean;
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { createKeybinding, Keybinding } from 'vs/base/common/keyCodes';
|
||||
import { IKeybindingItem } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { CharCode } from "vs/base/common/charCode";
|
||||
|
||||
export class NormalizedKeybindingItem {
|
||||
_normalizedKeybindingItemBrand: void;
|
||||
|
||||
public readonly keybinding: Keybinding;
|
||||
public readonly keypressFirstPart: string;
|
||||
public readonly keypressChordPart: string;
|
||||
public readonly bubble: boolean;
|
||||
public readonly command: string;
|
||||
public readonly commandArgs: any;
|
||||
public readonly when: ContextKeyExpr;
|
||||
public readonly isDefault: boolean;
|
||||
|
||||
public static fromKeybindingItem(source: IKeybindingItem, isDefault: boolean): NormalizedKeybindingItem {
|
||||
let when: ContextKeyExpr = null;
|
||||
if (source.when) {
|
||||
when = source.when.normalize();
|
||||
}
|
||||
let keybinding: Keybinding = null;
|
||||
if (source.keybinding !== 0) {
|
||||
keybinding = createKeybinding(source.keybinding);
|
||||
}
|
||||
return new NormalizedKeybindingItem(keybinding, source.command, source.commandArgs, when, isDefault);
|
||||
}
|
||||
|
||||
constructor(keybinding: Keybinding, command: string, commandArgs: any, when: ContextKeyExpr, isDefault: boolean) {
|
||||
this.keybinding = keybinding;
|
||||
|
||||
if (keybinding === null) {
|
||||
this.keypressFirstPart = null;
|
||||
this.keypressChordPart = null;
|
||||
} else if (keybinding.isChord()) {
|
||||
this.keypressFirstPart = keybinding.extractFirstPart().value.toString();
|
||||
this.keypressChordPart = keybinding.extractChordPart().value.toString();
|
||||
} else {
|
||||
this.keypressFirstPart = keybinding.value.toString();
|
||||
this.keypressChordPart = null;
|
||||
}
|
||||
|
||||
this.bubble = (command ? command.charCodeAt(0) === CharCode.Caret : false);
|
||||
this.command = this.bubble ? command.substr(1) : command;
|
||||
this.commandArgs = commandArgs;
|
||||
this.when = when;
|
||||
this.isDefault = isDefault;
|
||||
}
|
||||
}
|
||||
@@ -11,11 +11,12 @@ import { KeybindingLabels } from 'vs/platform/keybinding/common/keybindingLabels
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
import { KeybindingResolver, NormalizedKeybindingItem } from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import { ContextKeyExpr, IContextKeyService, IContextKeyServiceTarget } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
|
||||
import { IMessageService } from 'vs/platform/message/common/message';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { NormalizedKeybindingItem } from 'vs/platform/keybinding/common/normalizedKeybindingItem';
|
||||
|
||||
suite('AbstractKeybindingService', () => {
|
||||
|
||||
|
||||
@@ -6,9 +6,10 @@
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { createKeybinding, KeyCode, KeyMod, KeyChord } from 'vs/base/common/keyCodes';
|
||||
import { NormalizedKeybindingItem, IOSupport } from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import { IOSupport } from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import { IUserFriendlyKeybinding } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { ISimplifiedPlatform } from 'vs/platform/keybinding/common/keybindingLabels';
|
||||
import { NormalizedKeybindingItem } from 'vs/platform/keybinding/common/normalizedKeybindingItem';
|
||||
|
||||
suite('Keybinding IO', () => {
|
||||
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { createKeybinding, SimpleKeybinding, KeyCode, KeyMod, KeyChord } from 'vs/base/common/keyCodes';
|
||||
import { KeybindingResolver, NormalizedKeybindingItem } from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import { ContextKeyAndExpr, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { NormalizedKeybindingItem } from 'vs/platform/keybinding/common/normalizedKeybindingItem';
|
||||
|
||||
suite('KeybindingResolver', () => {
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import { ExtensionMessageCollector, ExtensionsRegistry } from 'vs/platform/exten
|
||||
import { Extensions, IJSONContributionRegistry } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
|
||||
import { AbstractKeybindingService } from 'vs/platform/keybinding/common/abstractKeybindingService';
|
||||
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
|
||||
import { KeybindingResolver, IOSupport, NormalizedKeybindingItem } from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import { KeybindingResolver, IOSupport } from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
import { IKeybindingEvent, IKeybindingItem, IUserFriendlyKeybinding, KeybindingSource } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
@@ -29,6 +29,7 @@ import { ConfigWatcher } from 'vs/base/node/config';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import * as dom from 'vs/base/browser/dom';
|
||||
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
|
||||
import { NormalizedKeybindingItem } from 'vs/platform/keybinding/common/normalizedKeybindingItem';
|
||||
|
||||
interface ContributedKeyBinding {
|
||||
command: string;
|
||||
|
||||
Reference in New Issue
Block a user