Skip to content

Commit

Permalink
Merge pull request #64807 from Microsoft/joao/outline
Browse files Browse the repository at this point in the history
Adopt AbstractTreeRenderer to get re-render behavior
  • Loading branch information
jrieken authored Dec 13, 2018
2 parents 0cd7350 + 601a048 commit aa310b3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
31 changes: 19 additions & 12 deletions src/vs/editor/contrib/documentSymbols/outlineTree2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import { MarkerSeverity } from 'vs/platform/markers/common/markers';
import { listErrorForeground, listWarningForeground } from 'vs/platform/theme/common/colorRegistry';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IIdentityProvider, IListVirtualDelegate } from 'vs/base/browser/ui/list/list';
import { ITreeRenderer, ITreeNode, ITreeFilter, TreeFilterResult, TreeVisibility, ITreeElement } from 'vs/base/browser/ui/tree/tree';
import { ITreeRenderer, ITreeNode, ITreeFilter, TreeFilterResult, TreeVisibility, ITreeElement, AbstractTreeRenderer } from 'vs/base/browser/ui/tree/tree';
import { Iterator } from 'vs/base/common/iterator';
import { Event } from 'vs/base/common/event';

export type NOutlineItem = OutlineGroup | OutlineElement;

Expand Down Expand Up @@ -73,7 +74,9 @@ export class NOutlineVirtualDelegate implements IListVirtualDelegate<NOutlineIte
}
}

export class NOutlineGroupRenderer implements ITreeRenderer<OutlineGroup, void, NOutlineGroupTemplate> {
export class NOutlineGroupRenderer
extends AbstractTreeRenderer<OutlineGroup, void, NOutlineGroupTemplate>
implements ITreeRenderer<OutlineGroup, void, NOutlineGroupTemplate> {

readonly templateId: string = NOutlineGroupTemplate.id;

Expand All @@ -85,26 +88,30 @@ export class NOutlineGroupRenderer implements ITreeRenderer<OutlineGroup, void,
}

renderElement(node: ITreeNode<OutlineGroup, void>, index: number, template: NOutlineGroupTemplate): void {
super.renderElement(node, index, template);
template.label.set(node.element.provider.displayName || localize('provider', "Outline Provider"));
}

disposeTemplate(template: NOutlineGroupTemplate): void {
template.label.dispose();
}

disposeElement(): void {
//
}
}

export class NOutlineElementRenderer implements ITreeRenderer<OutlineElement, void, NOutlineElementTemplate> {
export class NOutlineElementRenderer
extends AbstractTreeRenderer<OutlineElement, void, NOutlineGroupTemplate>
implements ITreeRenderer<OutlineElement, void, NOutlineElementTemplate> {

readonly templateId: string = NOutlineElementTemplate.id;

renderProblemColors = true;
renderProblemBadges = true;

constructor(@IThemeService readonly _themeService: IThemeService) { }
constructor(
onDidChange: Event<OutlineElement | OutlineElement[] | undefined>,
@IThemeService readonly _themeService: IThemeService
) {
super(onDidChange);
}

renderTemplate(container: HTMLElement): NOutlineElementTemplate {
const icon = dom.$('.outline-element-icon symbol-icon');
Expand All @@ -116,7 +123,10 @@ export class NOutlineElementRenderer implements ITreeRenderer<OutlineElement, vo
return { icon, labelContainer, label: new HighlightedLabel(labelContainer, true), detail, decoration };
}

renderElement({ element }: ITreeNode<OutlineElement, void>, index: number, template: NOutlineElementTemplate): void {
renderElement(node: ITreeNode<OutlineElement, void>, index: number, template: NOutlineElementTemplate): void {
super.renderElement(node, index, template);

const { element } = node;
template.icon.className = `outline-element-icon ${symbolKindToCssClass(element.symbol.kind)}`;
template.label.set(element.symbol.name, element.score ? createMatches(element.score[1]) : undefined, localize('title.template', "{0} ({1})", element.symbol.name, NOutlineElementRenderer._symbolKindNames[element.symbol.kind]));
template.detail.innerText = element.symbol.detail || '';
Expand Down Expand Up @@ -194,9 +204,6 @@ export class NOutlineElementRenderer implements ITreeRenderer<OutlineElement, vo
disposeTemplate(template: NOutlineElementTemplate): void {
template.label.dispose();
}

disposeElement(): void {
}
}

export function createModelIterator(model: OutlineModel): Iterator<ITreeElement<NOutlineItem>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Action, IAction, RadioGroup } from 'vs/base/common/actions';
import { firstIndex } from 'vs/base/common/arrays';
import { createCancelablePromise, TimeoutTimer } from 'vs/base/common/async';
import { isPromiseCanceledError, onUnexpectedError } from 'vs/base/common/errors';
import { Emitter } from 'vs/base/common/event';
import { Emitter, Event } from 'vs/base/common/event';
import { defaultGenerator } from 'vs/base/common/idGenerator';
import { KeyCode } from 'vs/base/common/keyCodes';
import { dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
Expand Down Expand Up @@ -356,8 +356,9 @@ export class OutlinePanel extends ViewletPanel {
}
};

this._treeGroupRenderer = this._instantiationService.createInstance(NOutlineGroupRenderer);
this._treeElementRenderer = this._instantiationService.createInstance(NOutlineElementRenderer);
// TODO@joh: pass along to the renderers an event which should trigger a re-render of elements
this._treeGroupRenderer = this._instantiationService.createInstance(NOutlineGroupRenderer, Event.None);
this._treeElementRenderer = this._instantiationService.createInstance(NOutlineElementRenderer, Event.None);
this._treeFilter = this._instantiationService.createInstance(NOutlineFilter);

this._tree = <any>this._instantiationService.createInstance(WorkbenchObjectTree,
Expand All @@ -373,7 +374,7 @@ export class OutlinePanel extends ViewletPanel {
this._treeElementRenderer.renderProblemColors = this._configurationService.getValue(OutlineConfigKeys.problemsColors);
this._treeElementRenderer.renderProblemBadges = this._configurationService.getValue(OutlineConfigKeys.problemsBadges);

this._disposables.push(this._tree, this._input);
this._disposables.push(this._tree, this._input, this._treeGroupRenderer, this._treeElementRenderer);
this._disposables.push(this._outlineViewState.onDidChange(this._onDidChangeUserState, this));

// feature: toggle icons
Expand Down

0 comments on commit aa310b3

Please sign in to comment.