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

#17468 Make start search action an editor command

上级 8a41bdb7
......@@ -15,7 +15,7 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { DefaultPreferencesEditor, DefaultPreferencesEditorInput } from 'vs/workbench/parts/preferences/browser/preferencesEditor';
import { OpenGlobalSettingsAction, OpenGlobalKeybindingsAction, OpenWorkspaceSettingsAction, StartSearchDefaultSettingsAction } from 'vs/workbench/parts/preferences/browser/preferencesActions';
import { OpenGlobalSettingsAction, OpenGlobalKeybindingsAction, OpenWorkspaceSettingsAction } from 'vs/workbench/parts/preferences/browser/preferencesActions';
import { IPreferencesService, CONTEXT_DEFAULT_SETTINGS_EDITOR, DEFAULT_EDITOR_COMMAND_COLLAPSE_ALL } from 'vs/workbench/parts/preferences/common/preferences';
import { PreferencesService } from 'vs/workbench/parts/preferences/browser/preferencesService';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
......@@ -68,7 +68,6 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(OpenGlobalSettingsActi
}), 'Preferences: Open User 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(OpenWorkspaceSettingsAction, OpenWorkspaceSettingsAction.ID, OpenWorkspaceSettingsAction.LABEL), 'Preferences: Open Workspace Settings', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(StartSearchDefaultSettingsAction, StartSearchDefaultSettingsAction.ID, '', { primary: KeyMod.CtrlCmd | KeyCode.KEY_F }, ContextKeyExpr.and(CONTEXT_DEFAULT_SETTINGS_EDITOR)), '');
MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
command: {
......
......@@ -8,9 +8,6 @@ import { TPromise } from 'vs/base/common/winjs.base';
import * as nls from 'vs/nls';
import { Action } from 'vs/base/common/actions';
import { IPreferencesService } from 'vs/workbench/parts/preferences/common/preferences';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { SideBySideEditor } from 'vs/workbench/browser/parts/editor/sideBySideEditor';
import { DefaultPreferencesEditor } from 'vs/workbench/parts/preferences/browser/preferencesEditor';
export class OpenGlobalSettingsAction extends Action {
......@@ -65,40 +62,3 @@ export class OpenWorkspaceSettingsAction extends Action {
return this.preferencesService.openWorkspaceSettings();
}
}
\ No newline at end of file
export class StartSearchDefaultSettingsAction extends Action {
public static ID = 'defaultSettings.action.focusSearch';
public static LABEL = nls.localize('startSearchDefaultSettings', "Focus Default Settings Search");
constructor(
id: string,
label: string,
@IWorkbenchEditorService private workbenchEditorService: IWorkbenchEditorService
) {
super(id, label);
}
get enabled(): boolean {
return this.getDefaultPreferencesEditor() !== null;
}
public run(event?: any): TPromise<void> {
const defaultPreferencesEditor = this.getDefaultPreferencesEditor();
if (defaultPreferencesEditor) {
defaultPreferencesEditor.focus();
}
return TPromise.as(null);
}
private getDefaultPreferencesEditor(): DefaultPreferencesEditor {
const activeEditor = this.workbenchEditorService.getActiveEditor();
if (activeEditor instanceof SideBySideEditor) {
const detailsEditor = activeEditor.getDetailsEditor();
if (detailsEditor instanceof DefaultPreferencesEditor) {
return detailsEditor;
}
}
return null;
}
}
\ No newline at end of file
......@@ -16,8 +16,10 @@ import { IAction } from 'vs/base/common/actions';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
import Event, { Emitter } from 'vs/base/common/event';
import { LinkedMap as Map } from 'vs/base/common/map';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { Registry } from 'vs/platform/platform';
import { EditorOptions, EditorInput } from 'vs/workbench/common/editor';
import { SideBySideEditor } from 'vs/workbench/browser/parts/editor/sideBySideEditor';
import { ResourceEditorModel } from 'vs/workbench/common/editor/resourceEditorModel';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'vs/platform/configuration/common/configurationRegistry';
......@@ -25,10 +27,10 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor';
import { CodeEditor } from 'vs/editor/browser/codeEditor';
import { Range } from 'vs/editor/common/core/range';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import {
IPreferencesService, ISettingsGroup, ISetting, IPreferencesEditorModel, IFilterResult, CONTEXT_DEFAULT_SETTINGS_EDITOR,
DEFAULT_EDITOR_COMMAND_COLLAPSE_ALL
DEFAULT_EDITOR_COMMAND_COLLAPSE_ALL, DEFAULT_EDITOR_COMMAND_FOCUS_SEARCH
} from 'vs/workbench/parts/preferences/common/preferences';
import { SettingsEditorModel, DefaultSettingsEditorModel } from 'vs/workbench/parts/preferences/common/preferencesModels';
import { editorContribution } from 'vs/editor/browser/editorBrowserExtensions';
......@@ -36,7 +38,7 @@ import { ICodeEditor, IEditorMouseEvent, IEditorContributionCtor } from 'vs/edit
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { DefaultSettingsHeaderWidget, SettingsGroupTitleWidget, SettingsCountWidget } from 'vs/workbench/parts/preferences/browser/preferencesWidgets';
import { IContextKeyService, IContextKey, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { CommonEditorRegistry, EditorCommand } from 'vs/editor/common/editorCommonExtensions';
import { CommonEditorRegistry, EditorCommand, Command } from 'vs/editor/common/editorCommonExtensions';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IThemeService } from 'vs/workbench/services/themes/common/themeService';
import { IModelService } from 'vs/editor/common/services/modelService';
......@@ -908,3 +910,30 @@ CommonEditorRegistry.registerEditorCommand(new DefaultSettingsEditorCommand({
precondition: ContextKeyExpr.and(CONTEXT_DEFAULT_SETTINGS_EDITOR),
handler: x => (<DefaultSettingsRenderer>x.getPreferencesRenderer()).collapseAll()
}));
class StartSearchDefaultSettingsCommand extends Command {
public runCommand(accessor: ServicesAccessor, args: any): void {
const defaultPreferencesEditor = this.getDefaultPreferencesEditor(accessor);
if (defaultPreferencesEditor) {
defaultPreferencesEditor.focus();
}
}
private getDefaultPreferencesEditor(accessor: ServicesAccessor): DefaultPreferencesEditor {
const activeEditor = accessor.get(IWorkbenchEditorService).getActiveEditor();
if (activeEditor instanceof SideBySideEditor) {
const detailsEditor = activeEditor.getDetailsEditor();
if (detailsEditor instanceof DefaultPreferencesEditor) {
return detailsEditor;
}
}
return null;
}
}
CommonEditorRegistry.registerEditorCommand(new StartSearchDefaultSettingsCommand({
id: DEFAULT_EDITOR_COMMAND_FOCUS_SEARCH,
precondition: ContextKeyExpr.and(CONTEXT_DEFAULT_SETTINGS_EDITOR),
kbOpts: { primary: KeyMod.CtrlCmd | KeyCode.KEY_F }
}));
\ No newline at end of file
......@@ -72,3 +72,4 @@ export interface IPreferencesService {
export const CONTEXT_DEFAULT_SETTINGS_EDITOR = new RawContextKey<boolean>('defaultSettingsEditor', false);
export const DEFAULT_EDITOR_COMMAND_COLLAPSE_ALL = 'defaultSettingsEditor.action.collapseAllGroups';
export const DEFAULT_EDITOR_COMMAND_FOCUS_SEARCH = 'defaultSettings.action.focusSearch';
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册