diff --git a/packages/plugin-ext/src/common/plugin-api-rpc.ts b/packages/plugin-ext/src/common/plugin-api-rpc.ts index 55d5960bb9657..242ae92d56364 100644 --- a/packages/plugin-ext/src/common/plugin-api-rpc.ts +++ b/packages/plugin-ext/src/common/plugin-api-rpc.ts @@ -383,6 +383,7 @@ export enum MainMessageType { } export interface MainMessageOptions { + detail?: string; modal?: boolean onCloseActionHandle?: number } diff --git a/packages/plugin-ext/src/main/browser/dialogs/modal-notification.ts b/packages/plugin-ext/src/main/browser/dialogs/modal-notification.ts index 207c8a62577dc..3fb5f2d305668 100644 --- a/packages/plugin-ext/src/main/browser/dialogs/modal-notification.ts +++ b/packages/plugin-ext/src/main/browser/dialogs/modal-notification.ts @@ -18,7 +18,8 @@ import { Message } from '@theia/core/shared/@phosphor/messaging'; import { codiconArray, Key } from '@theia/core/lib/browser'; import { AbstractDialog } from '@theia/core/lib/browser/dialogs'; import '../../../../src/main/browser/dialogs/style/modal-notification.css'; -import { MainMessageItem } from '../../../common/plugin-api-rpc'; +import { MainMessageItem, MainMessageOptions } from '../../../common/plugin-api-rpc'; +import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider'; export enum MessageType { Error = 'error', @@ -29,6 +30,7 @@ export enum MessageType { const NOTIFICATION = 'modal-Notification'; const ICON = 'icon'; const TEXT = 'text'; +const DETAIL = 'detail'; @injectable() export class ModalNotification extends AbstractDialog { @@ -36,7 +38,7 @@ export class ModalNotification extends AbstractDialog { protected actionTitle: string | undefined; constructor() { - super({ title: 'Theia' }); + super({ title: FrontendApplicationConfigProvider.get().applicationName }); } protected onCloseRequest(msg: Message): void { @@ -48,12 +50,12 @@ export class ModalNotification extends AbstractDialog { return this.actionTitle; } - showDialog(messageType: MessageType, text: string, actions: MainMessageItem[]): Promise { - this.contentNode.appendChild(this.createMessageNode(messageType, text, actions)); + showDialog(messageType: MessageType, text: string, options: MainMessageOptions, actions: MainMessageItem[]): Promise { + this.contentNode.appendChild(this.createMessageNode(messageType, text, options, actions)); return this.open(); } - protected createMessageNode(messageType: MessageType, text: string, actions: MainMessageItem[]): HTMLElement { + protected createMessageNode(messageType: MessageType, text: string, options: MainMessageOptions, actions: MainMessageItem[]): HTMLElement { const messageNode = document.createElement('div'); messageNode.classList.add(NOTIFICATION); @@ -67,6 +69,13 @@ export class ModalNotification extends AbstractDialog { const textElement = textContainer.appendChild(document.createElement('p')); textElement.textContent = text; + if (options.detail) { + const detailContainer = textContainer.appendChild(document.createElement('div')); + detailContainer.classList.add(DETAIL); + const detailElement = detailContainer.appendChild(document.createElement('p')); + detailElement.textContent = options.detail; + } + actions.forEach((action: MainMessageItem) => { const button = this.createButton(action.title); button.classList.add('main'); @@ -79,8 +88,10 @@ export class ModalNotification extends AbstractDialog { }, 'click'); }); - if (!actions.some(action => action.isCloseAffordance === true)) { - this.appendCloseButton('close'); + if (actions.length <= 0) { + this.appendAcceptButton(); + } else if (!actions.some(action => action.isCloseAffordance === true)) { + this.appendCloseButton('Close'); } return messageNode; diff --git a/packages/plugin-ext/src/main/browser/dialogs/style/modal-notification.css b/packages/plugin-ext/src/main/browser/dialogs/style/modal-notification.css index 7c69b3040c1c1..946eaec048af6 100644 --- a/packages/plugin-ext/src/main/browser/dialogs/style/modal-notification.css +++ b/packages/plugin-ext/src/main/browser/dialogs/style/modal-notification.css @@ -42,10 +42,10 @@ order: 1; } -.modal-Notification .icon .fa { +.modal-Notification .icon .codicon { line-height: inherit; vertical-align: middle; - font-size: 120%; + font-size: calc(var(--theia-ui-padding)*5); color: var(--theia-editorInfo-foreground); } @@ -106,3 +106,18 @@ .modal-Notification .buttons > button:hover { background-color: var(--theia-button-hoverBackground); } + +.modal-Notification .detail { + align-self: center; + order: 3; + flex: 1 100%; + color: var(--theia-descriptionForeground); +} + +.modal-Notification .detail > p { + margin: calc(var(--theia-ui-padding) * 2) 0px 0px 0px; +} + +.modal-Notification .text { + padding: calc(var(--theia-ui-padding)*1.5); +} diff --git a/packages/plugin-ext/src/main/browser/message-registry-main.ts b/packages/plugin-ext/src/main/browser/message-registry-main.ts index 988b65cf908d4..034197c5c29d3 100644 --- a/packages/plugin-ext/src/main/browser/message-registry-main.ts +++ b/packages/plugin-ext/src/main/browser/message-registry-main.ts @@ -40,7 +40,7 @@ export class MessageRegistryMainImpl implements MessageRegistryMain { type === MainMessageType.Warning ? MessageType.Warning : MessageType.Info; const modalNotification = new ModalNotification(); - return modalNotification.showDialog(messageType, message, actions); + return modalNotification.showDialog(messageType, message, options, actions); } switch (type) { case MainMessageType.Info: diff --git a/packages/plugin-ext/src/plugin/message-registry.ts b/packages/plugin-ext/src/plugin/message-registry.ts index 08a99bc0386e1..395289a298fed 100644 --- a/packages/plugin-ext/src/plugin/message-registry.ts +++ b/packages/plugin-ext/src/plugin/message-registry.ts @@ -50,14 +50,17 @@ export class MessageRegistryExt { } else { if ('modal' in optionsOrFirstItem) { options.modal = optionsOrFirstItem.modal; + if ('detail' in optionsOrFirstItem) { + options.detail = optionsOrFirstItem.detail; + } } } + for (const item of rest) { + pushItem(item); + } + const actionHandle = await this.proxy.$showMessage(type, message, options, actions); + return actionHandle !== undefined ? items[actionHandle] : undefined; } - for (const item of rest) { - pushItem(item); - } - const actionHandle = await this.proxy.$showMessage(type, message, options, actions); - return actionHandle !== undefined ? items[actionHandle] : undefined; - } + } } diff --git a/packages/plugin/src/theia.d.ts b/packages/plugin/src/theia.d.ts index e708c92d2ee6b..81383f19a4dc2 100644 --- a/packages/plugin/src/theia.d.ts +++ b/packages/plugin/src/theia.d.ts @@ -2395,6 +2395,13 @@ declare module '@theia/plugin' { */ export interface MessageOptions { + /* + * Human-readable detail message that is rendered + * less prominent. Note that detail is only shown + * for modal messages. + */ + detail?: string; + /** * Indicates that this message should be modal. */