Skip to content

Commit

Permalink
Navigation and inQuickOpen context key (#49340)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed May 8, 2018
1 parent 4fa2030 commit 50cf92c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/vs/platform/quickinput/common/quickInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
33 changes: 32 additions & 1 deletion src/vs/workbench/browser/parts/quickinput/quickInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.$;

Expand Down Expand Up @@ -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>;

Expand All @@ -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() {
Expand Down Expand Up @@ -449,14 +465,15 @@ 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) {
const resolved = this.controller.resolve(ok);
if (resolved) {
const result = resolved
.then(() => {
this.inQuickOpen(false);
this.container.style.display = 'none';
if (!focusLost) {
this.restoreFocus();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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>();

Expand Down Expand Up @@ -557,7 +554,6 @@ export class QuickOpenController extends Component implements IQuickOpenService
this.pickOpenWidget.hide(HideReason.FOCUS_LOST);
}

this.inQuickOpenMode.set(true);
this.emitQuickOpenVisibilityChange(true);
}

Expand Down Expand Up @@ -590,7 +586,6 @@ export class QuickOpenController extends Component implements IQuickOpenService
}

// Reset context keys
this.inQuickOpenMode.reset();
this.resetQuickOpenContextKeys();

// Events
Expand Down
17 changes: 13 additions & 4 deletions src/vs/workbench/browser/parts/quickopen/quickopen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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);
};
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

0 comments on commit 50cf92c

Please sign in to comment.