提交 70ee90dc 编写于 作者: B Benjamin Pasero

debt - move untitlededitorservice to common

上级 103d61e7
......@@ -22,7 +22,7 @@ import {TPromise} from 'vs/base/common/winjs.base';
import * as vscode from 'vscode';
import {WordHelper} from 'vs/editor/common/model/textModelWithTokensHelpers';
import {IFileService} from 'vs/platform/files/common/files';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/browser/untitledEditorService';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
export interface IModelAddedData {
url: URI;
......
......@@ -10,7 +10,7 @@ import {IEditorModesRegistry, Extensions} from 'vs/editor/common/modes/modesRegi
import {isUnspecific, guessMimeTypes, MIME_TEXT, suggestFilename} from 'vs/base/common/mime';
import labels = require('vs/base/common/labels');
import paths = require('vs/base/common/paths');
import {EditorModel, EncodingMode, IInputStatus, EditorInput, IResourceEditorInput, IEncodingSupport} from 'vs/workbench/common/editor';
import {UntitledEditorInput as AbstractUntitledEditorInput, EditorModel, EncodingMode, IInputStatus} from 'vs/workbench/common/editor';
import {Registry} from 'vs/platform/platform';
import {UntitledEditorModel} from 'vs/workbench/browser/parts/editor/untitledEditorModel';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
......@@ -20,7 +20,7 @@ import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
/**
* An editor input to be used for untitled text buffers.
*/
export class UntitledEditorInput extends EditorInput implements IResourceEditorInput, IEncodingSupport {
export class UntitledEditorInput extends AbstractUntitledEditorInput {
public static ID: string = 'workbench.editors.untitledEditorInput';
public static SCHEMA: string = 'untitled';
......
......@@ -36,7 +36,8 @@ import {IViewletRegistry, Extensions as ViewletExtensions} from 'vs/workbench/br
import {QuickOpenController} from 'vs/workbench/browser/parts/quickopen/quickOpenController';
import {getServices} from 'vs/platform/instantiation/common/extensions';
import {AbstractKeybindingService} from 'vs/platform/keybinding/browser/keybindingServiceImpl';
import {UntitledEditorService, IUntitledEditorService} from 'vs/workbench/services/untitled/browser/untitledEditorService';
import {UntitledEditorService} from 'vs/workbench/services/untitled/browser/untitledEditorService';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {WorkbenchEditorService} from 'vs/workbench/services/editor/browser/editorService';
import {Position, Parts, IPartService} from 'vs/workbench/services/part/common/partService';
import {DEFAULT_THEME_ID} from 'vs/platform/theme/common/themes';
......
......@@ -122,6 +122,80 @@ export abstract class EditorInput extends EventEmitter implements IEditorInput {
}
}
export interface IResourceEditorInput extends IEditorInput {
/**
* Gets the absolute file resource URI this input is about.
*/
getResource(): URI;
}
export enum EncodingMode {
/**
* Instructs the encoding support to encode the current input with the provided encoding
*/
Encode,
/**
* Instructs the encoding support to decode the current input with the provided encoding
*/
Decode
}
export interface IEncodingSupport {
/**
* Gets the encoding of the input if known.
*/
getEncoding(): string;
/**
* Sets the encoding for the input for saving.
*/
setEncoding(encoding: string, mode: EncodingMode): void;
}
/**
* This is a tagging interface to declare an editor input being capable of dealing with files. It is only used in the editor registry
* to register this kind of input to the platform.
*/
export interface IFileEditorInput extends IResourceEditorInput, IEncodingSupport {
/**
* Gets the mime type of the file this input is about.
*/
getMime(): string;
/**
* Sets the mime type of the file this input is about.
*/
setMime(mime: string): void;
/**
* Sets the absolute file resource URI this input is about.
*/
setResource(resource: URI): void;
}
/**
* The base class of untitled editor inputs in the workbench.
*/
export abstract class UntitledEditorInput extends EditorInput implements IResourceEditorInput, IEncodingSupport {
abstract getResource(): URI;
abstract isDirty(): boolean;
abstract suggestFileName(): string;
abstract getMime(): string;
abstract getEncoding(): string;
abstract setEncoding(encoding: string, mode: EncodingMode): void;
}
/**
* The base class of editor inputs that have an original and modified side.
*/
......@@ -395,62 +469,6 @@ export class TextDiffEditorOptions extends TextEditorOptions {
public autoRevealFirstChange: boolean;
}
export interface IResourceEditorInput extends IEditorInput {
/**
* Gets the absolute file resource URI this input is about.
*/
getResource(): URI;
}
export enum EncodingMode {
/**
* Instructs the encoding support to encode the current input with the provided encoding
*/
Encode,
/**
* Instructs the encoding support to decode the current input with the provided encoding
*/
Decode
}
export interface IEncodingSupport {
/**
* Gets the encoding of the input if known.
*/
getEncoding(): string;
/**
* Sets the encoding for the input for saving.
*/
setEncoding(encoding: string, mode: EncodingMode): void;
}
/**
* This is a tagging interface to declare an editor input being capable of dealing with files. It is only used in the editor registry
* to register this kind of input to the platform.
*/
export interface IFileEditorInput extends IResourceEditorInput, IEncodingSupport {
/**
* Gets the mime type of the file this input is about.
*/
getMime(): string;
/**
* Sets the mime type of the file this input is about.
*/
setMime(mime: string): void;
/**
* Sets the absolute file resource URI this input is about.
*/
setResource(resource: URI): void;
}
/**
* Given an input, tries to get the associated URI for it (either file or untitled scheme).
*/
......
......@@ -91,7 +91,8 @@ import {IWorkspaceContextService, IConfiguration, IWorkspace} from 'vs/platform/
import {IPluginService} from 'vs/platform/plugins/common/plugins';
import {MainThreadModeServiceImpl} from 'vs/editor/common/services/modeServiceImpl';
import {IModeService} from 'vs/editor/common/services/modeService';
import {IUntitledEditorService, UntitledEditorService} from 'vs/workbench/services/untitled/browser/untitledEditorService';
import {UntitledEditorService} from 'vs/workbench/services/untitled/browser/untitledEditorService';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {CrashReporter} from 'vs/workbench/electron-browser/crashReporter';
import {IThemeService, ThemeService} from 'vs/workbench/services/themes/node/themeService';
import { IServiceCtor, isServiceEvent } from 'vs/base/common/service';
......
......@@ -39,7 +39,7 @@ import {HTMLFrameEditorInput} from 'vs/workbench/parts/files/browser/editors/htm
import {DerivedFrameEditorInput} from 'vs/workbench/parts/files/browser/editors/derivedFrameEditorInput';
import {IActionProvider} from 'vs/base/parts/tree/browser/actionsRenderer';
import {WorkingFileEntry, WorkingFilesModel} from 'vs/workbench/parts/files/browser/workingFilesModel';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/browser/untitledEditorService';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {IQuickOpenService} from 'vs/workbench/services/quickopen/common/quickOpenService';
import {IViewletService} from 'vs/workbench/services/viewlet/common/viewletService';
......
......@@ -21,7 +21,7 @@ import {DerivedFrameEditorInput} from 'vs/workbench/parts/files/browser/editors/
import {State, TextFileEditorModel, CACHE} from 'vs/workbench/parts/files/browser/editors/textFileEditorModel';
import {IFrameEditor} from 'vs/workbench/browser/parts/editor/iframeEditor';
import {EventType as WorkbenchEventType, EditorInputEvent, UntitledEditorEvent} from 'vs/workbench/browser/events';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/browser/untitledEditorService';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {IQuickOpenService} from 'vs/workbench/services/quickopen/common/quickOpenService';
import {IActivityService, NumberBadge} from 'vs/workbench/services/activity/common/activityService';
......
......@@ -24,7 +24,7 @@ import {ContributableActionProvider} from 'vs/workbench/browser/actionBarRegistr
import {keybindingForAction, CloseWorkingFileAction, SelectResourceForCompareAction, CompareResourcesAction, SaveFileAsAction, SaveFileAction, RevertFileAction, OpenToSideAction} from 'vs/workbench/parts/files/browser/fileActions';
import {asFileResource} from 'vs/workbench/parts/files/common/files';
import {WorkingFileEntry, WorkingFilesModel} from 'vs/workbench/parts/files/browser/workingFilesModel';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/browser/untitledEditorService';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {IWorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService';
import {IContextMenuService} from 'vs/platform/contextview/browser/contextView';
......
......@@ -14,7 +14,7 @@ import {disposeAll, IDisposable} from 'vs/base/common/lifecycle';
import filesCommon = require('vs/workbench/parts/files/common/files');
import {IFileStat, FileChangeType, FileChangesEvent, EventType as FileEventType} from 'vs/platform/files/common/files';
import {EditorEvent, UntitledEditorEvent, EventType as WorkbenchEventType} from 'vs/workbench/browser/events';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/browser/untitledEditorService';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {IPartService} from 'vs/workbench/services/part/common/partService';
import {IWorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService';
......
......@@ -13,7 +13,7 @@ import plat = require('vs/base/common/platform');
import errors = require('vs/base/common/errors');
import URI from 'vs/base/common/uri';
import {EventType as WorkbenchEventType} from 'vs/workbench/browser/events';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/browser/untitledEditorService';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {IPartService} from 'vs/workbench/services/part/common/partService';
import {IWorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService';
import {IResourceInput} from 'vs/platform/editor/common/editor';
......
......@@ -20,7 +20,7 @@ import {CACHE, TextFileEditorModel} from 'vs/workbench/parts/files/browser/edito
import {ITextFileOperationResult, ConfirmResult} from 'vs/workbench/parts/files/common/files';
import {IWorkbenchActionRegistry, Extensions as ActionExtensions} from 'vs/workbench/browser/actionRegistry';
import {SyncActionDescriptor} from 'vs/platform/actions/common/actions';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/browser/untitledEditorService';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {IFileService} from 'vs/platform/files/common/files';
import {IInstantiationService, INullService} from 'vs/platform/instantiation/common/instantiation';
import {IEventService} from 'vs/platform/event/common/event';
......
......@@ -16,7 +16,7 @@ import {BaseEditor, IEditorRegistry, Extensions} from 'vs/workbench/browser/part
import {EditorInput, EditorOptions, IFileEditorInput, TextEditorOptions} from 'vs/workbench/common/editor';
import {UntitledEditorInput} from 'vs/workbench/browser/parts/editor/untitledEditorInput';
import {DiffEditorInput} from 'vs/workbench/browser/parts/editor/diffEditorInput';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/browser/untitledEditorService';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {IWorkbenchEditorService, EditorArrangement, IFileInput} from 'vs/workbench/services/editor/common/editorService';
import {IEditorInput, IEditorModel, IEditorOptions, Position, IEditor, IResourceInput, ITextEditorModel} from 'vs/platform/editor/common/editor';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
......
......@@ -11,7 +11,7 @@ import objects = require('vs/base/common/objects');
import filters = require('vs/base/common/filters');
import {Client} from 'vs/base/node/service.cp';
import {IProgress, LineMatch, FileMatch, ISearchComplete, ISearchProgressItem, QueryType, IFileMatch, ISearchQuery, ISearchConfiguration, ISearchService} from 'vs/platform/search/common/search';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/browser/untitledEditorService';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {IModelService} from 'vs/editor/common/services/modelService';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
......
......@@ -8,51 +8,8 @@ import URI from 'vs/base/common/uri';
import {EventType} from 'vs/base/common/events';
import arrays = require('vs/base/common/arrays');
import {UntitledEditorInput} from 'vs/workbench/browser/parts/editor/untitledEditorInput';
import {IInstantiationService, ServiceIdentifier, createDecorator} from 'vs/platform/instantiation/common/instantiation';
export interface IUntitledEditorServices {
untitledEditorService?: IUntitledEditorService;
}
export var IUntitledEditorService = createDecorator<IUntitledEditorService>('untitledEditorService');
export interface IUntitledEditorService {
serviceId : ServiceIdentifier<any>;
/**
* Returns the untitled editor input matching the provided resource.
*/
get(resource: URI): UntitledEditorInput;
/**
* Returns all untitled editor inputs.
*/
getAll(resources?: URI[]): UntitledEditorInput[];
/**
* Returns dirty untitled editors as resource URIs.
*/
getDirty(): URI[];
/**
* Returns true iff the provided resource is dirty.
*/
isDirty(resource: URI): boolean;
/**
* Creates a new untitled input with the optional resource URI or returns an existing one
* if the provided resource exists already as untitled input.
*
* It is valid to pass in a file resource. In that case the path will be used as identifier.
* The use case is to be able to create a new file with a specific path with VSCode.
*/
createOrGet(resource?: URI, modeId?: string): UntitledEditorInput;
/**
* A check to find out if a untitled resource has a file path associated or not.
*/
hasAssociatedFilePath(resource: URI): boolean;
}
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
export class UntitledEditorService implements IUntitledEditorService {
public serviceId = IUntitledEditorService;
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import URI from 'vs/base/common/uri';
import {UntitledEditorInput} from 'vs/workbench/common/editor';
import {ServiceIdentifier, createDecorator} from 'vs/platform/instantiation/common/instantiation';
export var IUntitledEditorService = createDecorator<IUntitledEditorService>('untitledEditorService');
export interface IUntitledEditorService {
serviceId : ServiceIdentifier<any>;
/**
* Returns the untitled editor input matching the provided resource.
*/
get(resource: URI): UntitledEditorInput;
/**
* Returns all untitled editor inputs.
*/
getAll(resources?: URI[]): UntitledEditorInput[];
/**
* Returns dirty untitled editors as resource URIs.
*/
getDirty(): URI[];
/**
* Returns true iff the provided resource is dirty.
*/
isDirty(resource: URI): boolean;
/**
* Creates a new untitled input with the optional resource URI or returns an existing one
* if the provided resource exists already as untitled input.
*
* It is valid to pass in a file resource. In that case the path will be used as identifier.
* The use case is to be able to create a new file with a specific path with VSCode.
*/
createOrGet(resource?: URI, modeId?: string): UntitledEditorInput;
/**
* A check to find out if a untitled resource has a file path associated or not.
*/
hasAssociatedFilePath(resource: URI): boolean;
}
\ No newline at end of file
......@@ -41,6 +41,7 @@ import {BaseWorkspaceContextService} from 'vs/platform/workspace/common/baseWork
import {IEditorInput, IEditorModel, IEditorOptions, ITextInput, Position, IEditor, IResourceInput, ITextEditorModel} from 'vs/platform/editor/common/editor';
import {IEventService} from 'vs/platform/event/common/event';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {IMessageService, IConfirmation} from 'vs/platform/message/common/message';
import Lifecycle = require('vs/base/common/lifecycle');
import {IRequestService} from 'vs/platform/request/common/request';
......@@ -355,8 +356,8 @@ export class MockRequestService extends BaseRequestService {
}
}
export class TestUntitledEditorService implements UntitledEditorService.IUntitledEditorService {
public serviceId = UntitledEditorService.IUntitledEditorService;
export class TestUntitledEditorService implements IUntitledEditorService {
public serviceId = IUntitledEditorService;
public get(resource: URI) {
return null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册