From 367514115a6269224aebef56c3ee865b4a53a176 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Wed, 8 Jun 2016 16:06:59 +0200 Subject: [PATCH] Add command ID for 'Collapse All' in Files Explorer (fixes #7411) --- .../parts/files/browser/explorerViewlet.ts | 9 +++- .../files/browser/fileActions.contribution.ts | 4 +- .../parts/files/browser/fileActions.ts | 52 +++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/parts/files/browser/explorerViewlet.ts b/src/vs/workbench/parts/files/browser/explorerViewlet.ts index 1cbcff1641b..f8c00f2cb96 100644 --- a/src/vs/workbench/parts/files/browser/explorerViewlet.ts +++ b/src/vs/workbench/parts/files/browser/explorerViewlet.ts @@ -30,6 +30,7 @@ import {EditorInput, EditorOptions} from 'vs/workbench/common/editor'; import {BaseEditor} from 'vs/workbench/browser/parts/editor/baseEditor'; import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService'; import {IEditorGroupService} from 'vs/workbench/services/group/common/groupService'; +import {IKeybindingService, IKeybindingContextKey} from 'vs/platform/keybinding/common/keybindingService'; export class ExplorerViewlet extends Viewlet { private viewletContainer: Builder; @@ -46,6 +47,8 @@ export class ExplorerViewlet extends Viewlet { private viewletState: FileViewletState; private dimension: Dimension; + private viewletVisibleContextKey: IKeybindingContextKey; + constructor( @ITelemetryService telemetryService: ITelemetryService, @IWorkspaceContextService private contextService: IWorkspaceContextService, @@ -53,11 +56,13 @@ export class ExplorerViewlet extends Viewlet { @IEditorGroupService private editorGroupService: IEditorGroupService, @IWorkbenchEditorService private editorService: IWorkbenchEditorService, @IConfigurationService private configurationService: IConfigurationService, - @IInstantiationService private instantiationService: IInstantiationService + @IInstantiationService private instantiationService: IInstantiationService, + @IKeybindingService keybindingService: IKeybindingService ) { super(VIEWLET_ID, telemetryService); this.viewletState = new FileViewletState(); + this.viewletVisibleContextKey = keybindingService.createKey('explorerViewletVisible', true); this.viewletSettings = this.getMemento(storageService, Scope.WORKSPACE); this.configurationService.onDidUpdateConfiguration(e => this.onConfigurationUpdated(e.config)); @@ -190,6 +195,8 @@ export class ExplorerViewlet extends Viewlet { } public setVisible(visible: boolean): TPromise { + this.viewletVisibleContextKey.set(visible); + return super.setVisible(visible).then(() => { return TPromise.join(this.views.map((view) => view.setVisible(visible))).then(() => void 0); }); diff --git a/src/vs/workbench/parts/files/browser/fileActions.contribution.ts b/src/vs/workbench/parts/files/browser/fileActions.contribution.ts index 2c6e50a04d2..2bd671ec5cf 100644 --- a/src/vs/workbench/parts/files/browser/fileActions.contribution.ts +++ b/src/vs/workbench/parts/files/browser/fileActions.contribution.ts @@ -10,7 +10,7 @@ import {Action, IAction} from 'vs/base/common/actions'; import {ActionItem, BaseActionItem, Separator} from 'vs/base/browser/ui/actionbar/actionbar'; import {Scope, IActionBarRegistry, Extensions as ActionBarExtensions, ActionBarContributor} from 'vs/workbench/browser/actionBarRegistry'; import {IEditorInputActionContext, IEditorInputAction, EditorInputActionContributor} from 'vs/workbench/browser/parts/editor/baseEditor'; -import {FocusOpenEditorsView, FocusFilesExplorer, GlobalCompareResourcesAction, GlobalNewFileAction, GlobalNewFolderAction, RevertFileAction, SaveFilesAction, SaveAllAction, SaveFileAction, keybindingForAction, MoveFileToTrashAction, TriggerRenameFileAction, PasteFileAction, CopyFileAction, SelectResourceForCompareAction, CompareResourcesAction, NewFolderAction, NewFileAction, OpenToSideAction, ShowActiveFileInExplorer} from 'vs/workbench/parts/files/browser/fileActions'; +import {FocusOpenEditorsView, FocusFilesExplorer, GlobalCompareResourcesAction, GlobalNewFileAction, GlobalNewFolderAction, RevertFileAction, SaveFilesAction, SaveAllAction, SaveFileAction, keybindingForAction, MoveFileToTrashAction, TriggerRenameFileAction, PasteFileAction, CopyFileAction, SelectResourceForCompareAction, CompareResourcesAction, NewFolderAction, NewFileAction, OpenToSideAction, ShowActiveFileInExplorer, CollapseExplorerView, RefreshExplorerView} from 'vs/workbench/parts/files/browser/fileActions'; import {RevertLocalChangesAction, AcceptLocalChangesAction, ConflictResolutionDiffEditorInput} from 'vs/workbench/parts/files/browser/saveErrorHandler'; import {SyncActionDescriptor} from 'vs/platform/actions/common/actions'; import {IWorkbenchActionRegistry, Extensions as ActionExtensions} from 'vs/workbench/common/actionRegistry'; @@ -172,3 +172,5 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(GlobalCompareResources registry.registerWorkbenchAction(new SyncActionDescriptor(FocusOpenEditorsView, FocusOpenEditorsView.ID, FocusOpenEditorsView.LABEL, { primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_E) }), 'Files: Focus on Open Editors View', category); registry.registerWorkbenchAction(new SyncActionDescriptor(FocusFilesExplorer, FocusFilesExplorer.ID, FocusFilesExplorer.LABEL), 'Files: Focus on Files Explorer', category); registry.registerWorkbenchAction(new SyncActionDescriptor(ShowActiveFileInExplorer, ShowActiveFileInExplorer.ID, ShowActiveFileInExplorer.LABEL), 'Files: Show Active File in Explorer', category); +registry.registerWorkbenchAction(new SyncActionDescriptor(CollapseExplorerView, CollapseExplorerView.ID, CollapseExplorerView.LABEL), 'Files: Collapse Folders in Explorer', category); +registry.registerWorkbenchAction(new SyncActionDescriptor(RefreshExplorerView, RefreshExplorerView.ID, RefreshExplorerView.LABEL), 'Files: Refresh Explorer', category); \ No newline at end of file diff --git a/src/vs/workbench/parts/files/browser/fileActions.ts b/src/vs/workbench/parts/files/browser/fileActions.ts index 4f73160ccc1..07f38085827 100644 --- a/src/vs/workbench/parts/files/browser/fileActions.ts +++ b/src/vs/workbench/parts/files/browser/fileActions.ts @@ -37,6 +37,7 @@ import {CACHE} from 'vs/workbench/parts/files/common/editors/textFileEditorModel import {IActionProvider} from 'vs/base/parts/tree/browser/actionsRenderer'; import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService'; import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService'; +import {CollapseAction} from 'vs/workbench/browser/viewlet'; import {IEditorGroupService} from 'vs/workbench/services/group/common/groupService'; import {IQuickOpenService} from 'vs/workbench/services/quickopen/common/quickOpenService'; import {IViewletService} from 'vs/workbench/services/viewlet/common/viewletService'; @@ -1806,6 +1807,57 @@ export class ShowActiveFileInExplorer extends Action { } } +export class CollapseExplorerView extends Action { + + public static ID = 'workbench.files.action.collapseExplorerFolders'; + public static LABEL = nls.localize('collapseExplorerFolders', "Collapse Folders in Explorer"); + + constructor( + id: string, + label: string, + @IViewletService private viewletService: IViewletService + ) { + super(id, label); + } + + public run(): TPromise { + return this.viewletService.openViewlet(VIEWLET_ID, true).then((viewlet: ExplorerViewlet) => { + const explorerView = viewlet.getExplorerView(); + if (explorerView) { + const viewer = explorerView.getViewer(); + if (viewer) { + const action = new CollapseAction(viewer, true, null); + action.run().done(); + action.dispose(); + } + } + }); + } +} + +export class RefreshExplorerView extends Action { + + public static ID = 'workbench.files.action.refreshExplorerView'; + public static LABEL = nls.localize('refreshExplorer', "Refresh Explorer"); + + constructor( + id: string, + label: string, + @IViewletService private viewletService: IViewletService + ) { + super(id, label); + } + + public run(): TPromise { + return this.viewletService.openViewlet(VIEWLET_ID, true).then((viewlet: ExplorerViewlet) => { + const explorerView = viewlet.getExplorerView(); + if (explorerView) { + explorerView.refresh(); + } + }); + } +} + export function keybindingForAction(id: string): Keybinding { switch (id) { case GlobalNewUntitledFileAction.ID: