Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973 (#6381)

* Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973

* disable strict null check
This commit is contained in:
Anthony Dresser
2019-07-15 22:35:46 -07:00
committed by GitHub
parent f720ec642f
commit 0b7e7ddbf9
2406 changed files with 59140 additions and 35464 deletions

View File

@@ -3,15 +3,17 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { INotificationService, INotification, INotificationHandle, Severity, NotificationMessage, INotificationActions, IPromptChoice, IPromptOptions } from 'vs/platform/notification/common/notification';
import { INotificationService, INotification, INotificationHandle, Severity, NotificationMessage, INotificationActions, IPromptChoice, IPromptOptions, IStatusMessageOptions } from 'vs/platform/notification/common/notification';
import { INotificationsModel, NotificationsModel, ChoiceAction } from 'vs/workbench/common/notifications';
import { dispose, Disposable, IDisposable } from 'vs/base/common/lifecycle';
import { Disposable, DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
import { Event } from 'vs/base/common/event';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { IAction } from 'vs/base/common/actions';
export class NotificationService extends Disposable implements INotificationService {
_serviceBrand: any;
_serviceBrand: ServiceIdentifier<INotificationService>;
private _model: INotificationsModel = this._register(new NotificationsModel());
@@ -26,7 +28,7 @@ export class NotificationService extends Disposable implements INotificationServ
return;
}
this.model.notify({ severity: Severity.Info, message });
this.model.addNotification({ severity: Severity.Info, message });
}
warn(message: NotificationMessage | NotificationMessage[]): void {
@@ -36,7 +38,7 @@ export class NotificationService extends Disposable implements INotificationServ
return;
}
this.model.notify({ severity: Severity.Warning, message });
this.model.addNotification({ severity: Severity.Warning, message });
}
error(message: NotificationMessage | NotificationMessage[]): void {
@@ -46,37 +48,32 @@ export class NotificationService extends Disposable implements INotificationServ
return;
}
this.model.notify({ severity: Severity.Error, message });
this.model.addNotification({ severity: Severity.Error, message });
}
notify(notification: INotification): INotificationHandle {
return this.model.notify(notification);
return this.model.addNotification(notification);
}
prompt(severity: Severity, message: string, choices: IPromptChoice[], options?: IPromptOptions): INotificationHandle {
const toDispose: IDisposable[] = [];
const toDispose = new DisposableStore();
let choiceClicked = false;
let handle: INotificationHandle;
// Convert choices into primary/secondary actions
const actions: INotificationActions = { primary: [], secondary: [] };
const primaryActions: IAction[] = [];
const secondaryActions: IAction[] = [];
choices.forEach((choice, index) => {
const action = new ChoiceAction(`workbench.dialog.choice.${index}`, choice);
if (!choice.isSecondary) {
if (!actions.primary) {
actions.primary = [];
}
actions.primary.push(action);
primaryActions.push(action);
} else {
if (!actions.secondary) {
actions.secondary = [];
}
actions.secondary.push(action);
secondaryActions.push(action);
}
// React to action being clicked
toDispose.push(action.onDidRun(() => {
toDispose.add(action.onDidRun(() => {
choiceClicked = true;
// Close notification unless we are told to keep open
@@ -85,16 +82,17 @@ export class NotificationService extends Disposable implements INotificationServ
}
}));
toDispose.push(action);
toDispose.add(action);
});
// Show notification with actions
const actions: INotificationActions = { primary: primaryActions, secondary: secondaryActions };
handle = this.notify({ severity, message, actions, sticky: options && options.sticky, silent: options && options.silent });
Event.once(handle.onDidClose)(() => {
// Cleanup when notification gets disposed
dispose(toDispose);
toDispose.dispose();
// Indicate cancellation to the outside if no action was executed
if (options && typeof options.onCancel === 'function' && !choiceClicked) {
@@ -104,6 +102,10 @@ export class NotificationService extends Disposable implements INotificationServ
return handle;
}
status(message: NotificationMessage, options?: IStatusMessageOptions): IDisposable {
return this.model.showStatusMessage(message, options);
}
}
registerSingleton(INotificationService, NotificationService, true);