Skip to content

Commit

Permalink
Expand all folders
Browse files Browse the repository at this point in the history
  • Loading branch information
dangus21 authored and miguelcsw committed Jul 23, 2024
1 parent 13d596e commit 24a4c70
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 47 deletions.
4 changes: 4 additions & 0 deletions src/vs/base/browser/ui/tree/asyncDataTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,10 @@ export class AsyncDataTree<TInput, T, TFilterData = void> implements IDisposable
this.tree.collapseAll();
}

expandAllFolders(): void {
this.tree.expandAll();
}

isCollapsible(element: T): boolean {
return this.tree.isCollapsible(this.getDataNode(element));
}
Expand Down
136 changes: 89 additions & 47 deletions src/vs/workbench/contrib/files/browser/views/explorerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,59 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as nls from 'vs/nls';
import { URI } from 'vs/base/common/uri';
import * as perf from 'vs/base/common/performance';
import { WorkbenchActionExecutedEvent, WorkbenchActionExecutedClassification } from 'vs/base/common/actions';
import { memoize } from 'vs/base/common/decorators';
import { IFilesConfiguration, ExplorerFolderContext, FilesExplorerFocusedContext, ExplorerFocusedContext, ExplorerRootContext, ExplorerResourceReadonlyContext, ExplorerResourceCut, ExplorerResourceMoveableToTrash, ExplorerCompressedFocusContext, ExplorerCompressedFirstFocusContext, ExplorerCompressedLastFocusContext, ExplorerResourceAvailableEditorIdsContext, VIEW_ID, ExplorerResourceNotReadonlyContext, ViewHasSomeCollapsibleRootItemContext, FoldersViewVisibleContext } from 'vs/workbench/contrib/files/common/files';
import { FileCopiedContext, NEW_FILE_COMMAND_ID, NEW_FOLDER_COMMAND_ID } from 'vs/workbench/contrib/files/browser/fileActions';
import { DelayedDragHandler } from 'vs/base/browser/dnd';
import * as DOM from 'vs/base/browser/dom';
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
import { ExplorerDecorationsProvider } from 'vs/workbench/contrib/files/browser/views/explorerDecorationsProvider';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress';
import { isInputElement } from 'vs/base/browser/ui/list/listWidget';
import { AbstractTreePart } from 'vs/base/browser/ui/tree/abstractTree';
import type { IAsyncDataTreeViewState } from 'vs/base/browser/ui/tree/asyncDataTree';
import { type ITreeContextMenuEvent, TreeVisibility } from 'vs/base/browser/ui/tree/tree';
import type { WorkbenchActionExecutedClassification, WorkbenchActionExecutedEvent } from 'vs/base/common/actions';
import { Codicon } from 'vs/base/common/codicons';
import { memoize } from 'vs/base/common/decorators';
import { Event } from 'vs/base/common/event';
import type { FuzzyScore } from 'vs/base/common/filters';
import type { IDisposable } from 'vs/base/common/lifecycle';
import { ResourceMap } from 'vs/base/common/map';
import * as perf from 'vs/base/common/performance';
import type { URI } from 'vs/base/common/uri';
import * as nls from 'vs/nls';
import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { type IConfigurationChangeEvent, IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ContextKeyExpr, type IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IContextKeyService, IContextKey, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { ResourceContextKey } from 'vs/workbench/common/contextkeys';
import { IDecorationsService } from 'vs/workbench/services/decorations/common/decorations';
import { WorkbenchCompressibleAsyncDataTree } from 'vs/platform/list/browser/listService';
import { DelayedDragHandler } from 'vs/base/browser/dnd';
import { IEditorService, SIDE_GROUP, ACTIVE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { IViewPaneOptions, ViewPane } from 'vs/workbench/browser/parts/views/viewPane';
import { EditorOpenSource } from 'vs/platform/editor/common/editor';
import { FileSystemProviderCapabilities, IFileService } from 'vs/platform/files/common/files';
import { IHoverService } from 'vs/platform/hover/browser/hover';
import { IInstantiationService, type ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { ILabelService } from 'vs/platform/label/common/label';
import { ExplorerDelegate, ExplorerDataSource, FilesRenderer, ICompressedNavigationController, FilesFilter, FileSorter, FileDragAndDrop, ExplorerCompressionDelegate, isCompressedFolderName } from 'vs/workbench/contrib/files/browser/views/explorerViewer';
import { IThemeService, IFileIconTheme } from 'vs/platform/theme/common/themeService';
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { ITreeContextMenuEvent, TreeVisibility } from 'vs/base/browser/ui/tree/tree';
import { MenuId, Action2, registerAction2 } from 'vs/platform/actions/common/actions';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { ExplorerItem, NewExplorerItem } from 'vs/workbench/contrib/files/common/explorerModel';
import { ResourceLabels } from 'vs/workbench/browser/labels';
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
import { IAsyncDataTreeViewState } from 'vs/base/browser/ui/tree/asyncDataTree';
import { FuzzyScore } from 'vs/base/common/filters';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { IFileService, FileSystemProviderCapabilities } from 'vs/platform/files/common/files';
import { IDisposable } from 'vs/base/common/lifecycle';
import { Event } from 'vs/base/common/event';
import { IViewDescriptorService } from 'vs/workbench/common/views';
import { IViewsService } from 'vs/workbench/services/views/common/viewsService';
import { WorkbenchCompressibleAsyncDataTree } from 'vs/platform/list/browser/listService';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress';
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { type IFileIconTheme, IThemeService } from 'vs/platform/theme/common/themeService';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { ResourceLabels } from 'vs/workbench/browser/labels';
import { type IViewPaneOptions, ViewPane } from 'vs/workbench/browser/parts/views/viewPane';
import { ResourceContextKey } from 'vs/workbench/common/contextkeys';
import { EditorResourceAccessor, SideBySideEditor } from 'vs/workbench/common/editor';
import { IExplorerService, IExplorerView } from 'vs/workbench/contrib/files/browser/files';
import { Codicon } from 'vs/base/common/codicons';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IViewDescriptorService } from 'vs/workbench/common/views';
import { FileCopiedContext, NEW_FILE_COMMAND_ID, NEW_FOLDER_COMMAND_ID } from 'vs/workbench/contrib/files/browser/fileActions';
import { IExplorerService, type IExplorerView } from 'vs/workbench/contrib/files/browser/files';
import { ExplorerDecorationsProvider } from 'vs/workbench/contrib/files/browser/views/explorerDecorationsProvider';
import { ExplorerCompressionDelegate, ExplorerDataSource, ExplorerDelegate, FileDragAndDrop, FileSorter, FilesFilter, FilesRenderer, type ICompressedNavigationController, isCompressedFolderName } from 'vs/workbench/contrib/files/browser/views/explorerViewer';
import { ExplorerItem, NewExplorerItem } from 'vs/workbench/contrib/files/common/explorerModel';
import { ExplorerCompressedFirstFocusContext, ExplorerCompressedFocusContext, ExplorerCompressedLastFocusContext, ExplorerFocusedContext, ExplorerFolderContext, ExplorerResourceAvailableEditorIdsContext, ExplorerResourceCut, ExplorerResourceMoveableToTrash, ExplorerResourceNotReadonlyContext, ExplorerResourceReadonlyContext, ExplorerRootContext, FilesExplorerFocusedContext, FoldersViewVisibleContext, type IFilesConfiguration, VIEW_ID, ViewHasSomeCollapsibleRootItemContext } from 'vs/workbench/contrib/files/common/files';
import { IDecorationsService } from 'vs/workbench/services/decorations/common/decorations';
import { IEditorResolverService } from 'vs/workbench/services/editor/common/editorResolverService';
import { EditorOpenSource } from 'vs/platform/editor/common/editor';
import { ResourceMap } from 'vs/base/common/map';
import { isInputElement } from 'vs/base/browser/ui/list/listWidget';
import { AbstractTreePart } from 'vs/base/browser/ui/tree/abstractTree';
import { IHoverService } from 'vs/platform/hover/browser/hover';
import { ACTIVE_GROUP, IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
import type { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { IViewsService } from 'vs/workbench/services/views/common/viewsService';


function hasExpandedRootChild(tree: WorkbenchCompressibleAsyncDataTree<ExplorerItem | ExplorerItem[], ExplorerItem, FuzzyScore>, treeInput: ExplorerItem[]): boolean {
Expand Down Expand Up @@ -686,7 +686,7 @@ export class ExplorerView extends ViewPane implements IExplorerView {
* Refresh the contents of the explorer to get up to date data from the disk about the file structure.
* If the item is passed we refresh only that level of the tree, otherwise we do a full refresh.
*/
refresh(recursive: boolean, item?: ExplorerItem, cancelEditing: boolean = true): Promise<void> {
refresh(recursive: boolean, item?: ExplorerItem, cancelEditing = true): Promise<void> {
if (!this.tree || !this.isBodyVisible() || (item && !this.tree.hasNode(item))) {
// Tree node doesn't exist yet, when it becomes visible we will refresh
return Promise.resolve(undefined);
Expand Down Expand Up @@ -885,6 +885,19 @@ export class ExplorerView extends ViewPane implements IExplorerView {
this.tree.collapseAll();
}

expandAllFolders(): void {
if (this.explorerService.isEditable(undefined)) {
this.tree.domFocus();
}

const treeInput = this.tree.getInput();
if (Array.isArray(treeInput)) {
treeInput.forEach(folder => folder.children.forEach(child => this.tree.expand(child, true)));
}

this.tree.expandAllFolders();
}

previousCompressedStat(): void {
const focused = this.tree.getFocus();
if (!focused.length) {
Expand Down Expand Up @@ -1074,3 +1087,32 @@ registerAction2(class extends Action2 {
}
}
});

registerAction2(class extends Action2 {
constructor() {
super({
id: 'workbench.files.action.expandExplorerFolders',
title: nls.localize2('expandExplorerFolders', "Expand Folders in Explorer"),
f1: true,
icon: Codicon.expandAll,
menu: {
id: MenuId.ViewTitle,
group: 'navigation',
when: ContextKeyExpr.equals('view', VIEW_ID),
order: 40
},
metadata: {
description: nls.localize2('expandExplorerFoldersMetadata', "Expands all folders in the Explorer.")
}
});
}

run(accessor: ServicesAccessor) {
const viewsService = accessor.get(IViewsService);
const view = viewsService.getViewWithId(VIEW_ID);
if (view !== null) {
const explorerView = view as ExplorerView;
explorerView.expandAllFolders();
}
}
});

0 comments on commit 24a4c70

Please sign in to comment.