Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tree widget indentation configurable #13179

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- [plugin] stub multiDocumentHighlightProvider proposed API [#13248](https://github.com/eclipse-theia/theia/pull/13248) - contributed on behalf of STMicroelectronics
- [terminal] update terminalQuickFixProvider proposed API according to vscode 1.85 version [#13240](https://github.com/eclipse-theia/theia/pull/13240) - contributed on behalf of STMicroelectronics
- [core] added preference 'workbench.tree.indent' to control the indentation in the tree widget [#13179](https://github.com/eclipse-theia/theia/pull/13179) - contributed on behalf of STMicroelectronics

## v1.45.0 - 12/21/2023

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/browser/frontend-application-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ import { bindCommonStylingParticipants } from './common-styling-participants';
import { HoverService } from './hover-service';
import { AdditionalViewsMenuWidget, AdditionalViewsMenuWidgetFactory } from './shell/additional-views-menu-widget';
import { LanguageIconLabelProvider } from './language-icon-provider';
import { bindTreePreferences } from './tree';

export { bindResourceProvider, bindMessageService, bindPreferenceService };

Expand Down Expand Up @@ -366,6 +367,7 @@ export const frontendApplicationModule = new ContainerModule((bind, _unbind, _is
bind(ThemeService).toSelf().inSingletonScope();

bindCorePreferences(bind);
bindTreePreferences(bind);

bind(MimeService).toSelf().inSingletonScope();

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/browser/tree/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ export * from './tree-container';
export * from './tree-decorator';
export * from './tree-search';
export * from './tree-compression';
export * from './tree-preference';
50 changes: 50 additions & 0 deletions packages/core/src/browser/tree/tree-preference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// *****************************************************************************
// Copyright (C) 2024 STMicroelectronics and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************

import { interfaces } from 'inversify';
import { PreferenceProxy, PreferenceContribution, PreferenceSchema } from '../preferences';
import { PreferenceProxyFactory } from '../preferences/injectable-preference-proxy';
import { nls } from '../../common/nls';

export const PREFERENCE_NAME_TREE_INDENT = 'workbench.tree.indent';

export const treePreferencesSchema: PreferenceSchema = {
type: 'object',
properties: {
[PREFERENCE_NAME_TREE_INDENT]: {
description: nls.localizeByDefault('Controls tree indentation in pixels.'),
type: 'number',
default: 8,
minimum: 4,
maximum: 40
},
}
};

export class TreeConfiguration {
[PREFERENCE_NAME_TREE_INDENT]: number;
}

export const TreePreferences = Symbol('treePreferences');
export type TreePreferences = PreferenceProxy<TreeConfiguration>;

export function bindTreePreferences(bind: interfaces.Bind): void {
bind(TreePreferences).toDynamicValue(ctx => {
const factory = ctx.container.get<PreferenceProxyFactory>(PreferenceProxyFactory);
return factory(treePreferencesSchema);
}).inSingletonScope();
bind(PreferenceContribution).toConstantValue({ schema: treePreferencesSchema });
}
22 changes: 19 additions & 3 deletions packages/core/src/browser/tree/tree-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import { LabelProvider } from '../label-provider';
import { CorePreferences } from '../core-preferences';
import { TreeFocusService } from './tree-focus-service';
import { useEffect } from 'react';
import { PreferenceService, PreferenceChange } from '../preferences';
import { PREFERENCE_NAME_TREE_INDENT } from './tree-preference';

const debounce = require('lodash.debounce');

Expand Down Expand Up @@ -73,8 +75,7 @@ export interface TreeProps {
readonly contextMenuPath?: MenuPath;

/**
* The size of the padding (in pixels) per hierarchy depth. The root element won't have left padding but
* the padding for the children will be calculated as `leftPadding * hierarchyDepth` and so on.
* The size of the padding (in pixels) for the root node of the tree.
*/
readonly leftPadding: number;

Expand Down Expand Up @@ -174,6 +175,9 @@ export class TreeWidget extends ReactWidget implements StatefulWidget {
@inject(SelectionService)
protected readonly selectionService: SelectionService;

@inject(PreferenceService)
protected readonly preferenceService: PreferenceService;

@inject(LabelProvider)
protected readonly labelProvider: LabelProvider;

Expand All @@ -182,6 +186,8 @@ export class TreeWidget extends ReactWidget implements StatefulWidget {

protected shouldScrollToRow = true;

protected treeIndent: number = 8;

constructor(
@inject(TreeProps) readonly props: TreeProps,
@inject(TreeModel) readonly model: TreeModel,
Expand All @@ -198,6 +204,7 @@ export class TreeWidget extends ReactWidget implements StatefulWidget {

@postConstruct()
protected init(): void {
this.treeIndent = this.preferenceService.get(PREFERENCE_NAME_TREE_INDENT, this.treeIndent);
if (this.props.search) {
this.searchBox = this.searchBoxFactory({ ...SearchBoxProps.DEFAULT, showButtons: true, showFilter: true });
this.searchBox.node.addEventListener('focus', () => {
Expand Down Expand Up @@ -264,6 +271,12 @@ export class TreeWidget extends ReactWidget implements StatefulWidget {
return;
}
}
}),
this.preferenceService.onPreferenceChanged((event: PreferenceChange) => {
if (event.preferenceName === PREFERENCE_NAME_TREE_INDENT) {
this.treeIndent = event.newValue;
this.update();
}
})
]);
setTimeout(() => {
Expand Down Expand Up @@ -1500,7 +1513,10 @@ export class TreeWidget extends ReactWidget implements StatefulWidget {
return this.labelProvider.getLongName(node);
}
protected getDepthPadding(depth: number): number {
return depth * this.props.leftPadding;
if (depth === 1) {
return this.props.leftPadding;
}
return depth * this.treeIndent;
}
}
export namespace TreeWidget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@

import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
import { FileNavigatorPreferences } from './navigator-preferences';
import { PreferenceService } from '@theia/core/lib/browser/preferences/preference-service';
import { FileTreeWidget } from '@theia/filesystem/lib/browser';
import { Attributes, HTMLAttributes } from '@theia/core/shared/react';
import { TreeNode } from '@theia/core/lib/browser';

@injectable()
export class AbstractNavigatorTreeWidget extends FileTreeWidget {

@inject(PreferenceService)
protected readonly preferenceService: PreferenceService;

@inject(FileNavigatorPreferences)
protected readonly navigatorPreferences: FileNavigatorPreferences;

Expand Down
Loading