Skip to content

Commit a79c9b4

Browse files
Sketchbook tree indentation (arduino#1097)
1 parent 0f8a29a commit a79c9b4

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-tree-widget.tsx

+29-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import * as React from '@theia/core/shared/react';
2-
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
2+
import {
3+
inject,
4+
injectable,
5+
postConstruct,
6+
} from '@theia/core/shared/inversify';
37
import { TreeNode } from '@theia/core/lib/browser/tree/tree';
48
import { CommandRegistry } from '@theia/core/lib/common/command';
59
import {
@@ -22,6 +26,11 @@ import { SelectableTreeNode } from '@theia/core/lib/browser/tree/tree-selection'
2226
import { Sketch } from '../../contributions/contribution';
2327
import { nls } from '@theia/core/lib/common';
2428

29+
const customTreeProps: TreeProps = {
30+
leftPadding: 20,
31+
expansionTogglePadding: 6,
32+
};
33+
2534
@injectable()
2635
export class SketchbookTreeWidget extends FileTreeWidget {
2736
@inject(CommandRegistry)
@@ -57,10 +66,14 @@ export class SketchbookTreeWidget extends FileTreeWidget {
5766
super.init();
5867
// cache the current open sketch uri
5968
const currentSketch = await this.sketchServiceClient.currentSketch();
60-
this.currentSketchUri = (CurrentSketch.isValid(currentSketch) && currentSketch.uri) || '';
69+
this.currentSketchUri =
70+
(CurrentSketch.isValid(currentSketch) && currentSketch.uri) || '';
6171
}
6272

63-
protected override createNodeClassNames(node: TreeNode, props: NodeProps): string[] {
73+
protected override createNodeClassNames(
74+
node: TreeNode,
75+
props: NodeProps
76+
): string[] {
6477
const classNames = super.createNodeClassNames(node, props);
6578

6679
if (
@@ -73,7 +86,10 @@ export class SketchbookTreeWidget extends FileTreeWidget {
7386
return classNames;
7487
}
7588

76-
protected override renderIcon(node: TreeNode, props: NodeProps): React.ReactNode {
89+
protected override renderIcon(
90+
node: TreeNode,
91+
props: NodeProps
92+
): React.ReactNode {
7793
if (SketchbookTree.SketchDirNode.is(node) || Sketch.isSketchFile(node.id)) {
7894
return <div className="sketch-folder-icon file-icon"></div>;
7995
}
@@ -199,4 +215,13 @@ export class SketchbookTreeWidget extends FileTreeWidget {
199215
}
200216
event.stopPropagation();
201217
}
218+
219+
protected override getPaddingLeft(node: TreeNode, props: NodeProps): number {
220+
return (
221+
props.depth * customTreeProps.leftPadding +
222+
(this.needsExpansionTogglePadding(node)
223+
? customTreeProps.expansionTogglePadding
224+
: 0)
225+
);
226+
}
202227
}

0 commit comments

Comments
 (0)