More adoption of KbCtxKey

This commit is contained in:
Alex Dima 2016-08-04 23:13:30 +02:00
parent acea018800
commit aadec363cd
21 changed files with 84 additions and 105 deletions

View file

@ -443,13 +443,5 @@ export function createMonacoEditorAPI(): typeof monaco.editor {
EditorScrollDirection: editorCommon.EditorScrollDirection,
EditorScrollByUnit: editorCommon.EditorScrollByUnit,
Handler: editorCommon.Handler,
// consts
KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS: editorCommon.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS,
KEYBINDING_CONTEXT_EDITOR_FOCUS: editorCommon.KEYBINDING_CONTEXT_EDITOR_FOCUS,
KEYBINDING_CONTEXT_EDITOR_READONLY: editorCommon.KEYBINDING_CONTEXT_EDITOR_READONLY,
KEYBINDING_CONTEXT_EDITOR_HAS_MULTIPLE_SELECTIONS: editorCommon.KEYBINDING_CONTEXT_EDITOR_HAS_MULTIPLE_SELECTIONS,
KEYBINDING_CONTEXT_EDITOR_HAS_NON_EMPTY_SELECTION: editorCommon.KEYBINDING_CONTEXT_EDITOR_HAS_NON_EMPTY_SELECTION,
KEYBINDING_CONTEXT_EDITOR_LANGUAGE_ID: editorCommon.KEYBINDING_CONTEXT_EDITOR_LANGUAGE_ID,
};
}

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)
this.textArea = <HTMLTextAreaElement>document.createElement('textarea');
this._keybindingService = keybindingService.createScoped(this.textArea);
this._editorTextFocusContextKey = this._keybindingService.createKey(editorCommon.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS, undefined);
this._editorTextFocusContextKey = editorCommon.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS.bindTo(this._keybindingService, undefined);
this.textArea.className = editorBrowser.ClassNames.TEXTAREA;
this.textArea.setAttribute('wrap', 'off');
this.textArea.setAttribute('autocorrect', 'off');

View file

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

View file

@ -3019,37 +3019,39 @@ export interface IDiffLineInformation {
/**
* A context key that is set when the editor's text has focus (cursor is blinking).
* @internal
*/
export const KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS = 'editorTextFocus';
export const KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS = new KbCtxKey('editorTextFocus');
/**
* A context key that is set when the editor's text or an editor's widget has focus.
* @internal
*/
export const KEYBINDING_CONTEXT_EDITOR_FOCUS = 'editorFocus';
export const KEYBINDING_CONTEXT_EDITOR_FOCUS = new KbCtxKey('editorFocus');
/**
* @internal
*/
export const KEYBINDING_CONTEXT_EDITOR_TAB_MOVES_FOCUS = 'editorTabMovesFocus';
export const KEYBINDING_CONTEXT_EDITOR_TAB_MOVES_FOCUS = new KbCtxKey('editorTabMovesFocus');
/**
* A context key that is set when the editor's text is readonly.
*/
export const KEYBINDING_CONTEXT_EDITOR_READONLY = 'editorReadonly';
/**
* A context key that is set when the editor has multiple selections (multiple cursors).
*/
export const KEYBINDING_CONTEXT_EDITOR_HAS_MULTIPLE_SELECTIONS = 'editorHasMultipleSelections';
/**
* A context key that is set when the editor has a non-collapsed selection.
*/
export const KEYBINDING_CONTEXT_EDITOR_HAS_NON_EMPTY_SELECTION = 'editorHasSelection';
/**
* A context key that is set to the language associated with the model associated with the editor.
*/
export const KEYBINDING_CONTEXT_EDITOR_LANGUAGE_ID = 'editorLangId';
/**
* @internal
*/
export const SHOW_ACCESSIBILITY_HELP_ACTION_ID = 'editor.action.showAccessibilityHelp';
export const KEYBINDING_CONTEXT_EDITOR_READONLY = new KbCtxKey('editorReadonly');
/**
* A context key that is set when the editor has multiple selections (multiple cursors).
* @internal
*/
export const KEYBINDING_CONTEXT_EDITOR_HAS_MULTIPLE_SELECTIONS = new KbCtxKey('editorHasMultipleSelections');
/**
* A context key that is set when the editor has a non-collapsed selection.
* @internal
*/
export const KEYBINDING_CONTEXT_EDITOR_HAS_NON_EMPTY_SELECTION = new KbCtxKey('editorHasSelection');
/**
* A context key that is set to the language associated with the model associated with the editor.
* @internal
*/
export const KEYBINDING_CONTEXT_EDITOR_LANGUAGE_ID = new KbCtxKey('editorLangId');
/**
* @internal
@ -3075,20 +3077,20 @@ export interface IEditorKbExpr {
* @internal
*/
export let EditorKbExpr: IEditorKbExpr = {
TextFocus: KbExpr.has(KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS),
Focus: KbExpr.has(KEYBINDING_CONTEXT_EDITOR_FOCUS),
TextFocus: KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS,
Focus: KEYBINDING_CONTEXT_EDITOR_FOCUS,
ReadOnly: KbExpr.has(KEYBINDING_CONTEXT_EDITOR_READONLY),
Writable: KbExpr.not(KEYBINDING_CONTEXT_EDITOR_READONLY),
ReadOnly: KEYBINDING_CONTEXT_EDITOR_READONLY,
Writable: KEYBINDING_CONTEXT_EDITOR_READONLY.toNegated(),
HasNonEmptySelection: KbExpr.has(KEYBINDING_CONTEXT_EDITOR_HAS_NON_EMPTY_SELECTION),
HasOnlyEmptySelection: KbExpr.not(KEYBINDING_CONTEXT_EDITOR_HAS_NON_EMPTY_SELECTION),
HasNonEmptySelection: KEYBINDING_CONTEXT_EDITOR_HAS_NON_EMPTY_SELECTION,
HasOnlyEmptySelection: KEYBINDING_CONTEXT_EDITOR_HAS_NON_EMPTY_SELECTION.toNegated(),
HasMultipleSelections: KbExpr.has(KEYBINDING_CONTEXT_EDITOR_HAS_MULTIPLE_SELECTIONS),
HasSingleSelection: KbExpr.not(KEYBINDING_CONTEXT_EDITOR_HAS_MULTIPLE_SELECTIONS),
HasMultipleSelections: KEYBINDING_CONTEXT_EDITOR_HAS_MULTIPLE_SELECTIONS,
HasSingleSelection: KEYBINDING_CONTEXT_EDITOR_HAS_MULTIPLE_SELECTIONS.toNegated(),
TabMovesFocus: KbExpr.has(KEYBINDING_CONTEXT_EDITOR_TAB_MOVES_FOCUS),
TabDoesNotMoveFocus: KbExpr.not(KEYBINDING_CONTEXT_EDITOR_TAB_MOVES_FOCUS),
TabMovesFocus: KEYBINDING_CONTEXT_EDITOR_TAB_MOVES_FOCUS,
TabDoesNotMoveFocus: KEYBINDING_CONTEXT_EDITOR_TAB_MOVES_FOCUS.toNegated(),
};

View file

@ -18,7 +18,7 @@ import {ServicesAccessor} from 'vs/platform/instantiation/common/instantiation';
import {KbExpr, KbCtxKey, IKeybindingContextKey, IKeybindingService} from 'vs/platform/keybinding/common/keybinding';
import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
import {GlobalScreenReaderNVDA} from 'vs/editor/common/config/commonEditorConfig';
import {ICommonCodeEditor, IEditorContribution, EditorKbExpr, SHOW_ACCESSIBILITY_HELP_ACTION_ID} from 'vs/editor/common/editorCommon';
import {ICommonCodeEditor, IEditorContribution, EditorKbExpr} from 'vs/editor/common/editorCommon';
import {CommonEditorRegistry, EditorAction, EditorCommand, Command} from 'vs/editor/common/editorCommonExtensions';
import {ICodeEditor, IOverlayWidget, IOverlayWidgetPosition} from 'vs/editor/browser/editorBrowser';
import {EditorBrowserRegistry} from 'vs/editor/browser/editorBrowserExtensions';
@ -193,7 +193,7 @@ class ShowAccessibilityHelpAction extends EditorAction {
constructor() {
super(
SHOW_ACCESSIBILITY_HELP_ACTION_ID,
'editor.action.showAccessibilityHelp',
nls.localize('ShowAccessibilityHelpAction',"Show Accessibility Help"),
'Show Accessibility Help',
false

View file

@ -34,7 +34,7 @@ export interface IFindStartOptions {
}
export const CONTEXT_FIND_WIDGET_VISIBLE = new KbCtxKey('findWidgetVisible');
export const CONTEXT_FIND_WIDGET_NOT_VISIBLE = CONTEXT_FIND_WIDGET_VISIBLE.negate();
export const CONTEXT_FIND_WIDGET_NOT_VISIBLE = CONTEXT_FIND_WIDGET_VISIBLE.toNegated();
export class CommonFindController extends Disposable implements editorCommon.IEditorContribution {

30
src/vs/monaco.d.ts vendored
View file

@ -2707,36 +2707,6 @@ declare module monaco.editor {
charChanges: ICharChange[];
}
/**
* A context key that is set when the editor's text has focus (cursor is blinking).
*/
export const KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS: string;
/**
* A context key that is set when the editor's text or an editor's widget has focus.
*/
export const KEYBINDING_CONTEXT_EDITOR_FOCUS: string;
/**
* A context key that is set when the editor's text is readonly.
*/
export const KEYBINDING_CONTEXT_EDITOR_READONLY: string;
/**
* A context key that is set when the editor has multiple selections (multiple cursors).
*/
export const KEYBINDING_CONTEXT_EDITOR_HAS_MULTIPLE_SELECTIONS: string;
/**
* A context key that is set when the editor has a non-collapsed selection.
*/
export const KEYBINDING_CONTEXT_EDITOR_HAS_NON_EMPTY_SELECTION: string;
/**
* A context key that is set to the language associated with the model associated with the editor.
*/
export const KEYBINDING_CONTEXT_EDITOR_LANGUAGE_ID: string;
export class BareFontInfo {
_bareFontInfoBrand: void;
fontFamily: string;

View file

@ -383,9 +383,13 @@ export class KbCtxKey extends KbDefinedExpression {
return target.getContextValue<T>(this.key);
}
public negate(): KbExpr {
public toNegated(): KbExpr {
return KbExpr.not(this.key);
}
public isEqualTo(value:string): KbExpr {
return KbExpr.equals(this.key, value);
}
}
export let KbExpr = {

View file

@ -19,7 +19,7 @@ import {ResourceEditorInput} from 'vs/workbench/common/editor/resourceEditorInpu
import {IInstantiationService, ServicesAccessor} from 'vs/platform/instantiation/common/instantiation';
import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
import {KbExpr, IKeybindings} from 'vs/platform/keybinding/common/keybinding';
import {TextDiffEditor} from 'vs/workbench/browser/parts/editor/textDiffEditor';
import {TextCompareEditorVisible, TextDiffEditor} from 'vs/workbench/browser/parts/editor/textDiffEditor';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {BinaryResourceDiffEditor} from 'vs/workbench/browser/parts/editor/binaryDiffEditor';
import {IEditorGroupService} from 'vs/workbench/services/group/common/groupService';
@ -94,7 +94,7 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(ChangeEncodingAction,
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'workbench.action.compareEditor.nextChange',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: KbExpr.has('textCompareEditorVisible'),
when: TextCompareEditorVisible,
primary: null,
handler: accessor => navigateInDiffEditor(accessor, true)
});
@ -102,7 +102,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'workbench.action.compareEditor.previousChange',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: KbExpr.has('textCompareEditorVisible'),
when: TextCompareEditorVisible,
primary: null,
handler: accessor => navigateInDiffEditor(accessor, false)
});

View file

@ -35,9 +35,11 @@ import {ServiceCollection} from 'vs/platform/instantiation/common/serviceCollect
import {IMessageService} from 'vs/platform/message/common/message';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {IModeService} from 'vs/editor/common/services/modeService';
import {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';
export const TextCompareEditorVisible = new KbCtxKey('textCompareEditorVisible');
/**
* The text editor that leverages the diff text editor for the editing experience.
*/
@ -66,7 +68,7 @@ export class TextDiffEditor extends BaseTextEditor {
) {
super(TextDiffEditor.ID, telemetryService, instantiationService, contextService, storageService, messageService, configurationService, eventService, editorService, modeService, themeService);
this.textDiffEditorVisible = keybindingService.createKey<boolean>('textCompareEditorVisible', false);
this.textDiffEditorVisible = TextCompareEditorVisible.bindTo(keybindingService, false);
}
public getTitle(): string {

View file

@ -12,10 +12,11 @@ import {IConfigurationRegistry, Extensions as ConfigurationExtensions} from 'vs/
import {IWorkbenchActionRegistry, Extensions} from 'vs/workbench/common/actionRegistry';
import {KeyMod, KeyCode} from 'vs/base/common/keyCodes';
import platform = require('vs/base/common/platform');
import {KbExpr, IKeybindings} from 'vs/platform/keybinding/common/keybinding';
import {IKeybindings} from 'vs/platform/keybinding/common/keybinding';
import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
import {IWindowService} from 'vs/workbench/services/window/electron-browser/windowService';
import {CloseEditorAction, ReloadWindowAction, ShowStartupPerformance, ZoomResetAction, ZoomOutAction, ZoomInAction, ToggleDevToolsAction, ToggleFullScreenAction, ToggleMenuBarAction, OpenRecentAction, CloseFolderAction, CloseWindowAction, NewWindowAction, CloseMessagesAction} from 'vs/workbench/electron-browser/actions';
import {MessagesVisibleContext, NoEditorsVisibleContext} from 'vs/workbench/electron-browser/workbench';
const closeEditorOrWindowKeybindings: IKeybindings = { primary: KeyMod.CtrlCmd | KeyCode.KEY_W, win: { primary: KeyMod.CtrlCmd | KeyCode.F4, secondary: [KeyMod.CtrlCmd | KeyCode.KEY_W] }};
@ -34,7 +35,7 @@ workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ZoomOu
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ZoomResetAction, ZoomResetAction.ID, ZoomResetAction.LABEL), 'View: Reset Zoom', viewCategory);
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ShowStartupPerformance, ShowStartupPerformance.ID, ShowStartupPerformance.LABEL), 'Developer: Startup Performance', developerCategory);
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ReloadWindowAction, ReloadWindowAction.ID, ReloadWindowAction.LABEL), 'Reload Window');
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(CloseMessagesAction, CloseMessagesAction.ID, CloseMessagesAction.LABEL, { primary: KeyCode.Escape, secondary: [KeyMod.Shift | KeyCode.Escape] }, KbExpr.has('globalMessageVisible')), 'Close Notification Messages');
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(CloseMessagesAction, CloseMessagesAction.ID, CloseMessagesAction.LABEL, { primary: KeyCode.Escape, secondary: [KeyMod.Shift | KeyCode.Escape] }, MessagesVisibleContext), 'Close Notification Messages');
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(CloseEditorAction, CloseEditorAction.ID, CloseEditorAction.LABEL, closeEditorOrWindowKeybindings), 'View: Close Editor', viewCategory);
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleFullScreenAction, ToggleFullScreenAction.ID, ToggleFullScreenAction.LABEL, { primary: KeyCode.F11, mac: { primary: KeyMod.CtrlCmd | KeyMod.WinCtrl | KeyCode.KEY_F } }), 'View: Toggle Full Screen', viewCategory);
if (platform.isWindows || platform.isLinux) {
@ -45,7 +46,7 @@ if (platform.isWindows || platform.isLinux) {
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'workbench.action.closeWindow',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: KbExpr.not('editorIsOpen'),
when: NoEditorsVisibleContext,
primary: closeEditorOrWindowKeybindings.primary,
handler: accessor => {
const windowService = accessor.get(IWindowService);

View file

@ -47,7 +47,7 @@ import {IStorageService, StorageScope} from 'vs/platform/storage/common/storage'
import {ContextMenuService} from 'vs/workbench/services/contextview/electron-browser/contextmenuService';
import {WorkbenchKeybindingService} from 'vs/workbench/services/keybinding/electron-browser/keybindingService';
import {IWorkspace, IConfiguration} from 'vs/platform/workspace/common/workspace';
import {IKeybindingService, IKeybindingContextKey} from 'vs/platform/keybinding/common/keybinding';
import {KbExpr, KbCtxKey, IKeybindingService, IKeybindingContextKey} from 'vs/platform/keybinding/common/keybinding';
import {IActivityService} from 'vs/workbench/services/activity/common/activityService';
import {IViewletService} from 'vs/workbench/services/viewlet/common/viewletService';
import {IPanelService} from 'vs/workbench/services/panel/common/panelService';
@ -68,6 +68,10 @@ import {IMenuService} from 'vs/platform/actions/common/actions';
import {MenuService} from 'vs/platform/actions/common/menuService';
import {IContextMenuService} from 'vs/platform/contextview/browser/contextView';
export const MessagesVisibleContext = new KbCtxKey('globalMessageVisible');
export const EditorsVisibleContext = new KbCtxKey('editorIsOpen');
export const NoEditorsVisibleContext:KbExpr = EditorsVisibleContext.toNegated();
interface WorkbenchParams {
workspace?: IWorkspace;
configuration: IConfiguration;
@ -199,8 +203,8 @@ export class Workbench implements IPartService {
}
// Contexts
this.messagesVisibleContext = this.keybindingService.createKey('globalMessageVisible', false);
this.editorsVisibleContext = this.keybindingService.createKey('editorIsOpen', false);
this.messagesVisibleContext = MessagesVisibleContext.bindTo(this.keybindingService, false);
this.editorsVisibleContext = EditorsVisibleContext.bindTo(this.keybindingService, false);
// Register Listeners
this.registerListeners();

View file

@ -17,7 +17,7 @@ export const VIEWLET_ID = 'workbench.view.debug';
export const REPL_ID = 'workbench.panel.repl';
export const DEBUG_SERVICE_ID = 'debugService';
export const CONTEXT_IN_DEBUG_MODE = new KbCtxKey('inDebugMode');
export const CONTEXT_NOT_IN_DEBUG_MODE:KbExpr = CONTEXT_IN_DEBUG_MODE.negate();
export const CONTEXT_NOT_IN_DEBUG_MODE:KbExpr = CONTEXT_IN_DEBUG_MODE.toNegated();
export const EDITOR_CONTRIBUTION_ID = 'editor.contrib.debug';
// raw

View file

@ -22,8 +22,7 @@ import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/edito
import {asFileEditorInput} from 'vs/workbench/common/editor';
import {KeyMod, KeyCode} from 'vs/base/common/keyCodes';
import {Extensions, IConfigurationRegistry} from 'vs/platform/configuration/common/configurationRegistry';
import {KbExpr} from 'vs/platform/keybinding/common/keybinding';
import {KEYBINDING_CONTEXT_TERMINAL_FOCUS} from 'vs/workbench/parts/terminal/electron-browser/terminal';
import {KEYBINDING_CONTEXT_TERMINAL_NOT_FOCUSED} from 'vs/workbench/parts/terminal/electron-browser/terminal';
import {DEFAULT_TERMINAL_WINDOWS, DEFAULT_TERMINAL_LINUX, DEFAULT_TERMINAL_OSX} from 'vs/workbench/parts/execution/electron-browser/terminal';
let configurationRegistry = <IConfigurationRegistry>Registry.as(Extensions.Configuration);
@ -135,7 +134,7 @@ actionBarRegistry.registerActionBarContributor(Scope.VIEWER, FileViewerActionCon
OpenConsoleAction.ID,
OpenConsoleAction.Label,
{ primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_C },
KbExpr.and(KbExpr.not(KEYBINDING_CONTEXT_TERMINAL_FOCUS))
KEYBINDING_CONTEXT_TERMINAL_NOT_FOCUSED
),
'Open New Command Prompt'
);

View file

@ -123,7 +123,7 @@ registerAction({
title: nls.localize('clearOutput.label', "Clear Output"),
menu: {
menuId: MenuId.EditorContext,
when: KbExpr.equals(KEYBINDING_CONTEXT_EDITOR_LANGUAGE_ID, OUTPUT_MODE_ID)
when: KEYBINDING_CONTEXT_EDITOR_LANGUAGE_ID.isEqualTo(OUTPUT_MODE_ID)
},
handler(accessor) {
accessor.get(IOutputService).getActiveChannel().clear();

View file

@ -21,12 +21,12 @@ import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegi
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {AsyncDescriptor} from 'vs/platform/instantiation/common/descriptors';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {KbExpr, IKeybindings} from 'vs/platform/keybinding/common/keybinding';
import {IKeybindings} from 'vs/platform/keybinding/common/keybinding';
import {IQuickOpenService} from 'vs/workbench/services/quickopen/common/quickOpenService';
import {IViewletService} from 'vs/workbench/services/viewlet/common/viewletService';
import {KeyMod, KeyCode} from 'vs/base/common/keyCodes';
import {OpenSearchViewletAction, ReplaceInFilesAction} from 'vs/workbench/parts/search/browser/searchActions';
import {VIEWLET_ID} from 'vs/workbench/parts/search/common/constants';
import {VIEWLET_ID, SearchViewletVisible} from 'vs/workbench/parts/search/common/constants';
import { registerContributions as replaceContributions } from 'vs/workbench/parts/search/browser/replaceContributions';
import { registerContributions as searchWidgetContributions } from 'vs/workbench/parts/search/browser/searchWidget';
@ -36,7 +36,7 @@ searchWidgetContributions();
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'workbench.action.search.toggleQueryDetails',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: KbExpr.has('searchViewletVisible'),
when: SearchViewletVisible,
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_J,
handler: accessor => {
let viewletService = accessor.get(IViewletService);

View file

@ -32,7 +32,7 @@ import {FileChangeType, FileChangesEvent, EventType as FileEventType} from 'vs/p
import {Viewlet} from 'vs/workbench/browser/viewlet';
import {Match, FileMatch, SearchModel, FileMatchOrMatch, IChangeEvent} from 'vs/workbench/parts/search/common/searchModel';
import {getExcludes, QueryBuilder} from 'vs/workbench/parts/search/common/searchQuery';
import {VIEWLET_ID} from 'vs/workbench/parts/search/common/constants';
import {VIEWLET_ID, SearchViewletVisible} from 'vs/workbench/parts/search/common/constants';
import {MessageType, InputBox } from 'vs/base/browser/ui/inputbox/inputBox';
import {ISearchProgressItem, ISearchComplete, ISearchQuery, IQueryOptions, ISearchConfiguration} from 'vs/platform/search/common/search';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
@ -105,7 +105,7 @@ export class SearchViewlet extends Viewlet {
super(VIEWLET_ID, telemetryService);
this.toDispose = [];
this.viewletVisible = keybindingService.createKey<boolean>('searchViewletVisible', true);
this.viewletVisible = SearchViewletVisible.bindTo(keybindingService, true);
this.callOnModelChange = [];
this.queryBuilder = this.instantiationService.createInstance(QueryBuilder);

View file

@ -3,4 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export const VIEWLET_ID = 'workbench.view.search';
import {KbCtxKey} from 'vs/platform/keybinding/common/keybinding';
export const VIEWLET_ID = 'workbench.view.search';
export const SearchViewletVisible = new KbCtxKey('searchViewletVisible');

View file

@ -9,7 +9,6 @@ import * as panel from 'vs/workbench/browser/panel';
import * as platform from 'vs/base/common/platform';
import nls = require('vs/nls');
import {Extensions, IConfigurationRegistry} from 'vs/platform/configuration/common/configurationRegistry';
import {KbExpr} from 'vs/platform/keybinding/common/keybinding';
import {ITerminalService, KEYBINDING_CONTEXT_TERMINAL_FOCUS, TERMINAL_PANEL_ID, TERMINAL_DEFAULT_SHELL_LINUX, TERMINAL_DEFAULT_SHELL_OSX, TERMINAL_DEFAULT_SHELL_WINDOWS} from 'vs/workbench/parts/terminal/electron-browser/terminal';
import {IWorkbenchActionRegistry, Extensions as ActionExtensions} from 'vs/workbench/common/actionRegistry';
import {KeyCode, KeyMod} from 'vs/base/common/keyCodes';
@ -106,7 +105,7 @@ actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(CopyTerminalSele
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_C,
// Don't apply to Mac since cmd+c works
mac: { primary: null }
}, KbExpr.and(KbExpr.has(KEYBINDING_CONTEXT_TERMINAL_FOCUS))), CopyTerminalSelectionAction.LABEL);
}, KEYBINDING_CONTEXT_TERMINAL_FOCUS), CopyTerminalSelectionAction.LABEL);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(CreateNewTerminalAction, CreateNewTerminalAction.ID, CreateNewTerminalAction.LABEL, {
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_BACKTICK,
mac: { primary: KeyMod.WinCtrl | KeyMod.Shift | KeyCode.US_BACKTICK }
@ -118,7 +117,7 @@ actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(TerminalPasteAct
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_V,
// Don't apply to Mac since cmd+v works
mac: { primary: null }
}, KbExpr.and(KbExpr.has(KEYBINDING_CONTEXT_TERMINAL_FOCUS))), CopyTerminalSelectionAction.LABEL);
}, KEYBINDING_CONTEXT_TERMINAL_FOCUS), CopyTerminalSelectionAction.LABEL);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(RunSelectedTextInTerminalAction, RunSelectedTextInTerminalAction.ID, RunSelectedTextInTerminalAction.LABEL), RunSelectedTextInTerminalAction.LABEL);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleTerminalAction, ToggleTerminalAction.ID, ToggleTerminalAction.LABEL, {
primary: KeyMod.CtrlCmd | KeyCode.US_BACKTICK,

View file

@ -11,6 +11,7 @@ import processes = require('vs/base/node/processes');
import {Builder} from 'vs/base/browser/builder';
import {TPromise} from 'vs/base/common/winjs.base';
import {createDecorator} from 'vs/platform/instantiation/common/instantiation';
import {KbCtxKey, KbExpr} from 'vs/platform/keybinding/common/keybinding';
export const TERMINAL_PANEL_ID = 'workbench.panel.terminal';
@ -23,7 +24,8 @@ export const TERMINAL_DEFAULT_SHELL_WINDOWS = processes.getWindowsShell();
/**
* A context key that is set when the integrated terminal has focus.
*/
export const KEYBINDING_CONTEXT_TERMINAL_FOCUS = 'terminalFocus';
export const KEYBINDING_CONTEXT_TERMINAL_FOCUS = new KbCtxKey('terminalFocus');
export const KEYBINDING_CONTEXT_TERMINAL_NOT_FOCUSED:KbExpr = KEYBINDING_CONTEXT_TERMINAL_FOCUS.toNegated();
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._onInstancesChanged = new Emitter<string>();
this._onInstanceTitleChanged = new Emitter<string>();
this._terminalFocusContextKey = this.keybindingService.createKey(KEYBINDING_CONTEXT_TERMINAL_FOCUS, undefined);
this._terminalFocusContextKey = KEYBINDING_CONTEXT_TERMINAL_FOCUS.bindTo(this.keybindingService, undefined);
}
public get onActiveInstanceChanged(): Event<string> {