Skip to content

Commit

Permalink
explorer.compressSingleChildFolders
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomoreno committed Nov 6, 2019
1 parent 26f3390 commit 619c082
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/vs/base/browser/ui/tree/asyncDataTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,10 @@ export interface ICompressibleAsyncDataTreeOptions<T, TFilterData = void> extend
readonly keyboardNavigationLabelProvider?: ICompressibleKeyboardNavigationLabelProvider<T>;
}

export interface ICompressibleAsyncDataTreeOptionsUpdate extends IAsyncDataTreeOptionsUpdate {
readonly compressionEnabled?: boolean;
}

export class CompressibleAsyncDataTree<TInput, T, TFilterData = void> extends AsyncDataTree<TInput, T, TFilterData> {

protected readonly tree: CompressibleObjectTree<IAsyncDataTreeNode<TInput, T>, TFilterData>;
Expand Down Expand Up @@ -1063,6 +1067,10 @@ export class CompressibleAsyncDataTree<TInput, T, TFilterData = void> extends As
};
}

updateOptions(options: ICompressibleAsyncDataTreeOptionsUpdate = {}): void {
this.tree.updateOptions(options);
}

getViewState(): IAsyncDataTreeViewState {
if (!this.identityProvider) {
throw new TreeError(this.user, 'Can\'t get tree view state without an identity provider');
Expand Down
16 changes: 10 additions & 6 deletions src/vs/base/browser/ui/tree/objectTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { ISequence } from 'vs/base/common/iterator';
import { AbstractTree, IAbstractTreeOptions } from 'vs/base/browser/ui/tree/abstractTree';
import { AbstractTree, IAbstractTreeOptions, IAbstractTreeOptionsUpdate } from 'vs/base/browser/ui/tree/abstractTree';
import { ISpliceable } from 'vs/base/common/sequence';
import { ITreeNode, ITreeModel, ITreeElement, ITreeRenderer, ITreeSorter, ICollapseStateChangeEvent } from 'vs/base/browser/ui/tree/tree';
import { ObjectTreeModel, IObjectTreeModel } from 'vs/base/browser/ui/tree/objectTreeModel';
Expand Down Expand Up @@ -160,6 +160,10 @@ function asObjectTreeOptions<T, TFilterData>(compressedTreeNodeProvider: () => I
};
}

export interface ICompressibleObjectTreeOptionsUpdate extends IAbstractTreeOptionsUpdate {
readonly compressionEnabled?: boolean;
}

export class CompressibleObjectTree<T extends NonNullable<any>, TFilterData = void> extends ObjectTree<T, TFilterData> implements ICompressedTreeNodeProvider<T, TFilterData> {

protected model!: CompressibleObjectTreeModel<T, TFilterData>;
Expand All @@ -184,12 +188,12 @@ export class CompressibleObjectTree<T extends NonNullable<any>, TFilterData = vo
return new CompressibleObjectTreeModel(user, view, options);
}

isCompressionEnabled(): boolean {
return this.model.isCompressionEnabled();
}
updateOptions(optionsUpdate: ICompressibleObjectTreeOptionsUpdate = {}): void {
super.updateOptions(optionsUpdate);

setCompressionEnabled(enabled: boolean): void {
this.model.setCompressionEnabled(enabled);
if (typeof optionsUpdate.compressionEnabled !== 'undefined') {
this.model.setCompressionEnabled(optionsUpdate.compressionEnabled);
}
}

getCompressedTreeNode(element: T | null = null): ITreeNode<ICompressedTreeNode<T> | null, TFilterData> {
Expand Down
6 changes: 2 additions & 4 deletions src/vs/base/test/browser/ui/tree/objectTree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,6 @@ suite('CompressibleObjectTree', function () {
const tree = new CompressibleObjectTree<number>('test', container, new Delegate(), [new Renderer()]);
tree.layout(200);

assert.equal(tree.isCompressionEnabled(), true);

tree.setChildren(null, Iterator.fromArray([
{
element: 1, children: Iterator.fromArray([{
Expand All @@ -367,11 +365,11 @@ suite('CompressibleObjectTree', function () {
let rows = toArray(container.querySelectorAll('.monaco-tl-contents')).map(row => row.textContent);
assert.deepEqual(rows, ['1/11/111', '1111', '1112', '1113']);

tree.setCompressionEnabled(false);
tree.updateOptions({ compressionEnabled: false });
rows = toArray(container.querySelectorAll('.monaco-tl-contents')).map(row => row.textContent);
assert.deepEqual(rows, ['1', '11', '111', '1111', '1112', '1113']);

tree.setCompressionEnabled(true);
tree.updateOptions({ compressionEnabled: true });
rows = toArray(container.querySelectorAll('.monaco-tl-contents')).map(row => row.textContent);
assert.deepEqual(rows, ['1/11/111', '1111', '1112', '1113']);
});
Expand Down
7 changes: 6 additions & 1 deletion src/vs/workbench/contrib/files/browser/files.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,12 @@ configurationRegistry.registerConfiguration({
],
description: nls.localize('explorer.incrementalNaming', "Controls what naming strategy to use when a giving a new name to a duplicated explorer item on paste."),
default: 'simple'
}
},
'explorer.compressSingleChildFolders': {
'type': 'boolean',
'description': nls.localize('compressSingleChildFolders', "Controls whether the explorer should compress single child folders in a combined tree element. Useful for Java project folder structures, for example."),
'default': false
},
}
});

Expand Down
9 changes: 8 additions & 1 deletion src/vs/workbench/contrib/files/browser/views/explorerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { first } from 'vs/base/common/arrays';
import { withNullAsUndefined } from 'vs/base/common/types';
import { IFileService, FileSystemProviderCapabilities } from 'vs/platform/files/common/files';
import { dispose } from 'vs/base/common/lifecycle';
import { Event } from 'vs/base/common/event';

export class ExplorerView extends ViewletPanel {
static readonly ID: string = 'workbench.explorer.fileView';
Expand Down Expand Up @@ -282,9 +283,11 @@ export class ExplorerView extends ViewletPanel {

this._register(createFileIconThemableTreeContainerScope(container, this.themeService));

const isCompressionEnabled = () => this.configurationService.getValue<boolean>('explorer.compressSingleChildFolders');

this.tree = this.instantiationService.createInstance<typeof WorkbenchCompressibleAsyncDataTree, WorkbenchCompressibleAsyncDataTree<ExplorerItem | ExplorerItem[], ExplorerItem, FuzzyScore>>(WorkbenchCompressibleAsyncDataTree, 'FileExplorer', container, new ExplorerDelegate(), new ExplorerCompressionDelegate(), [filesRenderer],
this.instantiationService.createInstance(ExplorerDataSource), {
// compressionEnabled: false,
compressionEnabled: isCompressionEnabled(),
accessibilityProvider: new ExplorerAccessibilityProvider(),
ariaLabel: nls.localize('treeAriaLabel', "Files Explorer"),
identityProvider: {
Expand Down Expand Up @@ -321,6 +324,10 @@ export class ExplorerView extends ViewletPanel {
});
this._register(this.tree);

// Bind configuration
const onDidChangeCompressionConfiguration = Event.filter(this.configurationService.onDidChangeConfiguration, e => e.affectsConfiguration('explorer.compressSingleChildFolders'));
this._register(onDidChangeCompressionConfiguration(_ => this.tree.updateOptions({ compressionEnabled: isCompressionEnabled() })));

// Bind context keys
FilesExplorerFocusedContext.bindTo(this.tree.contextKeyService);
ExplorerFocusedContext.bindTo(this.tree.contextKeyService);
Expand Down

0 comments on commit 619c082

Please sign in to comment.