mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Merge from vscode 1df23554b2e3d5f1efc6fbc76ee61d3f7f186c6d
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
import { IQuickPick, IQuickPickItem, IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
|
||||
import { IQuickAccessProvider, IQuickAccessRegistry, Extensions } from 'vs/platform/quickinput/common/quickAccess';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { localize } from 'vs/nls';
|
||||
import { DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
|
||||
|
||||
@@ -22,7 +21,7 @@ export class HelpQuickAccessProvider implements IQuickAccessProvider {
|
||||
|
||||
constructor(@IQuickInputService private readonly quickInputService: IQuickInputService) { }
|
||||
|
||||
provide(picker: IQuickPick<IHelpQuickAccessPickItem>, token: CancellationToken): IDisposable {
|
||||
provide(picker: IQuickPick<IHelpQuickAccessPickItem>): IDisposable {
|
||||
const disposables = new DisposableStore();
|
||||
|
||||
// Open a picker with the selected value if picked
|
||||
@@ -33,6 +32,15 @@ export class HelpQuickAccessProvider implements IQuickAccessProvider {
|
||||
}
|
||||
}));
|
||||
|
||||
// Also open a picker when we detect the user typed the exact
|
||||
// name of a provider (e.g. `?term` for terminals)
|
||||
disposables.add(picker.onDidChangeValue(value => {
|
||||
const providerDescriptor = this.registry.getQuickAccessProvider(value.substr(HelpQuickAccessProvider.PREFIX.length));
|
||||
if (providerDescriptor && providerDescriptor.prefix !== HelpQuickAccessProvider.PREFIX) {
|
||||
this.quickInputService.quickAccess.show(providerDescriptor.prefix);
|
||||
}
|
||||
}));
|
||||
|
||||
// Fill in all providers separated by editor/global scope
|
||||
const { editorProviders, globalProviders } = this.getQuickAccessProviders();
|
||||
picker.items = editorProviders.length === 0 || globalProviders.length === 0 ?
|
||||
@@ -57,7 +65,7 @@ export class HelpQuickAccessProvider implements IQuickAccessProvider {
|
||||
const globalProviders: IHelpQuickAccessPickItem[] = [];
|
||||
const editorProviders: IHelpQuickAccessPickItem[] = [];
|
||||
|
||||
for (const provider of this.registry.getQuickAccessProviders().sort((p1, p2) => p1.prefix.localeCompare(p2.prefix))) {
|
||||
for (const provider of this.registry.getQuickAccessProviders().sort((providerA, providerB) => providerA.prefix.localeCompare(providerB.prefix))) {
|
||||
for (const helpEntry of provider.helpEntries) {
|
||||
const prefix = helpEntry.prefix || provider.prefix;
|
||||
const label = prefix || '\u2026' /* ... */;
|
||||
@@ -65,8 +73,8 @@ export class HelpQuickAccessProvider implements IQuickAccessProvider {
|
||||
(helpEntry.needsEditor ? editorProviders : globalProviders).push({
|
||||
prefix,
|
||||
label,
|
||||
description: helpEntry.description,
|
||||
ariaLabel: localize('entryAriaLabel', "{0}, picker help", label)
|
||||
ariaLabel: localize('entryAriaLabel', "{0}, quick access help picker", label),
|
||||
description: helpEntry.description
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,6 +144,24 @@ Registry.add(Extensions.Quickaccess, new QuickAccessRegistry());
|
||||
|
||||
//#region Helper class for simple picker based providers
|
||||
|
||||
export enum TriggerAction {
|
||||
|
||||
/**
|
||||
* Do nothing after the button was clicked.
|
||||
*/
|
||||
NO_ACTION,
|
||||
|
||||
/**
|
||||
* Close the picker.
|
||||
*/
|
||||
CLOSE_PICKER,
|
||||
|
||||
/**
|
||||
* Update the results of the picker.
|
||||
*/
|
||||
REFRESH_PICKER
|
||||
}
|
||||
|
||||
export interface IPickerQuickAccessItem extends IQuickPickItem {
|
||||
|
||||
/**
|
||||
@@ -154,14 +172,15 @@ export interface IPickerQuickAccessItem extends IQuickPickItem {
|
||||
|
||||
/**
|
||||
* A method that will be executed when a button of the pick item was
|
||||
* clicked on. The picker will only close if `true` is returned.
|
||||
* clicked on.
|
||||
*
|
||||
* @param buttonIndex index of the button of the item that
|
||||
* was clicked.
|
||||
*
|
||||
* @returns a valud indicating if the picker should close or not.
|
||||
* @returns a value that indicates what should happen after the trigger
|
||||
* which can be a `Promise` for long running operations.
|
||||
*/
|
||||
trigger?(buttonIndex: number): boolean;
|
||||
trigger?(buttonIndex: number): TriggerAction | Promise<TriggerAction>;
|
||||
}
|
||||
|
||||
export abstract class PickerQuickAccessProvider<T extends IPickerQuickAccessItem> implements IQuickAccessProvider {
|
||||
@@ -192,13 +211,18 @@ export abstract class PickerQuickAccessProvider<T extends IPickerQuickAccessItem
|
||||
} else {
|
||||
picker.busy = true;
|
||||
try {
|
||||
picker.items = await res;
|
||||
const items = await res;
|
||||
if (token.isCancellationRequested) {
|
||||
return;
|
||||
}
|
||||
|
||||
picker.items = items;
|
||||
} finally {
|
||||
picker.busy = false;
|
||||
if (!token.isCancellationRequested) {
|
||||
picker.busy = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.getPicks(picker.value.substr(this.prefix.length).trim(), picksCts.token);
|
||||
};
|
||||
disposables.add(picker.onDidChangeValue(() => updatePickerItems()));
|
||||
updatePickerItems();
|
||||
@@ -213,13 +237,26 @@ export abstract class PickerQuickAccessProvider<T extends IPickerQuickAccessItem
|
||||
}));
|
||||
|
||||
// Trigger the pick with button index if button triggered
|
||||
disposables.add(picker.onDidTriggerItemButton(({ button, item }) => {
|
||||
disposables.add(picker.onDidTriggerItemButton(async ({ button, item }) => {
|
||||
if (typeof item.trigger === 'function') {
|
||||
const buttonIndex = item.buttons?.indexOf(button) ?? -1;
|
||||
if (buttonIndex >= 0) {
|
||||
const hide = item.trigger(buttonIndex);
|
||||
if (hide !== false) {
|
||||
picker.hide();
|
||||
const result = item.trigger(buttonIndex);
|
||||
const action = (typeof result === 'number') ? result : await result;
|
||||
|
||||
if (token.isCancellationRequested) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case TriggerAction.NO_ACTION:
|
||||
break;
|
||||
case TriggerAction.CLOSE_PICKER:
|
||||
picker.hide();
|
||||
break;
|
||||
case TriggerAction.REFRESH_PICKER:
|
||||
updatePickerItems();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user