quickopen.contribution.ts 7.3 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
5

6 7
import * as env from 'vs/base/common/platform';
import * as nls from 'vs/nls';
J
Johannes Rieken 已提交
8
import { QuickOpenHandlerDescriptor, IQuickOpenRegistry, Extensions as QuickOpenExtensions } from 'vs/workbench/browser/quickopen';
9
import { Registry } from 'vs/platform/registry/common/platform';
10
import { SyncActionDescriptor, MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
B
Benjamin Pasero 已提交
11
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
J
Johannes Rieken 已提交
12
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
13 14 15 16 17
import { GotoSymbolAction, GOTO_SYMBOL_PREFIX, SCOPE_PREFIX, GotoSymbolHandler } from 'vs/workbench/parts/quickopen/browser/gotoSymbolHandler';
import { ShowAllCommandsAction, ALL_COMMANDS_PREFIX, ClearCommandHistoryAction, CommandsHandler } from 'vs/workbench/parts/quickopen/browser/commandsHandler';
import { GotoLineAction, GOTO_LINE_PREFIX, GotoLineHandler } from 'vs/workbench/parts/quickopen/browser/gotoLineHandler';
import { HELP_PREFIX, HelpHandler } from 'vs/workbench/parts/quickopen/browser/helpHandler';
import { VIEW_PICKER_PREFIX, OpenViewPickerAction, QuickOpenViewPickerAction, ViewPickerHandler } from 'vs/workbench/parts/quickopen/browser/viewPickerHandler';
B
Benjamin Pasero 已提交
18 19
import { inQuickOpenContext, getQuickNavigateHandler } from 'vs/workbench/browser/parts/quickopen/quickopen';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
20
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
21 22

// Register Actions
23
const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
24
registry.registerWorkbenchAction(new SyncActionDescriptor(ClearCommandHistoryAction, ClearCommandHistoryAction.ID, ClearCommandHistoryAction.LABEL), 'Clear Command History');
25 26 27
registry.registerWorkbenchAction(new SyncActionDescriptor(ShowAllCommandsAction, ShowAllCommandsAction.ID, ShowAllCommandsAction.LABEL, {
	primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_P,
	secondary: [KeyCode.F1]
28
}), 'Show All Commands');
29 30 31 32

registry.registerWorkbenchAction(new SyncActionDescriptor(GotoLineAction, GotoLineAction.ID, GotoLineAction.LABEL, {
	primary: KeyMod.CtrlCmd | KeyCode.KEY_G,
	mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_G }
33
}), 'Go to Line...');
34 35 36

registry.registerWorkbenchAction(new SyncActionDescriptor(GotoSymbolAction, GotoSymbolAction.ID, GotoSymbolAction.LABEL, {
	primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_O
37
}), 'Go to Symbol in File...');
38

39 40 41
const inViewsPickerContextKey = 'inViewsPicker';
const inViewsPickerContext = ContextKeyExpr.and(inQuickOpenContext, ContextKeyExpr.has(inViewsPickerContextKey));

A
Alex Dima 已提交
42
const viewPickerKeybinding = { primary: KeyMod.CtrlCmd | KeyCode.KEY_Q, mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_Q }, linux: { primary: 0 } };
43

44 45 46
const viewCategory = nls.localize('view', "View");
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenViewPickerAction, OpenViewPickerAction.ID, OpenViewPickerAction.LABEL), 'View: Open View', viewCategory);
registry.registerWorkbenchAction(new SyncActionDescriptor(QuickOpenViewPickerAction, QuickOpenViewPickerAction.ID, QuickOpenViewPickerAction.LABEL, viewPickerKeybinding), 'View: Quick Open View', viewCategory);
47 48 49 50

const quickOpenNavigateNextInViewPickerId = 'workbench.action.quickOpenNavigateNextInViewPicker';
KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: quickOpenNavigateNextInViewPickerId,
51
	weight: KeybindingWeight.WorkbenchContrib + 50,
52 53 54 55 56 57 58 59 60 61
	handler: getQuickNavigateHandler(quickOpenNavigateNextInViewPickerId, true),
	when: inViewsPickerContext,
	primary: viewPickerKeybinding.primary,
	linux: viewPickerKeybinding.linux,
	mac: viewPickerKeybinding.mac
});

const quickOpenNavigatePreviousInViewPickerId = 'workbench.action.quickOpenNavigatePreviousInViewPicker';
KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: quickOpenNavigatePreviousInViewPickerId,
62
	weight: KeybindingWeight.WorkbenchContrib + 50,
63 64 65 66 67 68 69 70
	handler: getQuickNavigateHandler(quickOpenNavigatePreviousInViewPickerId, false),
	when: inViewsPickerContext,
	primary: viewPickerKeybinding.primary | KeyMod.Shift,
	linux: viewPickerKeybinding.linux,
	mac: {
		primary: viewPickerKeybinding.mac.primary | KeyMod.Shift
	}
});
B
Benjamin Pasero 已提交
71

72 73
// Register Quick Open Handler

B
Benjamin Pasero 已提交
74
Registry.as<IQuickOpenRegistry>(QuickOpenExtensions.Quickopen).registerQuickOpenHandler(
75
	new QuickOpenHandlerDescriptor(
76 77
		CommandsHandler,
		CommandsHandler.ID,
78
		ALL_COMMANDS_PREFIX,
79
		'inCommandsPicker',
80 81 82 83
		nls.localize('commandsHandlerDescriptionDefault', "Show and Run Commands")
	)
);

B
Benjamin Pasero 已提交
84
Registry.as<IQuickOpenRegistry>(QuickOpenExtensions.Quickopen).registerQuickOpenHandler(
85
	new QuickOpenHandlerDescriptor(
86 87
		GotoLineHandler,
		GotoLineHandler.ID,
88
		GOTO_LINE_PREFIX,
89
		undefined,
90 91 92 93 94 95 96 97 98 99
		[
			{
				prefix: GOTO_LINE_PREFIX,
				needsEditor: true,
				description: env.isMacintosh ? nls.localize('gotoLineDescriptionMac', "Go to Line") : nls.localize('gotoLineDescriptionWin', "Go to Line")
			},
		]
	)
);

B
Benjamin Pasero 已提交
100
Registry.as<IQuickOpenRegistry>(QuickOpenExtensions.Quickopen).registerQuickOpenHandler(
101
	new QuickOpenHandlerDescriptor(
102 103
		GotoSymbolHandler,
		GotoSymbolHandler.ID,
104
		GOTO_SYMBOL_PREFIX,
105
		'inFileSymbolsPicker',
106 107 108 109
		[
			{
				prefix: GOTO_SYMBOL_PREFIX,
				needsEditor: true,
110
				description: nls.localize('gotoSymbolDescription', "Go to Symbol in File")
111 112 113 114
			},
			{
				prefix: GOTO_SYMBOL_PREFIX + SCOPE_PREFIX,
				needsEditor: true,
115
				description: nls.localize('gotoSymbolDescriptionScoped', "Go to Symbol in File by Category")
116 117 118 119 120
			}
		]
	)
);

B
Benjamin Pasero 已提交
121
Registry.as<IQuickOpenRegistry>(QuickOpenExtensions.Quickopen).registerQuickOpenHandler(
122
	new QuickOpenHandlerDescriptor(
123 124
		HelpHandler,
		HelpHandler.ID,
125
		HELP_PREFIX,
126
		undefined,
127 128
		nls.localize('helpDescription', "Show Help")
	)
B
Benjamin Pasero 已提交
129 130 131 132
);

Registry.as<IQuickOpenRegistry>(QuickOpenExtensions.Quickopen).registerQuickOpenHandler(
	new QuickOpenHandlerDescriptor(
133 134
		ViewPickerHandler,
		ViewPickerHandler.ID,
B
Benjamin Pasero 已提交
135
		VIEW_PICKER_PREFIX,
136
		inViewsPickerContextKey,
B
Benjamin Pasero 已提交
137 138 139 140 141 142 143 144
		[
			{
				prefix: VIEW_PICKER_PREFIX,
				needsEditor: false,
				description: nls.localize('viewPickerDescription', "Open View")
			}
		]
	)
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
);

// View menu

MenuRegistry.appendMenuItem(MenuId.MenubarViewMenu, {
	group: '1_open',
	command: {
		id: ShowAllCommandsAction.ID,
		title: nls.localize({ key: 'miCommandPalette', comment: ['&& denotes a mnemonic'] }, "&&Command Palette...")
	},
	order: 1
});

MenuRegistry.appendMenuItem(MenuId.MenubarViewMenu, {
	group: '1_open',
	command: {
		id: OpenViewPickerAction.ID,
		title: nls.localize({ key: 'miOpenView', comment: ['&& denotes a mnemonic'] }, "&&Open View...")
	},
	order: 2
});
166 167 168 169

// Go to menu

MenuRegistry.appendMenuItem(MenuId.MenubarGoMenu, {
170
	group: '4_symbol_nav',
171 172 173 174
	command: {
		id: 'workbench.action.gotoSymbol',
		title: nls.localize({ key: 'miGotoSymbolInFile', comment: ['&& denotes a mnemonic'] }, "Go to &&Symbol in File...")
	},
175
	order: 1
176 177 178
});

MenuRegistry.appendMenuItem(MenuId.MenubarGoMenu, {
179
	group: '5_infile_nav',
180 181
	command: {
		id: 'workbench.action.gotoLine',
182
		title: nls.localize({ key: 'miGotoLine', comment: ['&& denotes a mnemonic'] }, "Go to &&Line/Column...")
183
	},
184
	order: 1
185
});