Skip to content

Commit

Permalink
finalize quickpick APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerLeonhardt committed Nov 9, 2021
1 parent 5fa4c88 commit f8ed49c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 38 deletions.
32 changes: 32 additions & 0 deletions src/vs/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,12 @@ declare module 'vscode' {
* Always show this item.
*/
alwaysShow?: boolean;

/**
* Optional buttons that will be rendered on this particular item. These buttons will trigger
* an {@link QuickPickItemButtonEvent} when clicked.
*/
readonly buttons?: QuickInputButton[];
}

/**
Expand Down Expand Up @@ -10199,6 +10205,12 @@ declare module 'vscode' {
*/
readonly onDidTriggerButton: Event<QuickInputButton>;

/**
* An event signaling when a button in a particular {@link QuickPickItem} was triggered.
* This event does not fire for buttons in the title bar.
*/
readonly onDidTriggerItemButton: Event<QuickPickItemButtonEvent<T>>;

/**
* Items to pick from. This can be read and updated by the extension.
*/
Expand All @@ -10219,6 +10231,11 @@ declare module 'vscode' {
*/
matchOnDetail: boolean;

/*
* An optional flag to maintain the scroll position of the quick pick when the quick pick items are updated. Defaults to false.
*/
keepScrollPosition?: boolean;

/**
* Active items. This can be read and updated by the extension.
*/
Expand Down Expand Up @@ -10330,6 +10347,21 @@ declare module 'vscode' {
private constructor();
}

/**
* An event signaling when a button in a particular {@link QuickPickItem} was triggered.
* This event does not fire for buttons in the title bar.
*/
export interface QuickPickItemButtonEvent<T extends QuickPickItem> {
/**
* The button that was clicked.
*/
readonly button: QuickInputButton;
/**
* The item that the button belongs to.
*/
readonly item: T;
}

/**
* An event describing an individual change in the text of a {@link TextDocument document}.
*/
Expand Down
26 changes: 0 additions & 26 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1120,18 +1120,6 @@ declare module 'vscode' {

//#endregion

//#region https://github.com/microsoft/vscode/issues/132068

export interface QuickPick<T extends QuickPickItem> extends QuickInput {

/*
* An optional flag to maintain the scroll position of the quick pick when the quick pick items are updated. Defaults to false.
*/
keepScrollPosition?: boolean;
}

//#endregion

//#region https://github.com/microsoft/vscode/issues/124970, Cell Execution State

/**
Expand Down Expand Up @@ -2803,20 +2791,6 @@ declare module 'vscode' {

//#endregion

//#region https://github.com/microsoft/vscode/issues/88716
export interface QuickPickItem {
buttons?: QuickInputButton[];
}
export interface QuickPick<T extends QuickPickItem> extends QuickInput {
readonly onDidTriggerItemButton: Event<QuickPickItemButtonEvent<T>>;
}
export interface QuickPickItemButtonEvent<T extends QuickPickItem> {
button: QuickInputButton;
item: T;
}

//#endregion

//#region @eamodio https://github.com/microsoft/vscode/issues/133935

export interface SourceControl {
Expand Down
21 changes: 9 additions & 12 deletions src/vs/workbench/api/common/extHostQuickOpen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export function createExtHostQuickOpen(mainContext: IMainContext, workspace: IEx
// ---- QuickInput

createQuickPick<T extends QuickPickItem>(extensionId: ExtensionIdentifier, enableProposedApi: boolean): QuickPick<T> {
const session: ExtHostQuickPick<T> = new ExtHostQuickPick(extensionId, enableProposedApi, () => this._sessions.delete(session._id));
const session: ExtHostQuickPick<T> = new ExtHostQuickPick(extensionId, () => this._sessions.delete(session._id));
this._sessions.set(session._id, session);
return session;
}
Expand Down Expand Up @@ -531,7 +531,7 @@ export function createExtHostQuickOpen(mainContext: IMainContext, workspace: IEx
private readonly _onDidChangeSelectionEmitter = new Emitter<T[]>();
private readonly _onDidTriggerItemButtonEmitter = new Emitter<QuickPickItemButtonEvent<T>>();

constructor(extensionId: ExtensionIdentifier, private readonly enableProposedApi: boolean, onDispose: () => void) {
constructor(extensionId: ExtensionIdentifier, onDispose: () => void) {
super(extensionId, onDispose);
this._disposables.push(
this._onDidChangeActiveEmitter,
Expand Down Expand Up @@ -561,16 +561,13 @@ export function createExtHostQuickOpen(mainContext: IMainContext, workspace: IEx
detail: item.detail,
picked: item.picked,
alwaysShow: item.alwaysShow,
// Proposed API only at the moment
buttons: item.buttons && this.enableProposedApi
? item.buttons.map<TransferQuickInputButton>((button, i) => {
return {
...getIconPathOrClass(button),
tooltip: button.tooltip,
handle: i
};
})
: undefined,
buttons: item.buttons?.map<TransferQuickInputButton>((button, i) => {
return {
...getIconPathOrClass(button),
tooltip: button.tooltip,
handle: i
};
}),
}))
});
}
Expand Down

0 comments on commit f8ed49c

Please sign in to comment.