diff --git a/packages/navigator/src/browser/navigator-context-key-service.ts b/packages/navigator/src/browser/navigator-context-key-service.ts index e8c7fd8b0d666..df741f240cdc4 100644 --- a/packages/navigator/src/browser/navigator-context-key-service.ts +++ b/packages/navigator/src/browser/navigator-context-key-service.ts @@ -45,12 +45,22 @@ export class NavigatorContextKeyService { return this._explorerResourceIsFolder; } + protected _isFileSystemResource: ContextKey; + + /** + * True when the Explorer or editor file is a file system resource that can be handled from a file system provider. + */ + get isFileSystemResource(): ContextKey { + return this._isFileSystemResource; + } + @postConstruct() protected init(): void { this._explorerViewletVisible = this.contextKeyService.createKey('explorerViewletVisible', false); this._explorerViewletFocus = this.contextKeyService.createKey('explorerViewletFocus', false); this._filesExplorerFocus = this.contextKeyService.createKey('filesExplorerFocus', false); this._explorerResourceIsFolder = this.contextKeyService.createKey('explorerResourceIsFolder', false); + this._isFileSystemResource = this.contextKeyService.createKey('isFileSystemResource', false); } } diff --git a/packages/navigator/src/browser/navigator-widget.tsx b/packages/navigator/src/browser/navigator-widget.tsx index c4a2ae3857cb3..030102a9f85e1 100644 --- a/packages/navigator/src/browser/navigator-widget.tsx +++ b/packages/navigator/src/browser/navigator-widget.tsx @@ -19,7 +19,7 @@ import { Message } from '@theia/core/shared/@phosphor/messaging'; import URI from '@theia/core/lib/common/uri'; import { CommandService } from '@theia/core/lib/common'; import { Key, TreeModel, ContextMenuRenderer, ExpandableTreeNode, TreeProps, TreeNode } from '@theia/core/lib/browser'; -import { DirNode } from '@theia/filesystem/lib/browser'; +import { DirNode, FileStatNodeData } from '@theia/filesystem/lib/browser'; import { WorkspaceService, WorkspaceCommands } from '@theia/workspace/lib/browser'; import { WorkspaceNode, WorkspaceRootNode } from './navigator-tree'; import { FileNavigatorModel } from './navigator-model'; @@ -210,6 +210,10 @@ export class FileNavigatorWidget extends AbstractNavigatorTreeWidget { protected updateSelectionContextKeys(): void { this.contextKeyService.explorerResourceIsFolder.set(DirNode.is(this.model.selectedNodes[0])); + // As `FileStatNode` only created if `FileService.resolve` was successful, we can safely assume that + // a valid `FileSystemProvider` is available for the selected node. So we skip an additional check + // for provider availability here and check the node type. + this.contextKeyService.isFileSystemResource.set(FileStatNodeData.is(this.model.selectedNodes[0])); } }