This repository has been archived by the owner on Jun 20, 2018. It is now read-only.
forked from eclipse-theia/theia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Oleksii Orel <oorel@redhat.com>
- Loading branch information
Showing
12 changed files
with
473 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
packages/plugin-ext/src/main/browser/dialogs/modal-notification.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (C) 2018 Red Hat, Inc. and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
import {injectable} from 'inversify'; | ||
import {Message} from '@phosphor/messaging'; | ||
import {Key} from '@theia/core/lib/browser'; | ||
import {MessageType} from '../message-registry-main'; | ||
import {AbstractDialog} from '@theia/core/lib/browser/dialogs'; | ||
import '../../../../src/main/browser/dialogs/style/modal-notification.css'; | ||
|
||
const NOTIFICATION = 'theia-Notification'; | ||
const ICON = 'icon'; | ||
const TEXT = 'text'; | ||
|
||
@injectable() | ||
export class ModalNotification extends AbstractDialog<string | undefined> { | ||
|
||
protected actionTitle: string | undefined; | ||
|
||
constructor() { | ||
super({title: 'Theia'}); | ||
} | ||
|
||
protected onCloseRequest(msg: Message): void { | ||
this.actionTitle = undefined; | ||
this.accept(); | ||
} | ||
|
||
get value(): string | undefined { | ||
return this.actionTitle; | ||
} | ||
|
||
showDialog(messageType: MessageType, text: string, actions: string[]): Promise<string | undefined> { | ||
this.contentNode.appendChild(this.createMessageNode(messageType, text, actions)); | ||
return this.open(); | ||
} | ||
|
||
protected createMessageNode(messageType: MessageType, text: string, actions: string[]): HTMLElement { | ||
const messageNode = document.createElement('div'); | ||
messageNode.classList.add(NOTIFICATION); | ||
|
||
const iconContainer = messageNode.appendChild(document.createElement('div')); | ||
iconContainer.classList.add(ICON); | ||
const iconElement = iconContainer.appendChild(document.createElement('i')); | ||
iconElement.classList.add('fa', this.toIconClass(messageType), 'fa-fw', messageType); | ||
|
||
const textContainer = messageNode.appendChild(document.createElement('div')); | ||
textContainer.classList.add(TEXT); | ||
const textElement = textContainer.appendChild(document.createElement('span')); | ||
textElement.textContent = text; | ||
|
||
actions.forEach((action: string) => { | ||
const button = this.createButton(action); | ||
button.classList.add('main'); | ||
this.controlPanel.appendChild(button); | ||
this.addKeyListener(button, | ||
Key.ENTER, | ||
() => { | ||
this.actionTitle = action; | ||
this.accept(); | ||
}, | ||
'click'); | ||
}); | ||
this.appendCloseButton('close'); | ||
|
||
return messageNode; | ||
} | ||
|
||
protected toIconClass(icon: string): string { | ||
if (icon === MessageType.Error) { | ||
return 'fa-times-circle'; | ||
} | ||
if (icon === MessageType.Warning) { | ||
return 'fa-warning'; | ||
} | ||
return 'fa-info-circle'; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/plugin-ext/src/main/browser/dialogs/style/modal-notification.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright (C) 2018 Red Hat, Inc. and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
.dialogContent .theia-Notification { | ||
min-width: inherit; | ||
box-shadow: none; | ||
animation: none; | ||
} | ||
|
||
.dialogContent .theia-Notification .icon { | ||
font-size: 20px; | ||
padding: 5px 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
packages/plugin-ext/src/main/browser/message-registry-main.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright (C) 2018 Red Hat, Inc. and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
import {interfaces} from 'inversify'; | ||
import * as theia from '@theia/plugin'; | ||
import {MessageService} from '@theia/core/lib/common/message-service'; | ||
import {MessageRegistryMain} from '../../api/plugin-api'; | ||
import {ModalNotification} from './dialogs/modal-notification'; | ||
|
||
export enum MessageType { | ||
Error = 'error', | ||
Warning = 'warning', | ||
Info = 'info' | ||
} | ||
|
||
export class MessageRegistryMainImpl implements MessageRegistryMain { | ||
private messageService: MessageService; | ||
|
||
constructor(container: interfaces.Container) { | ||
this.messageService = container.get(MessageService); | ||
} | ||
|
||
$showInformationMessage(message: string, | ||
optionsOrFirstItem: theia.MessageOptions | string | theia.MessageItem, | ||
items: string[] | theia.MessageItem[]): PromiseLike<string | theia.MessageItem | undefined> { | ||
return this.showMessage(MessageType.Info, message, optionsOrFirstItem, ...items); | ||
} | ||
|
||
$showWarningMessage(message: string, | ||
optionsOrFirstItem: theia.MessageOptions | string | theia.MessageItem, | ||
items: string[] | theia.MessageItem[]): PromiseLike<string | theia.MessageItem | undefined> { | ||
return this.showMessage(MessageType.Warning, message, optionsOrFirstItem, ...items); | ||
} | ||
|
||
$showErrorMessage(message: string, | ||
optionsOrFirstItem: theia.MessageOptions | string | theia.MessageItem, | ||
items: string[] | theia.MessageItem[]): PromiseLike<string | theia.MessageItem | undefined> { | ||
return this.showMessage(MessageType.Error, message, optionsOrFirstItem, ...items); | ||
} | ||
|
||
protected showMessage(type: MessageType, message: string, ...args: any[]): PromiseLike<string | theia.MessageItem | undefined> { | ||
const actionsMap = new Map<string, any>(); | ||
const actionTitles: string[] = []; | ||
const options: theia.MessageOptions = {modal: false}; | ||
|
||
let onCloseAction: string; | ||
if (!!args && args.length > 0) { | ||
const first = args[0]; | ||
if (first && first.modal) { | ||
options.modal = true; | ||
} | ||
args.forEach(arg => { | ||
if (!arg) { | ||
return; | ||
} | ||
let actionTitle: string; | ||
if (typeof arg === 'string') { | ||
actionTitle = arg; | ||
} else if (arg.title) { | ||
actionTitle = arg.title; | ||
actionsMap.set(actionTitle, arg); | ||
if (arg.isCloseAffordance) { | ||
onCloseAction = arg.title; | ||
} | ||
} else { | ||
return; | ||
} | ||
actionTitles.push(actionTitle); | ||
}); | ||
} | ||
|
||
let promise: Promise<string | undefined>; | ||
|
||
try { | ||
if (options.modal) { | ||
const modalNotification = new ModalNotification(); | ||
promise = modalNotification.showDialog(type, message, actionTitles).then(result => { | ||
return result !== undefined ? result : onCloseAction; | ||
}); | ||
} else { | ||
switch (type) { | ||
case MessageType.Info: | ||
promise = this.messageService.info(message, ...actionTitles); | ||
break; | ||
case MessageType.Warning: | ||
promise = this.messageService.warn(message, ...actionTitles); | ||
break; | ||
case MessageType.Error: | ||
promise = this.messageService.error(message, ...actionTitles); | ||
break; | ||
default: | ||
return Promise.reject(new Error(`Message type '${type}' is not supported yet!`)); | ||
} | ||
} | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
|
||
return Promise.resolve(promise.then(result => !!result && actionsMap.has(result) ? actionsMap.get(result) : result)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) 2018 Red Hat, Inc. and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
import { | ||
PLUGIN_RPC_CONTEXT as Ext, MessageRegistryMain | ||
} from '../api/plugin-api'; | ||
import {RPCProtocol} from '../api/rpc-protocol'; | ||
import {MessageItem, MessageOptions} from "@theia/plugin"; | ||
|
||
export class MessageRegistryExt { | ||
|
||
private proxy: MessageRegistryMain; | ||
|
||
constructor(rpc: RPCProtocol) { | ||
this.proxy = rpc.getProxy(Ext.MESSAGE_REGISTRY_MAIN); | ||
} | ||
|
||
showInformationMessage(message: string, | ||
optionsOrFirstItem: MessageOptions | string | MessageItem, | ||
items: string[] | MessageItem[]): PromiseLike<string | MessageItem | undefined> { | ||
return this.proxy.$showInformationMessage(message, optionsOrFirstItem, items); | ||
} | ||
|
||
showWarningMessage(message: string, | ||
optionsOrFirstItem: MessageOptions | string | MessageItem, | ||
items: string[] | MessageItem[]): PromiseLike<string | MessageItem | undefined> { | ||
return this.proxy.$showWarningMessage(message, optionsOrFirstItem, items); | ||
} | ||
|
||
showErrorMessage(message: string, | ||
optionsOrFirstItem: MessageOptions | string | MessageItem, | ||
items: string[] | MessageItem[]): PromiseLike<string | MessageItem | undefined> { | ||
return this.proxy.$showErrorMessage(message, optionsOrFirstItem, items); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.