Skip to content

Commit

Permalink
Add 'explorerFocus for keybinding when` context (fixes #15002)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Jan 31, 2017
1 parent 75c7e7e commit e1081a5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import { IContextKeyService, RawContextKey, IContextKey } from 'vs/platform/cont
import { IHistoryService } from 'vs/workbench/services/history/common/history';

const HELP_PREFIX = '?';
const QUICK_OPEN_MODE = new RawContextKey<boolean>('inQuickOpen', false);

interface IWorkbenchQuickOpenConfiguration {
workbench: {
Expand Down Expand Up @@ -116,7 +115,7 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe

this.promisesToCompleteOnHide = [];

this.inQuickOpenMode = QUICK_OPEN_MODE.bindTo(contextKeyService);
this.inQuickOpenMode = new RawContextKey<boolean>('inQuickOpen', false).bindTo(contextKeyService);

this._onShow = new Emitter<void>();
this._onHide = new Emitter<void>();
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/parts/files/browser/explorerViewlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { IAction, IActionRunner } from 'vs/base/common/actions';
import { TPromise } from 'vs/base/common/winjs.base';
import { Dimension, Builder } from 'vs/base/browser/builder';
import { Scope } from 'vs/workbench/common/memento';
import { VIEWLET_ID, ExplorerViewletVisible, IFilesConfiguration } from 'vs/workbench/parts/files/common/files';
import { VIEWLET_ID, ExplorerViewletVisibleContext, IFilesConfiguration } from 'vs/workbench/parts/files/common/files';
import { IViewletView, Viewlet } from 'vs/workbench/browser/viewlet';
import { SplitView, Orientation } from 'vs/base/browser/ui/splitview/splitview';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
Expand Down Expand Up @@ -66,7 +66,7 @@ export class ExplorerViewlet extends Viewlet {
this.views = [];

this.viewletState = new FileViewletState();
this.viewletVisibleContextKey = ExplorerViewletVisible.bindTo(contextKeyService);
this.viewletVisibleContextKey = ExplorerViewletVisibleContext.bindTo(contextKeyService);

this.viewletSettings = this.getMemento(storageService, Scope.WORKSPACE);
this.configurationService.onDidUpdateConfiguration(e => this.onConfigurationUpdated(e.config));
Expand Down
15 changes: 12 additions & 3 deletions src/vs/workbench/parts/files/browser/views/explorerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Action, IActionRunner, IAction } from 'vs/base/common/actions';
import { prepareActions } from 'vs/workbench/browser/actionBarRegistry';
import { ITree } from 'vs/base/parts/tree/browser/tree';
import { Tree } from 'vs/base/parts/tree/browser/treeImpl';
import { IFilesConfiguration } from 'vs/workbench/parts/files/common/files';
import { IFilesConfiguration, ExplorerFolderContext, ExplorerFocussedContext } from 'vs/workbench/parts/files/common/files';
import { FileOperation, FileOperationEvent, IResolveFileOptions, FileChangeType, FileChangesEvent, IFileChange, IFileService } from 'vs/platform/files/common/files';
import { RefreshViewExplorerAction, NewFolderAction, NewFileAction } from 'vs/workbench/parts/files/browser/fileActions';
import { FileDragAndDrop, FileFilter, FileSorter, FileController, FileRenderer, FileDataSource, FileViewletState, FileAccessibilityProvider } from 'vs/workbench/parts/files/browser/views/explorerViewer';
Expand All @@ -37,7 +37,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IProgressService } from 'vs/platform/progress/common/progress';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IMessageService, Severity } from 'vs/platform/message/common/message';
import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { ResourceContextKey } from 'vs/workbench/common/resourceContextKey';
import { IThemeService, IFileIconTheme } from 'vs/workbench/services/themes/common/themeService';

Expand All @@ -60,6 +60,8 @@ export class ExplorerView extends CollapsibleViewletView {
private resourceContext: ResourceContextKey;
private folderContext: IContextKey<boolean>;

private explorerFocussedContext: IContextKey<boolean>;

private shouldRefresh: boolean;

private autoReveal: boolean;
Expand Down Expand Up @@ -96,7 +98,8 @@ export class ExplorerView extends CollapsibleViewletView {
this.explorerImportDelayer = new ThrottledDelayer<void>(ExplorerView.EXPLORER_IMPORT_REFRESH_DELAY);

this.resourceContext = instantiationService.createInstance(ResourceContextKey);
this.folderContext = new RawContextKey<boolean>('explorerResourceIsFolder', undefined).bindTo(contextKeyService);
this.folderContext = ExplorerFolderContext.bindTo(contextKeyService);
this.explorerFocussedContext = ExplorerFocussedContext.bindTo(contextKeyService);
}

public renderHeader(container: HTMLElement): void {
Expand Down Expand Up @@ -355,6 +358,12 @@ export class ExplorerView extends CollapsibleViewletView {
this.folderContext.set(e.focus && e.focus.isDirectory);
}));

// Update explorer focus context
const explorerFocusTracker = DOM.trackFocus(this.explorerViewer.getHTMLElement());
explorerFocusTracker.addFocusListener(() => this.explorerFocussedContext.set(true));
explorerFocusTracker.addBlurListener(() => this.explorerFocussedContext.reset());
this.toDispose.push(explorerFocusTracker);

return this.explorerViewer;
}

Expand Down
13 changes: 12 additions & 1 deletion src/vs/workbench/parts/files/browser/views/openEditorsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IEditorStacksModel, IStacksModelChangeEvent, IEditorGroup } from 'vs/workbench/common/editor';
import { SaveAllAction } from 'vs/workbench/parts/files/browser/fileActions';
import { AdaptiveCollapsibleViewletView } from 'vs/workbench/browser/viewlet';
import { IFilesConfiguration, VIEWLET_ID } from 'vs/workbench/parts/files/common/files';
import { IFilesConfiguration, VIEWLET_ID, OpenEditorsFocussedContext } from 'vs/workbench/parts/files/common/files';
import { ITextFileService, AutoSaveMode } from 'vs/workbench/services/textfile/common/textfiles';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { Renderer, DataSource, Controller, AccessibilityProvider, ActionProvider, OpenEditor, DragAndDrop } from 'vs/workbench/parts/files/browser/views/openEditorsViewer';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { CloseAllEditorsAction } from 'vs/workbench/browser/parts/editor/editorActions';
import { ToggleEditorLayoutAction } from 'vs/workbench/browser/actions/toggleEditorLayout';
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';

const $ = dom.$;

Expand All @@ -46,6 +47,8 @@ export class OpenEditorsView extends AdaptiveCollapsibleViewletView {
private groupToRefresh: IEditorGroup;
private fullRefreshNeeded: boolean;

private openEditorsFocussedContext: IContextKey<boolean>;

constructor(actionRunner: IActionRunner, settings: any,
@IInstantiationService private instantiationService: IInstantiationService,
@IContextMenuService contextMenuService: IContextMenuService,
Expand All @@ -54,12 +57,14 @@ export class OpenEditorsView extends AdaptiveCollapsibleViewletView {
@IConfigurationService private configurationService: IConfigurationService,
@IKeybindingService keybindingService: IKeybindingService,
@IUntitledEditorService private untitledEditorService: IUntitledEditorService,
@IContextKeyService contextKeyService: IContextKeyService,
@IViewletService private viewletService: IViewletService
) {
super(actionRunner, OpenEditorsView.computeExpandedBodySize(editorGroupService.getStacksModel()), !!settings[OpenEditorsView.MEMENTO_COLLAPSED], nls.localize({ key: 'openEditosrSection', comment: ['Open is an adjective'] }, "Open Editors Section"), keybindingService, contextMenuService);

this.settings = settings;
this.model = editorGroupService.getStacksModel();
this.openEditorsFocussedContext = OpenEditorsFocussedContext.bindTo(contextKeyService);

this.structuralRefreshDelay = 0;
this.structuralTreeRefreshScheduler = new RunOnceScheduler(() => this.structuralTreeUpdate(), this.structuralRefreshDelay);
Expand Down Expand Up @@ -109,6 +114,12 @@ export class OpenEditorsView extends AdaptiveCollapsibleViewletView {
showTwistie: false
});

// Update open editors focus context
const explorerFocusTracker = dom.trackFocus(this.tree.getHTMLElement());
explorerFocusTracker.addFocusListener(() => this.openEditorsFocussedContext.set(true));
explorerFocusTracker.addBlurListener(() => this.openEditorsFocussedContext.reset());
this.toDispose.push(explorerFocusTracker);

this.fullRefreshNeeded = true;
this.structuralTreeUpdate();
}
Expand Down
8 changes: 7 additions & 1 deletion src/vs/workbench/parts/files/common/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
*/
export const VIEWLET_ID = 'workbench.view.explorer';

export const ExplorerViewletVisible = new RawContextKey<boolean>('explorerViewletVisible', true);
/**
* Context Keys to use with keybindings for the Explorer and Open Editors view
*/
export const ExplorerViewletVisibleContext = new RawContextKey<boolean>('explorerViewletVisible', true);
export const ExplorerFolderContext = new RawContextKey<boolean>('explorerResourceIsFolder', false);
export const ExplorerFocussedContext = new RawContextKey<boolean>('explorerFocus', false);
export const OpenEditorsFocussedContext = new RawContextKey<boolean>('openEditorsFocus', false);

/**
* File editor input id.
Expand Down

0 comments on commit e1081a5

Please sign in to comment.