提交 bd5a257a 编写于 作者: S Sandeep Somavarapu

#18095 Copy action to copy keybinding entry

上级 44bff9ac
......@@ -11,16 +11,17 @@ import * as DOM from 'vs/base/browser/dom';
import { Builder, Dimension } from 'vs/base/browser/builder';
import { HighlightedLabel } from 'vs/base/browser/ui/highlightedlabel/highlightedLabel';
import { IAction } from 'vs/base/common/actions';
import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
import { ActionBar, Separator } 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 { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
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 { IKeybindingService, KeybindingSource, IUserFriendlyKeybinding } 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, CONTEXT_KEYBINDINGS_EDITOR, KEYBINDINGS_EDITOR_COMMAND_REMOVE } from 'vs/workbench/parts/preferences/common/preferences';
import { IPreferencesService, IKeybindingsEditor, CONTEXT_KEYBINDING_FOCUS, CONTEXT_KEYBINDINGS_EDITOR, KEYBINDINGS_EDITOR_COMMAND_REMOVE, KEYBINDINGS_EDITOR_COMMAND_COPY } 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';
......@@ -89,6 +90,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
@IListService private listService: IListService,
@IContextKeyService private contextKeyService: IContextKeyService,
@IChoiceService private choiceService: IChoiceService,
@IClipboardService private clipboardService: IClipboardService,
@IInstantiationService private instantiationService: IInstantiationService
) {
super(KeybindingsEditor.ID, telemetryService, themeService);
......@@ -190,6 +192,18 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
return TPromise.as(null);
}
copyKeybinding(keybinding: IKeybindingItemEntry): TPromise<any> {
const userFriendlyKeybinding: IUserFriendlyKeybinding = {
command: keybinding.keybindingItem.command,
key: keybinding.keybindingItem.keybinding ? keybinding.keybindingItem.keybinding.getUserSettingsLabel() : ''
};
if (keybinding.keybindingItem.when) {
userFriendlyKeybinding.when = keybinding.keybindingItem.when.serialize();
}
this.clipboardService.writeText(JSON.stringify(userFriendlyKeybinding, null, ' '));
return TPromise.as(null);
}
search(filter: string): void {
this.searchWidget.focus();
}
......@@ -290,7 +304,7 @@ 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)]),
getActions: () => TPromise.as([this.createCopyAction(<IKeybindingItemEntry>e.element), new Separator(), this.createRemoveAction(<IKeybindingItemEntry>e.element)]),
getKeyBinding: (action) => this.keybindingsService.lookupKeybinding(action.id)
});
}
......@@ -319,6 +333,15 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
run: () => this.removeKeybinding(keybindingItem)
};
}
private createCopyAction(keybindingItem: IKeybindingItemEntry): IAction {
return <IAction>{
label: localize('copyLabel', "Copy"),
enabled: true,
id: KEYBINDINGS_EDITOR_COMMAND_COPY,
run: () => this.copyKeybinding(keybindingItem)
};
}
}
class Delegate implements IDelegate<IListEntry> {
......
......@@ -60,6 +60,7 @@
}
.keybindings-editor > .keybindings-body > .keybindings-list-container .monaco-list-row {
cursor: default;
display: flex;
}
......@@ -68,10 +69,6 @@
background-color: rgba(130, 130, 130, 0.04);
}
.keybindings-editor > .keybindings-body .keybindings-list-container .monaco-list-row.keybindings-list-header {
cursor: default;
}
.keybindings-editor > .keybindings-body .keybindings-list-container .monaco-list-row.keybindings-list-header.focused,
.keybindings-editor > .keybindings-body .keybindings-list-container .monaco-list-row.keybindings-list-header.selected,
.keybindings-editor > .keybindings-body .keybindings-list-container .monaco-list-row.keybindings-list-header:hover {
......
......@@ -18,7 +18,7 @@ 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 } 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 { IPreferencesService, IKeybindingsEditor, CONTEXT_KEYBINDING_FOCUS, CONTEXT_KEYBINDINGS_EDITOR, KEYBINDINGS_EDITOR_COMMAND_DEFINE, KEYBINDINGS_EDITOR_COMMAND_REMOVE, KEYBINDINGS_EDITOR_COMMAND_SEARCH, KEYBINDINGS_EDITOR_COMMAND_COPY } 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';
......@@ -212,4 +212,19 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: KEYBINDINGS_EDITOR_COMMAND_COPY,
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDING_FOCUS),
primary: KeyMod.CtrlCmd | KeyCode.KEY_C,
handler: (accessor, args: any) => {
const editor = accessor.get(IWorkbenchEditorService).getActiveEditor() as IKeybindingsEditor;
editor.copyKeybinding(editor.activeKeybindingEntry);
},
description: {
description: nls.localize('keybindings.editor.copy.description', "Copy Keybindings"),
args: []
}
});
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(PreferencesContentProvider);
\ No newline at end of file
......@@ -89,6 +89,7 @@ export interface IKeybindingsEditor extends IEditor {
search(filter: string): void;
defineKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise<any>;
removeKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise<any>;
copyKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise<any>;
}
export const CONTEXT_SETTINGS_EDITOR = new RawContextKey<boolean>('inSettingsEditor', false);
......@@ -98,4 +99,5 @@ export const CONTEXT_KEYBINDING_FOCUS = new RawContextKey<boolean>('keybindingFo
export const SETTINGS_EDITOR_COMMAND_SEARCH = 'settings.action.search';
export const KEYBINDINGS_EDITOR_COMMAND_SEARCH = 'keybindings.editor.searchKeybindings';
export const KEYBINDINGS_EDITOR_COMMAND_DEFINE = 'keybindings.editor.defineKeybinding';
export const KEYBINDINGS_EDITOR_COMMAND_REMOVE = 'keybindings.editor.removeKeybinding';
\ No newline at end of file
export const KEYBINDINGS_EDITOR_COMMAND_REMOVE = 'keybindings.editor.removeKeybinding';
export const KEYBINDINGS_EDITOR_COMMAND_COPY = 'keybindings.editor.copyKeybindingEntry';
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册