Skip to content

Commit

Permalink
fixup! Apply Timeline plugin API
Browse files Browse the repository at this point in the history
  • Loading branch information
vinokurig committed Sep 7, 2020
1 parent bc2e375 commit 15827e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
14 changes: 6 additions & 8 deletions packages/timeline/src/browser/timeline-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
@injectable()
export class TimelineService {
private readonly providers = new Map<string, TimelineProvider>();
private readonly providerSubscriptions = new Map<string, Disposable>();

private readonly onDidChangeProvidersEmitter = new Emitter<TimelineProvidersChangeEvent>();
readonly onDidChangeProviders: Event<TimelineProvidersChangeEvent> = this.onDidChangeProvidersEmitter.event;
Expand All @@ -42,21 +41,20 @@ export class TimelineService {

this.providers.set(id, provider);
if (provider.onDidChange) {
this.providerSubscriptions.set(id, provider.onDidChange(e => this.onDidChangeTimelineEmitter.fire(e)));
provider.onDidChange(e => this.onDidChangeTimelineEmitter.fire(e));
}
this.onDidChangeProvidersEmitter.fire({ added: [id] });

return Disposable.create(() => this.unregisterTimelineProvider(id));
}

unregisterTimelineProvider(id: string): void {
if (!this.providers.has(id)) {
return;
const provider = this.providers.get(id);
if (provider) {
provider.dispose();
this.providers.delete(id);
this.onDidChangeProvidersEmitter.fire({ removed: [id] });
}

this.providers.delete(id);
this.providerSubscriptions.delete(id);
this.onDidChangeProvidersEmitter.fire({ removed: [id] });
}

getSources(): TimelineSource[] {
Expand Down
12 changes: 8 additions & 4 deletions packages/timeline/src/browser/timeline-tree-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable } from 'inversify';
import { inject, injectable } from 'inversify';
import {
CompositeTreeNode,
SelectableTreeNode,
TreeModelImpl,
TreeModelImpl, TreeSelectionService,
} from '@theia/core/lib/browser/tree';
import { TimelineItem } from '../common/timeline-model';
import { TimelineContribution } from './timeline-contribution';
Expand All @@ -30,6 +30,8 @@ export interface TimelineNode extends SelectableTreeNode {
@injectable()
export class TimelineTreeModel extends TreeModelImpl {

@inject(TreeSelectionService) protected readonly selectionService: TreeSelectionService;

updateTree(items: TimelineItem[], hasMoreItems: boolean): void {
const root = {
id: 'timeline-tree-root',
Expand All @@ -50,12 +52,14 @@ export class TimelineTreeModel extends TreeModelImpl {
if (hasMoreItems) {
const loadMoreNode: TimelineItem = { label: 'Load-more', timestamp: 0, handle: '', uri: '', source: '' };
loadMoreNode.command = TimelineContribution.LOAD_MORE_COMMAND;
children.push({
const loadMore = {
timelineItem: loadMoreNode,
id: 'load-more',
parent: root,
selected: true
});
};
children.push(loadMore);
this.selectionService.addSelection(loadMore);
}
root.children = children;
this.root = root;
Expand Down

0 comments on commit 15827e2

Please sign in to comment.