mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
Navigation and inQuickOpen context key (#49340)
This commit is contained in:
parent
4fa2030d41
commit
50cf92c2f9
|
@ -16,17 +16,19 @@ export interface IQuickInputService {
|
|||
_serviceBrand: any;
|
||||
|
||||
/**
|
||||
* WIP.
|
||||
* Opens the quick input box for selecting items and returns a promise with the user selected item(s) if any.
|
||||
*/
|
||||
pick<T extends IPickOpenEntry, O extends IPickOptions>(picks: TPromise<T[]>, options?: O, token?: CancellationToken): TPromise<O extends { canPickMany: true } ? T[] : T>;
|
||||
|
||||
/**
|
||||
* Opens the quick open box for user input and returns a promise with the user typed value if any.
|
||||
* Opens the quick input box for text input and returns a promise with the user typed value if any.
|
||||
*/
|
||||
input(options?: IInputOptions, token?: CancellationToken): TPromise<string>;
|
||||
|
||||
focus(): void;
|
||||
|
||||
navigate(next: boolean): void;
|
||||
|
||||
accept(): TPromise<void>;
|
||||
|
||||
cancel(): TPromise<void>;
|
||||
|
|
|
@ -34,6 +34,7 @@ import { dispose, IDisposable } from 'vs/base/common/lifecycle';
|
|||
import { onUnexpectedError, canceled } from 'vs/base/common/errors';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IContextKeyService, RawContextKey, IContextKey } from 'vs/platform/contextkey/common/contextkey';
|
||||
|
||||
const $ = dom.$;
|
||||
|
||||
|
@ -307,6 +308,8 @@ export class QuickInputService extends Component implements IQuickInputService {
|
|||
private ready = false;
|
||||
private progressBar: ProgressBar;
|
||||
private ignoreFocusLost = false;
|
||||
private inQuickOpenCount = 0;
|
||||
private inQuickOpenContext: IContextKey<boolean>;
|
||||
|
||||
private controller: InputController<any>;
|
||||
|
||||
|
@ -317,9 +320,22 @@ export class QuickInputService extends Component implements IQuickInputService {
|
|||
@IPartService private partService: IPartService,
|
||||
@IQuickOpenService private quickOpenService: IQuickOpenService,
|
||||
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
|
||||
@IContextKeyService contextKeyService: IContextKeyService,
|
||||
@IThemeService themeService: IThemeService
|
||||
) {
|
||||
super(QuickInputService.ID, themeService);
|
||||
this.inQuickOpenContext = new RawContextKey<boolean>('inQuickOpen', false).bindTo(contextKeyService);
|
||||
this.toUnbind.push(this.quickOpenService.onShow(() => this.inQuickOpen(true)));
|
||||
this.toUnbind.push(this.quickOpenService.onHide(() => this.inQuickOpen(false)));
|
||||
}
|
||||
|
||||
private inQuickOpen(open: boolean) {
|
||||
this.inQuickOpenCount += open ? 1 : -1;
|
||||
if (this.inQuickOpenCount) {
|
||||
this.inQuickOpenContext.set(true);
|
||||
} else {
|
||||
this.inQuickOpenContext.reset();
|
||||
}
|
||||
}
|
||||
|
||||
private create() {
|
||||
|
@ -449,7 +465,7 @@ export class QuickInputService extends Component implements IQuickInputService {
|
|||
}
|
||||
|
||||
private close(ok?: true | Thenable<never>, focusLost?: boolean) {
|
||||
if (!this.container || this.container.style.display === 'none') {
|
||||
if (!this.isDisplayed()) {
|
||||
return TPromise.as(undefined);
|
||||
}
|
||||
if (this.controller) {
|
||||
|
@ -457,6 +473,7 @@ export class QuickInputService extends Component implements IQuickInputService {
|
|||
if (resolved) {
|
||||
const result = resolved
|
||||
.then(() => {
|
||||
this.inQuickOpen(false);
|
||||
this.container.style.display = 'none';
|
||||
if (!focusLost) {
|
||||
this.restoreFocus();
|
||||
|
@ -466,6 +483,7 @@ export class QuickInputService extends Component implements IQuickInputService {
|
|||
return result;
|
||||
}
|
||||
}
|
||||
this.inQuickOpen(false);
|
||||
this.container.style.display = 'none';
|
||||
if (!focusLost) {
|
||||
this.restoreFocus();
|
||||
|
@ -529,6 +547,9 @@ export class QuickInputService extends Component implements IQuickInputService {
|
|||
this.ui.message.style.display = this.controller.showUI.message ? '' : 'none';
|
||||
this.ui.checkboxList.display(this.controller.showUI.checkboxList);
|
||||
|
||||
if (this.container.style.display === 'none') {
|
||||
this.inQuickOpen(true);
|
||||
}
|
||||
this.container.style.display = '';
|
||||
this.updateLayout();
|
||||
this.ui.inputBox.setFocus();
|
||||
|
@ -572,6 +593,12 @@ export class QuickInputService extends Component implements IQuickInputService {
|
|||
}
|
||||
}
|
||||
|
||||
navigate(next: boolean) {
|
||||
if (this.isDisplayed() && this.ui.checkboxList.isDisplayed()) {
|
||||
this.ui.checkboxList.focus(next ? 'Next' : 'Previous');
|
||||
}
|
||||
}
|
||||
|
||||
accept() {
|
||||
return this.close(true);
|
||||
}
|
||||
|
@ -617,4 +644,8 @@ export class QuickInputService extends Component implements IQuickInputService {
|
|||
this.container.style.boxShadow = widgetShadowColor ? `0 5px 8px ${widgetShadowColor}` : undefined;
|
||||
}
|
||||
}
|
||||
|
||||
private isDisplayed() {
|
||||
return this.container && this.container.style.display !== 'none';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,7 +93,6 @@ export class QuickOpenController extends Component implements IQuickOpenService
|
|||
private handlerOnOpenCalled: { [prefix: string]: boolean; };
|
||||
private currentResultToken: string;
|
||||
private currentPickerToken: string;
|
||||
private inQuickOpenMode: IContextKey<boolean>;
|
||||
private promisesToCompleteOnHide: ValueCallback[];
|
||||
private previousActiveHandlerDescriptor: QuickOpenHandlerDescriptor;
|
||||
private actionProvider = new ContributableActionProvider();
|
||||
|
@ -121,8 +120,6 @@ export class QuickOpenController extends Component implements IQuickOpenService
|
|||
|
||||
this.editorHistoryHandler = this.instantiationService.createInstance(EditorHistoryHandler);
|
||||
|
||||
this.inQuickOpenMode = new RawContextKey<boolean>('inQuickOpen', false).bindTo(contextKeyService);
|
||||
|
||||
this._onShow = new Emitter<void>();
|
||||
this._onHide = new Emitter<void>();
|
||||
|
||||
|
@ -557,7 +554,6 @@ export class QuickOpenController extends Component implements IQuickOpenService
|
|||
this.pickOpenWidget.hide(HideReason.FOCUS_LOST);
|
||||
}
|
||||
|
||||
this.inQuickOpenMode.set(true);
|
||||
this.emitQuickOpenVisibilityChange(true);
|
||||
}
|
||||
|
||||
|
@ -590,7 +586,6 @@ export class QuickOpenController extends Component implements IQuickOpenService
|
|||
}
|
||||
|
||||
// Reset context keys
|
||||
this.inQuickOpenMode.reset();
|
||||
this.resetQuickOpenContextKeys();
|
||||
|
||||
// Events
|
||||
|
|
|
@ -9,6 +9,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
|
|||
import * as nls from 'vs/nls';
|
||||
import { Action } from 'vs/base/common/actions';
|
||||
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
|
||||
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
|
||||
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { ICommandHandler, CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
|
@ -46,6 +47,7 @@ export class BaseQuickOpenNavigateAction extends Action {
|
|||
private next: boolean,
|
||||
private quickNavigate: boolean,
|
||||
@IQuickOpenService private quickOpenService: IQuickOpenService,
|
||||
@IQuickInputService private quickInputService: IQuickInputService,
|
||||
@IKeybindingService private keybindingService: IKeybindingService
|
||||
) {
|
||||
super(id, label);
|
||||
|
@ -56,6 +58,7 @@ export class BaseQuickOpenNavigateAction extends Action {
|
|||
const quickNavigate = this.quickNavigate ? { keybindings: keys } : void 0;
|
||||
|
||||
this.quickOpenService.navigate(this.next, quickNavigate);
|
||||
this.quickInputService.navigate(this.next);
|
||||
|
||||
return TPromise.as(true);
|
||||
}
|
||||
|
@ -65,11 +68,13 @@ export function getQuickNavigateHandler(id: string, next?: boolean): ICommandHan
|
|||
return accessor => {
|
||||
const keybindingService = accessor.get(IKeybindingService);
|
||||
const quickOpenService = accessor.get(IQuickOpenService);
|
||||
const quickInputService = accessor.get(IQuickInputService);
|
||||
|
||||
const keys = keybindingService.lookupKeybindings(id);
|
||||
const quickNavigate = { keybindings: keys };
|
||||
|
||||
quickOpenService.navigate(next, quickNavigate);
|
||||
quickInputService.navigate(next);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -82,9 +87,10 @@ export class QuickOpenNavigateNextAction extends BaseQuickOpenNavigateAction {
|
|||
id: string,
|
||||
label: string,
|
||||
@IQuickOpenService quickOpenService: IQuickOpenService,
|
||||
@IQuickInputService quickInputService: IQuickInputService,
|
||||
@IKeybindingService keybindingService: IKeybindingService
|
||||
) {
|
||||
super(id, label, true, true, quickOpenService, keybindingService);
|
||||
super(id, label, true, true, quickOpenService, quickInputService, keybindingService);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,9 +103,10 @@ export class QuickOpenNavigatePreviousAction extends BaseQuickOpenNavigateAction
|
|||
id: string,
|
||||
label: string,
|
||||
@IQuickOpenService quickOpenService: IQuickOpenService,
|
||||
@IQuickInputService quickInputService: IQuickInputService,
|
||||
@IKeybindingService keybindingService: IKeybindingService
|
||||
) {
|
||||
super(id, label, false, true, quickOpenService, keybindingService);
|
||||
super(id, label, false, true, quickOpenService, quickInputService, keybindingService);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,9 +119,10 @@ export class QuickOpenSelectNextAction extends BaseQuickOpenNavigateAction {
|
|||
id: string,
|
||||
label: string,
|
||||
@IQuickOpenService quickOpenService: IQuickOpenService,
|
||||
@IQuickInputService quickInputService: IQuickInputService,
|
||||
@IKeybindingService keybindingService: IKeybindingService
|
||||
) {
|
||||
super(id, label, true, false, quickOpenService, keybindingService);
|
||||
super(id, label, true, false, quickOpenService, quickInputService, keybindingService);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,8 +135,9 @@ export class QuickOpenSelectPreviousAction extends BaseQuickOpenNavigateAction {
|
|||
id: string,
|
||||
label: string,
|
||||
@IQuickOpenService quickOpenService: IQuickOpenService,
|
||||
@IQuickInputService quickInputService: IQuickInputService,
|
||||
@IKeybindingService keybindingService: IKeybindingService
|
||||
) {
|
||||
super(id, label, false, false, quickOpenService, keybindingService);
|
||||
super(id, label, false, false, quickOpenService, quickInputService, keybindingService);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue