Merge from vscode 0f73473c08055054f317c1c94502f7f39fdbb164 (#6892)

* Merge from vscode 0f73473c08055054f317c1c94502f7f39fdbb164

* fix tslinting
This commit is contained in:
Anthony Dresser
2019-08-22 22:07:01 -07:00
committed by GitHub
parent 1372cbaee1
commit 658cf51887
91 changed files with 1092 additions and 317 deletions

View File

@@ -46,7 +46,7 @@ export class ProgressService extends Disposable implements IProgressService {
super();
}
withProgress<R = unknown>(options: IProgressOptions, task: (progress: IProgress<IProgressStep>) => Promise<R>, onDidCancel?: () => void): Promise<R> {
withProgress<R = unknown>(options: IProgressOptions, task: (progress: IProgress<IProgressStep>) => Promise<R>, onDidCancel?: (choice?: number) => void): Promise<R> {
const { location } = options;
if (typeof location === 'string') {
if (this.viewletService.getProgressIndicator(location)) {
@@ -142,7 +142,7 @@ export class ProgressService extends Disposable implements IProgressService {
}
}
private withNotificationProgress<P extends Promise<R>, R = unknown>(options: IProgressNotificationOptions, callback: (progress: IProgress<{ message?: string, increment?: number }>) => P, onDidCancel?: () => void): P {
private withNotificationProgress<P extends Promise<R>, R = unknown>(options: IProgressNotificationOptions, callback: (progress: IProgress<{ message?: string, increment?: number }>) => P, onDidCancel?: (choice?: number) => void): P {
const toDispose = new DisposableStore();
const createNotification = (message: string | undefined, increment?: number): INotificationHandle | undefined => {
@@ -152,6 +152,29 @@ export class ProgressService extends Disposable implements IProgressService {
const primaryActions = options.primaryActions ? Array.from(options.primaryActions) : [];
const secondaryActions = options.secondaryActions ? Array.from(options.secondaryActions) : [];
if (options.buttons) {
options.buttons.forEach((button, index) => {
const buttonAction = new class extends Action {
constructor() {
super(`progress.button.${button}`, button, undefined, true);
}
run(): Promise<any> {
if (typeof onDidCancel === 'function') {
onDidCancel(index);
}
return Promise.resolve(undefined);
}
};
toDispose.add(buttonAction);
primaryActions.push(buttonAction);
});
}
if (options.cancellable) {
const cancelAction = new class extends Action {
constructor() {
@@ -182,6 +205,10 @@ export class ProgressService extends Disposable implements IProgressService {
updateProgress(handle, increment);
Event.once(handle.onDidClose)(() => {
if (typeof onDidCancel === 'function') {
onDidCancel();
}
toDispose.dispose();
});
@@ -317,7 +344,7 @@ export class ProgressService extends Disposable implements IProgressService {
return promise;
}
private withDialogProgress<P extends Promise<R>, R = unknown>(options: IProgressOptions, task: (progress: IProgress<IProgressStep>) => P, onDidCancel?: () => void): P {
private withDialogProgress<P extends Promise<R>, R = unknown>(options: IProgressOptions, task: (progress: IProgress<IProgressStep>) => P, onDidCancel?: (choice?: number) => void): P {
const disposables = new DisposableStore();
const allowableCommands = [
'workbench.action.quit',
@@ -327,12 +354,17 @@ export class ProgressService extends Disposable implements IProgressService {
let dialog: Dialog;
const createDialog = (message: string) => {
const buttons = options.buttons || [];
buttons.push(options.cancellable ? localize('cancel', "Cancel") : localize('dismiss', "Dismiss"));
dialog = new Dialog(
this.layoutService.container,
message,
[options.cancellable ? localize('cancel', "Cancel") : localize('dismiss', "Dismiss")],
buttons,
{
type: 'pending',
cancelId: buttons.length - 1,
keyEventProcessor: (event: StandardKeyboardEvent) => {
const resolved = this.keybindingService.softDispatch(event, this.layoutService.container);
if (resolved && resolved.commandId) {
@@ -347,9 +379,9 @@ export class ProgressService extends Disposable implements IProgressService {
disposables.add(dialog);
disposables.add(attachDialogStyler(dialog, this.themeService));
dialog.show().then(() => {
dialog.show().then((dialogResult) => {
if (typeof onDidCancel === 'function') {
onDidCancel();
onDidCancel(dialogResult.button);
}
dispose(dialog);