diff --git a/src/vs/editor/common/editorCommon.ts b/src/vs/editor/common/editorCommon.ts index 48215fb6c21..af7fcb77898 100644 --- a/src/vs/editor/common/editorCommon.ts +++ b/src/vs/editor/common/editorCommon.ts @@ -20,7 +20,7 @@ import {Selection} from 'vs/editor/common/core/selection'; import {ModeTransition} from 'vs/editor/common/core/modeTransition'; import {IndentRange} from 'vs/editor/common/model/indentRanges'; import {ICommandHandlerDescription} from 'vs/platform/commands/common/commands'; -import {KbExpr} from 'vs/platform/keybinding/common/keybinding'; +import {KbExpr, KbCtxKey} from 'vs/platform/keybinding/common/keybinding'; /** * @internal @@ -3099,47 +3099,47 @@ export namespace ModeContextKeys { /** * @internal */ - export const hasCompletionItemProvider = 'editorHasCompletionItemProvider'; + export const hasCompletionItemProvider = new KbCtxKey('editorHasCompletionItemProvider'); /** * @internal */ - export const hasCodeActionsProvider = 'editorHasCodeActionsProvider'; + export const hasCodeActionsProvider = new KbCtxKey('editorHasCodeActionsProvider'); /** * @internal */ - export const hasCodeLensProvider = 'editorHasCodeLensProvider'; + export const hasCodeLensProvider = new KbCtxKey('editorHasCodeLensProvider'); /** * @internal */ - export const hasDefinitionProvider = 'editorHasDefinitionProvider'; + export const hasDefinitionProvider = new KbCtxKey('editorHasDefinitionProvider'); /** * @internal */ - export const hasHoverProvider = 'editorHasHoverProvider'; + export const hasHoverProvider = new KbCtxKey('editorHasHoverProvider'); /** * @internal */ - export const hasDocumentHighlightProvider = 'editorHasDocumentHighlightProvider'; + export const hasDocumentHighlightProvider = new KbCtxKey('editorHasDocumentHighlightProvider'); /** * @internal */ - export const hasDocumentSymbolProvider = 'editorHasDocumentSymbolProvider'; + export const hasDocumentSymbolProvider = new KbCtxKey('editorHasDocumentSymbolProvider'); /** * @internal */ - export const hasReferenceProvider = 'editorHasReferenceProvider'; + export const hasReferenceProvider = new KbCtxKey('editorHasReferenceProvider'); /** * @internal */ - export const hasRenameProvider = 'editorHasRenameProvider'; + export const hasRenameProvider = new KbCtxKey('editorHasRenameProvider'); /** * @internal */ - export const hasFormattingProvider = 'editorHasFormattingProvider'; + export const hasFormattingProvider = new KbCtxKey('editorHasFormattingProvider'); /** * @internal */ - export const hasSignatureHelpProvider = 'editorHasSignatureHelpProvider'; + export const hasSignatureHelpProvider = new KbCtxKey('editorHasSignatureHelpProvider'); } export class BareFontInfo { diff --git a/src/vs/editor/common/modes/editorModeContext.ts b/src/vs/editor/common/modes/editorModeContext.ts index 88821bb05bd..7b84e3bedce 100644 --- a/src/vs/editor/common/modes/editorModeContext.ts +++ b/src/vs/editor/common/modes/editorModeContext.ts @@ -32,17 +32,17 @@ export class EditorModeContext { ) { this._editor = editor; - this._hasCompletionItemProvider = keybindingService.createKey(ModeContextKeys.hasCompletionItemProvider, undefined); - this._hasCodeActionsProvider = keybindingService.createKey(ModeContextKeys.hasCodeActionsProvider, undefined); - this._hasCodeLensProvider = keybindingService.createKey(ModeContextKeys.hasCodeLensProvider, undefined); - this._hasDefinitionProvider = keybindingService.createKey(ModeContextKeys.hasDefinitionProvider, undefined); - this._hasHoverProvider = keybindingService.createKey(ModeContextKeys.hasHoverProvider, undefined); - this._hasDocumentHighlightProvider = keybindingService.createKey(ModeContextKeys.hasDocumentHighlightProvider, undefined); - this._hasDocumentSymbolProvider = keybindingService.createKey(ModeContextKeys.hasDocumentSymbolProvider, undefined); - this._hasReferenceProvider = keybindingService.createKey(ModeContextKeys.hasReferenceProvider, undefined); - this._hasRenameProvider = keybindingService.createKey(ModeContextKeys.hasRenameProvider, undefined); - this._hasFormattingProvider = keybindingService.createKey(ModeContextKeys.hasFormattingProvider, undefined); - this._hasSignatureHelpProvider = keybindingService.createKey(ModeContextKeys.hasSignatureHelpProvider, undefined); + this._hasCompletionItemProvider = ModeContextKeys.hasCompletionItemProvider.bindTo(keybindingService, undefined); + this._hasCodeActionsProvider = ModeContextKeys.hasCodeActionsProvider.bindTo(keybindingService, undefined); + this._hasCodeLensProvider = ModeContextKeys.hasCodeLensProvider.bindTo(keybindingService, undefined); + this._hasDefinitionProvider = ModeContextKeys.hasDefinitionProvider.bindTo(keybindingService, undefined); + this._hasHoverProvider = ModeContextKeys.hasHoverProvider.bindTo(keybindingService, undefined); + this._hasDocumentHighlightProvider = ModeContextKeys.hasDocumentHighlightProvider.bindTo(keybindingService, undefined); + this._hasDocumentSymbolProvider = ModeContextKeys.hasDocumentSymbolProvider.bindTo(keybindingService, undefined); + this._hasReferenceProvider = ModeContextKeys.hasReferenceProvider.bindTo(keybindingService, undefined); + this._hasRenameProvider = ModeContextKeys.hasRenameProvider.bindTo(keybindingService, undefined); + this._hasFormattingProvider = ModeContextKeys.hasFormattingProvider.bindTo(keybindingService, undefined); + this._hasSignatureHelpProvider = ModeContextKeys.hasSignatureHelpProvider.bindTo(keybindingService, undefined); // update when model/mode changes this._disposables.push(editor.onDidChangeModel(() => this._update())); diff --git a/src/vs/editor/contrib/format/common/formatActions.ts b/src/vs/editor/contrib/format/common/formatActions.ts index 531ca1bc93e..e16798fa58c 100644 --- a/src/vs/editor/contrib/format/common/formatActions.ts +++ b/src/vs/editor/contrib/format/common/formatActions.ts @@ -17,6 +17,9 @@ import {getOnTypeFormattingEdits, getDocumentFormattingEdits, getDocumentRangeFo import {EditOperationsCommand} from './formatCommand'; import {Selection} from 'vs/editor/common/core/selection'; +const ModeContextKeys = editorCommon.ModeContextKeys; +const EditorKbExpr = editorCommon.EditorKbExpr; + class FormatOnType implements editorCommon.IEditorContribution { public static ID = 'editor.contrib.autoFormat'; @@ -143,7 +146,7 @@ export class FormatAction extends EditorAction { ); this.kbOpts = { - kbExpr: KbExpr.and(editorCommon.EditorKbExpr.TextFocus, editorCommon.EditorKbExpr.Writable), + kbExpr: KbExpr.and(EditorKbExpr.TextFocus, EditorKbExpr.Writable), primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_F, linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_I } }; @@ -151,7 +154,7 @@ export class FormatAction extends EditorAction { this.menuOpts = { group: '1_modification', order: 1.3, - kbExpr: KbExpr.has(editorCommon.ModeContextKeys.hasFormattingProvider) + kbExpr: ModeContextKeys.hasFormattingProvider }; } diff --git a/src/vs/editor/contrib/goToDeclaration/browser/goToDeclaration.ts b/src/vs/editor/contrib/goToDeclaration/browser/goToDeclaration.ts index 171e474a849..80e93eea16a 100644 --- a/src/vs/editor/contrib/goToDeclaration/browser/goToDeclaration.ts +++ b/src/vs/editor/contrib/goToDeclaration/browser/goToDeclaration.ts @@ -7,7 +7,6 @@ import 'vs/css!./goToDeclaration'; import * as nls from 'vs/nls'; -import {KbExpr} from 'vs/platform/keybinding/common/keybinding'; import {Throttler} from 'vs/base/common/async'; import {onUnexpectedError} from 'vs/base/common/errors'; import {MarkedString, textToMarkedString} from 'vs/base/common/htmlContent'; @@ -33,6 +32,7 @@ import {IDisposable, dispose} from 'vs/base/common/lifecycle'; import {IPeekViewService} from 'vs/editor/contrib/zoneWidget/browser/peekViewWidget'; import {optional} from 'vs/platform/instantiation/common/instantiation'; +const ModeContextKeys = editorCommon.ModeContextKeys; export class DefinitionActionConfig { @@ -179,7 +179,7 @@ export class GoToDefinitionAction extends DefinitionAction { this.menuOpts = { group: 'navigation', order: 1.1, - kbExpr: KbExpr.has(editorCommon.ModeContextKeys.hasDefinitionProvider) + kbExpr: ModeContextKeys.hasDefinitionProvider }; } } @@ -222,7 +222,7 @@ export class PeekDefinitionAction extends DefinitionAction { this.menuOpts = { group: 'navigation', order: 1.2, - kbExpr: KbExpr.has(editorCommon.ModeContextKeys.hasDefinitionProvider) + kbExpr: ModeContextKeys.hasDefinitionProvider }; } diff --git a/src/vs/editor/contrib/parameterHints/browser/parameterHints.ts b/src/vs/editor/contrib/parameterHints/browser/parameterHints.ts index f50576dcc2c..d8695cc8bb7 100644 --- a/src/vs/editor/contrib/parameterHints/browser/parameterHints.ts +++ b/src/vs/editor/contrib/parameterHints/browser/parameterHints.ts @@ -104,7 +104,7 @@ KeybindingsRegistry.registerCommandDesc({ id: 'closeParameterHints', handler: handler('closeParameterHints', c => c.cancel()), weight, - when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(Context.Visible)), + when: KbExpr.and(EditorKbExpr.TextFocus, Context.Visible), primary: KeyCode.Escape, secondary: [KeyMod.Shift | KeyCode.Escape] }); @@ -113,7 +113,7 @@ KeybindingsRegistry.registerCommandDesc({ id: 'showPrevParameterHint', handler: handler('showPrevParameterHint', c => c.previous()), weight, - when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(Context.Visible), KbExpr.has(Context.MultipleSignatures)), + when: KbExpr.and(EditorKbExpr.TextFocus, Context.Visible, Context.MultipleSignatures), primary: KeyCode.UpArrow, secondary: [KeyMod.Alt | KeyCode.UpArrow], mac: { primary: KeyCode.UpArrow, secondary: [KeyMod.Alt | KeyCode.UpArrow, KeyMod.WinCtrl | KeyCode.KEY_P] } @@ -123,7 +123,7 @@ KeybindingsRegistry.registerCommandDesc({ id: 'showNextParameterHint', handler: handler('showNextParameterHint', c => c.next()), weight, - when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(Context.Visible), KbExpr.has(Context.MultipleSignatures)), + when: KbExpr.and(EditorKbExpr.TextFocus, Context.Visible, Context.MultipleSignatures), primary: KeyCode.DownArrow, secondary: [KeyMod.Alt | KeyCode.DownArrow], mac: { primary: KeyCode.DownArrow, secondary: [KeyMod.Alt | KeyCode.DownArrow, KeyMod.WinCtrl | KeyCode.KEY_N] } diff --git a/src/vs/editor/contrib/parameterHints/browser/parameterHintsWidget.ts b/src/vs/editor/contrib/parameterHints/browser/parameterHintsWidget.ts index 5a46eaec20d..fe309501c4b 100644 --- a/src/vs/editor/contrib/parameterHints/browser/parameterHintsWidget.ts +++ b/src/vs/editor/contrib/parameterHints/browser/parameterHintsWidget.ts @@ -178,8 +178,8 @@ export class ParameterHintsWidget implements IContentWidget, IDisposable { constructor(private editor: ICodeEditor, @IKeybindingService keybindingService: IKeybindingService) { this.model = new ParameterHintsModel(editor); - this.keyVisible = keybindingService.createKey(Context.Visible, false); - this.keyMultipleSignatures = keybindingService.createKey(Context.MultipleSignatures, false); + this.keyVisible = Context.Visible.bindTo(keybindingService, false); + this.keyMultipleSignatures = Context.MultipleSignatures.bindTo(keybindingService, false); this.visible = false; this.disposables = []; diff --git a/src/vs/editor/contrib/parameterHints/common/parameterHints.ts b/src/vs/editor/contrib/parameterHints/common/parameterHints.ts index 999c77b9ef2..a2e293b369f 100644 --- a/src/vs/editor/contrib/parameterHints/common/parameterHints.ts +++ b/src/vs/editor/contrib/parameterHints/common/parameterHints.ts @@ -11,10 +11,11 @@ import { CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions'; import { SignatureHelp, SignatureHelpProviderRegistry } from 'vs/editor/common/modes'; import { asWinJsPromise } from 'vs/base/common/async'; import { Position } from 'vs/editor/common/core/position'; +import { KbCtxKey } from 'vs/platform/keybinding/common/keybinding'; export const Context = { - Visible: 'parameterHintsVisible', - MultipleSignatures: 'parameterHintsMultipleSignatures', + Visible: new KbCtxKey('parameterHintsVisible'), + MultipleSignatures: new KbCtxKey('parameterHintsMultipleSignatures'), }; export function provideSignatureHelp(model:IReadOnlyModel, position:Position): TPromise { diff --git a/src/vs/editor/contrib/quickOpen/browser/quickOutline.ts b/src/vs/editor/contrib/quickOpen/browser/quickOutline.ts index 77a6682d972..924c9922cdc 100644 --- a/src/vs/editor/contrib/quickOpen/browser/quickOutline.ts +++ b/src/vs/editor/contrib/quickOpen/browser/quickOutline.ts @@ -19,7 +19,6 @@ import {BaseEditorQuickOpenAction, IDecorator} from './editorQuickOpen'; import {getDocumentSymbols, IOutline} from 'vs/editor/contrib/quickOpen/common/quickOpen'; import {ServicesAccessor} from 'vs/editor/common/editorCommonExtensions'; import {KeyCode, KeyMod} from 'vs/base/common/keyCodes'; -import {KbExpr} from 'vs/platform/keybinding/common/keybinding'; let SCOPE_PREFIX = ':'; @@ -126,7 +125,7 @@ export class QuickOutlineAction extends BaseEditorQuickOpenAction { this.menuOpts = { group: 'navigation', order: 3, - kbExpr: KbExpr.and(KbExpr.has(ModeContextKeys.hasDocumentSymbolProvider)) + kbExpr: ModeContextKeys.hasDocumentSymbolProvider }; } diff --git a/src/vs/editor/contrib/referenceSearch/browser/referenceSearch.ts b/src/vs/editor/contrib/referenceSearch/browser/referenceSearch.ts index da78304e754..be06676eae3 100644 --- a/src/vs/editor/contrib/referenceSearch/browser/referenceSearch.ts +++ b/src/vs/editor/contrib/referenceSearch/browser/referenceSearch.ts @@ -24,6 +24,9 @@ import {ReferenceWidget} from './referencesWidget'; import {ReferencesController, RequestOptions, ctxReferenceSearchVisible} from './referencesController'; import {ReferencesModel} from './referencesModel'; +const ModeContextKeys = editorCommon.ModeContextKeys; +const EditorKbExpr = editorCommon.EditorKbExpr; + const defaultReferenceSearchOptions: RequestOptions = { getMetaTitle(model) { return model.references.length > 1 && nls.localize('meta.titleReference', " – {0} references", model.references.length); @@ -40,7 +43,7 @@ export class ReferenceController implements editorCommon.IEditorContribution { @optional(IPeekViewService) peekViewService: IPeekViewService ) { if (peekViewService) { - keybindingService.createKey(peekViewService.contextKey, true); + peekViewService.contextKey.bindTo(keybindingService, true); } } @@ -63,12 +66,12 @@ export class ReferenceAction extends EditorAction { ); this.kbOpts = { - kbExpr: editorCommon.EditorKbExpr.TextFocus, + kbExpr: EditorKbExpr.TextFocus, primary: KeyMod.Shift | KeyCode.F12 }; this.menuOpts = { - kbExpr: KbExpr.has(editorCommon.ModeContextKeys.hasReferenceProvider), + kbExpr: ModeContextKeys.hasReferenceProvider, group: 'navigation', order: 1.3 }; @@ -190,7 +193,7 @@ KeybindingsRegistry.registerCommandDesc({ weight: CommonEditorRegistry.commandWeight(50), primary: KeyCode.Escape, secondary: [KeyMod.Shift | KeyCode.Escape], - when: KbExpr.and(KbExpr.has(ctxReferenceSearchVisible), KbExpr.not('config.editor.stablePeek')), + when: KbExpr.and(ctxReferenceSearchVisible, KbExpr.not('config.editor.stablePeek')), handler: closeActiveReferenceSearch }); @@ -199,6 +202,6 @@ KeybindingsRegistry.registerCommandDesc({ weight: CommonEditorRegistry.commandWeight(-101), primary: KeyCode.Escape, secondary: [KeyMod.Shift | KeyCode.Escape], - when: KbExpr.and(KbExpr.has(ReferenceWidget.INNER_EDITOR_CONTEXT_KEY), KbExpr.not('config.editor.stablePeek')), + when: KbExpr.and(ReferenceWidget.INNER_EDITOR_CONTEXT_KEY, KbExpr.not('config.editor.stablePeek')), handler: closeActiveReferenceSearch }); diff --git a/src/vs/editor/contrib/referenceSearch/browser/referencesController.ts b/src/vs/editor/contrib/referenceSearch/browser/referencesController.ts index b2044664772..b902bea5c22 100644 --- a/src/vs/editor/contrib/referenceSearch/browser/referencesController.ts +++ b/src/vs/editor/contrib/referenceSearch/browser/referencesController.ts @@ -11,7 +11,7 @@ import Severity from 'vs/base/common/severity'; import {TPromise} from 'vs/base/common/winjs.base'; import {IEditorService} from 'vs/platform/editor/common/editor'; import {IInstantiationService, optional} from 'vs/platform/instantiation/common/instantiation'; -import {IKeybindingContextKey, IKeybindingService} from 'vs/platform/keybinding/common/keybinding'; +import {IKeybindingContextKey, IKeybindingService, KbCtxKey} from 'vs/platform/keybinding/common/keybinding'; import {IMessageService} from 'vs/platform/message/common/message'; import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry'; import {IConfigurationService, getConfigurationValue} from 'vs/platform/configuration/common/configuration'; @@ -25,7 +25,7 @@ import {ReferencesModel, OneReference} from './referencesModel'; import {ReferenceWidget, LayoutData} from './referencesWidget'; import {Range} from 'vs/editor/common/core/range'; -export const ctxReferenceSearchVisible = 'referenceSearchVisible'; +export const ctxReferenceSearchVisible = new KbCtxKey('referenceSearchVisible'); export interface RequestOptions { getMetaTitle(model: ReferencesModel): string; @@ -62,7 +62,7 @@ export class ReferencesController implements editorCommon.IEditorContribution { @optional(IPeekViewService) private _peekViewService: IPeekViewService ) { this._editor = editor; - this._referenceSearchVisible = keybindingService.createKey(ctxReferenceSearchVisible, false); + this._referenceSearchVisible = ctxReferenceSearchVisible.bindTo(keybindingService, false); } public getId(): string { diff --git a/src/vs/editor/contrib/referenceSearch/browser/referencesWidget.ts b/src/vs/editor/contrib/referenceSearch/browser/referencesWidget.ts index fb7455e3aa8..6c4c823fe51 100644 --- a/src/vs/editor/contrib/referenceSearch/browser/referencesWidget.ts +++ b/src/vs/editor/contrib/referenceSearch/browser/referencesWidget.ts @@ -38,6 +38,7 @@ import {ICodeEditor} from 'vs/editor/browser/editorBrowser'; import {EmbeddedCodeEditorWidget} from 'vs/editor/browser/widget/embeddedCodeEditorWidget'; import {PeekViewWidget, IPeekViewService} from 'vs/editor/contrib/zoneWidget/browser/peekViewWidget'; import {FileReferences, OneReference, ReferencesModel} from './referencesModel'; +import {KbCtxKey} from 'vs/platform/keybinding/common/keybinding'; class DecorationsManager implements IDisposable { @@ -484,7 +485,7 @@ export interface SelectionEvent { */ export class ReferenceWidget extends PeekViewWidget { - public static INNER_EDITOR_CONTEXT_KEY = 'inReferenceSearchEditor'; + public static INNER_EDITOR_CONTEXT_KEY = new KbCtxKey('inReferenceSearchEditor'); private _model: ReferencesModel; private _decorationsManager: DecorationsManager; diff --git a/src/vs/editor/contrib/rename/browser/rename.ts b/src/vs/editor/contrib/rename/browser/rename.ts index 6506dfed4f1..096af508192 100644 --- a/src/vs/editor/contrib/rename/browser/rename.ts +++ b/src/vs/editor/contrib/rename/browser/rename.ts @@ -164,7 +164,7 @@ export class RenameAction extends EditorAction { this.menuOpts = { group: '1_modification', order: 1.1, - kbExpr: KbExpr.and(KbExpr.has(ModeContextKeys.hasRenameProvider), EditorKbExpr.Writable) + kbExpr: KbExpr.and(ModeContextKeys.hasRenameProvider, EditorKbExpr.Writable) }; } diff --git a/src/vs/editor/contrib/suggest/browser/suggest.ts b/src/vs/editor/contrib/suggest/browser/suggest.ts index f458a65fc89..31c09cbbf68 100644 --- a/src/vs/editor/contrib/suggest/browser/suggest.ts +++ b/src/vs/editor/contrib/suggest/browser/suggest.ts @@ -214,7 +214,7 @@ KeybindingsRegistry.registerCommandDesc({ id: 'acceptSelectedSuggestion', handler: handler('acceptSelectedSuggestion', c => c.acceptSelectedSuggestion()), weight, - when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(SuggestContext.Visible)), + when: KbExpr.and(EditorKbExpr.TextFocus, SuggestContext.Visible), primary: KeyCode.Tab }); @@ -222,7 +222,7 @@ KeybindingsRegistry.registerCommandDesc({ id: 'acceptSelectedSuggestionOnEnter', handler: handler('acceptSelectedSuggestionOnEnter', c => c.acceptSelectedSuggestion()), weight, - when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(SuggestContext.Visible), KbExpr.has('config.editor.acceptSuggestionOnEnter')), + when: KbExpr.and(EditorKbExpr.TextFocus, SuggestContext.Visible, KbExpr.has('config.editor.acceptSuggestionOnEnter')), primary: KeyCode.Enter }); @@ -230,7 +230,7 @@ KeybindingsRegistry.registerCommandDesc({ id: 'hideSuggestWidget', handler: handler('hideSuggestWidget', c => c.cancelSuggestWidget()), weight, - when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(SuggestContext.Visible)), + when: KbExpr.and(EditorKbExpr.TextFocus, SuggestContext.Visible), primary: KeyCode.Escape, secondary: [KeyMod.Shift | KeyCode.Escape] }); @@ -239,7 +239,7 @@ KeybindingsRegistry.registerCommandDesc({ id: 'selectNextSuggestion', handler: handler('selectNextSuggestion', c => c.selectNextSuggestion()), weight, - when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(SuggestContext.Visible), KbExpr.has(SuggestContext.MultipleSuggestions)), + when: KbExpr.and(EditorKbExpr.TextFocus, SuggestContext.Visible, SuggestContext.MultipleSuggestions), primary: KeyCode.DownArrow, secondary: [KeyMod.Alt | KeyCode.DownArrow], mac: { primary: KeyCode.DownArrow, secondary: [KeyMod.Alt | KeyCode.DownArrow, KeyMod.WinCtrl | KeyCode.KEY_N] } @@ -249,7 +249,7 @@ KeybindingsRegistry.registerCommandDesc({ id: 'selectNextPageSuggestion', handler: handler('selectNextPageSuggestion', c => c.selectNextPageSuggestion()), weight, - when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(SuggestContext.Visible), KbExpr.has(SuggestContext.MultipleSuggestions)), + when: KbExpr.and(EditorKbExpr.TextFocus, SuggestContext.Visible, SuggestContext.MultipleSuggestions), primary: KeyCode.PageDown, secondary: [KeyMod.Alt | KeyCode.PageDown] }); @@ -258,7 +258,7 @@ KeybindingsRegistry.registerCommandDesc({ id: 'selectPrevSuggestion', handler: handler('selectPrevSuggestion', c => c.selectPrevSuggestion()), weight, - when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(SuggestContext.Visible), KbExpr.has(SuggestContext.MultipleSuggestions)), + when: KbExpr.and(EditorKbExpr.TextFocus, SuggestContext.Visible, SuggestContext.MultipleSuggestions), primary: KeyCode.UpArrow, secondary: [KeyMod.Alt | KeyCode.UpArrow], mac: { primary: KeyCode.UpArrow, secondary: [KeyMod.Alt | KeyCode.UpArrow, KeyMod.WinCtrl | KeyCode.KEY_P] } @@ -268,7 +268,7 @@ KeybindingsRegistry.registerCommandDesc({ id: 'selectPrevPageSuggestion', handler: handler('selectPrevPageSuggestion', c => c.selectPrevPageSuggestion()), weight, - when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(SuggestContext.Visible), KbExpr.has(SuggestContext.MultipleSuggestions)), + when: KbExpr.and(EditorKbExpr.TextFocus, SuggestContext.Visible, SuggestContext.MultipleSuggestions), primary: KeyCode.PageUp, secondary: [KeyMod.Alt | KeyCode.PageUp] }); @@ -277,7 +277,7 @@ KeybindingsRegistry.registerCommandDesc({ id: 'toggleSuggestionDetails', handler: handler('toggleSuggestionDetails', c => c.toggleSuggestionDetails()), weight, - when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(SuggestContext.Visible)), + when: KbExpr.and(EditorKbExpr.TextFocus, SuggestContext.Visible), primary: KeyMod.CtrlCmd | KeyCode.Space, mac: { primary: KeyMod.WinCtrl | KeyCode.Space } }); diff --git a/src/vs/editor/contrib/suggest/browser/suggestWidget.ts b/src/vs/editor/contrib/suggest/browser/suggestWidget.ts index 1105fbb5a29..c3b3cbfa6da 100644 --- a/src/vs/editor/contrib/suggest/browser/suggestWidget.ts +++ b/src/vs/editor/contrib/suggest/browser/suggestWidget.ts @@ -366,9 +366,9 @@ export class SuggestWidget implements IContentWidget, IDisposable { this.model.onDidCancel(e => this.onDidCancel(e)) ]; - this.suggestWidgetVisible = keybindingService.createKey(SuggestContext.Visible, false); - this.suggestWidgetMultipleSuggestions = keybindingService.createKey(SuggestContext.MultipleSuggestions, false); - this.suggestionSupportsAutoAccept = keybindingService.createKey(SuggestContext.AcceptOnKey, true); + this.suggestWidgetVisible = SuggestContext.Visible.bindTo(keybindingService, false); + this.suggestWidgetMultipleSuggestions = SuggestContext.MultipleSuggestions.bindTo(keybindingService, false); + this.suggestionSupportsAutoAccept = SuggestContext.AcceptOnKey.bindTo(keybindingService, true); this.editor.addContentWidget(this); this.setState(State.Hidden); diff --git a/src/vs/editor/contrib/suggest/common/suggest.ts b/src/vs/editor/contrib/suggest/common/suggest.ts index 33fa8ed62aa..557711e5ebd 100644 --- a/src/vs/editor/contrib/suggest/common/suggest.ts +++ b/src/vs/editor/contrib/suggest/common/suggest.ts @@ -15,11 +15,12 @@ import {ISuggestResult, ISuggestSupport, ISuggestion, SuggestRegistry} from 'vs/ import {ISnippetsRegistry, Extensions} from 'vs/editor/common/modes/snippetsRegistry'; import {Position} from 'vs/editor/common/core/position'; import {Registry} from 'vs/platform/platform'; +import {KbCtxKey} from 'vs/platform/keybinding/common/keybinding'; export const Context = { - Visible: 'suggestWidgetVisible', - MultipleSuggestions: 'suggestWidgetMultipleSuggestions', - AcceptOnKey: 'suggestionSupportsAcceptOnKey' + Visible: new KbCtxKey('suggestWidgetVisible'), + MultipleSuggestions: new KbCtxKey('suggestWidgetMultipleSuggestions'), + AcceptOnKey: new KbCtxKey('suggestionSupportsAcceptOnKey') }; export interface ISuggestionItem { diff --git a/src/vs/editor/contrib/zoneWidget/browser/peekViewWidget.ts b/src/vs/editor/contrib/zoneWidget/browser/peekViewWidget.ts index 94f509366cb..afaccc35a92 100644 --- a/src/vs/editor/contrib/zoneWidget/browser/peekViewWidget.ts +++ b/src/vs/editor/contrib/zoneWidget/browser/peekViewWidget.ts @@ -19,13 +19,14 @@ import {ICodeEditorService} from 'vs/editor/common/services/codeEditorService'; import {ICodeEditor} from 'vs/editor/browser/editorBrowser'; import {IOptions, ZoneWidget} from './zoneWidget'; import {EmbeddedCodeEditorWidget} from 'vs/editor/browser/widget/embeddedCodeEditorWidget'; +import {KbCtxKey} from 'vs/platform/keybinding/common/keybinding'; export var IPeekViewService = createDecorator('peekViewService'); export interface IPeekViewService { _serviceBrand: any; isActive: boolean; - contextKey: string; + contextKey: KbCtxKey; } export function getOuterEditor(accessor: ServicesAccessor, args: any): ICommonCodeEditor { @@ -39,7 +40,7 @@ export function getOuterEditor(accessor: ServicesAccessor, args: any): ICommonCo export class PeekViewWidget extends ZoneWidget implements IPeekViewService { public _serviceBrand: any; - public contextKey: string; + public contextKey: KbCtxKey; private _onDidClose = new Emitter(); private _isActive = false; @@ -51,7 +52,7 @@ export class PeekViewWidget extends ZoneWidget implements IPeekViewService { protected _actionbarWidget: ActionBar; protected _bodyElement: HTMLDivElement; - constructor(editor: ICodeEditor, contextKey: string, options: IOptions = {}) { + constructor(editor: ICodeEditor, contextKey: KbCtxKey, options: IOptions = {}) { super(editor, options); this.contextKey = contextKey; } diff --git a/src/vs/platform/keybinding/common/keybinding.ts b/src/vs/platform/keybinding/common/keybinding.ts index 1e562eb1daa..54ea8f1daeb 100644 --- a/src/vs/platform/keybinding/common/keybinding.ts +++ b/src/vs/platform/keybinding/common/keybinding.ts @@ -70,7 +70,7 @@ function cmp(a:KbExpr, b:KbExpr): number { } export class KbDefinedExpression implements KbExpr { - constructor(private key: string) { + constructor(protected key: string) { } public getType(): KbExprType { @@ -369,6 +369,16 @@ export class KbAndExpression implements KbExpr { } } +export class KbCtxKey extends KbDefinedExpression { + + constructor(key:string) { + super(key); + } + + public bindTo(target:IKeybindingService, defaultValue:T): IKeybindingContextKey { + return target.createKey(this.key, defaultValue); + } +} export let KbExpr = { has: (key: string) => new KbDefinedExpression(key), diff --git a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts index 08b3a7efb26..78ed12cde45 100644 --- a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts +++ b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts @@ -39,11 +39,11 @@ import {IInstantiationService} from 'vs/platform/instantiation/common/instantiat import {IMessageService, Severity} from 'vs/platform/message/common/message'; import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry'; import {IWorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService'; -import {IKeybindingService, IKeybindingContextKey} from 'vs/platform/keybinding/common/keybinding'; +import {IKeybindingService, KbCtxKey, IKeybindingContextKey} from 'vs/platform/keybinding/common/keybinding'; import {IHistoryService} from 'vs/workbench/services/history/common/history'; const HELP_PREFIX = '?'; -const QUICK_OPEN_MODE = 'inQuickOpen'; +const QUICK_OPEN_MODE = new KbCtxKey('inQuickOpen'); interface IPickOpenEntryItem extends IPickOpenEntry { height?: number; @@ -103,7 +103,7 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe this.promisesToCompleteOnHide = []; - this.inQuickOpenMode = keybindingService.createKey(QUICK_OPEN_MODE, false); + this.inQuickOpenMode = QUICK_OPEN_MODE.bindTo(keybindingService, false); this._onShow = new Emitter(); this._onHide = new Emitter(); diff --git a/src/vs/workbench/parts/files/browser/explorerViewlet.ts b/src/vs/workbench/parts/files/browser/explorerViewlet.ts index 557ced2fa57..2631b84c9e0 100644 --- a/src/vs/workbench/parts/files/browser/explorerViewlet.ts +++ b/src/vs/workbench/parts/files/browser/explorerViewlet.ts @@ -11,7 +11,7 @@ import {IAction} from 'vs/base/common/actions'; import {TPromise} from 'vs/base/common/winjs.base'; import {Dimension, Builder} from 'vs/base/browser/builder'; import {Scope} from 'vs/workbench/common/memento'; -import {VIEWLET_ID, IFilesConfiguration} from 'vs/workbench/parts/files/common/files'; +import {VIEWLET_ID, ExplorerViewletVisible, IFilesConfiguration} from 'vs/workbench/parts/files/common/files'; import {IViewletView, Viewlet} from 'vs/workbench/browser/viewlet'; import {IActionRunner} from 'vs/base/common/actions'; import {SplitView, Orientation} from 'vs/base/browser/ui/splitview/splitview'; @@ -65,7 +65,7 @@ export class ExplorerViewlet extends Viewlet { this.views = []; this.viewletState = new FileViewletState(); - this.viewletVisibleContextKey = keybindingService.createKey('explorerViewletVisible', true); + this.viewletVisibleContextKey = ExplorerViewletVisible.bindTo(keybindingService, true); this.viewletSettings = this.getMemento(storageService, Scope.WORKSPACE); this.configurationService.onDidUpdateConfiguration(e => this.onConfigurationUpdated(e.config)); diff --git a/src/vs/workbench/parts/files/common/files.ts b/src/vs/workbench/parts/files/common/files.ts index ae31100c244..d9310ee1124 100644 --- a/src/vs/workbench/parts/files/common/files.ts +++ b/src/vs/workbench/parts/files/common/files.ts @@ -14,12 +14,15 @@ import {EncodingMode, EditorInput, IFileEditorInput, ConfirmResult, IWorkbenchEd import {IFileStat, IFilesConfiguration, IBaseStat, IResolveContentOptions} from 'vs/platform/files/common/files'; import {createDecorator} from 'vs/platform/instantiation/common/instantiation'; import {FileStat} from 'vs/workbench/parts/files/common/explorerViewModel'; +import {KbCtxKey} from 'vs/platform/keybinding/common/keybinding'; /** * Explorer viewlet id. */ export const VIEWLET_ID = 'workbench.view.explorer'; +export const ExplorerViewletVisible = new KbCtxKey('explorerViewletVisible'); + /** * File editor input id. */