Move defaultValue to KbCtxKey

This commit is contained in:
Alex Dima 2016-08-04 23:43:25 +02:00
parent aadec363cd
commit dd7c3d4ab0
35 changed files with 102 additions and 100 deletions

View file

@ -174,7 +174,7 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
// Text Area (The focus will always be in the textarea when the cursor is blinking) // Text Area (The focus will always be in the textarea when the cursor is blinking)
this.textArea = <HTMLTextAreaElement>document.createElement('textarea'); this.textArea = <HTMLTextAreaElement>document.createElement('textarea');
this._keybindingService = keybindingService.createScoped(this.textArea); this._keybindingService = keybindingService.createScoped(this.textArea);
this._editorTextFocusContextKey = editorCommon.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS.bindTo(this._keybindingService, undefined); this._editorTextFocusContextKey = editorCommon.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS.bindTo(this._keybindingService);
this.textArea.className = editorBrowser.ClassNames.TEXTAREA; this.textArea.className = editorBrowser.ClassNames.TEXTAREA;
this.textArea.setAttribute('wrap', 'off'); this.textArea.setAttribute('wrap', 'off');
this.textArea.setAttribute('autocorrect', 'off'); this.textArea.setAttribute('autocorrect', 'off');

View file

@ -145,12 +145,12 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom
this._commandService = commandService; this._commandService = commandService;
this._keybindingService = keybindingService; this._keybindingService = keybindingService;
this._editorIdContextKey = this._keybindingService.createKey('editorId', this.getId()); this._editorIdContextKey = this._keybindingService.createKey('editorId', this.getId());
this._editorFocusContextKey = editorCommon.KEYBINDING_CONTEXT_EDITOR_FOCUS.bindTo(this._keybindingService, undefined); this._editorFocusContextKey = editorCommon.KEYBINDING_CONTEXT_EDITOR_FOCUS.bindTo(this._keybindingService);
this._editorTabMovesFocusKey = editorCommon.KEYBINDING_CONTEXT_EDITOR_TAB_MOVES_FOCUS.bindTo(this._keybindingService, false); this._editorTabMovesFocusKey = editorCommon.KEYBINDING_CONTEXT_EDITOR_TAB_MOVES_FOCUS.bindTo(this._keybindingService);
this._editorReadonly = editorCommon.KEYBINDING_CONTEXT_EDITOR_READONLY.bindTo(this._keybindingService, false); this._editorReadonly = editorCommon.KEYBINDING_CONTEXT_EDITOR_READONLY.bindTo(this._keybindingService);
this._hasMultipleSelectionsKey = editorCommon.KEYBINDING_CONTEXT_EDITOR_HAS_MULTIPLE_SELECTIONS.bindTo(this._keybindingService, false); this._hasMultipleSelectionsKey = editorCommon.KEYBINDING_CONTEXT_EDITOR_HAS_MULTIPLE_SELECTIONS.bindTo(this._keybindingService);
this._hasNonEmptySelectionKey = editorCommon.KEYBINDING_CONTEXT_EDITOR_HAS_NON_EMPTY_SELECTION.bindTo(this._keybindingService, false); this._hasNonEmptySelectionKey = editorCommon.KEYBINDING_CONTEXT_EDITOR_HAS_NON_EMPTY_SELECTION.bindTo(this._keybindingService);
this._langIdKey = editorCommon.KEYBINDING_CONTEXT_EDITOR_LANGUAGE_ID.bindTo(this._keybindingService, undefined); this._langIdKey = editorCommon.KEYBINDING_CONTEXT_EDITOR_LANGUAGE_ID.bindTo(this._keybindingService);
this._lifetimeDispose.push(new EditorModeContext(this, this._keybindingService)); this._lifetimeDispose.push(new EditorModeContext(this, this._keybindingService));
this._decorationTypeKeysToIds = {}; this._decorationTypeKeysToIds = {};

View file

@ -3021,37 +3021,37 @@ export interface IDiffLineInformation {
* A context key that is set when the editor's text has focus (cursor is blinking). * A context key that is set when the editor's text has focus (cursor is blinking).
* @internal * @internal
*/ */
export const KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS = new KbCtxKey('editorTextFocus'); export const KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS = new KbCtxKey<boolean>('editorTextFocus', undefined);
/** /**
* A context key that is set when the editor's text or an editor's widget has focus. * A context key that is set when the editor's text or an editor's widget has focus.
* @internal * @internal
*/ */
export const KEYBINDING_CONTEXT_EDITOR_FOCUS = new KbCtxKey('editorFocus'); export const KEYBINDING_CONTEXT_EDITOR_FOCUS = new KbCtxKey<boolean>('editorFocus', undefined);
/** /**
* @internal * @internal
*/ */
export const KEYBINDING_CONTEXT_EDITOR_TAB_MOVES_FOCUS = new KbCtxKey('editorTabMovesFocus'); export const KEYBINDING_CONTEXT_EDITOR_TAB_MOVES_FOCUS = new KbCtxKey<boolean>('editorTabMovesFocus', false);
/** /**
* A context key that is set when the editor's text is readonly. * A context key that is set when the editor's text is readonly.
* @internal * @internal
*/ */
export const KEYBINDING_CONTEXT_EDITOR_READONLY = new KbCtxKey('editorReadonly'); export const KEYBINDING_CONTEXT_EDITOR_READONLY = new KbCtxKey<boolean>('editorReadonly', false);
/** /**
* A context key that is set when the editor has multiple selections (multiple cursors). * A context key that is set when the editor has multiple selections (multiple cursors).
* @internal * @internal
*/ */
export const KEYBINDING_CONTEXT_EDITOR_HAS_MULTIPLE_SELECTIONS = new KbCtxKey('editorHasMultipleSelections'); export const KEYBINDING_CONTEXT_EDITOR_HAS_MULTIPLE_SELECTIONS = new KbCtxKey<boolean>('editorHasMultipleSelections', false);
/** /**
* A context key that is set when the editor has a non-collapsed selection. * A context key that is set when the editor has a non-collapsed selection.
* @internal * @internal
*/ */
export const KEYBINDING_CONTEXT_EDITOR_HAS_NON_EMPTY_SELECTION = new KbCtxKey('editorHasSelection'); export const KEYBINDING_CONTEXT_EDITOR_HAS_NON_EMPTY_SELECTION = new KbCtxKey<boolean>('editorHasSelection', false);
/** /**
* A context key that is set to the language associated with the model associated with the editor. * A context key that is set to the language associated with the model associated with the editor.
* @internal * @internal
*/ */
export const KEYBINDING_CONTEXT_EDITOR_LANGUAGE_ID = new KbCtxKey('editorLangId'); export const KEYBINDING_CONTEXT_EDITOR_LANGUAGE_ID = new KbCtxKey<string>('editorLangId', undefined);
/** /**
* @internal * @internal
@ -3101,47 +3101,47 @@ export namespace ModeContextKeys {
/** /**
* @internal * @internal
*/ */
export const hasCompletionItemProvider = new KbCtxKey('editorHasCompletionItemProvider'); export const hasCompletionItemProvider = new KbCtxKey<boolean>('editorHasCompletionItemProvider', undefined);
/** /**
* @internal * @internal
*/ */
export const hasCodeActionsProvider = new KbCtxKey('editorHasCodeActionsProvider'); export const hasCodeActionsProvider = new KbCtxKey<boolean>('editorHasCodeActionsProvider', undefined);
/** /**
* @internal * @internal
*/ */
export const hasCodeLensProvider = new KbCtxKey('editorHasCodeLensProvider'); export const hasCodeLensProvider = new KbCtxKey<boolean>('editorHasCodeLensProvider', undefined);
/** /**
* @internal * @internal
*/ */
export const hasDefinitionProvider = new KbCtxKey('editorHasDefinitionProvider'); export const hasDefinitionProvider = new KbCtxKey<boolean>('editorHasDefinitionProvider', undefined);
/** /**
* @internal * @internal
*/ */
export const hasHoverProvider = new KbCtxKey('editorHasHoverProvider'); export const hasHoverProvider = new KbCtxKey<boolean>('editorHasHoverProvider', undefined);
/** /**
* @internal * @internal
*/ */
export const hasDocumentHighlightProvider = new KbCtxKey('editorHasDocumentHighlightProvider'); export const hasDocumentHighlightProvider = new KbCtxKey<boolean>('editorHasDocumentHighlightProvider', undefined);
/** /**
* @internal * @internal
*/ */
export const hasDocumentSymbolProvider = new KbCtxKey('editorHasDocumentSymbolProvider'); export const hasDocumentSymbolProvider = new KbCtxKey<boolean>('editorHasDocumentSymbolProvider', undefined);
/** /**
* @internal * @internal
*/ */
export const hasReferenceProvider = new KbCtxKey('editorHasReferenceProvider'); export const hasReferenceProvider = new KbCtxKey<boolean>('editorHasReferenceProvider', undefined);
/** /**
* @internal * @internal
*/ */
export const hasRenameProvider = new KbCtxKey('editorHasRenameProvider'); export const hasRenameProvider = new KbCtxKey<boolean>('editorHasRenameProvider', undefined);
/** /**
* @internal * @internal
*/ */
export const hasFormattingProvider = new KbCtxKey('editorHasFormattingProvider'); export const hasFormattingProvider = new KbCtxKey<boolean>('editorHasFormattingProvider', undefined);
/** /**
* @internal * @internal
*/ */
export const hasSignatureHelpProvider = new KbCtxKey('editorHasSignatureHelpProvider'); export const hasSignatureHelpProvider = new KbCtxKey<boolean>('editorHasSignatureHelpProvider', undefined);
} }
export class BareFontInfo { export class BareFontInfo {

View file

@ -32,17 +32,17 @@ export class EditorModeContext {
) { ) {
this._editor = editor; this._editor = editor;
this._hasCompletionItemProvider = ModeContextKeys.hasCompletionItemProvider.bindTo(keybindingService, undefined); this._hasCompletionItemProvider = ModeContextKeys.hasCompletionItemProvider.bindTo(keybindingService);
this._hasCodeActionsProvider = ModeContextKeys.hasCodeActionsProvider.bindTo(keybindingService, undefined); this._hasCodeActionsProvider = ModeContextKeys.hasCodeActionsProvider.bindTo(keybindingService);
this._hasCodeLensProvider = ModeContextKeys.hasCodeLensProvider.bindTo(keybindingService, undefined); this._hasCodeLensProvider = ModeContextKeys.hasCodeLensProvider.bindTo(keybindingService);
this._hasDefinitionProvider = ModeContextKeys.hasDefinitionProvider.bindTo(keybindingService, undefined); this._hasDefinitionProvider = ModeContextKeys.hasDefinitionProvider.bindTo(keybindingService);
this._hasHoverProvider = ModeContextKeys.hasHoverProvider.bindTo(keybindingService, undefined); this._hasHoverProvider = ModeContextKeys.hasHoverProvider.bindTo(keybindingService);
this._hasDocumentHighlightProvider = ModeContextKeys.hasDocumentHighlightProvider.bindTo(keybindingService, undefined); this._hasDocumentHighlightProvider = ModeContextKeys.hasDocumentHighlightProvider.bindTo(keybindingService);
this._hasDocumentSymbolProvider = ModeContextKeys.hasDocumentSymbolProvider.bindTo(keybindingService, undefined); this._hasDocumentSymbolProvider = ModeContextKeys.hasDocumentSymbolProvider.bindTo(keybindingService);
this._hasReferenceProvider = ModeContextKeys.hasReferenceProvider.bindTo(keybindingService, undefined); this._hasReferenceProvider = ModeContextKeys.hasReferenceProvider.bindTo(keybindingService);
this._hasRenameProvider = ModeContextKeys.hasRenameProvider.bindTo(keybindingService, undefined); this._hasRenameProvider = ModeContextKeys.hasRenameProvider.bindTo(keybindingService);
this._hasFormattingProvider = ModeContextKeys.hasFormattingProvider.bindTo(keybindingService, undefined); this._hasFormattingProvider = ModeContextKeys.hasFormattingProvider.bindTo(keybindingService);
this._hasSignatureHelpProvider = ModeContextKeys.hasSignatureHelpProvider.bindTo(keybindingService, undefined); this._hasSignatureHelpProvider = ModeContextKeys.hasSignatureHelpProvider.bindTo(keybindingService);
// update when model/mode changes // update when model/mode changes
this._disposables.push(editor.onDidChangeModel(() => this._update())); this._disposables.push(editor.onDidChangeModel(() => this._update()));

View file

@ -24,7 +24,7 @@ import {ICodeEditor, IOverlayWidget, IOverlayWidgetPosition} from 'vs/editor/bro
import {EditorBrowserRegistry} from 'vs/editor/browser/editorBrowserExtensions'; import {EditorBrowserRegistry} from 'vs/editor/browser/editorBrowserExtensions';
import {ToggleTabFocusModeAction} from 'vs/editor/contrib/toggleTabFocusMode/common/toggleTabFocusMode'; import {ToggleTabFocusModeAction} from 'vs/editor/contrib/toggleTabFocusMode/common/toggleTabFocusMode';
const CONTEXT_ACCESSIBILITY_WIDGET_VISIBLE = new KbCtxKey('accessibilityHelpWidgetVisible'); const CONTEXT_ACCESSIBILITY_WIDGET_VISIBLE = new KbCtxKey<boolean>('accessibilityHelpWidgetVisible', false);
const TOGGLE_EXPERIMENTAL_SCREEN_READER_SUPPORT_COMMAND_ID = 'toggleExperimentalScreenReaderSupport'; const TOGGLE_EXPERIMENTAL_SCREEN_READER_SUPPORT_COMMAND_ID = 'toggleExperimentalScreenReaderSupport';
class AccessibilityHelpController extends Disposable implements IEditorContribution { class AccessibilityHelpController extends Disposable implements IEditorContribution {
@ -75,7 +75,7 @@ class AccessibilityHelpWidget extends Widget implements IOverlayWidget {
this._editor = editor; this._editor = editor;
this._keybindingService = keybindingService; this._keybindingService = keybindingService;
this._isVisibleKey = CONTEXT_ACCESSIBILITY_WIDGET_VISIBLE.bindTo(keybindingService, false); this._isVisibleKey = CONTEXT_ACCESSIBILITY_WIDGET_VISIBLE.bindTo(keybindingService);
this._domNode = document.createElement('div'); this._domNode = document.createElement('div');
this._domNode.className = 'accessibilityHelpWidget'; this._domNode.className = 'accessibilityHelpWidget';

View file

@ -33,7 +33,7 @@ export interface IFindStartOptions {
shouldAnimate:boolean; shouldAnimate:boolean;
} }
export const CONTEXT_FIND_WIDGET_VISIBLE = new KbCtxKey('findWidgetVisible'); export const CONTEXT_FIND_WIDGET_VISIBLE = new KbCtxKey<boolean>('findWidgetVisible', false);
export const CONTEXT_FIND_WIDGET_NOT_VISIBLE = CONTEXT_FIND_WIDGET_VISIBLE.toNegated(); export const CONTEXT_FIND_WIDGET_NOT_VISIBLE = CONTEXT_FIND_WIDGET_VISIBLE.toNegated();
export class CommonFindController extends Disposable implements editorCommon.IEditorContribution { export class CommonFindController extends Disposable implements editorCommon.IEditorContribution {
@ -52,7 +52,7 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
constructor(editor:editorCommon.ICommonCodeEditor, @IKeybindingService keybindingService: IKeybindingService) { constructor(editor:editorCommon.ICommonCodeEditor, @IKeybindingService keybindingService: IKeybindingService) {
super(); super();
this._editor = editor; this._editor = editor;
this._findWidgetVisible = CONTEXT_FIND_WIDGET_VISIBLE.bindTo(keybindingService, false); this._findWidgetVisible = CONTEXT_FIND_WIDGET_VISIBLE.bindTo(keybindingService);
this._state = this._register(new FindReplaceState()); this._state = this._register(new FindReplaceState());
this._register(this._state.addChangeListener((e) => this._onStateChanged(e))); this._register(this._state.addChangeListener((e) => this._onStateChanged(e)));

View file

@ -454,7 +454,7 @@ class MarkerController implements editorCommon.IEditorContribution {
@ICommandService private _commandService: ICommandService @ICommandService private _commandService: ICommandService
) { ) {
this._editor = editor; this._editor = editor;
this._markersNavigationVisible = CONTEXT_MARKERS_NAVIGATION_VISIBLE.bindTo(this._keybindingService, false); this._markersNavigationVisible = CONTEXT_MARKERS_NAVIGATION_VISIBLE.bindTo(this._keybindingService);
} }
public getId(): string { public getId(): string {
@ -544,7 +544,7 @@ class PrevMarkerAction extends MarkerNavigationAction {
} }
} }
var CONTEXT_MARKERS_NAVIGATION_VISIBLE = new KbCtxKey('markersNavigationVisible'); var CONTEXT_MARKERS_NAVIGATION_VISIBLE = new KbCtxKey<boolean>('markersNavigationVisible', false);
const MarkerCommand = EditorCommand.bindToContribution<MarkerController>( const MarkerCommand = EditorCommand.bindToContribution<MarkerController>(
MarkerController.getMarkerController, { MarkerController.getMarkerController, {

View file

@ -178,8 +178,8 @@ export class ParameterHintsWidget implements IContentWidget, IDisposable {
constructor(private editor: ICodeEditor, @IKeybindingService keybindingService: IKeybindingService) { constructor(private editor: ICodeEditor, @IKeybindingService keybindingService: IKeybindingService) {
this.model = new ParameterHintsModel(editor); this.model = new ParameterHintsModel(editor);
this.keyVisible = Context.Visible.bindTo(keybindingService, false); this.keyVisible = Context.Visible.bindTo(keybindingService);
this.keyMultipleSignatures = Context.MultipleSignatures.bindTo(keybindingService, false); this.keyMultipleSignatures = Context.MultipleSignatures.bindTo(keybindingService);
this.visible = false; this.visible = false;
this.disposables = []; this.disposables = [];

View file

@ -14,8 +14,8 @@ import { Position } from 'vs/editor/common/core/position';
import { KbCtxKey } from 'vs/platform/keybinding/common/keybinding'; import { KbCtxKey } from 'vs/platform/keybinding/common/keybinding';
export const Context = { export const Context = {
Visible: new KbCtxKey('parameterHintsVisible'), Visible: new KbCtxKey<boolean>('parameterHintsVisible', false),
MultipleSignatures: new KbCtxKey('parameterHintsMultipleSignatures'), MultipleSignatures: new KbCtxKey<boolean>('parameterHintsMultipleSignatures', false),
}; };
export function provideSignatureHelp(model:IReadOnlyModel, position:Position): TPromise<SignatureHelp> { export function provideSignatureHelp(model:IReadOnlyModel, position:Position): TPromise<SignatureHelp> {

View file

@ -46,7 +46,7 @@ export class QuickFixController implements IEditorContribution {
this.editor = editor; this.editor = editor;
this.model = new QuickFixModel(this.editor, this._markerService, this.onAccept.bind(this)); this.model = new QuickFixModel(this.editor, this._markerService, this.onAccept.bind(this));
this.quickFixWidgetVisible = CONTEXT_QUICK_FIX_WIDGET_VISIBLE.bindTo(this._keybindingService, false); this.quickFixWidgetVisible = CONTEXT_QUICK_FIX_WIDGET_VISIBLE.bindTo(this._keybindingService);
this.suggestWidget = new QuickFixSelectionWidget(this.editor, telemetryService,() => { this.suggestWidget = new QuickFixSelectionWidget(this.editor, telemetryService,() => {
this.quickFixWidgetVisible.set(true); this.quickFixWidgetVisible.set(true);
},() => { },() => {
@ -143,7 +143,7 @@ export class QuickFixAction extends EditorAction {
} }
} }
var CONTEXT_QUICK_FIX_WIDGET_VISIBLE = new KbCtxKey('quickFixWidgetVisible'); var CONTEXT_QUICK_FIX_WIDGET_VISIBLE = new KbCtxKey<boolean>('quickFixWidgetVisible', false);
const QuickFixCommand = EditorCommand.bindToContribution<QuickFixController>( const QuickFixCommand = EditorCommand.bindToContribution<QuickFixController>(
QuickFixController.getQuickFixController, { QuickFixController.getQuickFixController, {

View file

@ -43,7 +43,7 @@ export class ReferenceController implements editorCommon.IEditorContribution {
@optional(IPeekViewService) peekViewService: IPeekViewService @optional(IPeekViewService) peekViewService: IPeekViewService
) { ) {
if (peekViewService) { if (peekViewService) {
peekViewService.contextKey.bindTo(keybindingService, true); peekViewService.contextKey.bindTo(keybindingService);
} }
} }

View file

@ -25,7 +25,7 @@ import {ReferencesModel, OneReference} from './referencesModel';
import {ReferenceWidget, LayoutData} from './referencesWidget'; import {ReferenceWidget, LayoutData} from './referencesWidget';
import {Range} from 'vs/editor/common/core/range'; import {Range} from 'vs/editor/common/core/range';
export const ctxReferenceSearchVisible = new KbCtxKey('referenceSearchVisible'); export const ctxReferenceSearchVisible = new KbCtxKey<boolean>('referenceSearchVisible', false);
export interface RequestOptions { export interface RequestOptions {
getMetaTitle(model: ReferencesModel): string; getMetaTitle(model: ReferencesModel): string;
@ -62,7 +62,7 @@ export class ReferencesController implements editorCommon.IEditorContribution {
@optional(IPeekViewService) private _peekViewService: IPeekViewService @optional(IPeekViewService) private _peekViewService: IPeekViewService
) { ) {
this._editor = editor; this._editor = editor;
this._referenceSearchVisible = ctxReferenceSearchVisible.bindTo(keybindingService, false); this._referenceSearchVisible = ctxReferenceSearchVisible.bindTo(keybindingService);
} }
public getId(): string { public getId(): string {

View file

@ -485,7 +485,7 @@ export interface SelectionEvent {
*/ */
export class ReferenceWidget extends PeekViewWidget { export class ReferenceWidget extends PeekViewWidget {
public static INNER_EDITOR_CONTEXT_KEY = new KbCtxKey('inReferenceSearchEditor'); public static INNER_EDITOR_CONTEXT_KEY = new KbCtxKey<boolean>('inReferenceSearchEditor', true);
private _model: ReferencesModel; private _model: ReferencesModel;
private _decorationsManager: DecorationsManager; private _decorationsManager: DecorationsManager;

View file

@ -26,7 +26,7 @@ import RenameInputField from './renameInputField';
// --- register actions and commands // --- register actions and commands
const CONTEXT_RENAME_INPUT_VISIBLE = new KbCtxKey('renameInputVisible'); const CONTEXT_RENAME_INPUT_VISIBLE = new KbCtxKey<boolean>('renameInputVisible', false);
class RenameController implements IEditorContribution { class RenameController implements IEditorContribution {
@ -48,7 +48,7 @@ class RenameController implements IEditorContribution {
@IKeybindingService keybindingService: IKeybindingService @IKeybindingService keybindingService: IKeybindingService
) { ) {
this._renameInputField = new RenameInputField(editor); this._renameInputField = new RenameInputField(editor);
this._renameInputVisible = CONTEXT_RENAME_INPUT_VISIBLE.bindTo(keybindingService, false); this._renameInputVisible = CONTEXT_RENAME_INPUT_VISIBLE.bindTo(keybindingService);
} }
public dispose(): void { public dispose(): void {

View file

@ -744,7 +744,7 @@ class SnippetController implements ISnippetController {
constructor(editor: editorCommon.ICommonCodeEditor, @IKeybindingService keybindingService: IKeybindingService) { constructor(editor: editorCommon.ICommonCodeEditor, @IKeybindingService keybindingService: IKeybindingService) {
this._editor = editor; this._editor = editor;
this._currentController = null; this._currentController = null;
this._inSnippetMode = CONTEXT_SNIPPET_MODE.bindTo(keybindingService, false); this._inSnippetMode = CONTEXT_SNIPPET_MODE.bindTo(keybindingService);
} }
public dispose(): void { public dispose(): void {
@ -935,7 +935,7 @@ class SnippetController implements ISnippetController {
} }
} }
export var CONTEXT_SNIPPET_MODE = new KbCtxKey('inSnippetMode'); export var CONTEXT_SNIPPET_MODE = new KbCtxKey<boolean>('inSnippetMode', false);
const SnippetCommand = EditorCommand.bindToContribution<ISnippetController>( const SnippetCommand = EditorCommand.bindToContribution<ISnippetController>(
getSnippetController, { getSnippetController, {

View file

@ -366,9 +366,9 @@ export class SuggestWidget implements IContentWidget, IDisposable {
this.model.onDidCancel(e => this.onDidCancel(e)) this.model.onDidCancel(e => this.onDidCancel(e))
]; ];
this.suggestWidgetVisible = SuggestContext.Visible.bindTo(keybindingService, false); this.suggestWidgetVisible = SuggestContext.Visible.bindTo(keybindingService);
this.suggestWidgetMultipleSuggestions = SuggestContext.MultipleSuggestions.bindTo(keybindingService, false); this.suggestWidgetMultipleSuggestions = SuggestContext.MultipleSuggestions.bindTo(keybindingService);
this.suggestionSupportsAutoAccept = SuggestContext.AcceptOnKey.bindTo(keybindingService, true); this.suggestionSupportsAutoAccept = SuggestContext.AcceptOnKey.bindTo(keybindingService);
this.editor.addContentWidget(this); this.editor.addContentWidget(this);
this.setState(State.Hidden); this.setState(State.Hidden);

View file

@ -22,7 +22,7 @@ let snippetsRegistry = <ISnippetsRegistry>Registry.as(Extensions.Snippets);
class TabCompletionController implements editorCommon.IEditorContribution { class TabCompletionController implements editorCommon.IEditorContribution {
static Id = 'editor.tabCompletionController'; static Id = 'editor.tabCompletionController';
static ContextKey = new KbCtxKey('hasSnippetCompletions'); static ContextKey = new KbCtxKey<boolean>('hasSnippetCompletions', undefined);
private _snippetController: ISnippetController; private _snippetController: ISnippetController;
private _cursorChangeSubscription: IDisposable; private _cursorChangeSubscription: IDisposable;
@ -33,7 +33,7 @@ class TabCompletionController implements editorCommon.IEditorContribution {
@IKeybindingService keybindingService: IKeybindingService @IKeybindingService keybindingService: IKeybindingService
) { ) {
this._snippetController = getSnippetController(editor); this._snippetController = getSnippetController(editor);
const hasSnippets = TabCompletionController.ContextKey.bindTo(keybindingService, undefined); const hasSnippets = TabCompletionController.ContextKey.bindTo(keybindingService);
this._cursorChangeSubscription = editor.onDidChangeCursorSelection(e => { this._cursorChangeSubscription = editor.onDidChangeCursorSelection(e => {
this._currentSnippets.length = 0; this._currentSnippets.length = 0;

View file

@ -19,9 +19,9 @@ import {Registry} from 'vs/platform/platform';
import {KbCtxKey} from 'vs/platform/keybinding/common/keybinding'; import {KbCtxKey} from 'vs/platform/keybinding/common/keybinding';
export const Context = { export const Context = {
Visible: new KbCtxKey('suggestWidgetVisible'), Visible: new KbCtxKey<boolean>('suggestWidgetVisible', false),
MultipleSuggestions: new KbCtxKey('suggestWidgetMultipleSuggestions'), MultipleSuggestions: new KbCtxKey<boolean>('suggestWidgetMultipleSuggestions', false),
AcceptOnKey: new KbCtxKey('suggestionSupportsAcceptOnKey') AcceptOnKey: new KbCtxKey<boolean>('suggestionSupportsAcceptOnKey', true)
}; };
export interface ISuggestionItem { export interface ISuggestionItem {

View file

@ -26,7 +26,7 @@ export var IPeekViewService = createDecorator<IPeekViewService>('peekViewService
export interface IPeekViewService { export interface IPeekViewService {
_serviceBrand: any; _serviceBrand: any;
isActive: boolean; isActive: boolean;
contextKey: KbCtxKey; contextKey: KbCtxKey<boolean>;
} }
export function getOuterEditor(accessor: ServicesAccessor, args: any): ICommonCodeEditor { export function getOuterEditor(accessor: ServicesAccessor, args: any): ICommonCodeEditor {
@ -40,7 +40,7 @@ export function getOuterEditor(accessor: ServicesAccessor, args: any): ICommonCo
export class PeekViewWidget extends ZoneWidget implements IPeekViewService { export class PeekViewWidget extends ZoneWidget implements IPeekViewService {
public _serviceBrand: any; public _serviceBrand: any;
public contextKey: KbCtxKey; public contextKey: KbCtxKey<boolean>;
private _onDidClose = new Emitter<PeekViewWidget>(); private _onDidClose = new Emitter<PeekViewWidget>();
private _isActive = false; private _isActive = false;
@ -52,7 +52,7 @@ export class PeekViewWidget extends ZoneWidget implements IPeekViewService {
protected _actionbarWidget: ActionBar; protected _actionbarWidget: ActionBar;
protected _bodyElement: HTMLDivElement; protected _bodyElement: HTMLDivElement;
constructor(editor: ICodeEditor, contextKey: KbCtxKey, options: IOptions = {}) { constructor(editor: ICodeEditor, contextKey: KbCtxKey<boolean>, options: IOptions = {}) {
super(editor, options); super(editor, options);
this.contextKey = contextKey; this.contextKey = contextKey;
} }

View file

@ -5,7 +5,6 @@
'use strict'; 'use strict';
import URI from 'vs/base/common/uri';
import Event, {Emitter} from 'vs/base/common/event'; import Event, {Emitter} from 'vs/base/common/event';
import {IDisposable, dispose} from 'vs/base/common/lifecycle'; import {IDisposable, dispose} from 'vs/base/common/lifecycle';
import {IAction} from 'vs/base/common/actions'; import {IAction} from 'vs/base/common/actions';
@ -101,7 +100,7 @@ class Menu implements IMenu {
const activeActions: MenuItemAction[] = []; const activeActions: MenuItemAction[] = [];
for (let action of actions) { for (let action of actions) {
if (this._keybindingService.contextMatchesRules(action.item.when)) { if (this._keybindingService.contextMatchesRules(action.item.when)) {
action.resource = ResourceContextKey.Resource.getValue<URI>(this._keybindingService); action.resource = ResourceContextKey.Resource.getValue(this._keybindingService);
activeActions.push(action); activeActions.push(action);
} }
} }

View file

@ -11,9 +11,9 @@ import {IModeService} from 'vs/editor/common/services/modeService';
export class ResourceContextKey implements IKeybindingContextKey<URI> { export class ResourceContextKey implements IKeybindingContextKey<URI> {
static Scheme = new KbCtxKey('resourceScheme'); static Scheme = new KbCtxKey<string>('resourceScheme', undefined);
static LangId = new KbCtxKey('resourceLangId'); static LangId = new KbCtxKey<string>('resourceLangId', undefined);
static Resource = new KbCtxKey('resource'); static Resource = new KbCtxKey<URI>('resource', undefined);
private _resourceKey: IKeybindingContextKey<URI>; private _resourceKey: IKeybindingContextKey<URI>;
private _schemeKey: IKeybindingContextKey<string>; private _schemeKey: IKeybindingContextKey<string>;
@ -23,9 +23,9 @@ export class ResourceContextKey implements IKeybindingContextKey<URI> {
@IKeybindingService keybindingService: IKeybindingService, @IKeybindingService keybindingService: IKeybindingService,
@IModeService private _modeService: IModeService @IModeService private _modeService: IModeService
) { ) {
this._schemeKey = ResourceContextKey.Scheme.bindTo(keybindingService, undefined); this._schemeKey = ResourceContextKey.Scheme.bindTo(keybindingService);
this._langIdKey = ResourceContextKey.LangId.bindTo(keybindingService, undefined); this._langIdKey = ResourceContextKey.LangId.bindTo(keybindingService);
this._resourceKey = ResourceContextKey.Resource.bindTo(keybindingService, undefined); this._resourceKey = ResourceContextKey.Resource.bindTo(keybindingService);
} }
set(value: URI) { set(value: URI) {

View file

@ -369,17 +369,20 @@ export class KbAndExpression implements KbExpr {
} }
} }
export class KbCtxKey extends KbDefinedExpression { export class KbCtxKey<T> extends KbDefinedExpression {
constructor(key:string) { private _defaultValue: T;
constructor(key:string, defaultValue:T) {
super(key); super(key);
this._defaultValue = defaultValue;
} }
public bindTo<T>(target:IKeybindingService, defaultValue:T): IKeybindingContextKey<T> { public bindTo(target:IKeybindingService): IKeybindingContextKey<T> {
return target.createKey(this.key, defaultValue); return target.createKey(this.key, this._defaultValue);
} }
public getValue<T>(target:IKeybindingService): T { public getValue(target:IKeybindingService): T {
return target.getContextValue<T>(this.key); return target.getContextValue<T>(this.key);
} }

View file

@ -38,7 +38,7 @@ import {IModeService} from 'vs/editor/common/services/modeService';
import {KbCtxKey, IKeybindingService, IKeybindingContextKey} from 'vs/platform/keybinding/common/keybinding'; import {KbCtxKey, IKeybindingService, IKeybindingContextKey} from 'vs/platform/keybinding/common/keybinding';
import {IThemeService} from 'vs/workbench/services/themes/common/themeService'; import {IThemeService} from 'vs/workbench/services/themes/common/themeService';
export const TextCompareEditorVisible = new KbCtxKey('textCompareEditorVisible'); export const TextCompareEditorVisible = new KbCtxKey<boolean>('textCompareEditorVisible', false);
/** /**
* The text editor that leverages the diff text editor for the editing experience. * The text editor that leverages the diff text editor for the editing experience.
@ -68,7 +68,7 @@ export class TextDiffEditor extends BaseTextEditor {
) { ) {
super(TextDiffEditor.ID, telemetryService, instantiationService, contextService, storageService, messageService, configurationService, eventService, editorService, modeService, themeService); super(TextDiffEditor.ID, telemetryService, instantiationService, contextService, storageService, messageService, configurationService, eventService, editorService, modeService, themeService);
this.textDiffEditorVisible = TextCompareEditorVisible.bindTo(keybindingService, false); this.textDiffEditorVisible = TextCompareEditorVisible.bindTo(keybindingService);
} }
public getTitle(): string { public getTitle(): string {

View file

@ -43,7 +43,7 @@ import {IKeybindingService, KbCtxKey, IKeybindingContextKey} from 'vs/platform/k
import {IHistoryService} from 'vs/workbench/services/history/common/history'; import {IHistoryService} from 'vs/workbench/services/history/common/history';
const HELP_PREFIX = '?'; const HELP_PREFIX = '?';
const QUICK_OPEN_MODE = new KbCtxKey('inQuickOpen'); const QUICK_OPEN_MODE = new KbCtxKey<boolean>('inQuickOpen', false);
interface IPickOpenEntryItem extends IPickOpenEntry { interface IPickOpenEntryItem extends IPickOpenEntry {
height?: number; height?: number;
@ -103,7 +103,7 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
this.promisesToCompleteOnHide = []; this.promisesToCompleteOnHide = [];
this.inQuickOpenMode = QUICK_OPEN_MODE.bindTo(keybindingService, false); this.inQuickOpenMode = QUICK_OPEN_MODE.bindTo(keybindingService);
this._onShow = new Emitter<void>(); this._onShow = new Emitter<void>();
this._onHide = new Emitter<void>(); this._onHide = new Emitter<void>();

View file

@ -68,8 +68,8 @@ import {IMenuService} from 'vs/platform/actions/common/actions';
import {MenuService} from 'vs/platform/actions/common/menuService'; import {MenuService} from 'vs/platform/actions/common/menuService';
import {IContextMenuService} from 'vs/platform/contextview/browser/contextView'; import {IContextMenuService} from 'vs/platform/contextview/browser/contextView';
export const MessagesVisibleContext = new KbCtxKey('globalMessageVisible'); export const MessagesVisibleContext = new KbCtxKey<boolean>('globalMessageVisible', false);
export const EditorsVisibleContext = new KbCtxKey('editorIsOpen'); export const EditorsVisibleContext = new KbCtxKey<boolean>('editorIsOpen', false);
export const NoEditorsVisibleContext:KbExpr = EditorsVisibleContext.toNegated(); export const NoEditorsVisibleContext:KbExpr = EditorsVisibleContext.toNegated();
interface WorkbenchParams { interface WorkbenchParams {
@ -203,8 +203,8 @@ export class Workbench implements IPartService {
} }
// Contexts // Contexts
this.messagesVisibleContext = MessagesVisibleContext.bindTo(this.keybindingService, false); this.messagesVisibleContext = MessagesVisibleContext.bindTo(this.keybindingService);
this.editorsVisibleContext = EditorsVisibleContext.bindTo(this.keybindingService, false); this.editorsVisibleContext = EditorsVisibleContext.bindTo(this.keybindingService);
// Register Listeners // Register Listeners
this.registerListeners(); this.registerListeners();

View file

@ -23,7 +23,7 @@ import debug = require('vs/workbench/parts/debug/common/debug');
import {IKeyboardEvent} from 'vs/base/browser/keyboardEvent'; import {IKeyboardEvent} from 'vs/base/browser/keyboardEvent';
const $ = dom.emmet; const $ = dom.emmet;
const CONTEXT_BREAKPOINT_WIDGET_VISIBLE = new KbCtxKey('breakpointWidgetVisible'); const CONTEXT_BREAKPOINT_WIDGET_VISIBLE = new KbCtxKey<boolean>('breakpointWidgetVisible', false);
const CLOSE_BREAKPOINT_WIDGET_COMMAND_ID = 'closeBreakpointWidget'; const CLOSE_BREAKPOINT_WIDGET_COMMAND_ID = 'closeBreakpointWidget';
export class BreakpointWidget extends ZoneWidget { export class BreakpointWidget extends ZoneWidget {
@ -43,7 +43,7 @@ export class BreakpointWidget extends ZoneWidget {
this.toDispose = []; this.toDispose = [];
this.create(); this.create();
this.breakpointWidgetVisible = CONTEXT_BREAKPOINT_WIDGET_VISIBLE.bindTo(keybindingService, false); this.breakpointWidgetVisible = CONTEXT_BREAKPOINT_WIDGET_VISIBLE.bindTo(keybindingService);
this.breakpointWidgetVisible.set(true); this.breakpointWidgetVisible.set(true);
BreakpointWidget.INSTANCE = this; BreakpointWidget.INSTANCE = this;
this.toDispose.push(editor.onDidChangeModel(() => this.dispose())); this.toDispose.push(editor.onDidChangeModel(() => this.dispose()));

View file

@ -16,7 +16,7 @@ import {KbCtxKey, KbExpr} from 'vs/platform/keybinding/common/keybinding';
export const VIEWLET_ID = 'workbench.view.debug'; export const VIEWLET_ID = 'workbench.view.debug';
export const REPL_ID = 'workbench.panel.repl'; export const REPL_ID = 'workbench.panel.repl';
export const DEBUG_SERVICE_ID = 'debugService'; export const DEBUG_SERVICE_ID = 'debugService';
export const CONTEXT_IN_DEBUG_MODE = new KbCtxKey('inDebugMode'); export const CONTEXT_IN_DEBUG_MODE = new KbCtxKey<boolean>('inDebugMode', false);
export const CONTEXT_NOT_IN_DEBUG_MODE:KbExpr = CONTEXT_IN_DEBUG_MODE.toNegated(); export const CONTEXT_NOT_IN_DEBUG_MODE:KbExpr = CONTEXT_IN_DEBUG_MODE.toNegated();
export const EDITOR_CONTRIBUTION_ID = 'editor.contrib.debug'; export const EDITOR_CONTRIBUTION_ID = 'editor.contrib.debug';

View file

@ -109,7 +109,7 @@ export class DebugService implements debug.IDebugService {
this._state = debug.State.Disabled; this._state = debug.State.Disabled;
} }
this.configurationManager = this.instantiationService.createInstance(ConfigurationManager, this.storageService.get(DEBUG_SELECTED_CONFIG_NAME_KEY, StorageScope.WORKSPACE, 'null')); this.configurationManager = this.instantiationService.createInstance(ConfigurationManager, this.storageService.get(DEBUG_SELECTED_CONFIG_NAME_KEY, StorageScope.WORKSPACE, 'null'));
this.inDebugMode = debug.CONTEXT_IN_DEBUG_MODE.bindTo(keybindingService, false); this.inDebugMode = debug.CONTEXT_IN_DEBUG_MODE.bindTo(keybindingService);
this.model = new model.Model(this.loadBreakpoints(), this.storageService.getBoolean(DEBUG_BREAKPOINTS_ACTIVATED_KEY, StorageScope.WORKSPACE, true), this.loadFunctionBreakpoints(), this.model = new model.Model(this.loadBreakpoints(), this.storageService.getBoolean(DEBUG_BREAKPOINTS_ACTIVATED_KEY, StorageScope.WORKSPACE, true), this.loadFunctionBreakpoints(),
this.loadExceptionBreakpoints(), this.loadWatchExpressions()); this.loadExceptionBreakpoints(), this.loadWatchExpressions());

View file

@ -65,7 +65,7 @@ export class ExplorerViewlet extends Viewlet {
this.views = []; this.views = [];
this.viewletState = new FileViewletState(); this.viewletState = new FileViewletState();
this.viewletVisibleContextKey = ExplorerViewletVisible.bindTo<boolean>(keybindingService, true); this.viewletVisibleContextKey = ExplorerViewletVisible.bindTo(keybindingService);
this.viewletSettings = this.getMemento(storageService, Scope.WORKSPACE); this.viewletSettings = this.getMemento(storageService, Scope.WORKSPACE);
this.configurationService.onDidUpdateConfiguration(e => this.onConfigurationUpdated(e.config)); this.configurationService.onDidUpdateConfiguration(e => this.onConfigurationUpdated(e.config));

View file

@ -21,7 +21,7 @@ import {KbCtxKey} from 'vs/platform/keybinding/common/keybinding';
*/ */
export const VIEWLET_ID = 'workbench.view.explorer'; export const VIEWLET_ID = 'workbench.view.explorer';
export const ExplorerViewletVisible = new KbCtxKey('explorerViewletVisible'); export const ExplorerViewletVisible = new KbCtxKey<boolean>('explorerViewletVisible', true);
/** /**
* File editor input id. * File editor input id.

View file

@ -105,7 +105,7 @@ export class SearchViewlet extends Viewlet {
super(VIEWLET_ID, telemetryService); super(VIEWLET_ID, telemetryService);
this.toDispose = []; this.toDispose = [];
this.viewletVisible = SearchViewletVisible.bindTo(keybindingService, true); this.viewletVisible = SearchViewletVisible.bindTo(keybindingService);
this.callOnModelChange = []; this.callOnModelChange = [];
this.queryBuilder = this.instantiationService.createInstance(QueryBuilder); this.queryBuilder = this.instantiationService.createInstance(QueryBuilder);

View file

@ -63,7 +63,7 @@ class ReplaceAllAction extends Action {
export class SearchWidget extends Widget { export class SearchWidget extends Widget {
static REPLACE_ACTIVE_CONTEXT_KEY= new KbCtxKey('replaceActive'); static REPLACE_ACTIVE_CONTEXT_KEY= new KbCtxKey<boolean>('replaceActive', false);
private static REPLACE_ALL_DISABLED_LABEL= nls.localize('search.action.replaceAll.disabled.label', "Replace All (Submit Search to Enable)"); private static REPLACE_ALL_DISABLED_LABEL= nls.localize('search.action.replaceAll.disabled.label', "Replace All (Submit Search to Enable)");
private static REPLACE_ALL_ENABLED_LABEL=(keyBindingService: IKeybindingService):string=>{ private static REPLACE_ALL_ENABLED_LABEL=(keyBindingService: IKeybindingService):string=>{
let keybindings = keyBindingService.lookupKeybindings(ReplaceAllAction.ID); let keybindings = keyBindingService.lookupKeybindings(ReplaceAllAction.ID);
@ -103,7 +103,7 @@ export class SearchWidget extends Widget {
constructor(container: Builder, private contextViewService: IContextViewService, options: ISearchWidgetOptions= Object.create(null), constructor(container: Builder, private contextViewService: IContextViewService, options: ISearchWidgetOptions= Object.create(null),
private keyBindingService: IKeybindingService, private instantiationService: IInstantiationService) { private keyBindingService: IKeybindingService, private instantiationService: IInstantiationService) {
super(); super();
this.replaceActive = SearchWidget.REPLACE_ACTIVE_CONTEXT_KEY.bindTo(this.keyBindingService, false); this.replaceActive = SearchWidget.REPLACE_ACTIVE_CONTEXT_KEY.bindTo(this.keyBindingService);
this.render(container, options); this.render(container, options);
} }

View file

@ -7,4 +7,4 @@ import {KbCtxKey} from 'vs/platform/keybinding/common/keybinding';
export const VIEWLET_ID = 'workbench.view.search'; export const VIEWLET_ID = 'workbench.view.search';
export const SearchViewletVisible = new KbCtxKey('searchViewletVisible'); export const SearchViewletVisible = new KbCtxKey<boolean>('searchViewletVisible', true);

View file

@ -24,7 +24,7 @@ export const TERMINAL_DEFAULT_SHELL_WINDOWS = processes.getWindowsShell();
/** /**
* A context key that is set when the integrated terminal has focus. * A context key that is set when the integrated terminal has focus.
*/ */
export const KEYBINDING_CONTEXT_TERMINAL_FOCUS = new KbCtxKey('terminalFocus'); export const KEYBINDING_CONTEXT_TERMINAL_FOCUS = new KbCtxKey<boolean>('terminalFocus', undefined);
export const KEYBINDING_CONTEXT_TERMINAL_NOT_FOCUSED:KbExpr = KEYBINDING_CONTEXT_TERMINAL_FOCUS.toNegated(); export const KEYBINDING_CONTEXT_TERMINAL_NOT_FOCUSED:KbExpr = KEYBINDING_CONTEXT_TERMINAL_FOCUS.toNegated();
export const ITerminalService = createDecorator<ITerminalService>(TERMINAL_SERVICE_ID); export const ITerminalService = createDecorator<ITerminalService>(TERMINAL_SERVICE_ID);

View file

@ -49,7 +49,7 @@ export class TerminalService implements ITerminalService {
this._onActiveInstanceChanged = new Emitter<string>(); this._onActiveInstanceChanged = new Emitter<string>();
this._onInstancesChanged = new Emitter<string>(); this._onInstancesChanged = new Emitter<string>();
this._onInstanceTitleChanged = new Emitter<string>(); this._onInstanceTitleChanged = new Emitter<string>();
this._terminalFocusContextKey = KEYBINDING_CONTEXT_TERMINAL_FOCUS.bindTo(this.keybindingService, undefined); this._terminalFocusContextKey = KEYBINDING_CONTEXT_TERMINAL_FOCUS.bindTo(this.keybindingService);
} }
public get onActiveInstanceChanged(): Event<string> { public get onActiveInstanceChanged(): Event<string> {