diff --git a/src/vs/workbench/api/common/extHostDocuments.ts b/src/vs/workbench/api/common/extHostDocuments.ts index 1ce73b4a28c..bde5e1c4e49 100644 --- a/src/vs/workbench/api/common/extHostDocuments.ts +++ b/src/vs/workbench/api/common/extHostDocuments.ts @@ -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; diff --git a/src/vs/workbench/browser/parts/editor/untitledEditorInput.ts b/src/vs/workbench/browser/parts/editor/untitledEditorInput.ts index f261afcadcb..e4343889507 100644 --- a/src/vs/workbench/browser/parts/editor/untitledEditorInput.ts +++ b/src/vs/workbench/browser/parts/editor/untitledEditorInput.ts @@ -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'; diff --git a/src/vs/workbench/browser/workbench.ts b/src/vs/workbench/browser/workbench.ts index 7e710f212cd..02b75caf767 100644 --- a/src/vs/workbench/browser/workbench.ts +++ b/src/vs/workbench/browser/workbench.ts @@ -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'; diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index cca0fa75f12..4ca3e73fb5d 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -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). */ diff --git a/src/vs/workbench/electron-browser/shell.ts b/src/vs/workbench/electron-browser/shell.ts index 9a2055e688a..5c9867ae5d2 100644 --- a/src/vs/workbench/electron-browser/shell.ts +++ b/src/vs/workbench/electron-browser/shell.ts @@ -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'; diff --git a/src/vs/workbench/parts/files/browser/fileActions.ts b/src/vs/workbench/parts/files/browser/fileActions.ts index 09517b1dd3e..2101422c375 100644 --- a/src/vs/workbench/parts/files/browser/fileActions.ts +++ b/src/vs/workbench/parts/files/browser/fileActions.ts @@ -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'; diff --git a/src/vs/workbench/parts/files/browser/fileTracker.ts b/src/vs/workbench/parts/files/browser/fileTracker.ts index 3c2f07c0cfb..0bb0b197c20 100644 --- a/src/vs/workbench/parts/files/browser/fileTracker.ts +++ b/src/vs/workbench/parts/files/browser/fileTracker.ts @@ -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'; diff --git a/src/vs/workbench/parts/files/browser/views/workingFilesViewer.ts b/src/vs/workbench/parts/files/browser/views/workingFilesViewer.ts index 5c2cd8d2c7d..832d5d8b7e5 100644 --- a/src/vs/workbench/parts/files/browser/views/workingFilesViewer.ts +++ b/src/vs/workbench/parts/files/browser/views/workingFilesViewer.ts @@ -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'; diff --git a/src/vs/workbench/parts/files/browser/workingFilesModel.ts b/src/vs/workbench/parts/files/browser/workingFilesModel.ts index ab022a4a063..506625ec593 100644 --- a/src/vs/workbench/parts/files/browser/workingFilesModel.ts +++ b/src/vs/workbench/parts/files/browser/workingFilesModel.ts @@ -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'; diff --git a/src/vs/workbench/parts/files/electron-browser/electronFileTracker.ts b/src/vs/workbench/parts/files/electron-browser/electronFileTracker.ts index 18b388c0bc8..20fec2073be 100644 --- a/src/vs/workbench/parts/files/electron-browser/electronFileTracker.ts +++ b/src/vs/workbench/parts/files/electron-browser/electronFileTracker.ts @@ -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'; diff --git a/src/vs/workbench/parts/files/electron-browser/textFileServices.ts b/src/vs/workbench/parts/files/electron-browser/textFileServices.ts index 85d75947e67..30e292f0209 100644 --- a/src/vs/workbench/parts/files/electron-browser/textFileServices.ts +++ b/src/vs/workbench/parts/files/electron-browser/textFileServices.ts @@ -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'; diff --git a/src/vs/workbench/services/editor/browser/editorService.ts b/src/vs/workbench/services/editor/browser/editorService.ts index 19960f555d1..1f1a67c8aab 100644 --- a/src/vs/workbench/services/editor/browser/editorService.ts +++ b/src/vs/workbench/services/editor/browser/editorService.ts @@ -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'; diff --git a/src/vs/workbench/services/search/node/searchService.ts b/src/vs/workbench/services/search/node/searchService.ts index b8ee3161a70..7aecdcf69ce 100644 --- a/src/vs/workbench/services/search/node/searchService.ts +++ b/src/vs/workbench/services/search/node/searchService.ts @@ -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'; diff --git a/src/vs/workbench/services/untitled/browser/untitledEditorService.ts b/src/vs/workbench/services/untitled/browser/untitledEditorService.ts index f6f519e4baf..bb8595ba1d0 100644 --- a/src/vs/workbench/services/untitled/browser/untitledEditorService.ts +++ b/src/vs/workbench/services/untitled/browser/untitledEditorService.ts @@ -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('untitledEditorService'); - -export interface IUntitledEditorService { - serviceId : ServiceIdentifier; - - /** - * 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; diff --git a/src/vs/workbench/services/untitled/common/untitledEditorService.ts b/src/vs/workbench/services/untitled/common/untitledEditorService.ts new file mode 100644 index 00000000000..4e9dfbc9db8 --- /dev/null +++ b/src/vs/workbench/services/untitled/common/untitledEditorService.ts @@ -0,0 +1,50 @@ +/*--------------------------------------------------------------------------------------------- + * 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('untitledEditorService'); + +export interface IUntitledEditorService { + + serviceId : ServiceIdentifier; + + /** + * 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 diff --git a/src/vs/workbench/test/browser/servicesTestUtils.ts b/src/vs/workbench/test/browser/servicesTestUtils.ts index a4636c5cb9d..eb9c3a96ec9 100644 --- a/src/vs/workbench/test/browser/servicesTestUtils.ts +++ b/src/vs/workbench/test/browser/servicesTestUtils.ts @@ -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;