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

notifications - adjust height computation

上级 5a78ea43
......@@ -50,38 +50,35 @@ export class NotificationsListDelegate implements IDelegate<INotificationViewIte
return offsetHelper;
}
public getHeight(element: INotificationViewItem): number {
public getHeight(notification: INotificationViewItem): number {
// First row: message and actions
let expandedHeight = NotificationsListDelegate.ROW_HEIGHT;
if (!element.expanded) {
if (!notification.expanded) {
return expandedHeight; // return early if there are no more rows to show
}
// Dynamic height: if message overflows
const preferredMessageHeight = this.computePreferredRows(element.message) * NotificationsListDelegate.LINE_HEIGHT;
const messageOverflows = expandedHeight < preferredMessageHeight;
const preferredMessageHeight = this.computePreferredRows(notification) * NotificationsListDelegate.LINE_HEIGHT;
const messageOverflows = NotificationsListDelegate.LINE_HEIGHT < preferredMessageHeight;
if (messageOverflows) {
const overflow = preferredMessageHeight - expandedHeight;
const overflow = preferredMessageHeight - NotificationsListDelegate.LINE_HEIGHT;
expandedHeight += overflow;
}
// Add some padding to separate from details row
if (messageOverflows) {
expandedHeight += NotificationsListDelegate.LINE_HEIGHT;
// Last row: source and actions if we have any
if (notification.source || notification.actions.length > 0) {
expandedHeight += NotificationsListDelegate.ROW_HEIGHT;
}
// Last row: source and actions
expandedHeight += NotificationsListDelegate.ROW_HEIGHT;
return expandedHeight;
}
private computePreferredRows(message: IMarkdownString): number {
private computePreferredRows(notification: INotificationViewItem): number {
// Render message markdown into offset helper
const renderedMessage = NotificationMessageMarkdownRenderer.render(message);
const renderedMessage = NotificationMessageMarkdownRenderer.render(notification.message);
this.offsetHelper.appendChild(renderedMessage);
// Compute message width taking overflow into account
......@@ -271,7 +268,18 @@ export class NotificationRenderer implements IRenderer<INotificationViewItem, IN
actions.push(configureNotificationAction);
data.toDispose.push(configureNotificationAction);
let showExpandCollapseAction = false;
if (notification.canCollapse) {
if (notification.expanded) {
showExpandCollapseAction = true; // allow to collapse an expanded message
} else if (notification.source || notification.actions.length > 0) {
showExpandCollapseAction = true; // allow to expand to details row
} else if (data.message.scrollWidth > data.message.clientWidth) {
showExpandCollapseAction = true; // allow to expand if message overflows
}
}
if (showExpandCollapseAction) {
actions.push(notification.expanded ? this.collapseNotificationAction : this.expandNotificationAction);
}
......@@ -283,7 +291,7 @@ export class NotificationRenderer implements IRenderer<INotificationViewItem, IN
data.toolbar.push(actions, { icon: true, label: false });
// Source
if (notification.expanded) {
if (notification.expanded && notification.source) {
data.source.innerText = localize('notificationSource', "Source: {0}", notification.source);
} else {
data.source.innerText = '';
......
......@@ -10,7 +10,6 @@ import { IMarkdownString } from 'vs/base/common/htmlContent';
import { IAction } from 'vs/base/common/actions';
import { INotification, INotificationHandle } from 'vs/platform/notification/common/notification';
import { toErrorMessage } from 'vs/base/common/errorMessage';
import { localize } from 'vs/nls';
import Event, { Emitter, once } from 'vs/base/common/event';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { isPromiseCanceledError } from 'vs/base/common/errors';
......@@ -131,7 +130,7 @@ export interface INotificationViewItem {
export class NotificationViewItem implements INotificationViewItem {
private static DEFAULT_SOURCE = localize('product', "Product");
private static MAX_MESSAGE_LENGTH = 500;
private _expanded: boolean;
private toDispose: IDisposable[];
......@@ -160,11 +159,15 @@ export class NotificationViewItem implements INotificationViewItem {
message = notification.message;
}
if (!message) {
if (!message || typeof message.value !== 'string') {
return null; // we need a message to show
}
return new NotificationViewItem(severity, message, notification.source || NotificationViewItem.DEFAULT_SOURCE, notification.actions || []);
if (message.value.length > NotificationViewItem.MAX_MESSAGE_LENGTH) {
message.value = `${message.value.substr(0, NotificationViewItem.MAX_MESSAGE_LENGTH)}...`;
}
return new NotificationViewItem(severity, message, notification.source, notification.actions || []);
}
private constructor(private _severity: Severity, private _message: IMarkdownString, private _source: string, private _actions: IAction[]) {
......
......@@ -39,7 +39,8 @@ export class NotificationService implements INotificationService {
setTimeout(() => {
this.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).'
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).',
source: 'GitLens Extension'
});
this.notify({
severity: Severity.Warning,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册