mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
Streamline QuickInput API (#49340)
This commit is contained in:
@@ -819,7 +819,9 @@ export interface ExtHostQuickOpenShape {
|
||||
$onDidChangeActive(sessionId: number, handles: number[]): void;
|
||||
$onDidChangeSelection(sessionId: number, handles: number[]): void;
|
||||
$onDidAccept(sessionId: number): void;
|
||||
$onDidChangeValue(sessionId: number, value: string): void;
|
||||
$onDidTriggerButton(sessionId: number, handle: number): void;
|
||||
$onDidHide(sessionId: number): void;
|
||||
}
|
||||
|
||||
export interface ShellLaunchConfigDto {
|
||||
|
||||
@@ -8,7 +8,6 @@ import { asWinJsPromise, wireCancellationToken } from 'vs/base/common/async';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { assign } from 'vs/base/common/objects';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { ExtHostCommands } from 'vs/workbench/api/node/extHostCommands';
|
||||
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
|
||||
@@ -164,9 +163,16 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {
|
||||
return session;
|
||||
}
|
||||
|
||||
$onDidChangeValue(sessionId: number, value: string): void {
|
||||
const session = this._sessions.get(sessionId);
|
||||
if (session) {
|
||||
session._fireDidChangeValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
$onDidAccept(sessionId: number): void {
|
||||
const session = this._sessions.get(sessionId);
|
||||
if (session instanceof ExtHostQuickPick) {
|
||||
if (session) {
|
||||
session._fireDidAccept();
|
||||
}
|
||||
}
|
||||
@@ -174,7 +180,7 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {
|
||||
$onDidChangeActive(sessionId: number, handles: number[]): void {
|
||||
const session = this._sessions.get(sessionId);
|
||||
if (session instanceof ExtHostQuickPick) {
|
||||
session._fireDidChangeFocus(handles);
|
||||
session._fireDidChangeActive(handles);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,6 +197,13 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {
|
||||
session._fireDidTriggerButton(handle);
|
||||
}
|
||||
}
|
||||
|
||||
$onDidHide(sessionId: number): void {
|
||||
const session = this._sessions.get(sessionId);
|
||||
if (session) {
|
||||
session._fireDidHide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ExtHostQuickInput implements QuickInput {
|
||||
@@ -202,8 +215,12 @@ class ExtHostQuickInput implements QuickInput {
|
||||
private _enabled = true;
|
||||
private _busy = false;
|
||||
private _ignoreFocusOut = true;
|
||||
private _value = '';
|
||||
private _placeholder: string;
|
||||
private _buttons: QuickInputButton[] = [];
|
||||
private _handlesToButtons = new Map<number, QuickInputButton>();
|
||||
private _onDidAcceptEmitter = new Emitter<void>();
|
||||
private _onDidChangeValueEmitter = new Emitter<string>();
|
||||
private _onDidTriggerButtonEmitter = new Emitter<QuickInputButton>();
|
||||
private _onDidHideEmitter = new Emitter<void>();
|
||||
private _updateTimeout: number;
|
||||
@@ -213,6 +230,8 @@ class ExtHostQuickInput implements QuickInput {
|
||||
protected _disposables: IDisposable[] = [
|
||||
this._onDidTriggerButtonEmitter,
|
||||
this._onDidHideEmitter,
|
||||
this._onDidAcceptEmitter,
|
||||
this._onDidChangeValueEmitter
|
||||
];
|
||||
|
||||
constructor(protected _proxy: MainThreadQuickOpenShape, protected _extensionId: string, private _onDidDispose: () => void) {
|
||||
@@ -245,6 +264,28 @@ class ExtHostQuickInput implements QuickInput {
|
||||
this.update({ ignoreFocusOut });
|
||||
}
|
||||
|
||||
get value() {
|
||||
return this._value;
|
||||
}
|
||||
|
||||
set value(value: string) {
|
||||
this._value = value;
|
||||
this.update({ value });
|
||||
}
|
||||
|
||||
get placeholder() {
|
||||
return this._placeholder;
|
||||
}
|
||||
|
||||
set placeholder(placeholder: string) {
|
||||
this._placeholder = placeholder;
|
||||
this.update({ placeholder });
|
||||
}
|
||||
|
||||
onDidChangeValue = this._onDidChangeValueEmitter.event;
|
||||
|
||||
onDidAccept = this._onDidAcceptEmitter.event;
|
||||
|
||||
get buttons() {
|
||||
return this._buttons;
|
||||
}
|
||||
@@ -278,36 +319,53 @@ class ExtHostQuickInput implements QuickInput {
|
||||
|
||||
onDidHide = this._onDidHideEmitter.event;
|
||||
|
||||
_fireDidAccept() {
|
||||
this._onDidAcceptEmitter.fire();
|
||||
}
|
||||
|
||||
_fireDidChangeValue(value) {
|
||||
this._value = value;
|
||||
this._onDidChangeValueEmitter.fire(value);
|
||||
}
|
||||
|
||||
_fireDidTriggerButton(handle: number) {
|
||||
const button = this._handlesToButtons.get(handle);
|
||||
this._onDidTriggerButtonEmitter.fire(button);
|
||||
}
|
||||
|
||||
_fireDidHide() {
|
||||
this._onDidHideEmitter.fire();
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
if (this._disposed) {
|
||||
return;
|
||||
}
|
||||
this._disposed = true;
|
||||
this._fireDidHide();
|
||||
this._disposables = dispose(this._disposables);
|
||||
if (this._updateTimeout) {
|
||||
clearTimeout(this._updateTimeout);
|
||||
this._updateTimeout = undefined;
|
||||
}
|
||||
this._proxy.$dispose(this._id);
|
||||
this._onDidDispose();
|
||||
this._proxy.$dispose(this._id);
|
||||
}
|
||||
|
||||
protected update(properties: Record<string, any>): void {
|
||||
if (this._disposed) {
|
||||
return;
|
||||
}
|
||||
assign(this._pendingUpdate, properties);
|
||||
for (const key of Object.keys(properties)) {
|
||||
const value = properties[key];
|
||||
this._pendingUpdate[key] = value === undefined ? null : value;
|
||||
}
|
||||
|
||||
if (!this._visible) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (properties.visible) {
|
||||
if ('visible' in this._pendingUpdate) {
|
||||
if (this._updateTimeout) {
|
||||
clearTimeout(this._updateTimeout);
|
||||
this._updateTimeout = undefined;
|
||||
@@ -360,16 +418,12 @@ function getIconUri(iconPath: string | URI) {
|
||||
|
||||
class ExtHostQuickPick extends ExtHostQuickInput implements QuickPick {
|
||||
|
||||
private _value = '';
|
||||
private _placeholder: string;
|
||||
private _onDidChangeValueEmitter = new Emitter<string>();
|
||||
private _onDidAcceptEmitter = new Emitter<void>();
|
||||
private _items: QuickPickItem[] = [];
|
||||
private _handlesToItems = new Map<number, QuickPickItem>();
|
||||
private _canSelectMany = false;
|
||||
private _matchOnDescription = true;
|
||||
private _matchOnDetail = true;
|
||||
private _focusedItems: QuickPickItem[] = [];
|
||||
private _activeItems: QuickPickItem[] = [];
|
||||
private _onDidChangeActiveEmitter = new Emitter<QuickPickItem[]>();
|
||||
private _selectedItems: QuickPickItem[] = [];
|
||||
private _onDidChangeSelectionEmitter = new Emitter<QuickPickItem[]>();
|
||||
@@ -377,36 +431,12 @@ class ExtHostQuickPick extends ExtHostQuickInput implements QuickPick {
|
||||
constructor(proxy: MainThreadQuickOpenShape, extensionId: string, onDispose: () => void) {
|
||||
super(proxy, extensionId, onDispose);
|
||||
this._disposables.push(
|
||||
this._onDidChangeValueEmitter,
|
||||
this._onDidAcceptEmitter,
|
||||
this._onDidChangeActiveEmitter,
|
||||
this._onDidChangeSelectionEmitter,
|
||||
);
|
||||
this.update({ type: 'quickPick' });
|
||||
}
|
||||
|
||||
get value() {
|
||||
return this._value;
|
||||
}
|
||||
|
||||
set value(value: string) {
|
||||
this._value = value;
|
||||
this.update({ value });
|
||||
}
|
||||
|
||||
get placeholder() {
|
||||
return this._placeholder;
|
||||
}
|
||||
|
||||
set placeholder(placeholder: string) {
|
||||
this._placeholder = placeholder;
|
||||
this.update({ placeholder });
|
||||
}
|
||||
|
||||
onDidChangeValue = this._onDidChangeValueEmitter.event;
|
||||
|
||||
onDidAccept = this._onDidAcceptEmitter.event;
|
||||
|
||||
get items() {
|
||||
return this._items;
|
||||
}
|
||||
@@ -456,7 +486,7 @@ class ExtHostQuickPick extends ExtHostQuickInput implements QuickPick {
|
||||
}
|
||||
|
||||
get activeItems() {
|
||||
return this._focusedItems;
|
||||
return this._activeItems;
|
||||
}
|
||||
|
||||
onDidChangeActive = this._onDidChangeActiveEmitter.event;
|
||||
@@ -467,13 +497,9 @@ class ExtHostQuickPick extends ExtHostQuickInput implements QuickPick {
|
||||
|
||||
onDidChangeSelection = this._onDidChangeSelectionEmitter.event;
|
||||
|
||||
_fireDidAccept() {
|
||||
this._onDidAcceptEmitter.fire();
|
||||
}
|
||||
|
||||
_fireDidChangeFocus(handles: number[]) {
|
||||
_fireDidChangeActive(handles: number[]) {
|
||||
const items = handles.map(handle => this._handlesToItems.get(handle));
|
||||
this._focusedItems = items;
|
||||
this._activeItems = items;
|
||||
this._onDidChangeActiveEmitter.fire(items);
|
||||
}
|
||||
|
||||
@@ -486,41 +512,15 @@ class ExtHostQuickPick extends ExtHostQuickInput implements QuickPick {
|
||||
|
||||
class ExtHostInputBox extends ExtHostQuickInput implements InputBox {
|
||||
|
||||
private _value = '';
|
||||
private _placeholder: string;
|
||||
private _password: boolean;
|
||||
private _prompt: string;
|
||||
private _validationMessage: string;
|
||||
private _onDidChangeValueEmitter = new Emitter<string>();
|
||||
private _onDidAcceptEmitter = new Emitter<string>();
|
||||
|
||||
constructor(proxy: MainThreadQuickOpenShape, extensionId: string, onDispose: () => void) {
|
||||
super(proxy, extensionId, onDispose);
|
||||
this._disposables.push(
|
||||
this._onDidChangeValueEmitter,
|
||||
this._onDidAcceptEmitter,
|
||||
);
|
||||
this.update({ type: 'inputBox' });
|
||||
}
|
||||
|
||||
get value() {
|
||||
return this._value;
|
||||
}
|
||||
|
||||
set value(value: string) {
|
||||
this._value = value;
|
||||
this.update({ value });
|
||||
}
|
||||
|
||||
get placeholder() {
|
||||
return this._placeholder;
|
||||
}
|
||||
|
||||
set placeholder(placeholder: string) {
|
||||
this._placeholder = placeholder;
|
||||
this.update({ placeholder });
|
||||
}
|
||||
|
||||
get password() {
|
||||
return this._password;
|
||||
}
|
||||
@@ -547,8 +547,4 @@ class ExtHostInputBox extends ExtHostQuickInput implements InputBox {
|
||||
this._validationMessage = validationMessage;
|
||||
this.update({ validationMessage });
|
||||
}
|
||||
|
||||
onDidChangeValue = this._onDidChangeValueEmitter.event;
|
||||
|
||||
onDidAccept = this._onDidAcceptEmitter.event;
|
||||
}
|
||||
Reference in New Issue
Block a user