Skip to content

Commit

Permalink
sketchbook tree indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
francescospissu committed Jun 22, 2022
1 parent 0f8a29a commit a0aa333
Showing 1 changed file with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as React from '@theia/core/shared/react';
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
import {
inject,
injectable,
postConstruct,
} from '@theia/core/shared/inversify';
import { TreeNode } from '@theia/core/lib/browser/tree/tree';
import { CommandRegistry } from '@theia/core/lib/common/command';
import {
Expand All @@ -22,6 +26,11 @@ import { SelectableTreeNode } from '@theia/core/lib/browser/tree/tree-selection'
import { Sketch } from '../../contributions/contribution';
import { nls } from '@theia/core/lib/common';

const customTreeProps: TreeProps = {
leftPadding: 20,
expansionTogglePadding: 6,
};

@injectable()
export class SketchbookTreeWidget extends FileTreeWidget {
@inject(CommandRegistry)
Expand Down Expand Up @@ -57,10 +66,14 @@ export class SketchbookTreeWidget extends FileTreeWidget {
super.init();
// cache the current open sketch uri
const currentSketch = await this.sketchServiceClient.currentSketch();
this.currentSketchUri = (CurrentSketch.isValid(currentSketch) && currentSketch.uri) || '';
this.currentSketchUri =
(CurrentSketch.isValid(currentSketch) && currentSketch.uri) || '';
}

protected override createNodeClassNames(node: TreeNode, props: NodeProps): string[] {
protected override createNodeClassNames(
node: TreeNode,
props: NodeProps
): string[] {
const classNames = super.createNodeClassNames(node, props);

if (
Expand All @@ -73,7 +86,10 @@ export class SketchbookTreeWidget extends FileTreeWidget {
return classNames;
}

protected override renderIcon(node: TreeNode, props: NodeProps): React.ReactNode {
protected override renderIcon(
node: TreeNode,
props: NodeProps
): React.ReactNode {
if (SketchbookTree.SketchDirNode.is(node) || Sketch.isSketchFile(node.id)) {
return <div className="sketch-folder-icon file-icon"></div>;
}
Expand Down Expand Up @@ -199,4 +215,13 @@ export class SketchbookTreeWidget extends FileTreeWidget {
}
event.stopPropagation();
}

protected override getPaddingLeft(node: TreeNode, props: NodeProps): number {
return (
props.depth * customTreeProps.leftPadding +
(this.needsExpansionTogglePadding(node)
? customTreeProps.expansionTogglePadding
: 0)
);
}
}

0 comments on commit a0aa333

Please sign in to comment.