Skip to content

Commit

Permalink
Added progress extension
Browse files Browse the repository at this point in the history
Signed-off-by: jpinkney <josh.pinkney@mail.utoronto.ca>
  • Loading branch information
JPinkney committed Sep 22, 2018
1 parent 3ea4d25 commit 833ff6b
Show file tree
Hide file tree
Showing 18 changed files with 573 additions and 7 deletions.
1 change: 1 addition & 0 deletions examples/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@theia/preferences": "^0.3.14",
"@theia/preview": "^0.3.14",
"@theia/process": "^0.3.14",
"@theia/progress-monitor": "^0.3.14",
"@theia/python": "^0.3.14",
"@theia/search-in-workspace": "^0.3.14",
"@theia/task": "^0.3.14",
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/browser/status-bar/status-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface StatusBar {
setBackgroundColor(color?: string): Promise<void>;
setElement(id: string, entry: StatusBarEntry): Promise<void>;
removeElement(id: string): Promise<void>;
getElementByClass(className: string): Promise<NodeListOf<Element>>;
}

@injectable()
Expand Down Expand Up @@ -98,6 +99,11 @@ export class StatusBarImpl extends ReactWidget implements StatusBar {
this.update();
}

async getElementByClass(className: string) {
await this.ready;
return this.node.getElementsByClassName(className);
}

async setBackgroundColor(color?: string): Promise<void> {
await this.ready;
this.internalSetBackgroundColor(color);
Expand Down
1 change: 1 addition & 0 deletions packages/java/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@theia/editor": "^0.3.14",
"@theia/languages": "^0.3.14",
"@theia/monaco": "^0.3.14",
"@theia/progress-monitor": "^0.3.14",
"@types/glob": "^5.0.30",
"@types/tar": "4.0.0",
"glob": "^7.1.2",
Expand Down
18 changes: 11 additions & 7 deletions packages/java/src/browser/java-client-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ import {
LanguageClientOptions
} from '@theia/languages/lib/browser';
import { JAVA_LANGUAGE_ID, JAVA_LANGUAGE_NAME } from '../common';
import {
ActionableNotification,
ActionableMessage,
StatusReport,
StatusNotification,
} from './java-protocol';
import { ActionableNotification, ActionableMessage, StatusReport, StatusNotification, ProgressReportNotification } from './java-protocol';
import { ProgressReport, ProgressService } from '@theia/progress-monitor/lib/browser';

@injectable()
export class JavaClientContribution extends BaseLanguageClientContribution {
Expand All @@ -50,7 +46,8 @@ export class JavaClientContribution extends BaseLanguageClientContribution {
@inject(Window) protected readonly window: Window,
@inject(CommandService) protected readonly commandService: CommandService,
@inject(StatusBar) protected readonly statusBar: StatusBar,
@inject(SemanticHighlightingService) protected readonly semanticHighlightingService: SemanticHighlightingService
@inject(SemanticHighlightingService) protected readonly semanticHighlightingService: SemanticHighlightingService,
@inject(ProgressService) protected readonly progressMonitorService: ProgressService
) {
super(workspace, languages, languageClientFactory);
}
Expand All @@ -66,6 +63,7 @@ export class JavaClientContribution extends BaseLanguageClientContribution {
protected onReady(languageClient: ILanguageClient): void {
languageClient.onNotification(ActionableNotification.type, this.showActionableMessage.bind(this));
languageClient.onNotification(StatusNotification.type, this.showStatusMessage.bind(this));
languageClient.onNotification(ProgressReportNotification.type, this.showProgressReportNotifications.bind(this));
super.onReady(languageClient);
}

Expand All @@ -92,6 +90,11 @@ export class JavaClientContribution extends BaseLanguageClientContribution {
}, 5000);
}

protected showProgressReportNotifications(progressReport: ProgressReport) {
const javaProgressReport = Object.assign(progressReport, { location: 'Java' });
this.progressMonitorService.addOrUpdateContribution(javaProgressReport);
}

protected showActionableMessage(message: ActionableMessage): void {
const items = message.commands || [];
this.window.showMessage(message.severity, message.message, ...items).then(command => {
Expand All @@ -108,6 +111,7 @@ export class JavaClientContribution extends BaseLanguageClientContribution {
extendedClientCapabilities: {
classFileContentsSupport: true,
semanticHighlighting: true
progressReportProvider: true
}
};
return options;
Expand Down
5 changes: 5 additions & 0 deletions packages/java/src/browser/java-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import { RequestType, NotificationType } from 'vscode-jsonrpc';
import { VersionedTextDocumentIdentifier, TextDocumentIdentifier, Command, MessageType } from '@theia/languages/lib/browser';
import { ProgressReport } from '@theia/progress-monitor/lib/browser';

export interface StatusReport {
message: string;
Expand Down Expand Up @@ -54,3 +55,7 @@ export namespace ActionableNotification {
export namespace SemanticHighlight {
export const type = new NotificationType<SemanticHighlightingParams, void>('textDocument/semanticHighlighting');
}

export namespace ProgressReportNotification {
export const type = new NotificationType<ProgressReport, void>('language/progressReport');
}
8 changes: 8 additions & 0 deletions packages/progress-monitor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Theia - Progress Monitor Extension

Contributes a progress widget to Theia.

## License

- [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/)
- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)
10 changes: 10 additions & 0 deletions packages/progress-monitor/compile.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../configs/base.tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib"
},
"include": [
"src"
]
}
47 changes: 47 additions & 0 deletions packages/progress-monitor/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "@theia/progress-monitor",
"version": "0.3.14",
"description": "Theia - Progress Monitor",
"dependencies": {
"@theia/core": "^0.3.14",
"@theia/editor": "^0.3.14"
},
"publishConfig": {
"access": "public"
},
"theiaExtensions": [
{
"frontend": "lib/browser/progress-monitor-frontend-module"
}
],
"keywords": [
"theia-extension"
],
"license": "EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0",
"repository": {
"type": "git",
"url": "https://github.com/theia-ide/theia.git"
},
"bugs": {
"url": "https://github.com/theia-ide/theia/issues"
},
"homepage": "https://github.com/theia-ide/theia",
"files": [
"lib",
"src"
],
"scripts": {
"prepare": "yarn run clean && yarn run build",
"clean": "theiaext clean",
"build": "theiaext build",
"watch": "theiaext watch",
"test": "theiaext test",
"docs": "theiaext docs"
},
"devDependencies": {
"@theia/ext-scripts": "^0.3.14"
},
"nyc": {
"extends": "../../configs/nyc.json"
}
}
17 changes: 17 additions & 0 deletions packages/progress-monitor/src/browser/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/********************************************************************************
* Copyright (C) 2018 Red Hat, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
export * from './progress-service';
export * from './progress-protocol';
91 changes: 91 additions & 0 deletions packages/progress-monitor/src/browser/progress-dialog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/********************************************************************************
* Copyright (C) 2018 Red Hat, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable, inject, postConstruct } from 'inversify';
import { Message } from '@phosphor/messaging';
import { Disposable } from '@theia/core';
import { Widget, BaseWidget, Key, StatusBar } from '@theia/core/lib/browser';
import { ProgressWidget } from './progress-widget';

@injectable()
export class ProgressDialog extends BaseWidget {

protected contentNode: HTMLDivElement;

protected isOpen: boolean = false;

@inject(ProgressWidget) readonly widget: ProgressWidget;
@inject(StatusBar) protected readonly statusBar: StatusBar;

constructor() {
super();
this.contentNode = document.createElement('div');
this.contentNode.classList.add(ProgressWidget.Styles.PROGRESS_MONITOR_CONTENT);

this.node.classList.add(ProgressWidget.Styles.PROGRESS_WIDGET_DIALOG);

this.node.appendChild(this.contentNode);
this.update();
}

@postConstruct()
protected init() {
this.toDispose.push(this.widget);
}

protected onUpdateRequest(msg: Message): void {
super.onUpdateRequest(msg);
this.widget.update();
}

protected onAfterAttach(msg: Message): void {
super.onAfterAttach(msg);
Widget.attach(this.widget, this.contentNode);
this.toDisposeOnDetach.push(Disposable.create(() =>
Widget.detach(this.widget)
));

this.addKeyListener(document.body, Key.ESCAPE, e => {
this.closeDialog();
});
this.addEventListener(document.body, 'click', e => {
this.closeDialog();
e.stopPropagation();
}, true);
}

closeDialog() {
this.isOpen = false;
this.close();
}

protected onActivateRequest(msg: Message): void {
super.onActivateRequest(msg);
this.widget.activate();
}

async toggleOpen(): Promise<void> {
if (this.isOpen) {
this.closeDialog();
} else {
const progressStatusBar = await this.statusBar.getElementByClass(ProgressWidget.Styles.PROGRESS_STATUS_BAR);
Widget.attach(this, progressStatusBar[0] as HTMLElement);
this.activate();
this.isOpen = true;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/********************************************************************************
* Copyright (C) 2018 Red Hat, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { ContainerModule, interfaces } from 'inversify';
import { WidgetFactory, FrontendApplicationContribution } from '@theia/core/lib/browser';
import { ProgressService } from './progress-service';
import { ProgressDialog } from './progress-dialog';
import { ProgressStatusBar } from './progress-status-bar';
import { ProgressWidget } from './progress-widget';

export default new ContainerModule((bind: interfaces.Bind) => {

bind(ProgressDialog).toSelf().inSingletonScope();

bind(ProgressStatusBar).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toService(ProgressStatusBar);

bind(ProgressService).toSelf().inSingletonScope();

bind(ProgressWidget).toSelf();
bind(WidgetFactory).toDynamicValue(ctx => ({
id: 'progress-monitor',
createWidget: () => ctx.container.get(ProgressWidget)
}));

});
24 changes: 24 additions & 0 deletions packages/progress-monitor/src/browser/progress-protocol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/********************************************************************************
* Copyright (C) 2018 Red Hat, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

export interface ProgressReport {
readonly location: string; // Location denoting what part of theia this item is coming from
readonly id: string;
readonly task: string;
readonly workDone: number;
readonly totalWork: number;
readonly complete: boolean;
}
Loading

0 comments on commit 833ff6b

Please sign in to comment.