Skip to content

Commit

Permalink
introduce isFileSystemResourceOrUntitled to be used for compare
Browse files Browse the repository at this point in the history
fixes #56316
  • Loading branch information
isidorn committed Aug 24, 2018
1 parent 77abb32 commit 3149c5b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/vs/workbench/common/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/cont
import { IModeService } from 'vs/editor/common/services/modeService';
import { IFileService } from 'vs/platform/files/common/files';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { Schemas } from 'vs/base/common/network';

export class ResourceContextKey implements IContextKey<URI>, IDisposable {

Expand All @@ -21,6 +22,7 @@ export class ResourceContextKey implements IContextKey<URI>, IDisposable {
static Extension = new RawContextKey<string>('resourceExtname', undefined);
static HasResource = new RawContextKey<boolean>('resourceSet', false);
static IsFileSystemResource = new RawContextKey<boolean>('isFileSystemResource', false);
static IsFileSystemResourceOrUntitled = new RawContextKey<boolean>('isFileSystemResourceOrUntitled', false);

private _resourceKey: IContextKey<URI>;
private _schemeKey: IContextKey<string>;
Expand All @@ -29,6 +31,7 @@ export class ResourceContextKey implements IContextKey<URI>, IDisposable {
private _extensionKey: IContextKey<string>;
private _hasResource: IContextKey<boolean>;
private _isfileSystemResource: IContextKey<boolean>;
private _isFileSystemResourceOrUntitled: IContextKey<boolean>;
private toDispose: IDisposable[] = [];

constructor(
Expand All @@ -43,9 +46,11 @@ export class ResourceContextKey implements IContextKey<URI>, IDisposable {
this._extensionKey = ResourceContextKey.Extension.bindTo(contextKeyService);
this._hasResource = ResourceContextKey.HasResource.bindTo(contextKeyService);
this._isfileSystemResource = ResourceContextKey.IsFileSystemResource.bindTo(contextKeyService);
this._isFileSystemResourceOrUntitled = ResourceContextKey.IsFileSystemResourceOrUntitled.bindTo(contextKeyService);
this.toDispose.push(_fileService.onDidChangeFileSystemProviderRegistrations(() => {
const resource = this._resourceKey.get();
this._isfileSystemResource.set(resource && _fileService.canHandleResource(resource));
this._isFileSystemResourceOrUntitled.set(this._isfileSystemResource.get() || this._schemeKey.get() === Schemas.untitled);
}));
}

Expand All @@ -57,6 +62,7 @@ export class ResourceContextKey implements IContextKey<URI>, IDisposable {
this._extensionKey.set(value && paths.extname(value.fsPath));
this._hasResource.set(!!value);
this._isfileSystemResource.set(value && this._fileService.canHandleResource(value));
this._isFileSystemResourceOrUntitled.set(this._isfileSystemResource.get() || this._schemeKey.get() === Schemas.untitled);
}

reset(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
group: '3_compare',
order: 20,
command: compareResourceCommand,
when: ContextKeyExpr.and(ResourceContextKey.IsFileSystemResource, ResourceSelectedForCompareContext, WorkbenchListDoubleSelection.toNegated())
when: ContextKeyExpr.and(ResourceContextKey.IsFileSystemResourceOrUntitled, ResourceSelectedForCompareContext, WorkbenchListDoubleSelection.toNegated())
});

const selectForCompareCommand = {
Expand All @@ -279,7 +279,7 @@ MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
group: '3_compare',
order: 30,
command: selectForCompareCommand,
when: ContextKeyExpr.and(ResourceContextKey.IsFileSystemResource, WorkbenchListDoubleSelection.toNegated())
when: ContextKeyExpr.and(ResourceContextKey.IsFileSystemResourceOrUntitled, WorkbenchListDoubleSelection.toNegated())
});

const compareSelectedCommand = {
Expand All @@ -290,7 +290,7 @@ MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
group: '3_compare',
order: 30,
command: compareSelectedCommand,
when: ContextKeyExpr.and(ResourceContextKey.IsFileSystemResource, WorkbenchListDoubleSelection)
when: ContextKeyExpr.and(ResourceContextKey.IsFileSystemResourceOrUntitled, WorkbenchListDoubleSelection)
});

MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
Expand Down

0 comments on commit 3149c5b

Please sign in to comment.