mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Port VS Code telemetry opt-in dialog (#1130)
This commit is contained in:
@@ -3,11 +3,12 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { INotificationService, INotification, INotificationHandle, Severity, NotificationMessage } from 'vs/platform/notification/common/notification';
|
||||
import { INotificationService, INotification, INotificationHandle, Severity, NotificationMessage, INotificationActions, IPromptChoice } from 'vs/platform/notification/common/notification';
|
||||
import { INotificationsModel, NotificationsModel } from 'vs/workbench/common/notifications';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { Action } from 'vs/base/common/actions';
|
||||
import { once } from 'vs/base/common/event';
|
||||
|
||||
export class NotificationService implements INotificationService {
|
||||
|
||||
@@ -62,6 +63,51 @@ export class NotificationService implements INotificationService {
|
||||
return this.model.notify(notification);
|
||||
}
|
||||
|
||||
public prompt(severity: Severity, message: string, choices: IPromptChoice[], onCancel?: () => void): INotificationHandle {
|
||||
let handle: INotificationHandle;
|
||||
let choiceClicked = false;
|
||||
|
||||
// Convert choices into primary/secondary actions
|
||||
const actions: INotificationActions = { primary: [], secondary: [] };
|
||||
choices.forEach((choice, index) => {
|
||||
const action = new Action(`workbench.dialog.choice.${index}`, choice.label, null, true, () => {
|
||||
choiceClicked = true;
|
||||
|
||||
// Pass to runner
|
||||
choice.run();
|
||||
|
||||
// Close notification unless we are told to keep open
|
||||
if (!choice.keepOpen) {
|
||||
handle.close();
|
||||
}
|
||||
|
||||
return TPromise.as(void 0);
|
||||
});
|
||||
|
||||
if (!choice.isSecondary) {
|
||||
actions.primary.push(action);
|
||||
} else {
|
||||
actions.secondary.push(action);
|
||||
}
|
||||
});
|
||||
|
||||
// Show notification with actions
|
||||
handle = this.notify({ severity, message, actions });
|
||||
|
||||
once(handle.onDidClose)(() => {
|
||||
|
||||
// Cleanup when notification gets disposed
|
||||
dispose(...actions.primary, ...actions.secondary);
|
||||
|
||||
// Indicate cancellation to the outside if no action was executed
|
||||
if (!choiceClicked && typeof onCancel === 'function') {
|
||||
onCancel();
|
||||
}
|
||||
});
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this.toDispose = dispose(this.toDispose);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user