Skip to content

Commit

Permalink
add 'resourceFilename' context key
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Aug 23, 2016
1 parent ef69c1d commit 6110660
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/vs/platform/actions/common/resourceContextKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,36 @@
'use strict';

import URI from 'vs/base/common/uri';
import {basename} from 'vs/base/common/paths';
import {RawContextKey, IContextKeyService, IContextKey} from 'vs/platform/contextkey/common/contextkey';
import {IModeService} from 'vs/editor/common/services/modeService';

export class ResourceContextKey implements IContextKey<URI> {


static Scheme = new RawContextKey<string>('resourceScheme', undefined);
static Filename = new RawContextKey<string>('resourceFilename', undefined);
static LangId = new RawContextKey<string>('resourceLangId', undefined);
static Resource = new RawContextKey<URI>('resource', undefined);

private _resourceKey: IContextKey<URI>;
private _schemeKey: IContextKey<string>;
private _filenameKey: IContextKey<string>;
private _langIdKey: IContextKey<string>;

constructor(
@IContextKeyService contextKeyService: IContextKeyService,
@IModeService private _modeService: IModeService
) {
this._schemeKey = ResourceContextKey.Scheme.bindTo(contextKeyService);
this._filenameKey = ResourceContextKey.Filename.bindTo(contextKeyService);
this._langIdKey = ResourceContextKey.LangId.bindTo(contextKeyService);
this._resourceKey = ResourceContextKey.Resource.bindTo(contextKeyService);
}

set(value: URI) {
this._resourceKey.set(value);
this._schemeKey.set(value && value.scheme);
this._filenameKey.set(value && basename(value.fsPath));
this._langIdKey.set(value && this._modeService.getModeIdByFilenameOrFirstLine(value.fsPath));
}

Expand Down

0 comments on commit 6110660

Please sign in to comment.