quickOpen.ts 5.0 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

J
Johannes Rieken 已提交
7
import { TPromise } from 'vs/base/common/winjs.base';
B
Benjamin Pasero 已提交
8
import uri from 'vs/base/common/uri';
B
Benjamin Pasero 已提交
9
import Event from 'vs/base/common/event';
J
Johannes Rieken 已提交
10 11 12
import { CancellationToken } from 'vs/base/common/cancellation';
import { IQuickNavigateConfiguration, IAutoFocus, IEntryRunContext } from 'vs/base/parts/quickopen/common/quickOpen';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
13
import { IAction } from "vs/base/common/actions";
14
import { FileKind } from "vs/platform/files/common/files";
E
Erich Gamma 已提交
15

B
Benjamin Pasero 已提交
16 17
export interface IFilePickOpenEntry extends IPickOpenEntry {
	resource: uri;
18
	fileKind?: FileKind;
B
Benjamin Pasero 已提交
19 20
}

21 22 23 24
export interface IPickOpenAction extends IAction {
	run(item: IPickOpenItem): TPromise<any>;
}

E
Erich Gamma 已提交
25 26 27 28
export interface IPickOpenEntry {
	id?: string;
	label: string;
	description?: string;
J
Johannes Rieken 已提交
29
	detail?: string;
B
Benjamin Pasero 已提交
30
	separator?: ISeparator;
31
	alwaysShow?: boolean;
32
	run?: (context: IEntryRunContext) => void;
33
	action?: IAction;
B
Benjamin Pasero 已提交
34 35
}

36 37 38 39 40
export interface IPickOpenItem {
	remove: () => void;
	getResource: () => uri;
}

B
Benjamin Pasero 已提交
41 42 43
export interface ISeparator {
	border?: boolean;
	label?: string;
E
Erich Gamma 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
}

export interface IPickOptions {

	/**
	 * an optional string to show as place holder in the input box to guide the user what she picks on
	 */
	placeHolder?: string;

	/**
	 * optional auto focus settings
	 */
	autoFocus?: IAutoFocus;

	/**
	 * an optional flag to include the description when filtering the picks
	 */
	matchOnDescription?: boolean;
62 63 64 65 66

	/**
	 * an optional flag to include the detail when filtering the picks
	 */
	matchOnDetail?: boolean;
67

68 69 70
	/**
	 * an optional flag to not close the picker on focus lost
	 */
71
	ignoreFocusLost?: boolean;
B
Benjamin Pasero 已提交
72 73 74 75 76

	/**
	 * enables quick navigate in the picker to open an element without typing
	 */
	quickNavigateConfiguration?: IQuickNavigateConfiguration;
77 78 79 80 81

	/**
	 * a context key to set when this picker is active
	 */
	contextKey?: string;
E
Erich Gamma 已提交
82 83 84 85 86 87 88 89 90
}

export interface IInputOptions {

	/**
	 * the value to prefill in the input box
	 */
	value?: string;

91
	/**
92
	 * the selection of value, default to the whole word
93
	 */
94
	valueSelection?: [number, number];
95

E
Erich Gamma 已提交
96 97 98 99 100 101 102 103 104 105 106 107 108 109
	/**
	 * the text to display underneath the input box
	 */
	prompt?: string;

	/**
	 * an optional string to show as place holder in the input box to guide the user what to type
	 */
	placeHolder?: string;

	/**
	 * set to true to show a password prompt that will not show the typed value
	 */
	password?: boolean;
110

111 112
	ignoreFocusLost?: boolean;

113 114 115 116
	/**
	 * an optional function that is used to validate user input.
	 */
	validateInput?: (input: string) => TPromise<string>;
E
Erich Gamma 已提交
117 118
}

B
Benjamin Pasero 已提交
119 120
export interface IShowOptions {
	quickNavigateConfiguration?: IQuickNavigateConfiguration;
121
	inputSelection?: { start: number; end: number; };
B
Benjamin Pasero 已提交
122 123
}

B
Benjamin Pasero 已提交
124
export const IQuickOpenService = createDecorator<IQuickOpenService>('quickOpenService');
E
Erich Gamma 已提交
125 126

export interface IQuickOpenService {
127 128

	_serviceBrand: any;
E
Erich Gamma 已提交
129 130 131 132 133 134 135 136

	/**
	 * Asks the container to show the quick open control with the optional prefix set. If the optional parameter
	 * is set for quick navigation mode, the quick open control will quickly navigate when the quick navigate
	 * key is pressed and will run the selection after the ctrl key is released.
	 *
	 * The returned promise completes when quick open is closing.
	 */
B
Benjamin Pasero 已提交
137
	show(prefix?: string, options?: IShowOptions): TPromise<void>;
E
Erich Gamma 已提交
138 139

	/**
140
	 * A convenient way to bring up quick open as a picker with custom elements. This bypasses the quick open handler
E
Erich Gamma 已提交
141 142 143 144 145
	 * registry and just leverages the quick open widget to select any kind of entries.
	 *
	 * Passing in a promise will allow you to resolve the elements in the background while quick open will show a
	 * progress bar spinning.
	 */
146 147 148 149
	pick(picks: TPromise<string[]>, options?: IPickOptions, token?: CancellationToken): TPromise<string>;
	pick<T extends IPickOpenEntry>(picks: TPromise<T[]>, options?: IPickOptions, token?: CancellationToken): TPromise<T>;
	pick(picks: string[], options?: IPickOptions, token?: CancellationToken): TPromise<string>;
	pick<T extends IPickOpenEntry>(picks: T[], options?: IPickOptions, token?: CancellationToken): TPromise<T>;
E
Erich Gamma 已提交
150 151

	/**
152
	 * Allows to navigate from the outside in an opened picker.
E
Erich Gamma 已提交
153
	 */
154
	navigate(next: boolean, quickNavigate?: IQuickNavigateConfiguration): void;
E
Erich Gamma 已提交
155 156 157 158

	/**
	 * Opens the quick open box for user input and returns a promise with the user typed value if any.
	 */
159
	input(options?: IInputOptions, token?: CancellationToken): TPromise<string>;
E
Erich Gamma 已提交
160

161 162 163 164 165 166 167 168 169 170
	/**
	 * Accepts the selected value in quick open if visible.
	 */
	accept(): void;

	/**
	 * Focus into the quick open if visible.
	 */
	focus(): void;

171 172 173 174 175
	/**
	 * Closes any opened quick open.
	 */
	close(): void;

E
Erich Gamma 已提交
176 177 178
	/**
	 * Allows to register on the event that quick open is showing
	 */
179
	onShow: Event<void>;
E
Erich Gamma 已提交
180 181 182 183

	/**
	 * Allows to register on the event that quick open is hiding
	 */
184
	onHide: Event<void>;
185
}