Skip to content

Commit

Permalink
Get basic tree-like behaviour working
Browse files Browse the repository at this point in the history
See #605.
  • Loading branch information
DanTup committed Jun 6, 2018
1 parent 2bbe47e commit c7c2b28
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/views/flutter_outline_view.ts
Expand Up @@ -34,12 +34,13 @@ export class FlutterOutlineProvider implements vs.TreeDataProvider<FlutterWidget
}

private update() {
if (!this.flutterOutline || !this.activeEditor || this.flutterOutline.file !== this.activeEditor.document.fileName)
if (!this.flutterOutline || !this.activeEditor || this.flutterOutline.file !== this.activeEditor.document.fileName || !this.flutterOutline.outline || !this.flutterOutline.outline.children || this.flutterOutline.outline.children.length === 0) {
FlutterOutlineProvider.hideTree();
return;
}

FlutterOutlineProvider.showTree();

// Do tree...
this.refresh();
}

private setTrackingFile(editor: vs.TextEditor) {
Expand All @@ -63,7 +64,15 @@ export class FlutterOutlineProvider implements vs.TreeDataProvider<FlutterWidget
}

public getChildren(element?: FlutterWidgetItem): FlutterWidgetItem[] {
return [];
if (!element) {
if (this.flutterOutline && this.flutterOutline.outline && this.flutterOutline.outline.children && this.flutterOutline.outline.length) {
return this.flutterOutline.outline.children.map((c) => new FlutterWidgetItem(c));
} else {
return [];
}
} else {
return element.outline.children.map((c) => new FlutterWidgetItem(c));
}
}

private static setTreeVisible(visible: boolean) {
Expand All @@ -81,12 +90,14 @@ export class FlutterOutlineProvider implements vs.TreeDataProvider<FlutterWidget

class FlutterWidgetItem extends vs.TreeItem {
constructor(
public readonly label: string,
public readonly depPath: string,
public readonly collapsibleState?: vs.TreeItemCollapsibleState,
public readonly command?: vs.Command,
public readonly outline: as.FlutterOutline,
) {
super(label, collapsibleState);
super(
outline.label || outline.kind,
outline.children && outline.children.length
? vs.TreeItemCollapsibleState.Collapsed
: vs.TreeItemCollapsibleState.None,
);
}

public contextValue = "flutterWidget";
Expand Down

0 comments on commit c7c2b28

Please sign in to comment.