UNPKG

6.45 kBTypeScriptView Raw
1import { Event, Emitter, WaitUntilEvent } from '../../common/event';
2import { Disposable, DisposableCollection } from '../../common/disposable';
3import { CancellationToken } from '../../common/cancellation';
4import { Mutable } from '../../common';
5export declare const Tree: unique symbol;
6/**
7 * The tree - an abstract data type.
8 */
9export interface Tree extends Disposable {
10 /**
11 * A root node of this tree.
12 * Undefined if there is no root node.
13 * Setting a root node refreshes the tree.
14 */
15 root: TreeNode | undefined;
16 /**
17 * Emit when the tree is changed.
18 */
19 readonly onChanged: Event<void>;
20 /**
21 * Return a node for the given identifier or undefined if such does not exist.
22 */
23 getNode(id: string | undefined): TreeNode | undefined;
24 /**
25 * Return a valid node in this tree matching to the given; otherwise undefined.
26 */
27 validateNode(node: TreeNode | undefined): TreeNode | undefined;
28 /**
29 * Refresh children of the root node.
30 *
31 * Return a valid refreshed composite root or `undefined` if such does not exist.
32 */
33 refresh(): Promise<Readonly<CompositeTreeNode> | undefined>;
34 /**
35 * Refresh children of a node for the give node id if it is valid.
36 *
37 * Return a valid refreshed composite node or `undefined` if such does not exist.
38 */
39 refresh(parent: Readonly<CompositeTreeNode>): Promise<Readonly<CompositeTreeNode> | undefined>;
40 /**
41 * Emit when the children of the given node are refreshed.
42 */
43 readonly onNodeRefreshed: Event<Readonly<CompositeTreeNode> & WaitUntilEvent>;
44 /**
45 * Emits when the busy state of the given node is changed.
46 */
47 readonly onDidChangeBusy: Event<TreeNode>;
48 /**
49 * Marks the give node as busy after a specified number of milliseconds.
50 * A token source of the given token should be canceled to unmark.
51 */
52 markAsBusy(node: Readonly<TreeNode>, ms: number, token: CancellationToken): Promise<void>;
53}
54/**
55 * The tree node.
56 */
57export interface TreeNode {
58 /**
59 * An unique id of this node.
60 */
61 readonly id: string;
62 /**
63 * A human-readable name of this tree node.
64 *
65 * @deprecated use `LabelProvider.getName` instead or move this property to your tree node type
66 */
67 readonly name?: string;
68 /**
69 * A css string for this tree node icon.
70 *
71 * @deprecated use `LabelProvider.getIcon` instead or move this property to your tree node type
72 */
73 readonly icon?: string;
74 /**
75 * A human-readable description of this tree node.
76 *
77 * @deprecated use `LabelProvider.getLongName` instead or move this property to your tree node type
78 */
79 readonly description?: string;
80 /**
81 * Test whether this node should be rendered.
82 * If undefined then node will be rendered.
83 */
84 readonly visible?: boolean;
85 /**
86 * A parent node of this tree node.
87 * Undefined if this node is root.
88 */
89 readonly parent: Readonly<CompositeTreeNode> | undefined;
90 /**
91 * A previous sibling of this tree node.
92 */
93 readonly previousSibling?: TreeNode;
94 /**
95 * A next sibling of this tree node.
96 */
97 readonly nextSibling?: TreeNode;
98 /**
99 * Whether this node is busy. Greater than 0 then busy; otherwise not.
100 */
101 readonly busy?: number;
102}
103export declare namespace TreeNode {
104 function is(node: unknown): node is TreeNode;
105 function equals(left: TreeNode | undefined, right: TreeNode | undefined): boolean;
106 function isVisible(node: TreeNode | undefined): boolean;
107}
108/**
109 * The composite tree node.
110 */
111export interface CompositeTreeNode extends TreeNode {
112 /**
113 * Child nodes of this tree node.
114 */
115 children: ReadonlyArray<TreeNode>;
116}
117export declare namespace CompositeTreeNode {
118 function is(node: unknown): node is CompositeTreeNode;
119 function getFirstChild(parent: CompositeTreeNode): TreeNode | undefined;
120 function getLastChild(parent: CompositeTreeNode): TreeNode | undefined;
121 function isAncestor(parent: CompositeTreeNode, child: TreeNode | undefined): boolean;
122 function indexOf(parent: CompositeTreeNode, node: TreeNode | undefined): number;
123 function addChildren(parent: CompositeTreeNode, children: TreeNode[]): CompositeTreeNode;
124 function addChild(parent: CompositeTreeNode, child: TreeNode): CompositeTreeNode;
125 function removeChild(parent: CompositeTreeNode, child: TreeNode): void;
126 function setParent(child: TreeNode, index: number, parent: CompositeTreeNode): void;
127}
128/**
129 * A default implementation of the tree.
130 */
131export declare class TreeImpl implements Tree {
132 protected _root: TreeNode | undefined;
133 protected readonly onChangedEmitter: Emitter<void>;
134 protected readonly onNodeRefreshedEmitter: Emitter<CompositeTreeNode & WaitUntilEvent>;
135 protected readonly toDispose: DisposableCollection;
136 protected readonly onDidChangeBusyEmitter: Emitter<TreeNode>;
137 readonly onDidChangeBusy: Event<TreeNode>;
138 protected nodes: {
139 [id: string]: Mutable<TreeNode> | undefined;
140 };
141 constructor();
142 dispose(): void;
143 get root(): TreeNode | undefined;
144 protected toDisposeOnSetRoot: DisposableCollection;
145 set root(root: TreeNode | undefined);
146 get onChanged(): Event<void>;
147 protected fireChanged(): void;
148 get onNodeRefreshed(): Event<CompositeTreeNode & WaitUntilEvent>;
149 protected fireNodeRefreshed(parent: CompositeTreeNode): Promise<void>;
150 getNode(id: string | undefined): TreeNode | undefined;
151 validateNode(node: TreeNode | undefined): TreeNode | undefined;
152 refresh(raw?: CompositeTreeNode, cancellationToken?: CancellationToken): Promise<CompositeTreeNode | undefined>;
153 protected resolveChildren(parent: CompositeTreeNode): Promise<TreeNode[]>;
154 protected setChildren(parent: CompositeTreeNode, children: TreeNode[]): Promise<CompositeTreeNode | undefined>;
155 protected removeNode(node: TreeNode | undefined): void;
156 protected getRootNode(node: TreeNode): TreeNode;
157 protected addNode(node: TreeNode | undefined): void;
158 markAsBusy(raw: TreeNode, ms: number, token: CancellationToken): Promise<void>;
159 protected doMarkAsBusy(node: Mutable<TreeNode>, ms: number, token: CancellationToken): Promise<void>;
160 protected doSetBusy(node: Mutable<TreeNode>): void;
161 protected doResetBusy(node: Mutable<TreeNode>): void;
162}
163//# sourceMappingURL=tree.d.ts.map
\No newline at end of file