Skip to content

Commit

Permalink
Handle isFileSystemResource context key (#13664)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhuebner authored May 6, 2024
1 parent ef04dc7 commit f27d3b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/navigator/src/browser/navigator-context-key-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,22 @@ export class NavigatorContextKeyService {
return this._explorerResourceIsFolder;
}

protected _isFileSystemResource: ContextKey<boolean>;

/**
* True when the Explorer or editor file is a file system resource that can be handled from a file system provider.
*/
get isFileSystemResource(): ContextKey<boolean> {
return this._isFileSystemResource;
}

@postConstruct()
protected init(): void {
this._explorerViewletVisible = this.contextKeyService.createKey<boolean>('explorerViewletVisible', false);
this._explorerViewletFocus = this.contextKeyService.createKey<boolean>('explorerViewletFocus', false);
this._filesExplorerFocus = this.contextKeyService.createKey<boolean>('filesExplorerFocus', false);
this._explorerResourceIsFolder = this.contextKeyService.createKey<boolean>('explorerResourceIsFolder', false);
this._isFileSystemResource = this.contextKeyService.createKey<boolean>('isFileSystemResource', false);
}

}
6 changes: 5 additions & 1 deletion packages/navigator/src/browser/navigator-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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]));
}

}

0 comments on commit f27d3b2

Please sign in to comment.