提交 62279723 编写于 作者: B Benjamin Pasero

more mime reduction

上级 b7a8be16
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import {TPromise} from 'vs/base/common/winjs.base';
import mime = require('vs/base/common/mime');
import {PLAINTEXT_MODE_ID} from 'vs/editor/common/modes/modesRegistry';
import strinput = require('vs/workbench/common/editor/stringEditorInput');
import {EditorInput, EditorModel} from 'vs/workbench/common/editor';
import uri from 'vs/base/common/uri';
......@@ -17,11 +17,11 @@ export class DebugStringEditorInput extends strinput.StringEditorInput {
private resourceUrl: uri,
description: string,
value: string,
mimeType: string,
modeId: string,
singleton: boolean,
@IInstantiationService instantiationService: IInstantiationService
) {
super(name, description, value, mimeType || mime.MIME_TEXT, singleton, instantiationService);
super(name, description, value, modeId || PLAINTEXT_MODE_ID, singleton, instantiationService);
}
public getResource(): uri {
......
......@@ -119,8 +119,8 @@ export class TextFileEditor extends BaseTextEditor {
// Different Input (Reload)
return this.editorService.resolveEditorModel(input, true /* Reload */).then(resolvedModel => {
// There is a special case where the text editor has to handle binary file editor input: if a file with application/unknown
// mime has been resolved and cached before, it maybe an actual instance of BinaryEditorModel. In this case our text
// There is a special case where the text editor has to handle binary file editor input: if a binary file
// has been resolved and cached before, it maybe an actual instance of BinaryEditorModel. In this case our text
// editor has to open this model using the binary editor. We return early in this case.
if (resolvedModel instanceof BinaryEditorModel) {
return this.openAsBinary(input, options);
......@@ -161,7 +161,7 @@ export class TextFileEditor extends BaseTextEditor {
// In case we tried to open a file inside the text editor and the response
// indicates that this is not a text file, reopen the file through the binary
// editor by using application/octet-stream as mime.
// editor.
if ((<IFileOperationResult>error).fileOperationResult === FileOperationResult.FILE_IS_BINARY) {
return this.openAsBinary(input, options);
}
......
......@@ -13,7 +13,6 @@ import {Action} from 'vs/base/common/actions';
import URI from 'vs/base/common/uri';
import product from 'vs/platform/product';
import {EditorModel} from 'vs/workbench/common/editor';
import {guessMimeTypes} from 'vs/base/common/mime';
import {EditorInputAction} from 'vs/workbench/browser/parts/editor/baseEditor';
import {ResourceEditorInput} from 'vs/workbench/common/editor/resourceEditorInput';
import {DiffEditorInput} from 'vs/workbench/common/editor/diffEditorInput';
......@@ -174,12 +173,10 @@ export class ConflictResolutionDiffEditorInput extends DiffEditorInput {
export class FileOnDiskEditorInput extends ResourceEditorInput {
private fileResource: URI;
private lastModified: number;
private mime: string;
private createdEditorModel: boolean;
constructor(
fileResource: URI,
mime: string,
name: string,
description: string,
@IModelService modelService: IModelService,
......@@ -193,7 +190,6 @@ export class FileOnDiskEditorInput extends ResourceEditorInput {
super(name, description, URI.from({ scheme: 'disk', path: fileResource.fsPath }), modelService, instantiationService);
this.fileResource = fileResource;
this.mime = mime;
}
public getLastModified(): number {
......@@ -208,7 +204,7 @@ export class FileOnDiskEditorInput extends ResourceEditorInput {
const codeEditorModel = this.modelService.getModel(this.resource);
if (!codeEditorModel) {
this.modelService.createModel(content.value, this.modeService.getOrCreateMode(this.mime), this.resource);
this.modelService.createModel(content.value, this.modeService.getOrCreateModeByFilenameOrFirstLine(this.resource.fsPath), this.resource);
this.createdEditorModel = true;
} else {
codeEditorModel.setValueFromRawText(content.value);
......@@ -261,8 +257,7 @@ class ResolveSaveConflictMessage implements IMessageWithAction {
this.actions = [
new Action('workbench.files.action.resolveConflict', nls.localize('compareChanges', "Compare"), null, true, () => {
if (!this.model.isDisposed()) {
const mime = guessMimeTypes(resource.fsPath).join(', ');
const originalInput = this.instantiationService.createInstance(FileOnDiskEditorInput, resource, mime, paths.basename(resource.fsPath), resource.fsPath);
const originalInput = this.instantiationService.createInstance(FileOnDiskEditorInput, resource, paths.basename(resource.fsPath), resource.fsPath);
const modifiedInput = this.instantiationService.createInstance(FileEditorInput, resource, void 0);
const conflictInput = this.instantiationService.createInstance(ConflictResolutionDiffEditorInput, this.model, nls.localize('saveConflictDiffLabel', "{0} (on disk) ↔ {1} (in {2})", modifiedInput.getName(), modifiedInput.getName(), product.nameLong), nls.localize('resolveSaveConflict', "Resolve save conflict"), originalInput, modifiedInput);
......
......@@ -72,7 +72,6 @@ export interface IFilesConfiguration extends IFilesConfiguration, IWorkbenchEdit
export interface IFileResource {
resource: URI;
isDirectory: boolean;
mimes: string[];
}
/**
......@@ -84,7 +83,6 @@ export function asFileResource(obj: any): IFileResource {
return {
resource: stat.resource,
mimes: stat.mime ? stat.mime.split(', ') : [],
isDirectory: stat.isDirectory
};
}
......
......@@ -15,7 +15,7 @@ import {registerSingleton} from 'vs/platform/instantiation/common/extensions';
import {IWorkbenchActionRegistry, Extensions as ActionExtensions} from 'vs/workbench/common/actionRegistry';
import {OutputService} from 'vs/workbench/parts/output/browser/outputServices';
import {ToggleOutputAction, ClearOutputAction} from 'vs/workbench/parts/output/browser/outputActions';
import {OUTPUT_MIME, OUTPUT_MODE_ID, OUTPUT_PANEL_ID, IOutputService} from 'vs/workbench/parts/output/common/output';
import {OUTPUT_MODE_ID, OUTPUT_PANEL_ID, IOutputService} from 'vs/workbench/parts/output/common/output';
import panel = require('vs/workbench/browser/panel');
import {EditorContextKeys} from 'vs/editor/common/editorCommon';
import {CommandsRegistry, ICommandHandler} from 'vs/platform/commands/common/commands';
......@@ -28,8 +28,7 @@ registerSingleton(IOutputService, OutputService);
ModesRegistry.registerLanguage({
id: OUTPUT_MODE_ID,
extensions: [],
aliases: [null],
mimetypes: [OUTPUT_MIME]
aliases: [null]
});
// Register Output Panel
......
......@@ -11,7 +11,7 @@ import {TPromise} from 'vs/base/common/winjs.base';
import {RunOnceScheduler} from 'vs/base/common/async';
import {EditorModel} from 'vs/workbench/common/editor';
import {StringEditorInput} from 'vs/workbench/common/editor/stringEditorInput';
import {OUTPUT_EDITOR_INPUT_ID, OUTPUT_PANEL_ID, IOutputEvent, OUTPUT_MIME, IOutputService, MAX_OUTPUT_LENGTH, IOutputChannel} from 'vs/workbench/parts/output/common/output';
import {OUTPUT_EDITOR_INPUT_ID, OUTPUT_PANEL_ID, IOutputEvent, OUTPUT_MODE_ID, IOutputService, MAX_OUTPUT_LENGTH, IOutputChannel} from 'vs/workbench/parts/output/common/output';
import {OutputPanel} from 'vs/workbench/parts/output/browser/outputPanel';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IPanelService} from 'vs/workbench/services/panel/common/panelService';
......@@ -49,7 +49,7 @@ export class OutputEditorInput extends StringEditorInput {
@IOutputService private outputService: IOutputService,
@IPanelService private panelService: IPanelService
) {
super(nls.localize('output', "Output"), outputChannel ? nls.localize('outputChannel', "for '{0}'", outputChannel.label) : '', '', OUTPUT_MIME, true, instantiationService);
super(nls.localize('output', "Output"), outputChannel ? nls.localize('outputChannel', "for '{0}'", outputChannel.label) : '', '', OUTPUT_MODE_ID, true, instantiationService);
this.bufferedOutput = '';
this.toDispose = [];
......
......@@ -11,11 +11,6 @@ import {createDecorator} from 'vs/platform/instantiation/common/instantiation';
import {IEditor} from 'vs/platform/editor/common/editor';
import {RawContextKey} from 'vs/platform/contextkey/common/contextkey';
/**
* Mime type used by the output editor.
*/
export const OUTPUT_MIME = 'text/x-code-output';
/**
* Id used by the output editor.
*/
......
......@@ -14,7 +14,7 @@ import * as Platform from 'vs/platform/platform';
import {SyncDescriptor} from 'vs/platform/instantiation/common/descriptors';
import {StringEditorInput} from 'vs/workbench/common/editor/stringEditorInput';
import {ITelemetryService, NullTelemetryService} from 'vs/platform/telemetry/common/telemetry';
import mime = require('vs/base/common/mime');
import {PLAINTEXT_MODE_ID} from 'vs/editor/common/modes/modesRegistry';
let EditorRegistry: IEditorRegistry = Platform.Registry.as(Extensions.Editors);
......@@ -189,10 +189,10 @@ suite('Workbench BaseEditor', () => {
let inst = new TestInstantiationService();
inst.createInstance(EditorRegistry.getEditor(inst.createInstance(MyStringInput, 'fake', '', '', mime.MIME_TEXT, false)), 'id').then(editor => {
inst.createInstance(EditorRegistry.getEditor(inst.createInstance(MyStringInput, 'fake', '', '', PLAINTEXT_MODE_ID, false)), 'id').then(editor => {
assert.strictEqual(editor.getId(), 'myEditor');
return inst.createInstance(EditorRegistry.getEditor(inst.createInstance(StringEditorInput, 'fake', '', '', mime.MIME_TEXT, false)), 'id').then(editor => {
return inst.createInstance(EditorRegistry.getEditor(inst.createInstance(StringEditorInput, 'fake', '', '', PLAINTEXT_MODE_ID, false)), 'id').then(editor => {
assert.strictEqual(editor.getId(), 'myOtherEditor');
(<any>EditorRegistry).setEditors(oldEditors);
......@@ -210,7 +210,7 @@ suite('Workbench BaseEditor', () => {
let inst = new TestInstantiationService();
inst.createInstance(EditorRegistry.getEditor(inst.createInstance(MyStringInput, 'fake', '', '', mime.MIME_TEXT, false)), 'id').then(editor => {
inst.createInstance(EditorRegistry.getEditor(inst.createInstance(MyStringInput, 'fake', '', '', PLAINTEXT_MODE_ID, false)), 'id').then(editor => {
assert.strictEqual('myOtherEditor', editor.getId());
(<any>EditorRegistry).setEditors(oldEditors);
......@@ -221,7 +221,7 @@ suite('Workbench BaseEditor', () => {
let inst = new TestInstantiationService();
let action = new MyAction('id', 'label');
action.input = inst.createInstance(StringEditorInput, 'input', '', '', mime.MIME_TEXT, false);
action.input = inst.createInstance(StringEditorInput, 'input', '', '', PLAINTEXT_MODE_ID, false);
assert.equal(action.didCallIsEnabled, true);
});
......@@ -231,12 +231,12 @@ suite('Workbench BaseEditor', () => {
let contributor = new MyEditorInputActionContributor();
assert(!contributor.hasActions(null));
assert(contributor.hasActions({ editor: new MyEditor('id', NullTelemetryService), input: inst.createInstance(StringEditorInput, 'fake', '', '', mime.MIME_TEXT, false), position: 0 }));
assert(contributor.hasActions({ editor: new MyEditor('id', NullTelemetryService), input: inst.createInstance(StringEditorInput, 'fake', '', '', PLAINTEXT_MODE_ID, false), position: 0 }));
let actionsFirst = contributor.getActions({ editor: new MyEditor('id', NullTelemetryService), input: inst.createInstance(StringEditorInput, 'fake', '', '', mime.MIME_TEXT, false), position: 0 });
let actionsFirst = contributor.getActions({ editor: new MyEditor('id', NullTelemetryService), input: inst.createInstance(StringEditorInput, 'fake', '', '', PLAINTEXT_MODE_ID, false), position: 0 });
assert.strictEqual(actionsFirst.length, 2);
let input = inst.createInstance(StringEditorInput, 'fake', '', '', mime.MIME_TEXT, false);
let input = inst.createInstance(StringEditorInput, 'fake', '', '', PLAINTEXT_MODE_ID, false);
let actions = contributor.getActions({ editor: new MyEditor('id', NullTelemetryService), input: input, position: 0 });
assert(actions[0] === actionsFirst[0]);
assert(actions[1] === actionsFirst[1]);
......
......@@ -32,12 +32,12 @@ suite('Workbench - StringEditorInput', () => {
test('StringEditorInput', function (done) {
let input = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mime', false);
let otherInput = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'othervalue', 'mime', false);
let otherInputSame = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mime', false);
let input = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
let otherInput = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'othervalue', 'mode', false);
let otherInputSame = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
let inputSingleton = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mime', true);
let otherInputSingleton = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'othervalue', 'mime', true);
let inputSingleton = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', true);
let otherInputSingleton = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'othervalue', 'mode', true);
assert(inputSingleton.matches(otherInputSingleton));
(<any>otherInputSingleton).singleton = false;
assert(!inputSingleton.matches(otherInputSingleton));
......@@ -48,15 +48,15 @@ suite('Workbench - StringEditorInput', () => {
assert(!input.matches(null));
assert(input.getName());
input = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mime', false);
input = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
input = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mime', false);
input = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
editorService.resolveEditorModel(input, true).then(resolved => {
let resolvedModelA = resolved;
return editorService.resolveEditorModel(input, true).then(resolved => {
assert(resolvedModelA === resolved); // assert: Resolved Model cached per instance
let otherInput = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mime', false);
let otherInput = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
return editorService.resolveEditorModel(otherInput, true).then(resolved => {
assert(resolvedModelA !== resolved); // NOT assert: Different instance, different model
......@@ -78,7 +78,7 @@ suite('Workbench - StringEditorInput', () => {
});
test('StringEditorInput - setValue, clearValue, append', function () {
let input = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mime', false);
let input = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
assert.strictEqual(input.getValue(), 'value');
input.setValue('foo');
......@@ -94,10 +94,10 @@ suite('Workbench - StringEditorInput', () => {
test('Input.matches() - StringEditorInput', function () {
let inst = new TestInstantiationService();
let stringEditorInput = inst.createInstance(StringEditorInput, 'name', 'description', 'value', 'mime', false);
let stringEditorInput = inst.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
let promiseEditorInput = inst.createInstance(ResourceEditorInput, 'name', 'description', URI.from({ scheme: 'inMemory', authority: null, path: 'thePath' }));
let stringEditorInput2 = inst.createInstance(StringEditorInput, 'name', 'description', 'value', 'mime', false);
let stringEditorInput2 = inst.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
let promiseEditorInput2 = inst.createInstance(ResourceEditorInput, 'name', 'description', URI.from({ scheme: 'inMemory', authority: null, path: 'thePath' }));
assert.strictEqual(stringEditorInput.matches(null), false);
......
......@@ -23,7 +23,7 @@ suite('Workbench - StringEditorModel', () => {
test('StringEditorModel', function (done) {
instantiationService.stub(IModelService, createMockModelService(instantiationService));
let m = instantiationService.createInstance(StringEditorModel, 'value', 'mime', null);
let m = instantiationService.createInstance(StringEditorModel, 'value', 'mode', null);
m.load().then(model => {
assert(model === m);
......@@ -45,7 +45,7 @@ suite('Workbench - StringEditorModel', () => {
test('StringEditorModel - setValue, clearValue, append, trim', function (done) {
instantiationService.stub(IModelService, createMockModelService(instantiationService));
let m = instantiationService.createInstance(StringEditorModel, 'value', 'mime', null);
let m = instantiationService.createInstance(StringEditorModel, 'value', 'mode', null);
m.load().then(model => {
assert(model === m);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册