mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-12 19:18:32 -05:00
Merge from vscode e3c4990c67c40213af168300d1cfeb71d680f877 (#16569)
This commit is contained in:
@@ -19,7 +19,8 @@ import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
import { WorkbenchActionExecutedEvent, WorkbenchActionExecutedClassification } from 'vs/base/common/actions';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { isPromiseCanceledError } from 'vs/base/common/errors';
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
import { toErrorMessage } from 'vs/base/common/errorMessage';
|
||||
|
||||
export interface ICommandQuickPick extends IPickerQuickAccessItem {
|
||||
@@ -47,14 +48,14 @@ export abstract class AbstractCommandsQuickAccessProvider extends PickerQuickAcc
|
||||
@IKeybindingService private readonly keybindingService: IKeybindingService,
|
||||
@ICommandService private readonly commandService: ICommandService,
|
||||
@ITelemetryService private readonly telemetryService: ITelemetryService,
|
||||
@INotificationService private readonly notificationService: INotificationService
|
||||
@IDialogService private readonly dialogService: IDialogService
|
||||
) {
|
||||
super(AbstractCommandsQuickAccessProvider.PREFIX, options);
|
||||
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
protected async getPicks(filter: string, disposables: DisposableStore, token: CancellationToken): Promise<Array<ICommandQuickPick | IQuickPickSeparator>> {
|
||||
protected async _getPicks(filter: string, disposables: DisposableStore, token: CancellationToken): Promise<Array<ICommandQuickPick | IQuickPickSeparator>> {
|
||||
|
||||
// Ask subclass for all command picks
|
||||
const allCommandPicks = await this.getCommandPicks(disposables, token);
|
||||
@@ -162,7 +163,7 @@ export abstract class AbstractCommandsQuickAccessProvider extends PickerQuickAcc
|
||||
await this.commandService.executeCommand(commandPick.commandId);
|
||||
} catch (error) {
|
||||
if (!isPromiseCanceledError(error)) {
|
||||
this.notificationService.error(localize('canNotRun', "Command '{0}' resulted in an error ({1})", commandPick.label, toErrorMessage(error)));
|
||||
this.dialogService.show(Severity.Error, localize('canNotRun', "Command '{0}' resulted in an error ({1})", commandPick.label, toErrorMessage(error)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { IQuickPick, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
|
||||
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
|
||||
import { IQuickPickSeparator, IKeyMods, IQuickPickAcceptEvent } from 'vs/base/parts/quickinput/common/quickInput';
|
||||
import { IQuickPickSeparator, IKeyMods, IQuickPickDidAcceptEvent } from 'vs/base/parts/quickinput/common/quickInput';
|
||||
import { IQuickAccessProvider } from 'vs/platform/quickinput/common/quickAccess';
|
||||
import { IDisposable, DisposableStore, Disposable, MutableDisposable } from 'vs/base/common/lifecycle';
|
||||
import { timeout, isThenable } from 'vs/base/common/async';
|
||||
@@ -42,7 +42,7 @@ export interface IPickerQuickAccessItem extends IQuickPickItem {
|
||||
* @param keyMods the state of modifier keys when the item was accepted.
|
||||
* @param event the underlying event that caused the accept to trigger.
|
||||
*/
|
||||
accept?(keyMods: IKeyMods, event: IQuickPickAcceptEvent): void;
|
||||
accept?(keyMods: IKeyMods, event: IQuickPickDidAcceptEvent): void;
|
||||
|
||||
/**
|
||||
* A method that will be executed when a button of the pick item was
|
||||
@@ -122,7 +122,7 @@ export abstract class PickerQuickAccessProvider<T extends IPickerQuickAccessItem
|
||||
// Collect picks and support both long running and short or combined
|
||||
const picksToken = picksCts.token;
|
||||
const picksFilter = picker.value.substr(this.prefix.length).trim();
|
||||
const providedPicks = this.getPicks(picksFilter, picksDisposables, picksToken);
|
||||
const providedPicks = this._getPicks(picksFilter, picksDisposables, picksToken);
|
||||
|
||||
const applyPicks = (picks: Picks<T>, skipEmpty?: boolean): boolean => {
|
||||
let items: readonly Pick<T>[];
|
||||
@@ -330,5 +330,5 @@ export abstract class PickerQuickAccessProvider<T extends IPickerQuickAccessItem
|
||||
* @returns the picks either directly, as promise or combined fast and slow results.
|
||||
* Pickers can return `null` to signal that no change in picks is needed.
|
||||
*/
|
||||
protected abstract getPicks(filter: string, disposables: DisposableStore, token: CancellationToken): Picks<T> | Promise<Picks<T>> | FastAndSlowPicks<T> | null;
|
||||
protected abstract _getPicks(filter: string, disposables: DisposableStore, token: CancellationToken): Picks<T> | Promise<Picks<T>> | FastAndSlowPicks<T> | null;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,17 @@ export class QuickAccessController extends Disposable implements IQuickAccessCon
|
||||
super();
|
||||
}
|
||||
|
||||
pick(value = '', options?: IQuickAccessOptions): Promise<IQuickPickItem[] | undefined> {
|
||||
return this.doShowOrPick(value, true, options);
|
||||
}
|
||||
|
||||
show(value = '', options?: IQuickAccessOptions): void {
|
||||
this.doShowOrPick(value, false, options);
|
||||
}
|
||||
|
||||
private doShowOrPick(value: string, pick: true, options?: IQuickAccessOptions): Promise<IQuickPickItem[] | undefined>;
|
||||
private doShowOrPick(value: string, pick: false, options?: IQuickAccessOptions): void;
|
||||
private doShowOrPick(value: string, pick: boolean, options?: IQuickAccessOptions): Promise<IQuickPickItem[] | undefined> | void {
|
||||
|
||||
// Find provider for the value to show
|
||||
const [provider, descriptor] = this.getOrInstantiateProvider(value);
|
||||
@@ -99,6 +109,18 @@ export class QuickAccessController extends Disposable implements IQuickAccessCon
|
||||
picker.ariaLabel = descriptor?.placeholder;
|
||||
}
|
||||
|
||||
// Pick mode: setup a promise that can be resolved
|
||||
// with the selected items and prevent execution
|
||||
let pickPromise: Promise<IQuickPickItem[]> | undefined = undefined;
|
||||
let pickResolve: Function | undefined = undefined;
|
||||
if (pick) {
|
||||
pickPromise = new Promise<IQuickPickItem[]>(resolve => pickResolve = resolve);
|
||||
disposables.add(once(picker.onWillAccept)(e => {
|
||||
e.veto();
|
||||
picker.hide();
|
||||
}));
|
||||
}
|
||||
|
||||
// Register listeners
|
||||
disposables.add(this.registerPickerListeners(picker, provider, descriptor, value));
|
||||
|
||||
@@ -119,12 +141,20 @@ export class QuickAccessController extends Disposable implements IQuickAccessCon
|
||||
|
||||
// Start to dispose once picker hides
|
||||
disposables.dispose();
|
||||
|
||||
// Resolve pick promise with selected items
|
||||
pickResolve?.(picker.selectedItems);
|
||||
});
|
||||
|
||||
// Finally, show the picker. This is important because a provider
|
||||
// may not call this and then our disposables would leak that rely
|
||||
// on the onDidHide event.
|
||||
picker.show();
|
||||
|
||||
// Pick mode: return with promise
|
||||
if (pick) {
|
||||
return pickPromise;
|
||||
}
|
||||
}
|
||||
|
||||
private adjustValueSelection(picker: IQuickPick<IQuickPickItem>, descriptor?: IQuickAccessProviderDescriptor, options?: IQuickAccessOptions): void {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { IQuickInputService, IQuickPickItem, IPickOptions, IInputOptions, IQuick
|
||||
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IThemeService, Themable } from 'vs/platform/theme/common/themeService';
|
||||
import { inputBackground, inputForeground, inputBorder, inputValidationInfoBackground, inputValidationInfoForeground, inputValidationInfoBorder, inputValidationWarningBackground, inputValidationWarningForeground, inputValidationWarningBorder, inputValidationErrorBackground, inputValidationErrorForeground, inputValidationErrorBorder, badgeBackground, badgeForeground, contrastBorder, buttonForeground, buttonBackground, buttonHoverBackground, progressBarBackground, widgetShadow, listFocusForeground, activeContrastBorder, pickerGroupBorder, pickerGroupForeground, quickInputForeground, quickInputBackground, quickInputTitleBackground, quickInputListFocusBackground, keybindingLabelBackground, keybindingLabelForeground, keybindingLabelBorder, keybindingLabelBottomBorder } from 'vs/platform/theme/common/colorRegistry';
|
||||
import { inputBackground, inputForeground, inputBorder, inputValidationInfoBackground, inputValidationInfoForeground, inputValidationInfoBorder, inputValidationWarningBackground, inputValidationWarningForeground, inputValidationWarningBorder, inputValidationErrorBackground, inputValidationErrorForeground, inputValidationErrorBorder, badgeBackground, badgeForeground, contrastBorder, buttonForeground, buttonBackground, buttonHoverBackground, progressBarBackground, widgetShadow, activeContrastBorder, pickerGroupBorder, pickerGroupForeground, quickInputForeground, quickInputBackground, quickInputTitleBackground, quickInputListFocusBackground, keybindingLabelBackground, keybindingLabelForeground, keybindingLabelBorder, keybindingLabelBottomBorder, quickInputListFocusForeground } from 'vs/platform/theme/common/colorRegistry';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { computeStyles } from 'vs/platform/theme/common/styler';
|
||||
import { IContextKeyService, RawContextKey, IContextKey } from 'vs/platform/contextkey/common/contextkey';
|
||||
@@ -219,7 +219,7 @@ export class QuickInputService extends Themable implements IQuickInputService {
|
||||
list: computeStyles(this.theme, {
|
||||
listBackground: quickInputBackground,
|
||||
// Look like focused when inactive.
|
||||
listInactiveFocusForeground: listFocusForeground,
|
||||
listInactiveFocusForeground: quickInputListFocusForeground,
|
||||
listInactiveFocusBackground: quickInputListFocusBackground,
|
||||
listFocusOutline: activeContrastBorder,
|
||||
listInactiveFocusOutline: activeContrastBorder,
|
||||
|
||||
@@ -36,6 +36,13 @@ export interface IQuickAccessController {
|
||||
* Open the quick access picker with the optional value prefilled.
|
||||
*/
|
||||
show(value?: string, options?: IQuickAccessOptions): void;
|
||||
|
||||
/**
|
||||
* Same as `show()` but instead of executing the selected pick item,
|
||||
* it will be returned. May return `undefined` in case no item was
|
||||
* picked by the user.
|
||||
*/
|
||||
pick(value?: string, options?: IQuickAccessOptions): Promise<IQuickPickItem[] | undefined>;
|
||||
}
|
||||
|
||||
export enum DefaultQuickAccessFilterValue {
|
||||
|
||||
Reference in New Issue
Block a user