提交 3e9dc784 编写于 作者: B Benjamin Pasero

check for model lang id for icons too (part of #11806)

上级 7ca6f5ed
......@@ -13,9 +13,11 @@ import {IModeService} from 'vs/editor/common/services/modeService';
import {IEditorInput} from 'vs/platform/editor/common/editor';
import {getResource} from 'vs/workbench/common/editor';
import {getPathLabel} from 'vs/base/common/labels';
import {PLAINTEXT_MODE_ID} from 'vs/editor/common/modes/modesRegistry';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {IDisposable, dispose} from 'vs/base/common/lifecycle';
import {IModelService} from 'vs/editor/common/services/modelService';
export interface IEditorLabel {
name: string;
......@@ -38,7 +40,8 @@ export class ResourceLabel extends IconLabel {
@IExtensionService private extensionService: IExtensionService,
@IWorkspaceContextService protected contextService: IWorkspaceContextService,
@IConfigurationService private configurationService: IConfigurationService,
@IModeService private modeService: IModeService
@IModeService private modeService: IModeService,
@IModelService private modelService: IModelService
) {
super(container, options);
......@@ -80,7 +83,7 @@ export class ResourceLabel extends IconLabel {
title = getPathLabel(resource.fsPath);
}
const extraClasses = getIconClasses(this.modeService, resource, this.options && this.options.isFolder);
const extraClasses = getIconClasses(this.modelService, this.modeService, resource, this.options && this.options.isFolder);
if (this.options && this.options.extraClasses) {
extraClasses.push(...this.options.extraClasses);
}
......@@ -127,12 +130,18 @@ export class FileLabel extends ResourceLabel {
}
}
export function getIconClasses(modeService: IModeService, arg1?: uri | string, isFolder?: boolean): string[] {
export function getIconClasses(modelService: IModelService, modeService: IModeService, resource: uri, isFolder?: boolean): string[] {
let path: string;
if (typeof arg1 === 'string') {
path = arg1;
} else if (arg1) {
path = arg1.fsPath;
let configuredLangId: string;
if (resource) {
path = resource.fsPath;
const model = modelService.getModel(resource);
if (model) {
const modeId = model.getModeId();
if (modeId && modeId !== PLAINTEXT_MODE_ID) {
configuredLangId = modeId; // only take if the mode is specific (aka no just plain text)
}
}
}
// we always set these base classes even if we do not have a path
......@@ -151,11 +160,14 @@ export function getIconClasses(modeService: IModeService, arg1?: uri | string, i
// Files
else {
// Name
const name = dotSegments[0]; // file.txt => "file", .dockerfile => "", file.some.txt => "file"
if (name) {
classes.push(`${cssEscape(name.toLowerCase())}-name-file-icon`);
}
// Extension(s)
const extensions = dotSegments.splice(1);
if (extensions.length > 0) {
for (let i = 0; i < extensions.length; i++) {
......@@ -163,9 +175,10 @@ export function getIconClasses(modeService: IModeService, arg1?: uri | string, i
}
}
const langId = modeService.getModeIdByFilenameOrFirstLine(path);
if (langId) {
classes.push(`${cssEscape(langId)}-lang-file-icon`);
// Configured Language
configuredLangId = configuredLangId || modeService.getModeIdByFilenameOrFirstLine(path);
if (configuredLangId) {
classes.push(`${cssEscape(configuredLangId)}-lang-file-icon`);
}
}
}
......
......@@ -17,6 +17,7 @@ import {QuickOpenModel, QuickOpenEntry, QuickOpenEntryGroup} from 'vs/base/parts
import scorer = require('vs/base/common/scorer');
import {IModeService} from 'vs/editor/common/services/modeService';
import {getIconClasses} from 'vs/workbench/browser/labels';
import {IModelService} from 'vs/editor/common/services/modelService';
import {QuickOpenHandler} from 'vs/workbench/browser/quickopen';
import {Position} from 'vs/platform/editor/common/editor';
import {IEditorGroupService} from 'vs/workbench/services/group/common/groupService';
......@@ -33,6 +34,7 @@ export class EditorPickerEntry extends QuickOpenEntryGroup {
private _group: IEditorGroup,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IModeService private modeService: IModeService,
@IModelService private modelService: IModelService,
@IEditorGroupService editorGroupService: IEditorGroupService
) {
super();
......@@ -42,7 +44,7 @@ export class EditorPickerEntry extends QuickOpenEntryGroup {
public getLabelOptions(): IIconLabelOptions {
return {
extraClasses: getIconClasses(this.modeService, this.getResource()),
extraClasses: getIconClasses(this.modelService, this.modeService, this.getResource()),
italic: this._group.isPreview(this.editor)
};
}
......
......@@ -774,7 +774,7 @@ export class ChangeModeAction extends Action {
}
// Change mode
models.forEach((textModel) => {
models.forEach(textModel => {
this.modelService.setMode(textModel, mode);
});
}
......
......@@ -27,6 +27,7 @@ import paths = require('vs/base/common/paths');
import {Registry} from 'vs/platform/platform';
import {IModeService} from 'vs/editor/common/services/modeService';
import {getIconClasses} from 'vs/workbench/browser/labels';
import {IModelService} from 'vs/editor/common/services/modelService';
import {EditorInput, getUntitledOrFileResource, IWorkbenchEditorConfiguration} from 'vs/workbench/common/editor';
import {WorkbenchComponent} from 'vs/workbench/common/component';
import Event, {Emitter} from 'vs/base/common/event';
......@@ -948,7 +949,8 @@ class PickOpenEntry extends PlaceholderQuickOpenEntry {
constructor(
item: IPickOpenEntry,
private onPreview: () => void,
@IModeService private modeService: IModeService
@IModeService private modeService: IModeService,
@IModelService private modelService: IModelService
) {
super(item.label);
......@@ -965,7 +967,7 @@ class PickOpenEntry extends PlaceholderQuickOpenEntry {
public getLabelOptions(): IIconLabelOptions {
return {
extraClasses: this.resource ? getIconClasses(this.modeService, this.resource, this.isFolder) : []
extraClasses: this.resource ? getIconClasses(this.modelService, this.modeService, this.resource, this.isFolder) : []
};
}
......@@ -1020,6 +1022,7 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry {
input: EditorInput,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IModeService private modeService: IModeService,
@IModelService private modelService: IModelService,
@IConfigurationService private configurationService: IConfigurationService
) {
super(editorService);
......@@ -1038,7 +1041,7 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry {
public getLabelOptions(): IIconLabelOptions {
return {
extraClasses: getIconClasses(this.modeService, this.resource)
extraClasses: getIconClasses(this.modelService, this.modeService, this.resource)
};
}
......
......@@ -16,6 +16,7 @@ import {IIconLabelOptions} from 'vs/base/browser/ui/iconLabel/iconLabel';
import {IRange} from 'vs/editor/common/editorCommon';
import {IModeService} from 'vs/editor/common/services/modeService';
import {getIconClasses} from 'vs/workbench/browser/labels';
import {IModelService} from 'vs/editor/common/services/modelService';
import {IThemeService} from 'vs/workbench/services/themes/common/themeService';
import {IAutoFocus} from 'vs/base/parts/quickopen/common/quickOpen';
import {QuickOpenEntry, QuickOpenModel} from 'vs/base/parts/quickopen/browser/quickOpenModel';
......@@ -47,6 +48,7 @@ export class FileEntry extends EditorQuickOpenEntry {
private icon: string,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IModeService private modeService: IModeService,
@IModelService private modelService: IModelService,
@IConfigurationService private configurationService: IConfigurationService,
@IWorkspaceContextService contextService: IWorkspaceContextService
) {
......@@ -59,7 +61,7 @@ export class FileEntry extends EditorQuickOpenEntry {
public getLabelOptions(): IIconLabelOptions {
return {
extraClasses: getIconClasses(this.modeService, this.resource)
extraClasses: getIconClasses(this.modelService, this.modeService, this.resource)
};
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册