提交 b709b4de 编写于 作者: B Benjamin Pasero

notifications - some polish and validation

上级 7b4a881d
......@@ -8,21 +8,24 @@
import { Severity } from 'vs/platform/message/common/message';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IMarkdownString } from 'vs/base/common/htmlContent';
import { IAction } from 'vs/base/common/actions';
export const INotificationService = createDecorator<INotificationService>('notificationService');
export interface INotification extends IDisposable {
export interface INotification {
severity: Severity;
message: string | IMarkdownString | Error;
source?: string;
actions?: IAction[];
}
export interface INotificationHandle extends IDisposable {
}
export interface INotificationService {
_serviceBrand: any;
notify(sev: Severity, message: string): INotification;
// notify(sev: Severity, message: Error): () => void;
// notify(sev: Severity, message: string[]): () => void;
// notify(sev: Severity, message: Error[]): () => void;
// notify(sev: Severity, message: IMessageWithAction): () => void;
notify(notification: INotification): INotificationHandle;
}
\ No newline at end of file
......@@ -1578,9 +1578,14 @@ export class ShowAboutDialogAction extends Action {
}
run(): TPromise<void> {
this.notificationService.notify(Severity.Info, 'This is a info message with a [link](https://code.visualstudio.com). This is a info message with a [link](https://code.visualstudio.com). This is a info message with a [link](https://code.visualstudio.com). This is a info message with a [link](https://code.visualstudio.com).');
this.notificationService.notify(Severity.Warning, 'This is a warning message with a [link](https://code.visualstudio.com).');
this.notificationService.notify(Severity.Error, 'This is a error message with a [link](https://code.visualstudio.com). This is a error message with a [link](https://code.visualstudio.com). This is a error message with a [link](https://code.visualstudio.com). This is a error message with a [link](https://code.visualstudio.com). This is a error message with a [link](https://code.visualstudio.com). This is a error message with a [link](https://code.visualstudio.com). This is a error message with a [link](https://code.visualstudio.com).This is a error message with a [link](https://code.visualstudio.com). This is a error message with a [link](https://code.visualstudio.com). This is a error message with a [link](https://code.visualstudio.com). This is a error message with a [link](https://code.visualstudio.com).');
this.notificationService.notify({ severity: Severity.Info, message: 'This is a info message with a [link](https://code.visualstudio.com). This is a info message with a [link](https://code.visualstudio.com). This is a info message with a [link](https://code.visualstudio.com). This is a info message with a [link](https://code.visualstudio.com).' });
this.notificationService.notify({
severity: Severity.Warning, message: 'This is a warning message with a [link](https://code.visualstudio.com).', actions: [
new Action('id.reload', 'Reload Window', null, true, () => { console.log('Reload Window'); return void 0; }),
new Action('id.cancel', 'Cancel', null, true, () => { console.log('Cancel'); return void 0; })
]
});
this.notificationService.notify({ severity: Severity.Error, message: 'This is a error message with a [link](https://code.visualstudio.com). This is a error message with a [link](https://code.visualstudio.com). This is a error message with a [link](https://code.visualstudio.com). This is a error message with a [link](https://code.visualstudio.com). This is a error message with a [link](https://code.visualstudio.com). This is a error message with a [link](https://code.visualstudio.com). This is a error message with a [link](https://code.visualstudio.com).This is a error message with a [link](https://code.visualstudio.com). This is a error message with a [link](https://code.visualstudio.com). This is a error message with a [link](https://code.visualstudio.com). This is a error message with a [link](https://code.visualstudio.com).' });
return TPromise.as(undefined);
}
......
......@@ -10,6 +10,7 @@
left: 50%;
margin-left: -300px;
display: none;
background: #1E1E1E; /* TODO make themable */
}
.monaco-workbench > .notifications-list-container.visible {
......@@ -17,13 +18,13 @@
}
.monaco-workbench > .notifications-list-container .monaco-list-row {
border-left: 2px solid grey; /* TODO make themable */
border-right: 2px solid grey;
border-bottom: 2px solid grey;
border-left: 2px solid #323232; /* TODO make themable */
border-right: 2px solid #323232;
border-bottom: 2px solid #323232;
}
.monaco-workbench > .notifications-list-container .monaco-list-row:first {
border-top: 2px solid grey;
border-top: 2px solid #323232;
}
/** Notification: Container */
......
......@@ -6,7 +6,6 @@
'use strict';
import 'vs/css!./media/notificationList';
import { Severity } from 'vs/platform/message/common/message';
import { addClass } from 'vs/base/browser/dom';
import { WorkbenchList } from 'vs/platform/list/browser/listService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
......@@ -14,13 +13,15 @@ import { INotificationViewItem, NotificationViewItem } from 'vs/workbench/servic
import { NotificationRenderer, NotificationsDelegate } from 'vs/workbench/services/notification/browser/notificationViewer';
import { IListOptions } from 'vs/base/browser/ui/list/listWidget';
import { localize } from 'vs/nls';
import { Themable, NOTIFICATIONS_BACKGROUND, NOTIFICATIONS_FOREGROUND } from 'vs/workbench/common/theme';
import { Themable } from 'vs/workbench/common/theme';
import { IThemeService, registerThemingParticipant, ITheme, ICssStyleCollector } from 'vs/platform/theme/common/themeService';
import { contrastBorder, widgetShadow, textLinkForeground } from 'vs/platform/theme/common/colorRegistry';
import { IMarkdownString } from 'vs/base/common/htmlContent';
import { Action } from 'vs/base/common/actions';
import { INotification, INotificationHandle } from 'vs/platform/notification/common/notification';
export class NotificationList extends Themable {
private static NO_OP_NOTIFICATION: INotificationHandle = { dispose: () => void 0 };
private listContainer: HTMLElement;
private list: WorkbenchList<INotificationViewItem>;
......@@ -36,12 +37,6 @@ export class NotificationList extends Themable {
protected updateStyles(): void {
if (this.listContainer) {
const background = this.getColor(NOTIFICATIONS_BACKGROUND);
this.listContainer.style.background = background ? background.toString() : null;
const foreground = this.getColor(NOTIFICATIONS_FOREGROUND);
this.listContainer.style.color = foreground ? foreground.toString() : null;
const outlineColor = this.getColor(contrastBorder);
this.listContainer.style.outlineColor = outlineColor ? outlineColor.toString() : null;
......@@ -84,21 +79,18 @@ export class NotificationList extends Themable {
this.updateStyles();
}
public show(severity: Severity, notification: string): void {
public show(notification: INotification): INotificationHandle {
const viewItem = NotificationViewItem.create(notification);
if (!viewItem) {
return NotificationList.NO_OP_NOTIFICATION;
}
addClass(this.listContainer, 'visible');
this.list.splice(0, 0, [
new NotificationViewItem(
severity,
{ value: notification, isTrusted: true } as IMarkdownString,
'VS Code Core',
[
new Action('id.reload', 'Reload Window', null, true, () => { console.log('Reload Window'); return void 0; }),
new Action('id.cancel', 'Cancel', null, true, () => { console.log('Cancel'); return void 0; })
]
)
]);
this.list.splice(0, 0, [viewItem]);
this.list.layout();
return { dispose: () => void 0 };
}
}
......
......@@ -5,8 +5,7 @@
'use strict';
import { INotificationService, INotification } from 'vs/platform/notification/common/notification';
import { Severity } from 'vs/platform/message/common/message';
import { INotificationService, INotification, INotificationHandle } from 'vs/platform/notification/common/notification';
import { NotificationList } from 'vs/workbench/services/notification/browser/notificationList';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
......@@ -27,13 +26,11 @@ export class NotificationService implements INotificationService {
this.handler = this.instantiationService.createInstance(NotificationList, document.getElementById('workbench.main.container'));
}
public notify(sev: Severity, message: string): INotification {
public notify(notification: INotification): INotificationHandle {
if (!this.handler) {
this.createHandler();
}
this.handler.show(sev, message);
return { dispose: () => void 0 };
return this.handler.show(notification);
}
}
\ No newline at end of file
......@@ -8,6 +8,9 @@
import { Severity } from 'vs/platform/message/common/message';
import { IMarkdownString } from 'vs/base/common/htmlContent';
import { IAction } from 'vs/base/common/actions';
import { INotification } from 'vs/platform/notification/common/notification';
import { toErrorMessage } from 'vs/base/common/errorMessage';
import { localize } from 'vs/nls';
export class INotificationsModel {
......@@ -29,9 +32,34 @@ export interface INotificationViewItem {
}
export class NotificationViewItem implements INotificationViewItem {
private _expanded: boolean = false;
private static DEFAULT_SOURCE = localize('product', "Product");
private _expanded: boolean;
constructor(private _severity: Severity, private _message: IMarkdownString, private _source: string, private _actions: IAction[]) {
this._expanded = _actions.length > 0;
}
public static create(notification: INotification): INotificationViewItem {
if (!notification || !notification.message) {
return null; // we need a message to show
}
let message: IMarkdownString;
if (notification.message instanceof Error) {
message = { value: toErrorMessage(notification.message, false), isTrusted: true };
} else if (typeof notification.message === 'string') {
message = { value: notification.message, isTrusted: true };
} else if (notification.message.value) {
message = notification.message;
}
if (!message) {
return null; // we need a message to show
}
return new NotificationViewItem(notification.severity, message, notification.source || NotificationViewItem.DEFAULT_SOURCE, notification.actions || []);
}
public get expanded(): boolean {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册