Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle isFileSystemResource context key #13664

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]));
dhuebner marked this conversation as resolved.
Show resolved Hide resolved
}

}
Loading