From 6e3c4680d45c8e1889a2361139f3b7020d5f7313 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 20 Oct 2016 06:48:50 +0200 Subject: [PATCH] fix #14020 --- .../parts/files/browser/explorerViewlet.ts | 47 ++++++++++++++----- .../parts/files/browser/views/emptyView.ts | 11 +++-- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/vs/workbench/parts/files/browser/explorerViewlet.ts b/src/vs/workbench/parts/files/browser/explorerViewlet.ts index 18e022f86f9..303b193d072 100644 --- a/src/vs/workbench/parts/files/browser/explorerViewlet.ts +++ b/src/vs/workbench/parts/files/browser/explorerViewlet.ts @@ -39,6 +39,8 @@ export class ExplorerViewlet extends Viewlet { private explorerView: ExplorerView; private openEditorsView: OpenEditorsView; + private emptyView: EmptyView; + private openEditorsVisible: boolean; private lastFocusedView: ExplorerView | OpenEditorsView | EmptyView; private focusListener: IDisposable; @@ -84,9 +86,13 @@ export class ExplorerViewlet extends Viewlet { public getActions(): IAction[] { if (this.openEditorsVisible) { return []; - } else { + } + + if (this.explorerView) { return this.explorerView.getActions(); } + + return []; } private onConfigurationUpdated(config: IFilesConfiguration): TPromise { @@ -142,7 +148,7 @@ export class ExplorerViewlet extends Viewlet { } private addExplorerView(): void { - let explorerView: ExplorerView | EmptyView; + let explorerOrEmptyView: ExplorerView | EmptyView; // With a Workspace if (this.contextService.getWorkspace()) { @@ -179,20 +185,21 @@ export class ExplorerViewlet extends Viewlet { const explorerInstantiator = this.instantiationService.createChild(new ServiceCollection([IWorkbenchEditorService, delegatingEditorService])); const headerSize = this.openEditorsVisible ? undefined : 0; // If open editors are not visible set header size explicitly to 0, otherwise const it be computed by super class. - this.explorerView = explorerView = explorerInstantiator.createInstance(ExplorerView, this.viewletState, this.getActionRunner(), this.viewletSettings, headerSize); + this.explorerView = explorerOrEmptyView = explorerInstantiator.createInstance(ExplorerView, this.viewletState, this.getActionRunner(), this.viewletSettings, headerSize); } // No workspace else { - explorerView = this.instantiationService.createInstance(EmptyView); + this.emptyView = explorerOrEmptyView = this.instantiationService.createInstance(EmptyView); } if (this.openEditorsVisible) { - this.splitView.addView(explorerView); + this.splitView.addView(explorerOrEmptyView); } else { - explorerView.render(this.viewletContainer.getHTMLElement(), Orientation.VERTICAL); + explorerOrEmptyView.render(this.viewletContainer.getHTMLElement(), Orientation.VERTICAL); } - this.views.push(explorerView); + + this.views.push(explorerOrEmptyView); } public getExplorerView(): ExplorerView { @@ -214,12 +221,16 @@ export class ExplorerViewlet extends Viewlet { public focus(): void { super.focus(); + const hasOpenedEditors = !!this.editorGroupService.getStacksModel().activeGroup; + if (this.lastFocusedView && this.lastFocusedView.isExpanded() && this.hasSelectionOrFocus(this.lastFocusedView)) { - this.lastFocusedView.focusBody(); - return; + if (this.lastFocusedView !== this.openEditorsView || hasOpenedEditors) { + this.lastFocusedView.focusBody(); + return; + } } - if (this.hasSelectionOrFocus(this.openEditorsView)) { + if (this.hasSelectionOrFocus(this.openEditorsView) && hasOpenedEditors) { return this.openEditorsView.focusBody(); } @@ -227,14 +238,18 @@ export class ExplorerViewlet extends Viewlet { return this.explorerView.focusBody(); } - if (this.openEditorsView && this.openEditorsView.isExpanded()) { - return this.openEditorsView.focusBody(); + if (this.openEditorsView && this.openEditorsView.isExpanded() && hasOpenedEditors) { + return this.openEditorsView.focusBody(); // we have entries in the opened editors view to focus on } if (this.explorerView && this.explorerView.isExpanded()) { return this.explorerView.focusBody(); } + if (this.emptyView && this.emptyView.isExpanded()) { + return this.emptyView.focusBody(); + } + return this.openEditorsView.focus(); } @@ -262,6 +277,7 @@ export class ExplorerViewlet extends Viewlet { public layout(dimension: Dimension): void { this.dimension = dimension; + if (this.openEditorsVisible) { this.splitView.layout(dimension.height); } else if (this.explorerView) { @@ -298,15 +314,22 @@ export class ExplorerViewlet extends Viewlet { this.splitView.dispose(); this.splitView = null; } + if (this.explorerView) { this.explorerView.dispose(); this.explorerView = null; } + if (this.openEditorsView) { this.openEditorsView.dispose(); this.openEditorsView = null; } + if (this.emptyView) { + this.emptyView.dispose(); + this.emptyView = null; + } + if (this.focusListener) { this.focusListener.dispose(); this.focusListener = null; diff --git a/src/vs/workbench/parts/files/browser/views/emptyView.ts b/src/vs/workbench/parts/files/browser/views/emptyView.ts index 4fcd31de06a..f64aab91298 100644 --- a/src/vs/workbench/parts/files/browser/views/emptyView.ts +++ b/src/vs/workbench/parts/files/browser/views/emptyView.ts @@ -18,6 +18,7 @@ import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/action import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; export class EmptyView extends CollapsibleView { + private openFolderButton: Button; constructor( @IInstantiationService private instantiationService: IInstantiationService) { super({ @@ -39,9 +40,9 @@ export class EmptyView extends CollapsibleView { let section = $('div.section').appendTo(container); - let button = new Button(section); - button.label = nls.localize('openFolder', "Open Folder"); - button.addListener2('click', () => { + this.openFolderButton = new Button(section); + this.openFolderButton.label = nls.localize('openFolder', "Open Folder"); + this.openFolderButton.addListener2('click', () => { this.runWorkbenchAction(env.isMacintosh ? 'workbench.action.files.openFileFolder' : 'workbench.action.files.openFolder'); }); } @@ -68,7 +69,9 @@ export class EmptyView extends CollapsibleView { } public focusBody(): void { - // Ignore + if (this.openFolderButton) { + this.openFolderButton.getElement().focus(); + } } protected reveal(element: any, relativeTop?: number): TPromise { -- GitLab