提交 1a7b4197 编写于 作者: S Sandeep Somavarapu

#18095 Keybindings editor

- Register keybinding for remove action
- Make other actions as just keybinding actions
上级 8f5b2f5d
......@@ -15,12 +15,12 @@ import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { EditorInput } from 'vs/workbench/common/editor';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { KeybindingsEditorModel, IKeybindingItemEntry, IKeybindingItem, IListEntry, KEYBINDING_ENTRY_TEMPLATE_ID, KEYBINDING_HEADER_TEMPLATE_ID } from 'vs/workbench/parts/preferences/common/keybindingsEditorModel';
import { KeybindingsEditorModel, IKeybindingItemEntry, IListEntry, KEYBINDING_ENTRY_TEMPLATE_ID, KEYBINDING_HEADER_TEMPLATE_ID } from 'vs/workbench/parts/preferences/common/keybindingsEditorModel';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IKeybindingService, KeybindingSource } from 'vs/platform/keybinding/common/keybinding';
import { SearchWidget } from 'vs/workbench/parts/preferences/browser/preferencesWidgets';
import { DefineKeybindingWidget } from 'vs/workbench/parts/preferences/browser/keybindingWidgets';
import { IPreferencesService, IKeybindingsEditor, CONTEXT_KEYBINDING_FOCUS, KEYBINDINGS_EDITOR_ID, CONTEXT_KEYBINDINGS_EDITOR } from 'vs/workbench/parts/preferences/common/preferences';
import { IPreferencesService, IKeybindingsEditor, CONTEXT_KEYBINDING_FOCUS, KEYBINDINGS_EDITOR_ID, CONTEXT_KEYBINDINGS_EDITOR, KEYBINDINGS_EDITOR_COMMAND_REMOVE } from 'vs/workbench/parts/preferences/common/preferences';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { renderHtml } from 'vs/base/browser/htmlContentRenderer';
import { IKeybindingEditingService } from 'vs/workbench/services/keybinding/common/keybindingEditing';
......@@ -29,6 +29,7 @@ import { List } from 'vs/base/browser/ui/list/listWidget';
import { IDelegate, IRenderer, IListContextMenuEvent, IListEvent } from 'vs/base/browser/ui/list/list';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IChoiceService, Severity } from 'vs/platform/message/common/message';
let $ = DOM.$;
......@@ -85,6 +86,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
@IKeybindingEditingService private keybindingEditingService: IKeybindingEditingService,
@IListService private listService: IListService,
@IContextKeyService private contextKeyService: IContextKeyService,
@IChoiceService private choiceService: IChoiceService,
@IInstantiationService private instantiationService: IInstantiationService
) {
super(KeybindingsEditor.ID, telemetryService, themeService);
......@@ -161,6 +163,21 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
});
}
removeKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise<any> {
if (keybindingEntry.keybindingItem.keybinding) { // This should be a pre-condition
const options: string[] = [localize('ok', "Ok"), localize('cancel', "Cancel")];
return this.choiceService.choose(Severity.Info, localize('confirmRemove', "Remove keybinding '{0}' from command '{1}'", keybindingEntry.keybindingItem.keybinding.getAriaLabel(), keybindingEntry.keybindingItem.commandLabel || keybindingEntry.keybindingItem.commandLabel), options, true)
.then(option => {
if (option === 0) {
return this.keybindingEditingService.removeKeybinding(keybindingEntry.keybindingItem);
}
return null;
})
.then(() => this.focus());
}
return TPromise.as(null);
}
search(filter: string): void {
this.searchWidget.focus();
}
......@@ -223,7 +240,8 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
if (e.element.templateId === KEYBINDING_ENTRY_TEMPLATE_ID) {
this.contextMenuService.showContextMenu({
getAnchor: () => e.anchor,
getActions: () => TPromise.as([this.createRemoveAction((<IKeybindingItemEntry>e.element).keybindingItem)])
getActions: () => TPromise.as([this.createRemoveAction(<IKeybindingItemEntry>e.element)]),
getKeyBinding: (action) => this.keybindingsService.lookupKeybinding(action.id)
});
}
}
......@@ -243,12 +261,12 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
}
}
private createRemoveAction(keybinding: IKeybindingItem): IAction {
private createRemoveAction(keybindingItem: IKeybindingItemEntry): IAction {
return <IAction>{
label: localize('removeLabel', "Remove Keybinding"),
enabled: !!keybinding.keybinding,
id: 'removeKeybinding',
run: () => this.keybindingEditingService.removeKeybinding(keybinding)
enabled: !!keybindingItem.keybindingItem.keybinding,
id: KEYBINDINGS_EDITOR_COMMAND_REMOVE,
run: () => this.removeKeybinding(keybindingItem)
};
}
}
......
......@@ -156,7 +156,7 @@
}
.keybindings-editor > .keybindings-body > .keybindings-list-container .monaco-list-row.selected > .column.actions .monaco-action-bar,
.keybindings-editor > .keybindings-body > .keybindings-list-container .monaco-list-row.focused > .column.actions .monaco-action-bar,
.keybindings-editor > .keybindings-body > .keybindings-list-container .monaco-list:focus .monaco-list-row.focused > .column.actions .monaco-action-bar,
.keybindings-editor > .keybindings-body > .keybindings-list-container .monaco-list-row:hover > .column.actions .monaco-action-bar {
display: flex;
}
......
......@@ -7,6 +7,7 @@
import * as nls from 'vs/nls';
import URI from 'vs/base/common/uri';
import { Registry } from 'vs/platform/platform';
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actionRegistry';
import { EditorInput, IEditorRegistry, Extensions as EditorExtensions, IEditorInputFactory } from 'vs/workbench/common/editor';
import { EditorDescriptor } from 'vs/workbench/browser/parts/editor/baseEditor';
......@@ -16,13 +17,14 @@ import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { DefaultPreferencesEditorInput, PreferencesEditor, PreferencesEditorInput } from 'vs/workbench/parts/preferences/browser/preferencesEditor';
import { KeybindingsEditor, KeybindingsEditorInput } from 'vs/workbench/parts/preferences/browser/keybindingsEditor';
import { OpenGlobalSettingsAction, OpenGlobalKeybindingsAction, OpenWorkspaceSettingsAction, ConfigureLanguageBasedSettingsAction, DefineKeybindingAction, SearchKeybindingAction } from 'vs/workbench/parts/preferences/browser/preferencesActions';
import { IPreferencesService, CONTEXT_KEYBINDING_FOCUS, CONTEXT_KEYBINDINGS_EDITOR } from 'vs/workbench/parts/preferences/common/preferences';
import { OpenGlobalSettingsAction, OpenGlobalKeybindingsAction, OpenWorkspaceSettingsAction, ConfigureLanguageBasedSettingsAction } from 'vs/workbench/parts/preferences/browser/preferencesActions';
import { IPreferencesService, IKeybindingsEditor, CONTEXT_KEYBINDING_FOCUS, CONTEXT_KEYBINDINGS_EDITOR, KEYBINDINGS_EDITOR_COMMAND_DEFINE, KEYBINDINGS_EDITOR_COMMAND_REMOVE, KEYBINDINGS_EDITOR_COMMAND_SEARCH } from 'vs/workbench/parts/preferences/common/preferences';
import { PreferencesService } from 'vs/workbench/parts/preferences/browser/preferencesService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { PreferencesContentProvider } from 'vs/workbench/parts/preferences/common/preferencesContentProvider';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
registerSingleton(IPreferencesService, PreferencesService);
......@@ -164,10 +166,50 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(OpenGlobalSettingsActi
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenWorkspaceSettingsAction, OpenWorkspaceSettingsAction.ID, OpenWorkspaceSettingsAction.LABEL), 'Preferences: Open Workspace Settings', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenGlobalKeybindingsAction, OpenGlobalKeybindingsAction.ID, OpenGlobalKeybindingsAction.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_S) }), 'Preferences: Open Keyboard Shortcuts', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(ConfigureLanguageBasedSettingsAction, ConfigureLanguageBasedSettingsAction.ID, ConfigureLanguageBasedSettingsAction.LABEL), 'Preferences: Configure Language Specific Settings', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(SearchKeybindingAction, SearchKeybindingAction.ID, SearchKeybindingAction.LABEL, {
primary: KeyMod.CtrlCmd | KeyCode.KEY_F,
}, CONTEXT_KEYBINDINGS_EDITOR), '');
registry.registerWorkbenchAction(new SyncActionDescriptor(DefineKeybindingAction, DefineKeybindingAction.ID, DefineKeybindingAction.LABEL, {
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: KEYBINDINGS_EDITOR_COMMAND_DEFINE,
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDING_FOCUS),
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_K),
}, ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDING_FOCUS)), '');
handler: (accessor, args: any) => {
const editor = accessor.get(IWorkbenchEditorService).getActiveEditor() as IKeybindingsEditor;
editor.defineKeybinding(editor.activeKeybindingEntry);
},
description: {
description: nls.localize('keybindings.editor.define.description', "Define Keybinding"),
args: []
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: KEYBINDINGS_EDITOR_COMMAND_REMOVE,
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDING_FOCUS),
primary: KeyCode.Delete,
mac: {
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.Backspace)
},
handler: (accessor, args: any) => {
const editor = accessor.get(IWorkbenchEditorService).getActiveEditor() as IKeybindingsEditor;
editor.removeKeybinding(editor.activeKeybindingEntry);
},
description: {
description: nls.localize('keybindings.editor.remove.description', "Remove Keybinding"),
args: []
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: KEYBINDINGS_EDITOR_COMMAND_SEARCH,
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDING_FOCUS),
primary: KeyMod.CtrlCmd | KeyCode.KEY_F,
handler: (accessor, args: any) => (accessor.get(IWorkbenchEditorService).getActiveEditor() as IKeybindingsEditor).search(''),
description: {
description: nls.localize('keybindings.editor.search.description', "Search Keybindings"),
args: []
}
});
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(PreferencesContentProvider);
\ No newline at end of file
......@@ -10,8 +10,7 @@ import URI from 'vs/base/common/uri';
import { Action } from 'vs/base/common/actions';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IQuickOpenService, IPickOpenEntry, IFilePickOpenEntry } from 'vs/platform/quickOpen/common/quickOpen';
import { IPreferencesService, IKeybindingsEditor, KEYBINDINGS_EDITOR_ID } from 'vs/workbench/parts/preferences/common/preferences';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IPreferencesService } from 'vs/workbench/parts/preferences/common/preferences';
export class OpenGlobalSettingsAction extends Action {
......@@ -114,51 +113,4 @@ export class ConfigureLanguageBasedSettingsAction extends Action {
});
}
}
export class DefineKeybindingAction extends Action {
public static ID = 'keybindings.editor.define';
public static LABEL = nls.localize('keybindings.editor.define', "Define Keybinding");
constructor(
id: string,
label: string,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
const activeEditor = this.editorService.getActiveEditor();
if (activeEditor.getId() === KEYBINDINGS_EDITOR_ID) {
const keybindingsEditor = activeEditor as IKeybindingsEditor;
if (keybindingsEditor.activeKeybindingEntry) {
return keybindingsEditor.defineKeybinding(keybindingsEditor.activeKeybindingEntry);
}
}
return TPromise.as(null);
}
}
export class SearchKeybindingAction extends Action {
public static ID = 'keybindings.editor.search';
public static LABEL = nls.localize('keybindings.editor.search', "Search Keybindings");
constructor(
id: string,
label: string,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
const activeEditor = this.editorService.getActiveEditor();
if (activeEditor.getId() === KEYBINDINGS_EDITOR_ID) {
(activeEditor as IKeybindingsEditor).search('');
}
return TPromise.as(null);
}
}
\ No newline at end of file
......@@ -88,6 +88,7 @@ export interface IKeybindingsEditor extends IEditor {
search(filter: string): void;
defineKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise<any>;
removeKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise<any>;
}
export const KEYBINDINGS_EDITOR_ID = 'workbench.editor.keybindings';
......@@ -95,4 +96,7 @@ export const CONTEXT_SETTINGS_EDITOR = new RawContextKey<boolean>('inSettingsEdi
export const CONTEXT_KEYBINDINGS_EDITOR = new RawContextKey<boolean>('inKeybindings', false);
export const CONTEXT_KEYBINDING_FOCUS = new RawContextKey<boolean>('keybindingFocus', false);
export const SETTINGS_EDITOR_COMMAND_SEARCH = 'settings.action.search';
\ No newline at end of file
export const SETTINGS_EDITOR_COMMAND_SEARCH = 'settings.action.search';
export const KEYBINDINGS_EDITOR_COMMAND_SEARCH = 'keybindings.editor.search';
export const KEYBINDINGS_EDITOR_COMMAND_DEFINE = 'keybindings.editor.define';
export const KEYBINDINGS_EDITOR_COMMAND_REMOVE = 'keybindings.editor.remove';
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册