Skip to content

Commit

Permalink
Back button constant (#49340)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Jun 19, 2018
1 parent 2afaa0d commit c361c4a
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/vs/platform/quickinput/common/quickInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ export interface IQuickInputService {
*/
input(options?: IInputOptions, token?: CancellationToken): TPromise<string>;

backButton: IQuickInputButton;

createQuickPick(): IQuickPick;
createInputBox(): IInputBox;

Expand All @@ -195,5 +197,7 @@ export interface IQuickInputService {

accept(): TPromise<void>;

back(): TPromise<void>;

cancel(): TPromise<void>;
}
6 changes: 4 additions & 2 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@ declare module 'vscode' {

export namespace window {

export const quickInputBackButton: QuickInputButton;

/**
* Implementation incomplete. See #49340.
*/
Expand Down Expand Up @@ -610,8 +612,8 @@ declare module 'vscode' {
}

export interface QuickInputButton {
iconPath: string | Uri | { light: string | Uri; dark: string | Uri } | ThemeIcon;
tooltip?: string | undefined;
readonly iconPath: string | Uri | { light: string | Uri; dark: string | Uri } | ThemeIcon;
readonly tooltip?: string | undefined;
}

//#endregion
Expand Down
18 changes: 12 additions & 6 deletions src/vs/workbench/api/electron-browser/mainThreadQuickOpen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,20 @@ export class MainThreadQuickOpen implements MainThreadQuickOpenShape {
session.hide();
}
} else if (param === 'buttons') {
params.buttons.forEach(button => {
const iconPath = button.iconPath;
iconPath.dark = URI.revive(iconPath.dark);
if (iconPath.light) {
iconPath.light = URI.revive(iconPath.light);
session[param] = params.buttons.map(button => {
if (button.handle === -1) {
return this._quickInputService.backButton;
}
const { iconPath, tooltip, handle } = button;
return {
iconPath: {
dark: URI.revive(iconPath.dark),
light: iconPath.light && URI.revive(iconPath.light)
},
tooltip,
handle
};
});
session[param] = params[param];
} else {
session[param] = params[param];
}
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/api/node/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ export function createApiFactory(
registerProtocolHandler: proposedApiFunction(extension, (handler: vscode.ProtocolHandler) => {
return extHostUrls.registerProtocolHandler(extension.id, handler);
}),
get quickInputBackButton() {
return proposedApiFunction(extension, (): vscode.QuickInputButton => {
return extHostQuickOpen.backButton;
})();
},
createQuickPick: proposedApiFunction(extension, (): vscode.QuickPick => {
return extHostQuickOpen.createQuickPick(extension.id);
}),
Expand Down
9 changes: 7 additions & 2 deletions src/vs/workbench/api/node/extHostQuickOpen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { ExtHostQuickOpenShape, IMainContext, MainContext, MainThreadQuickOpenSh
import URI from 'vs/base/common/uri';
import { ThemeIcon } from 'vs/workbench/api/node/extHostTypes';

const backButton: QuickInputButton = { iconPath: 'back.svg' };

export type Item = string | QuickPickItem;

export class ExtHostQuickOpen implements ExtHostQuickOpenShape {
Expand Down Expand Up @@ -151,6 +153,8 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {

// ---- QuickInput

backButton = backButton;

createQuickPick(extensionId: string): QuickPick {
const session = new ExtHostQuickPick(this._proxy, extensionId, () => this._sessions.delete(session._id));
this._sessions.set(session._id, session);
Expand Down Expand Up @@ -324,13 +328,14 @@ class ExtHostQuickInput implements QuickInput {
this._buttons = buttons;
this._handlesToButtons.clear();
buttons.forEach((button, i) => {
this._handlesToButtons.set(i, button);
const handle = button === backButton ? -1 : i;
this._handlesToButtons.set(handle, button);
});
this.update({
buttons: buttons.map<TransferQuickInputButton>((button, i) => ({
iconPath: getIconUris(button.iconPath),
tooltip: button.tooltip,
handle: i,
handle: button === backButton ? -1 : i,
}))
});
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
*--------------------------------------------------------------------------------------------*/
'use strict';

import { QuickPickManyToggle } from 'vs/workbench/browser/parts/quickinput/quickInput';
import { QuickPickManyToggle, BackAction } from 'vs/workbench/browser/parts/quickinput/quickInput';
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { Registry } from 'vs/platform/registry/common/platform';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { inQuickOpenContext } from 'vs/workbench/browser/parts/quickopen/quickopen';

KeybindingsRegistry.registerCommandAndKeybindingRule(QuickPickManyToggle);

const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
registry.registerWorkbenchAction(new SyncActionDescriptor(BackAction, BackAction.ID, BackAction.LABEL, { primary: null, win: { primary: KeyMod.Alt | KeyCode.LeftArrow }, mac: { primary: KeyMod.WinCtrl | KeyCode.US_MINUS }, linux: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.US_MINUS } }, inQuickOpenContext, KeybindingsRegistry.WEIGHT.workbenchContrib(50)), 'Back');
39 changes: 39 additions & 0 deletions src/vs/workbench/browser/parts/quickinput/quickInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ interface QuickInputUI {
progressBar: ProgressBar;
list: QuickInputList;
onDidAccept: Event<void>;
onDidTriggerButton: Event<IQuickInputButton>;
ignoreFocusOut: boolean;
show(controller: QuickInput): void;
setVisibilities(visibilities: Visibilities): void;
Expand Down Expand Up @@ -166,6 +167,13 @@ class QuickInput implements IQuickInput {
if (this.visible) {
return;
}
this.disposables.push(
this.ui.onDidTriggerButton(button => {
if (this.buttons.indexOf(button) !== -1) {
this.onDidTriggerButtonEmitter.fire(button);
}
}),
);
this.ui.show(this);
this.visible = true;
this.update();
Expand Down Expand Up @@ -642,6 +650,7 @@ export class QuickInputService extends Component implements IQuickInputService {
private inQuickOpenWidgets: Record<string, boolean> = {};
private inQuickOpenContext: IContextKey<boolean>;
private onDidAcceptEmitter = new Emitter<void>();
private onDidTriggerButtonEmitter = new Emitter<IQuickInputButton>();

private controller: QuickInput;

Expand Down Expand Up @@ -806,6 +815,7 @@ export class QuickInputService extends Component implements IQuickInputService {
progressBar,
list,
onDidAccept: this.onDidAcceptEmitter.event,
onDidTriggerButton: this.onDidTriggerButtonEmitter.event,
ignoreFocusOut: false,
show: controller => this.show(controller),
hide: () => this.hide(),
Expand Down Expand Up @@ -928,6 +938,15 @@ export class QuickInputService extends Component implements IQuickInputService {
});
}

backButton = {
iconPath: {
dark: URI.parse(require.toUrl('vs/workbench/browser/parts/quickinput/media/dark/back.svg')),
light: URI.parse(require.toUrl('vs/workbench/browser/parts/quickinput/media/light/back.svg'))
},
tooltip: localize('quickInput.back', "Back"),
handle: -1 // TODO
};

createQuickPick(): IQuickPick {
this.create();
return new QuickPick(this.ui);
Expand Down Expand Up @@ -1034,6 +1053,11 @@ export class QuickInputService extends Component implements IQuickInputService {
return TPromise.as(undefined);
}

back() {
this.onDidTriggerButtonEmitter.fire(this.backButton);
return TPromise.as(undefined);
}

cancel() {
this.hide();
return TPromise.as(undefined);
Expand Down Expand Up @@ -1111,3 +1135,18 @@ export const QuickPickManyToggle: ICommandAndKeybindingRule = {
quickInputService.toggle();
}
};

export class BackAction extends Action {

public static readonly ID = 'workbench.action.quickInputBack';
public static readonly LABEL = localize('back', "Back");

constructor(id: string, label: string, @IQuickInputService private quickInputService: IQuickInputService) {
super(id, label);
}

public run(): TPromise<any> {
this.quickInputService.back();
return TPromise.as(null);
}
}

0 comments on commit c361c4a

Please sign in to comment.