提交 27a53ad3 编写于 作者: S Sandeep Somavarapu

#18095 Include when and source label in Search

上级 0c126b4f
......@@ -18,7 +18,7 @@ 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, IUserFriendlyKeybinding } from 'vs/platform/keybinding/common/keybinding';
import { IKeybindingService, 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, KEYBINDINGS_EDITOR_COMMAND_COPY, KEYBINDINGS_EDITOR_COMMAND_RESET, KEYBINDINGS_EDITOR_COMMAND_DEFINE } from 'vs/workbench/parts/preferences/common/preferences';
......@@ -225,7 +225,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
key: keybinding.keybindingItem.keybinding ? keybinding.keybindingItem.keybinding.getUserSettingsLabel() : ''
};
if (keybinding.keybindingItem.when) {
userFriendlyKeybinding.when = keybinding.keybindingItem.when.serialize();
userFriendlyKeybinding.when = keybinding.keybindingItem.when;
}
this.clipboardService.writeText(JSON.stringify(userFriendlyKeybinding, null, ' '));
return TPromise.as(null);
......@@ -400,7 +400,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
private createResetAction(keybindingItem: IKeybindingItemEntry): IAction {
return <IAction>{
label: localize('resetLabel', "Reset Keybinding"),
enabled: !!keybindingItem.keybindingItem.keybinding && keybindingItem.keybindingItem.source === KeybindingSource.User,
enabled: !!keybindingItem.keybindingItem.keybinding && !keybindingItem.keybindingItem.keybindingItem.isDefault,
id: KEYBINDINGS_EDITOR_COMMAND_RESET,
run: () => this.resetKeybinding(keybindingItem)
};
......@@ -621,7 +621,8 @@ class SourceColumn extends Column {
}
render(keybindingItemEntry: IKeybindingItemEntry): void {
this.sourceColumn.textContent = keybindingItemEntry.keybindingItem.source === KeybindingSource.User ? localize('user', "User") : localize('default', "Default");
DOM.clearNode(this.sourceColumn);
new HighlightedLabel(this.sourceColumn).set(keybindingItemEntry.keybindingItem.source, keybindingItemEntry.sourceMatches);
}
}
......@@ -635,12 +636,12 @@ class WhenColumn extends Column {
}
render(keybindingItemEntry: IKeybindingItemEntry): void {
DOM.clearNode(this.whenColumn);
DOM.toggleClass(this.whenColumn, 'code', !!keybindingItemEntry.keybindingItem.when);
DOM.toggleClass(this.whenColumn, 'empty', !keybindingItemEntry.keybindingItem.when);
if (keybindingItemEntry.keybindingItem.when) {
const when = keybindingItemEntry.keybindingItem.when.serialize();
this.whenColumn.textContent = when;
this.whenColumn.title = when;
new HighlightedLabel(this.whenColumn).set(keybindingItemEntry.keybindingItem.when, keybindingItemEntry.whenMatches);
this.whenColumn.title = keybindingItemEntry.keybindingItem.when;
} else {
this.whenColumn.textContent = '';
}
......
......@@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { localize } from 'vs/nls';
import { TPromise } from 'vs/base/common/winjs.base';
import { distinct } from 'vs/base/common/arrays';
import { language, LANGUAGE_DEFAULT } from 'vs/base/common/platform';
......@@ -13,10 +14,9 @@ import { CommonEditorRegistry, EditorAction } from 'vs/editor/common/editorCommo
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actionRegistry';
import { EditorModel } from 'vs/workbench/common/editor';
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
import { IKeybindingService, KeybindingSource } from 'vs/platform/keybinding/common/keybinding';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
export const KEYBINDING_ENTRY_TEMPLATE_ID = 'keybinding.entry.template';
export const KEYBINDING_HEADER_TEMPLATE_ID = 'keybinding.header.template';
......@@ -31,6 +31,8 @@ export interface IKeybindingItemEntry extends IListEntry {
commandIdMatches?: IMatch[];
commandLabelMatches?: IMatch[];
commandDefaultLabelMatches?: IMatch[];
sourceMatches?: IMatch[];
whenMatches?: IMatch[];
keybindingMatches?: IMatch[];
}
......@@ -40,8 +42,8 @@ export interface IKeybindingItem {
commandLabel: string;
commandDefaultLabel: string;
command: string;
source: KeybindingSource;
when: ContextKeyExpr;
source: string;
when: string;
}
const wordFilter = or(matchesPrefix, matchesWords, matchesContiguousSubString);
......@@ -67,7 +69,12 @@ export class KeybindingsEditorModel extends EditorModel {
const result: IKeybindingItemEntry[] = [];
for (const keybindingItem of this._keybindingItems) {
let keybindingMatches = new KeybindingMatches(keybindingItem, searchValue);
if (keybindingMatches.commandIdMatches || keybindingMatches.commandLabelMatches || keybindingMatches.commandDefaultLabelMatches || keybindingMatches.keybindingMatches) {
if (keybindingMatches.commandIdMatches
|| keybindingMatches.commandLabelMatches
|| keybindingMatches.commandDefaultLabelMatches
|| keybindingMatches.sourceMatches
|| keybindingMatches.whenMatches
|| keybindingMatches.keybindingMatches) {
result.push({
id: KeybindingsEditorModel.getId(keybindingItem),
templateId: KEYBINDING_ENTRY_TEMPLATE_ID,
......@@ -75,7 +82,9 @@ export class KeybindingsEditorModel extends EditorModel {
commandDefaultLabelMatches: keybindingMatches.commandDefaultLabelMatches,
keybindingItem,
keybindingMatches: keybindingMatches.keybindingMatches,
commandIdMatches: keybindingMatches.commandIdMatches
commandIdMatches: keybindingMatches.commandIdMatches,
sourceMatches: keybindingMatches.sourceMatches,
whenMatches: keybindingMatches.whenMatches
});
}
}
......@@ -109,7 +118,7 @@ export class KeybindingsEditorModel extends EditorModel {
}
private static getId(keybindingItem: IKeybindingItem): string {
return keybindingItem.command + (keybindingItem.keybinding ? keybindingItem.keybinding.getAriaLabel() : '') + keybindingItem.source + (keybindingItem.when ? keybindingItem.when.serialize() : '');
return keybindingItem.command + (keybindingItem.keybinding ? keybindingItem.keybinding.getAriaLabel() : '') + keybindingItem.source + keybindingItem.when;
}
private static compareKeybindingData(a: IKeybindingItem, b: IKeybindingItem): number {
......@@ -131,7 +140,7 @@ export class KeybindingsEditorModel extends EditorModel {
}
}
if (a.command === b.command) {
return a.source === KeybindingSource.User ? -1 : 1;
return a.keybindingItem.isDefault ? 1 : -1;
}
return a.command.localeCompare(b.command);
}
......@@ -140,14 +149,15 @@ export class KeybindingsEditorModel extends EditorModel {
const workbenchAction = workbenchActionsRegistry.getWorkbenchAction(command);
const editorAction: EditorAction = editorActions[command];
const commandDefaultLabel = workbenchAction && language !== LANGUAGE_DEFAULT ? workbenchActionsRegistry.getAlias(workbenchAction.id) : null;
keybindingItem = keybindingItem ? keybindingItem : new ResolvedKeybindingItem(null, command, null, null, true);
return <IKeybindingItem>{
keybinding: keybindingItem ? keybindingItem.resolvedKeybinding : null,
keybindingItem: keybindingItem ? keybindingItem : new ResolvedKeybindingItem(null, command, null, null, true),
keybinding: keybindingItem.resolvedKeybinding,
keybindingItem,
command,
commandLabel: editorAction ? editorAction.label : workbenchAction ? workbenchAction.label : '',
commandDefaultLabel,
when: keybindingItem ? keybindingItem.when : null,
source: !keybindingItem || keybindingItem.isDefault ? KeybindingSource.Default : KeybindingSource.User
when: keybindingItem.when ? keybindingItem.when.serialize() : '',
source: keybindingItem.isDefault ? localize('default', "Default") : localize('user', "User")
};
}
}
......@@ -156,12 +166,16 @@ class KeybindingMatches {
public readonly commandIdMatches: IMatch[] = null;
public readonly commandLabelMatches: IMatch[] = null;
public readonly commandDefaultLabelMatches: IMatch[] = null;
public readonly sourceMatches: IMatch[] = null;
public readonly whenMatches: IMatch[] = null;
public readonly keybindingMatches: IMatch[] = null;
constructor(keybindingItem: IKeybindingItem, searchValue: string) {
this.commandIdMatches = this.matches(searchValue, keybindingItem.command, or(matchesWords, matchesCamelCase));
this.commandLabelMatches = keybindingItem.commandLabel ? this.matches(searchValue, keybindingItem.commandLabel, (word, wordToMatchAgainst) => matchesWords(word, keybindingItem.commandLabel, true)) : null;
this.commandDefaultLabelMatches = keybindingItem.commandDefaultLabel ? this.matches(searchValue, keybindingItem.commandDefaultLabel, (word, wordToMatchAgainst) => matchesWords(word, keybindingItem.commandDefaultLabel, true)) : null;
this.sourceMatches = this.matches(searchValue, keybindingItem.source, (word, wordToMatchAgainst) => matchesWords(word, keybindingItem.source, true));
this.whenMatches = keybindingItem.when ? this.matches(searchValue, keybindingItem.when, or(matchesWords, matchesCamelCase)) : null;
this.keybindingMatches = keybindingItem.keybinding ? this.keyMatches(searchValue, keybindingItem.keybinding.getAriaLabel(), or(matchesWords, matchesCamelCase)) : null;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册