Skip to content

Commit f365098

Browse files
committed
resourece: get rid of isFile context key
fixes microsoft#48275
1 parent 52cf58a commit f365098

2 files changed

Lines changed: 12 additions & 19 deletions

File tree

src/vs/workbench/common/resources.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import URI from 'vs/base/common/uri';
99
import * as paths from 'vs/base/common/paths';
1010
import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
1111
import { IModeService } from 'vs/editor/common/services/modeService';
12-
import { IFileService } from 'vs/platform/files/common/files';
1312

1413
export class ResourceContextKey implements IContextKey<URI> {
1514

@@ -19,28 +18,24 @@ export class ResourceContextKey implements IContextKey<URI> {
1918
static Resource = new RawContextKey<URI>('resource', undefined);
2019
static Extension = new RawContextKey<string>('resourceExtname', undefined);
2120
static HasResource = new RawContextKey<boolean>('resourceSet', false);
22-
static IsFile = new RawContextKey<boolean>('resourceIsFile', false);
2321

2422
private _resourceKey: IContextKey<URI>;
2523
private _schemeKey: IContextKey<string>;
2624
private _filenameKey: IContextKey<string>;
2725
private _langIdKey: IContextKey<string>;
2826
private _extensionKey: IContextKey<string>;
2927
private _hasResource: IContextKey<boolean>;
30-
private _isFile: IContextKey<boolean>;
3128

3229
constructor(
3330
@IContextKeyService contextKeyService: IContextKeyService,
34-
@IModeService private readonly _modeService: IModeService,
35-
@IFileService private readonly _fileService: IFileService
31+
@IModeService private readonly _modeService: IModeService
3632
) {
3733
this._schemeKey = ResourceContextKey.Scheme.bindTo(contextKeyService);
3834
this._filenameKey = ResourceContextKey.Filename.bindTo(contextKeyService);
3935
this._langIdKey = ResourceContextKey.LangId.bindTo(contextKeyService);
4036
this._resourceKey = ResourceContextKey.Resource.bindTo(contextKeyService);
4137
this._extensionKey = ResourceContextKey.Extension.bindTo(contextKeyService);
4238
this._hasResource = ResourceContextKey.HasResource.bindTo(contextKeyService);
43-
this._isFile = ResourceContextKey.IsFile.bindTo(contextKeyService);
4439
}
4540

4641
set(value: URI) {
@@ -50,7 +45,6 @@ export class ResourceContextKey implements IContextKey<URI> {
5045
this._langIdKey.set(value && this._modeService.getModeIdByFilenameOrFirstLine(value.fsPath));
5146
this._extensionKey.set(value && paths.extname(value.fsPath));
5247
this._hasResource.set(!!value);
53-
this._isFile.set(value && this._fileService.canHandleResource(value));
5448
}
5549

5650
reset(): void {
@@ -60,7 +54,6 @@ export class ResourceContextKey implements IContextKey<URI> {
6054
this._langIdKey.reset();
6155
this._extensionKey.reset();
6256
this._hasResource.reset();
63-
this._isFile.reset();
6457
}
6558

6659
get(): URI {

src/vs/workbench/parts/files/electron-browser/fileActions.contribution.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ const copyRelativePathCommand = {
114114

115115
// Editor Title Context Menu
116116
appendEditorTitleContextMenuItem(REVEAL_IN_OS_COMMAND_ID, REVEAL_IN_OS_LABEL, ResourceContextKey.Scheme.isEqualTo(Schemas.file));
117-
appendEditorTitleContextMenuItem(COPY_PATH_COMMAND_ID, copyPathCommand.title, ResourceContextKey.IsFile, copyRelativePathCommand);
118-
appendEditorTitleContextMenuItem(REVEAL_IN_EXPLORER_COMMAND_ID, nls.localize('revealInSideBar', "Reveal in Side Bar"), ResourceContextKey.IsFile);
117+
appendEditorTitleContextMenuItem(COPY_PATH_COMMAND_ID, copyPathCommand.title, ResourceContextKey.HasResource, copyRelativePathCommand);
118+
appendEditorTitleContextMenuItem(REVEAL_IN_EXPLORER_COMMAND_ID, nls.localize('revealInSideBar', "Reveal in Side Bar"), ResourceContextKey.HasResource);
119119

120120
function appendEditorTitleContextMenuItem(id: string, title: string, when: ContextKeyExpr, alt?: { id: string, title: string }): void {
121121

@@ -186,7 +186,7 @@ MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
186186
group: 'navigation',
187187
order: 10,
188188
command: openToSideCommand,
189-
when: ResourceContextKey.IsFile
189+
when: ResourceContextKey.HasResource
190190
});
191191

192192
const revealInOsCommand = {
@@ -205,7 +205,7 @@ MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
205205
order: 40,
206206
command: copyPathCommand,
207207
alt: copyRelativePathCommand,
208-
when: ResourceContextKey.IsFile
208+
when: ResourceContextKey.HasResource
209209
});
210210

211211
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
@@ -216,7 +216,7 @@ MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
216216
title: SAVE_FILE_LABEL,
217217
precondition: DirtyEditorContext
218218
},
219-
when: ContextKeyExpr.and(ResourceContextKey.IsFile, AutoSaveContext.notEqualsTo('afterDelay') && AutoSaveContext.notEqualsTo(''))
219+
when: ContextKeyExpr.and(ResourceContextKey.Scheme.isEqualTo(Schemas.file), AutoSaveContext.notEqualsTo('afterDelay') && AutoSaveContext.notEqualsTo(''))
220220
});
221221

222222
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
@@ -227,7 +227,7 @@ MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
227227
title: nls.localize('revert', "Revert File"),
228228
precondition: DirtyEditorContext
229229
},
230-
when: ContextKeyExpr.and(ResourceContextKey.IsFile, AutoSaveContext.notEqualsTo('afterDelay') && AutoSaveContext.notEqualsTo(''))
230+
when: ContextKeyExpr.and(ResourceContextKey.Scheme.isEqualTo(Schemas.file), AutoSaveContext.notEqualsTo('afterDelay') && AutoSaveContext.notEqualsTo(''))
231231
});
232232

233233
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
@@ -256,7 +256,7 @@ MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
256256
title: nls.localize('compareWithSaved', "Compare with Saved"),
257257
precondition: DirtyEditorContext
258258
},
259-
when: ContextKeyExpr.and(ResourceContextKey.IsFile, AutoSaveContext.notEqualsTo('afterDelay') && AutoSaveContext.notEqualsTo(''), WorkbenchListDoubleSelection.toNegated())
259+
when: ContextKeyExpr.and(ResourceContextKey.Scheme.isEqualTo(Schemas.file), AutoSaveContext.notEqualsTo('afterDelay') && AutoSaveContext.notEqualsTo(''), WorkbenchListDoubleSelection.toNegated())
260260
});
261261

262262
const compareResourceCommand = {
@@ -372,21 +372,21 @@ MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
372372
group: '3_compare',
373373
order: 20,
374374
command: compareResourceCommand,
375-
when: ContextKeyExpr.and(ExplorerFolderContext.toNegated(), ResourceContextKey.IsFile, ResourceSelectedForCompareContext, WorkbenchListDoubleSelection.toNegated())
375+
when: ContextKeyExpr.and(ExplorerFolderContext.toNegated(), ResourceContextKey.HasResource, ResourceSelectedForCompareContext, WorkbenchListDoubleSelection.toNegated())
376376
});
377377

378378
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
379379
group: '3_compare',
380380
order: 30,
381381
command: selectForCompareCommand,
382-
when: ContextKeyExpr.and(ExplorerFolderContext.toNegated(), ResourceContextKey.IsFile, WorkbenchListDoubleSelection.toNegated())
382+
when: ContextKeyExpr.and(ExplorerFolderContext.toNegated(), ResourceContextKey.HasResource, WorkbenchListDoubleSelection.toNegated())
383383
});
384384

385385
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
386386
group: '3_compare',
387387
order: 30,
388388
command: compareSelectedCommand,
389-
when: ContextKeyExpr.and(ExplorerFolderContext.toNegated(), ResourceContextKey.IsFile, WorkbenchListDoubleSelection)
389+
when: ContextKeyExpr.and(ExplorerFolderContext.toNegated(), ResourceContextKey.HasResource, WorkbenchListDoubleSelection)
390390
});
391391

392392
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
@@ -415,7 +415,7 @@ MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
415415
order: 30,
416416
command: copyPathCommand,
417417
alt: copyRelativePathCommand,
418-
when: ResourceContextKey.IsFile
418+
when: ResourceContextKey.HasResource
419419
});
420420

421421
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {

0 commit comments

Comments
 (0)