diff --git a/src/vs/base/common/labels.ts b/src/vs/base/common/labels.ts index e00cc11da16..cb962143454 100644 --- a/src/vs/base/common/labels.ts +++ b/src/vs/base/common/labels.ts @@ -8,6 +8,7 @@ import URI from 'vs/base/common/uri'; import platform = require('vs/base/common/platform'); import { nativeSep, normalize, isEqualOrParent, isEqual, basename as pathsBasename, join } from 'vs/base/common/paths'; import { endsWith, ltrim } from 'vs/base/common/strings'; +import { Schemas } from 'vs/base/common/network'; export interface IWorkspaceFolderProvider { getWorkspaceFolder(resource: URI): { uri: URI }; @@ -29,7 +30,7 @@ export function getPathLabel(resource: URI | string, rootProvider?: IWorkspaceFo resource = URI.file(resource); } - if (resource.scheme !== 'file' && resource.scheme !== 'untitled') { + if (resource.scheme !== Schemas.file && resource.scheme !== Schemas.untitled) { return resource.with({ query: null, fragment: null }).toString(true); } diff --git a/src/vs/code/electron-main/launch.ts b/src/vs/code/electron-main/launch.ts index d64f080e42e..b5520dfda67 100644 --- a/src/vs/code/electron-main/launch.ts +++ b/src/vs/code/electron-main/launch.ts @@ -16,6 +16,7 @@ import { OpenContext } from 'vs/platform/windows/common/windows'; import { IWindowsMainService, ICodeWindow } from 'vs/platform/windows/electron-main/windows'; import { whenDeleted } from 'vs/base/node/pfs'; import { IWorkspacesMainService } from 'vs/platform/workspaces/common/workspaces'; +import { Schemas } from 'vs/base/common/network'; export const ID = 'launchService'; export const ILaunchService = createDecorator(ID); @@ -203,7 +204,7 @@ export class LaunchService implements ILaunchService { } else if (window.openedWorkspace) { const rootFolders = this.workspacesMainService.resolveWorkspaceSync(window.openedWorkspace.configPath).folders; rootFolders.forEach(root => { - if (root.uri.scheme === 'file') { + if (root.uri.scheme === Schemas.file) { folders.push(root.uri.fsPath); } }); diff --git a/src/vs/platform/backup/test/electron-main/backupMainService.test.ts b/src/vs/platform/backup/test/electron-main/backupMainService.test.ts index 60c83ef1746..d49a9e7ad73 100644 --- a/src/vs/platform/backup/test/electron-main/backupMainService.test.ts +++ b/src/vs/platform/backup/test/electron-main/backupMainService.test.ts @@ -23,6 +23,7 @@ import { ConsoleLogMainService } from 'vs/platform/log/common/log'; import { IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces'; import { createHash } from 'crypto'; import { getRandomTestPath } from 'vs/workbench/test/workbenchTestServices'; +import { Schemas } from 'vs/base/common/network'; suite('BackupMainService', () => { const parentDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'backupservice'); @@ -122,8 +123,8 @@ suite('BackupMainService', () => { // 3) backup workspace path exists with empty folders within fs.mkdirSync(service.toBackupPath(fooFile.fsPath)); fs.mkdirSync(service.toBackupPath(barFile.fsPath)); - fs.mkdirSync(path.join(service.toBackupPath(fooFile.fsPath), 'file')); - fs.mkdirSync(path.join(service.toBackupPath(barFile.fsPath), 'untitled')); + fs.mkdirSync(path.join(service.toBackupPath(fooFile.fsPath), Schemas.file)); + fs.mkdirSync(path.join(service.toBackupPath(barFile.fsPath), Schemas.untitled)); service.registerFolderBackupSync(fooFile.fsPath); service.registerFolderBackupSync(barFile.fsPath); service.loadSync(); @@ -133,7 +134,7 @@ suite('BackupMainService', () => { // 4) backup workspace path points to a workspace that no longer exists // so it should convert the backup worspace to an empty workspace backup - const fileBackups = path.join(service.toBackupPath(fooFile.fsPath), 'file'); + const fileBackups = path.join(service.toBackupPath(fooFile.fsPath), Schemas.file); fs.mkdirSync(service.toBackupPath(fooFile.fsPath)); fs.mkdirSync(service.toBackupPath(barFile.fsPath)); fs.mkdirSync(fileBackups); @@ -169,8 +170,8 @@ suite('BackupMainService', () => { // 3) backup workspace path exists with empty folders within fs.mkdirSync(service.toBackupPath(fooFile.fsPath)); fs.mkdirSync(service.toBackupPath(barFile.fsPath)); - fs.mkdirSync(path.join(service.toBackupPath(fooFile.fsPath), 'file')); - fs.mkdirSync(path.join(service.toBackupPath(barFile.fsPath), 'untitled')); + fs.mkdirSync(path.join(service.toBackupPath(fooFile.fsPath), Schemas.file)); + fs.mkdirSync(path.join(service.toBackupPath(barFile.fsPath), Schemas.untitled)); service.registerWorkspaceBackupSync(toWorkspace(fooFile.fsPath)); service.registerWorkspaceBackupSync(toWorkspace(barFile.fsPath)); service.loadSync(); @@ -180,7 +181,7 @@ suite('BackupMainService', () => { // 4) backup workspace path points to a workspace that no longer exists // so it should convert the backup worspace to an empty workspace backup - const fileBackups = path.join(service.toBackupPath(fooFile.fsPath), 'file'); + const fileBackups = path.join(service.toBackupPath(fooFile.fsPath), Schemas.file); fs.mkdirSync(service.toBackupPath(fooFile.fsPath)); fs.mkdirSync(service.toBackupPath(barFile.fsPath)); fs.mkdirSync(fileBackups); diff --git a/src/vs/platform/clipboard/electron-browser/clipboardService.ts b/src/vs/platform/clipboard/electron-browser/clipboardService.ts index 29e7ad73131..5bbc662702d 100644 --- a/src/vs/platform/clipboard/electron-browser/clipboardService.ts +++ b/src/vs/platform/clipboard/electron-browser/clipboardService.ts @@ -9,6 +9,7 @@ import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService import { clipboard } from 'electron'; import URI from 'vs/base/common/uri'; import { isMacintosh } from 'vs/base/common/platform'; +import { Schemas } from 'vs/base/common/network'; export class ClipboardService implements IClipboardService { @@ -40,7 +41,7 @@ export class ClipboardService implements IClipboardService { } public writeFiles(resources: URI[]): void { - const files = resources.filter(f => f.scheme === 'file'); + const files = resources.filter(f => f.scheme === Schemas.file); if (files.length) { clipboard.writeBuffer(ClipboardService.FILE_FORMAT, this.filesToBuffer(files)); diff --git a/src/vs/platform/windows/electron-main/windowsService.ts b/src/vs/platform/windows/electron-main/windowsService.ts index 25ac113b9fd..f5daf2d90e4 100644 --- a/src/vs/platform/windows/electron-main/windowsService.ts +++ b/src/vs/platform/windows/electron-main/windowsService.ts @@ -19,6 +19,7 @@ import { IWindowsMainService, ISharedProcess } from 'vs/platform/windows/electro import { IHistoryMainService, IRecentlyOpened } from 'vs/platform/history/common/history'; import { IWorkspaceIdentifier, IWorkspaceFolderCreationData } from 'vs/platform/workspaces/common/workspaces'; import { ICommandAction } from 'vs/platform/actions/common/actions'; +import { Schemas } from 'vs/base/common/network'; export class WindowsService implements IWindowsService, IDisposable { @@ -40,7 +41,7 @@ export class WindowsService implements IWindowsService, IDisposable { ) { // Catch file URLs chain(urlService.onOpenURL) - .filter(uri => uri.authority === 'file' && !!uri.path) + .filter(uri => uri.authority === Schemas.file && !!uri.path) .map(uri => URI.file(uri.fsPath)) .on(this.openFileForURI, this, this.disposables); diff --git a/src/vs/platform/workspaces/electron-main/workspacesMainService.ts b/src/vs/platform/workspaces/electron-main/workspacesMainService.ts index f06b9ccc058..da321bf8c23 100644 --- a/src/vs/platform/workspaces/electron-main/workspacesMainService.ts +++ b/src/vs/platform/workspaces/electron-main/workspacesMainService.ts @@ -25,6 +25,7 @@ import { applyEdit } from 'vs/base/common/jsonFormatter'; import { massageFolderPathForWorkspace } from 'vs/platform/workspaces/node/workspaces'; import { toWorkspaceFolders } from 'vs/platform/workspace/common/workspace'; import URI from 'vs/base/common/uri'; +import { Schemas } from 'vs/base/common/network'; export interface IStoredWorkspace { folders: IStoredWorkspaceFolder[]; @@ -152,7 +153,7 @@ export class WorkspacesMainService implements IWorkspacesMainService { let storedWorkspace: IStoredWorkspaceFolder; // File URI - if (folderResource.scheme === 'file') { + if (folderResource.scheme === Schemas.file) { storedWorkspace = { path: massageFolderPathForWorkspace(folderResource.fsPath, untitledWorkspaceConfigFolder, []) }; } diff --git a/src/vs/workbench/api/electron-browser/mainThreadDocuments.ts b/src/vs/workbench/api/electron-browser/mainThreadDocuments.ts index 4d1f5845bda..e982594e80f 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadDocuments.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadDocuments.ts @@ -18,6 +18,7 @@ import { ITextModelService } from 'vs/editor/common/services/resolverService'; import { MainThreadDocumentsAndEditors } from './mainThreadDocumentsAndEditors'; import { ITextEditorModel } from 'vs/workbench/common/editor'; import { ITextModel } from 'vs/editor/common/model'; +import { Schemas } from 'vs/base/common/network'; export class BoundModelReferenceCollection { @@ -180,10 +181,10 @@ export class MainThreadDocuments implements MainThreadDocumentsShape { let promise: TPromise; switch (uri.scheme) { - case 'untitled': + case Schemas.untitled: promise = this._handleUnititledScheme(uri); break; - case 'file': + case Schemas.file: default: promise = this._handleAsResourceInput(uri); break; @@ -212,7 +213,7 @@ export class MainThreadDocuments implements MainThreadDocumentsShape { } private _handleUnititledScheme(uri: URI): TPromise { - let asFileUri = uri.with({ scheme: 'file' }); + let asFileUri = uri.with({ scheme: Schemas.file }); return this._fileService.resolveFile(asFileUri).then(stats => { // don't create a new file ontop of an existing file return TPromise.wrapError(new Error('file already exists on disk')); diff --git a/src/vs/workbench/api/node/extHostDocumentContentProviders.ts b/src/vs/workbench/api/node/extHostDocumentContentProviders.ts index 719db9d89b8..747090213d8 100644 --- a/src/vs/workbench/api/node/extHostDocumentContentProviders.ts +++ b/src/vs/workbench/api/node/extHostDocumentContentProviders.ts @@ -13,6 +13,7 @@ import * as vscode from 'vscode'; import { asWinJsPromise } from 'vs/base/common/async'; import { MainContext, ExtHostDocumentContentProvidersShape, MainThreadDocumentContentProvidersShape, IMainContext } from './extHost.protocol'; import { ExtHostDocumentsAndEditors } from './extHostDocumentsAndEditors'; +import { Schemas } from 'vs/base/common/network'; export class ExtHostDocumentContentProvider implements ExtHostDocumentContentProvidersShape { @@ -34,7 +35,7 @@ export class ExtHostDocumentContentProvider implements ExtHostDocumentContentPro registerTextDocumentContentProvider(scheme: string, provider: vscode.TextDocumentContentProvider): vscode.Disposable { // todo@remote // check with scheme from fs-providers! - if (scheme === 'file' || scheme === 'untitled') { + if (scheme === Schemas.file || scheme === Schemas.untitled) { throw new Error(`scheme '${scheme}' already registered`); } diff --git a/src/vs/workbench/browser/dnd.ts b/src/vs/workbench/browser/dnd.ts index cb22598f28b..2f10dd1edea 100644 --- a/src/vs/workbench/browser/dnd.ts +++ b/src/vs/workbench/browser/dnd.ts @@ -77,7 +77,7 @@ export function extractResources(e: DragEvent, externalOnly?: boolean): (IDragge try { const draggedEditors = JSON.parse(rawEditorsData) as ISerializedDraggedEditor[]; draggedEditors.forEach(draggedEditor => { - resources.push({ resource: URI.parse(draggedEditor.resource), backupResource: URI.parse(draggedEditor.backupResource), viewState: draggedEditor.viewState, isExternal: false }); + resources.push({ resource: URI.parse(draggedEditor.resource), backupResource: draggedEditor.backupResource ? URI.parse(draggedEditor.backupResource) : void 0, viewState: draggedEditor.viewState, isExternal: false }); }); } catch (error) { // Invalid transfer @@ -363,10 +363,10 @@ export function fillResourceDataTransfers(accessor: ServicesAccessor, resources: // Text: allows to paste into text-capable areas const lineDelimiter = isWindows ? '\r\n' : '\n'; - event.dataTransfer.setData(DataTransfers.TEXT, sources.map(source => source.resource.scheme === 'file' ? getPathLabel(source.resource) : source.resource.toString()).join(lineDelimiter)); + event.dataTransfer.setData(DataTransfers.TEXT, sources.map(source => source.resource.scheme === Schemas.file ? getPathLabel(source.resource) : source.resource.toString()).join(lineDelimiter)); // Download URL: enables support to drag a tab as file to desktop (only single file supported, not directories) - if (sources.length === 1 && firstSource.resource.scheme === 'file' && !firstSource.isDirectory) { + if (sources.length === 1 && firstSource.resource.scheme === Schemas.file && !firstSource.isDirectory) { event.dataTransfer.setData(DataTransfers.DOWNLOAD_URL, [MIME_BINARY, basename(firstSource.resource.fsPath), firstSource.resource.toString()].join(':')); } diff --git a/src/vs/workbench/browser/parts/editor/editorStatus.ts b/src/vs/workbench/browser/parts/editor/editorStatus.ts index 34eb19499a0..94103617f9b 100644 --- a/src/vs/workbench/browser/parts/editor/editorStatus.ts +++ b/src/vs/workbench/browser/parts/editor/editorStatus.ts @@ -59,6 +59,7 @@ import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; // TODO@Sandeep layer breaker // tslint:disable-next-line:import-patterns import { IPreferencesService } from 'vs/workbench/parts/preferences/common/preferences'; +import { Schemas } from 'vs/base/common/network'; function toEditorWithEncodingSupport(input: IEditorInput): IEncodingSupport { if (input instanceof SideBySideEditorInput) { @@ -814,7 +815,7 @@ export class ChangeModeAction extends Action { const resource = toResource(activeEditor.input, { supportSideBySide: true }); let hasLanguageSupport = !!resource; - if (resource.scheme === 'untitled' && !this.untitledEditorService.hasAssociatedFilePath(resource)) { + if (resource.scheme === Schemas.untitled && !this.untitledEditorService.hasAssociatedFilePath(resource)) { hasLanguageSupport = false; // no configuration for untitled resources (e.g. "Untitled-1") } diff --git a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts index 0dbb76d454d..0ef84d14de7 100644 --- a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts +++ b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts @@ -56,6 +56,7 @@ import { getBaseLabel } from 'vs/base/common/labels'; import { WorkbenchTree } from 'vs/platform/list/browser/listService'; import { matchesFuzzyOcticonAware, parseOcticons, IParsedOcticons } from 'vs/base/common/octicon'; import { IMatch } from 'vs/base/common/filters'; +import { Schemas } from 'vs/base/common/network'; const HELP_PREFIX = '?'; @@ -1353,7 +1354,7 @@ function resourceForEditorHistory(input: EditorInput, fileService: IFileService) // For the editor history we only prefer resources that are either untitled or // can be handled by the file service which indicates they are editable resources. - if (resource && (fileService.canHandleResource(resource) || resource.scheme === 'untitled')) { + if (resource && (fileService.canHandleResource(resource) || resource.scheme === Schemas.untitled)) { return resource; } diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index b50dfa83473..e3fca67780a 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -16,6 +16,7 @@ import { IInstantiationService, IConstructorSignature0 } from 'vs/platform/insta import { RawContextKey } from 'vs/platform/contextkey/common/contextkey'; import { Registry } from 'vs/platform/registry/common/platform'; import { ITextModel } from 'vs/editor/common/model'; +import { Schemas } from 'vs/base/common/network'; export const TextCompareEditorVisible = new RawContextKey('textCompareEditorVisible', false); @@ -862,7 +863,7 @@ export const EditorCommands = { export interface IResourceOptions { supportSideBySide?: boolean; - filter?: 'file' | 'untitled' | ['file', 'untitled'] | ['untitled', 'file']; + filter?: string | string[]; } export function toResource(editor: IEditorInput, options?: IResourceOptions): URI { @@ -887,18 +888,18 @@ export function toResource(editor: IEditorInput, options?: IResourceOptions): UR let includeFiles: boolean; let includeUntitled: boolean; if (Array.isArray(options.filter)) { - includeFiles = (options.filter.indexOf('file') >= 0); - includeUntitled = (options.filter.indexOf('untitled') >= 0); + includeFiles = (options.filter.indexOf(Schemas.file) >= 0); + includeUntitled = (options.filter.indexOf(Schemas.untitled) >= 0); } else { - includeFiles = (options.filter === 'file'); - includeUntitled = (options.filter === 'untitled'); + includeFiles = (options.filter === Schemas.file); + includeUntitled = (options.filter === Schemas.untitled); } - if (includeFiles && resource.scheme === 'file') { + if (includeFiles && resource.scheme === Schemas.file) { return resource; } - if (includeUntitled && resource.scheme === 'untitled') { + if (includeUntitled && resource.scheme === Schemas.untitled) { return resource; } diff --git a/src/vs/workbench/parts/backup/common/backupRestorer.ts b/src/vs/workbench/parts/backup/common/backupRestorer.ts index 6e1d90e3e7e..073d35d4a7d 100644 --- a/src/vs/workbench/parts/backup/common/backupRestorer.ts +++ b/src/vs/workbench/parts/backup/common/backupRestorer.ts @@ -7,7 +7,7 @@ import URI from 'vs/base/common/uri'; import { TPromise } from 'vs/base/common/winjs.base'; -import { IUntitledEditorService, UNTITLED_SCHEMA } from 'vs/workbench/services/untitled/common/untitledEditorService'; +import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService'; import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; import errors = require('vs/base/common/errors'); import { IBackupFileService } from 'vs/workbench/services/backup/common/backup'; @@ -69,7 +69,7 @@ export class BackupRestorer implements IWorkbenchContribution { if (stacks.isOpen(backup)) { if (backup.scheme === Schemas.file) { restorePromises.push(this.textFileService.models.loadOrCreate(backup).then(null, () => unresolved.push(backup))); - } else if (backup.scheme === UNTITLED_SCHEMA) { + } else if (backup.scheme === Schemas.untitled) { restorePromises.push(this.untitledEditorService.loadOrCreate({ resource: backup }).then(null, () => unresolved.push(backup))); } } else { @@ -92,7 +92,7 @@ export class BackupRestorer implements IWorkbenchContribution { private resolveInput(resource: URI, index: number, hasOpenedEditors: boolean): IResourceInput | IUntitledResourceInput { const options = { pinned: true, preserveFocus: true, inactive: index > 0 || hasOpenedEditors }; - if (resource.scheme === UNTITLED_SCHEMA && !BackupRestorer.UNTITLED_REGEX.test(resource.fsPath)) { + if (resource.scheme === Schemas.untitled && !BackupRestorer.UNTITLED_REGEX.test(resource.fsPath)) { return { filePath: resource.fsPath, options }; } diff --git a/src/vs/workbench/parts/files/common/explorerModel.ts b/src/vs/workbench/parts/files/common/explorerModel.ts index 621a89dba03..60168c40f3b 100644 --- a/src/vs/workbench/parts/files/common/explorerModel.ts +++ b/src/vs/workbench/parts/files/common/explorerModel.ts @@ -16,6 +16,7 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace import { IEditorGroup, toResource, IEditorIdentifier } from 'vs/workbench/common/editor'; import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { getPathLabel } from 'vs/base/common/labels'; +import { Schemas } from 'vs/base/common/network'; export class Model { @@ -397,7 +398,7 @@ export class OpenEditor implements IEditorIdentifier { } public isUntitled(): boolean { - return !!toResource(this.editor, { supportSideBySide: true, filter: 'untitled' }); + return !!toResource(this.editor, { supportSideBySide: true, filter: Schemas.untitled }); } public isDirty(): boolean { diff --git a/src/vs/workbench/parts/files/electron-browser/fileActions.contribution.ts b/src/vs/workbench/parts/files/electron-browser/fileActions.contribution.ts index fe2d75be9bd..f1b3a6d358c 100644 --- a/src/vs/workbench/parts/files/electron-browser/fileActions.contribution.ts +++ b/src/vs/workbench/parts/files/electron-browser/fileActions.contribution.ts @@ -24,6 +24,7 @@ import { AutoSaveContext } from 'vs/workbench/services/textfile/common/textfiles import { ResourceContextKey } from 'vs/workbench/common/resources'; import { WorkbenchListDoubleSelection } from 'vs/platform/list/browser/listService'; import URI from 'vs/base/common/uri'; +import { Schemas } from 'vs/base/common/network'; // Contribute Global Actions const category = nls.localize('filesCategory', "File"); @@ -228,7 +229,7 @@ MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, { id: SAVE_FILE_AS_COMMAND_ID, title: SAVE_FILE_AS_LABEL }, - when: ResourceContextKey.Scheme.isEqualTo('untitled') + when: ResourceContextKey.Scheme.isEqualTo(Schemas.untitled) }); MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, { diff --git a/src/vs/workbench/parts/files/electron-browser/fileCommands.ts b/src/vs/workbench/parts/files/electron-browser/fileCommands.ts index ee8f3d96a5e..df9b91cf387 100644 --- a/src/vs/workbench/parts/files/electron-browser/fileCommands.ts +++ b/src/vs/workbench/parts/files/electron-browser/fileCommands.ts @@ -42,6 +42,7 @@ import { sequence } from 'vs/base/common/async'; import { getResourceForCommand, getMultiSelectedResources } from 'vs/workbench/parts/files/browser/files'; import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing'; import { getMultiSelectedEditorContexts } from 'vs/workbench/browser/parts/editor/editorCommands'; +import { Schemas } from 'vs/base/common/network'; // Commands @@ -84,12 +85,12 @@ export const openWindowCommand = (accessor: ServicesAccessor, paths: string[], f function save(resource: URI, isSaveAs: boolean, editorService: IWorkbenchEditorService, fileService: IFileService, untitledEditorService: IUntitledEditorService, textFileService: ITextFileService, editorGroupService: IEditorGroupService): TPromise { - if (resource && (fileService.canHandleResource(resource) || resource.scheme === 'untitled')) { + if (resource && (fileService.canHandleResource(resource) || resource.scheme === Schemas.untitled)) { // Save As (or Save untitled with associated path) - if (isSaveAs || resource.scheme === 'untitled') { + if (isSaveAs || resource.scheme === Schemas.untitled) { let encodingOfSource: string; - if (resource.scheme === 'untitled') { + if (resource.scheme === Schemas.untitled) { encodingOfSource = untitledEditorService.getEncoding(resource); } else if (resource.scheme === 'file') { const textModel = textFileService.models.get(resource); @@ -101,14 +102,14 @@ function save(resource: URI, isSaveAs: boolean, editorService: IWorkbenchEditorS const editor = getCodeEditor(activeEditor); if (editor) { const activeResource = toResource(activeEditor.input, { supportSideBySide: true }); - if (activeResource && (fileService.canHandleResource(activeResource) || resource.scheme === 'untitled') && activeResource.toString() === resource.toString()) { + if (activeResource && (fileService.canHandleResource(activeResource) || resource.scheme === Schemas.untitled) && activeResource.toString() === resource.toString()) { viewStateOfSource = editor.saveViewState(); } } // Special case: an untitled file with associated path gets saved directly unless "saveAs" is true let savePromise: TPromise; - if (!isSaveAs && resource.scheme === 'untitled' && untitledEditorService.hasAssociatedFilePath(resource)) { + if (!isSaveAs && resource.scheme === Schemas.untitled && untitledEditorService.hasAssociatedFilePath(resource)) { savePromise = textFileService.save(resource).then((result) => { if (result) { return URI.file(resource.fsPath); @@ -199,7 +200,7 @@ function saveAll(saveAllArguments: any, editorService: IWorkbenchEditorService, const untitledToReopen: { input: IResourceInput, position: Position }[] = []; results.results.forEach(result => { - if (!result.success || result.source.scheme !== 'untitled') { + if (!result.success || result.source.scheme !== Schemas.untitled) { return; } @@ -246,7 +247,7 @@ CommandsRegistry.registerCommand({ const messageService = accessor.get(IMessageService); const resources = getMultiSelectedResources(resource, accessor.get(IListService), editorService); - if (resource && resource.scheme !== 'untitled') { + if (resource && resource.scheme !== Schemas.untitled) { return textFileService.revertAll(resources, { force: true }).then(null, error => { messageService.show(Severity.Error, nls.localize('genericRevertError', "Failed to revert '{0}': {1}", basename(resource.fsPath), toErrorMessage(error, false))); }); @@ -530,7 +531,7 @@ CommandsRegistry.registerCommand({ const editorGroup = editorGroupService.getStacksModel().getGroup(context.groupId); editorGroup.getEditors().forEach(editor => { const resource = toResource(editor, { supportSideBySide: true }); - if (resource && (resource.scheme === 'untitled' || fileService.canHandleResource(resource))) { + if (resource && (resource.scheme === Schemas.untitled || fileService.canHandleResource(resource))) { saveAllArg.push(resource); } }); diff --git a/src/vs/workbench/parts/files/electron-browser/views/explorerView.ts b/src/vs/workbench/parts/files/electron-browser/views/explorerView.ts index 664c1f0f91f..4c1612cbf09 100644 --- a/src/vs/workbench/parts/files/electron-browser/views/explorerView.ts +++ b/src/vs/workbench/parts/files/electron-browser/views/explorerView.ts @@ -43,6 +43,7 @@ import { isLinux } from 'vs/base/common/platform'; import { IDecorationsService } from 'vs/workbench/services/decorations/browser/decorations'; import { WorkbenchTree } from 'vs/platform/list/browser/listService'; import { DelayedDragHandler } from 'vs/base/browser/dnd'; +import { Schemas } from 'vs/base/common/network'; export interface IExplorerViewOptions extends IViewletViewOptions { viewletState: FileViewletState; @@ -238,7 +239,7 @@ export class ExplorerView extends TreeViewsViewletPanel implements IExplorerView // Handle closed or untitled file (convince explorer to not reopen any file when getting visible) const activeInput = this.editorService.getActiveEditorInput(); - if (!activeInput || toResource(activeInput, { supportSideBySide: true, filter: 'untitled' })) { + if (!activeInput || toResource(activeInput, { supportSideBySide: true, filter: Schemas.untitled })) { this.settings[ExplorerView.MEMENTO_LAST_ACTIVE_FILE_RESOURCE] = void 0; clearFocus = true; } diff --git a/src/vs/workbench/services/backup/test/node/backupFileService.test.ts b/src/vs/workbench/services/backup/test/node/backupFileService.test.ts index 2b9552200f4..048787bcf7d 100644 --- a/src/vs/workbench/services/backup/test/node/backupFileService.test.ts +++ b/src/vs/workbench/services/backup/test/node/backupFileService.test.ts @@ -22,6 +22,7 @@ import { Workspace, toWorkspaceFolders } from 'vs/platform/workspace/common/work import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService'; import { DefaultEndOfLine } from 'vs/editor/common/model'; import { snapshotToString } from 'vs/platform/files/common/files'; +import { Schemas } from 'vs/base/common/network'; const parentDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'backupfileservice'); const backupHome = path.join(parentDir, 'Backups'); @@ -31,7 +32,7 @@ const workspaceResource = Uri.file(platform.isWindows ? 'c:\\workspace' : '/work const workspaceBackupPath = path.join(backupHome, crypto.createHash('md5').update(workspaceResource.fsPath).digest('hex')); const fooFile = Uri.file(platform.isWindows ? 'c:\\Foo' : '/Foo'); const barFile = Uri.file(platform.isWindows ? 'c:\\Bar' : '/Bar'); -const untitledFile = Uri.from({ scheme: 'untitled', path: 'Untitled-1' }); +const untitledFile = Uri.from({ scheme: Schemas.untitled, path: 'Untitled-1' }); const fooBackupPath = path.join(workspaceBackupPath, 'file', crypto.createHash('md5').update(fooFile.fsPath).digest('hex')); const barBackupPath = path.join(workspaceBackupPath, 'file', crypto.createHash('md5').update(barFile.fsPath).digest('hex')); const untitledBackupPath = path.join(workspaceBackupPath, 'untitled', crypto.createHash('md5').update(untitledFile.fsPath).digest('hex')); @@ -80,7 +81,7 @@ suite('BackupFileService', () => { test('should get the correct backup path for untitled files', () => { // Format should be: /// - const backupResource = Uri.from({ scheme: 'untitled', path: 'Untitled-1' }); + const backupResource = Uri.from({ scheme: Schemas.untitled, path: 'Untitled-1' }); const workspaceHash = crypto.createHash('md5').update(workspaceResource.fsPath).digest('hex'); const filePathHash = crypto.createHash('md5').update(backupResource.fsPath).digest('hex'); const expectedPath = Uri.file(path.join(backupHome, workspaceHash, 'untitled', filePathHash)).fsPath; diff --git a/src/vs/workbench/services/editor/common/editorService.ts b/src/vs/workbench/services/editor/common/editorService.ts index b34c179fee1..ed79b0cdc37 100644 --- a/src/vs/workbench/services/editor/common/editorService.ts +++ b/src/vs/workbench/services/editor/common/editorService.ts @@ -14,7 +14,7 @@ import { Registry } from 'vs/platform/registry/common/platform'; import { basename, dirname } from 'vs/base/common/paths'; import { EditorInput, EditorOptions, TextEditorOptions, Extensions as EditorExtensions, SideBySideEditorInput, IFileEditorInput, IFileInputFactory, IEditorInputFactoryRegistry } from 'vs/workbench/common/editor'; import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput'; -import { IUntitledEditorService, UNTITLED_SCHEMA } from 'vs/workbench/services/untitled/common/untitledEditorService'; +import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService'; import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import nls = require('vs/nls'); @@ -24,6 +24,7 @@ import { once } from 'vs/base/common/event'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { IFileService } from 'vs/platform/files/common/files'; import { DataUriEditorInput } from 'vs/workbench/common/editor/dataUriEditorInput'; +import { Schemas } from 'vs/base/common/network'; export const IWorkbenchEditorService = createDecorator('editorService'); @@ -314,7 +315,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { // Untitled file support const untitledInput = input; - if (!untitledInput.resource || typeof untitledInput.filePath === 'string' || (untitledInput.resource instanceof URI && untitledInput.resource.scheme === UNTITLED_SCHEMA)) { + if (!untitledInput.resource || typeof untitledInput.filePath === 'string' || (untitledInput.resource instanceof URI && untitledInput.resource.scheme === Schemas.untitled)) { return this.untitledEditorService.createOrGet(untitledInput.filePath ? URI.file(untitledInput.filePath) : untitledInput.resource, untitledInput.language, untitledInput.contents, untitledInput.encoding); } @@ -383,7 +384,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { const res = input.getResource(); // Do not try to extract any paths from simple untitled editors - if (res.scheme === 'untitled' && !this.untitledEditorService.hasAssociatedFilePath(res)) { + if (res.scheme === Schemas.untitled && !this.untitledEditorService.hasAssociatedFilePath(res)) { return input.getName(); } diff --git a/src/vs/workbench/services/search/node/searchService.ts b/src/vs/workbench/services/search/node/searchService.ts index 2f71778178a..89eb1d54de6 100644 --- a/src/vs/workbench/services/search/node/searchService.ts +++ b/src/vs/workbench/services/search/node/searchService.ts @@ -158,7 +158,7 @@ export class SearchService implements ISearchService { } // Support untitled files - if (resource.scheme === 'untitled') { + if (resource.scheme === Schemas.untitled) { if (!this.untitledEditorService.exists(resource)) { return; } diff --git a/src/vs/workbench/services/textfile/common/textFileService.ts b/src/vs/workbench/services/textfile/common/textFileService.ts index 42f1d466370..4ea770bb452 100644 --- a/src/vs/workbench/services/textfile/common/textFileService.ts +++ b/src/vs/workbench/services/textfile/common/textFileService.ts @@ -22,7 +22,7 @@ import { IFileService, IResolveContentOptions, IFilesConfiguration, FileOperatio import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; -import { IUntitledEditorService, UNTITLED_SCHEMA } from 'vs/workbench/services/untitled/common/untitledEditorService'; +import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService'; import { UntitledEditorModel } from 'vs/workbench/common/editor/untitledEditorModel'; import { TextFileEditorModelManager } from 'vs/workbench/services/textfile/common/textFileEditorModelManager'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; @@ -233,7 +233,7 @@ export abstract class TextFileService implements ITextFileService { dirtyToBackup.forEach(s => { if (s.scheme === Schemas.file) { filesToBackup.push(textFileEditorModelManager.get(s)); - } else if (s.scheme === UNTITLED_SCHEMA) { + } else if (s.scheme === Schemas.untitled) { untitledToBackup.push(s); } }); @@ -416,7 +416,7 @@ export abstract class TextFileService implements ITextFileService { const filesToSave: URI[] = []; const untitledToSave: URI[] = []; toSave.forEach(s => { - if ((Array.isArray(arg1) || arg1 === true /* includeUntitled */) && s.scheme === UNTITLED_SCHEMA) { + if ((Array.isArray(arg1) || arg1 === true /* includeUntitled */) && s.scheme === Schemas.untitled) { untitledToSave.push(s); } else { filesToSave.push(s); @@ -540,7 +540,7 @@ export abstract class TextFileService implements ITextFileService { targetPromise = TPromise.wrap(target); } else { let dialogPath = resource.fsPath; - if (resource.scheme === UNTITLED_SCHEMA) { + if (resource.scheme === Schemas.untitled) { dialogPath = this.suggestFileName(resource); } @@ -574,7 +574,7 @@ export abstract class TextFileService implements ITextFileService { let modelPromise: TPromise = TPromise.as(null); if (resource.scheme === Schemas.file) { modelPromise = TPromise.as(this._models.get(resource)); - } else if (resource.scheme === UNTITLED_SCHEMA && this.untitledEditorService.exists(resource)) { + } else if (resource.scheme === Schemas.untitled && this.untitledEditorService.exists(resource)) { modelPromise = this.untitledEditorService.loadOrCreate({ resource }); } diff --git a/src/vs/workbench/services/textmodelResolver/common/textModelResolverService.ts b/src/vs/workbench/services/textmodelResolver/common/textModelResolverService.ts index 129a84d5081..7c9c4ada5f3 100644 --- a/src/vs/workbench/services/textmodelResolver/common/textModelResolverService.ts +++ b/src/vs/workbench/services/textmodelResolver/common/textModelResolverService.ts @@ -15,7 +15,7 @@ import { ResourceEditorModel } from 'vs/workbench/common/editor/resourceEditorMo import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import network = require('vs/base/common/network'); import { ITextModelService, ITextModelContentProvider, ITextEditorModel } from 'vs/editor/common/services/resolverService'; -import { IUntitledEditorService, UNTITLED_SCHEMA } from 'vs/workbench/services/untitled/common/untitledEditorService'; +import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService'; import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel'; class ResourceModelCollection extends ReferenceCollection> { @@ -119,7 +119,7 @@ export class TextModelResolverService implements ITextModelService { // Untitled Schema: go through cached input // TODO ImmortalReference is a hack - if (resource.scheme === UNTITLED_SCHEMA) { + if (resource.scheme === network.Schemas.untitled) { return this.untitledEditorService.loadOrCreate({ resource }).then(model => new ImmortalReference(model)); } diff --git a/src/vs/workbench/services/untitled/common/untitledEditorService.ts b/src/vs/workbench/services/untitled/common/untitledEditorService.ts index 6806f656748..fed40daa61a 100644 --- a/src/vs/workbench/services/untitled/common/untitledEditorService.ts +++ b/src/vs/workbench/services/untitled/common/untitledEditorService.ts @@ -18,8 +18,6 @@ import { Schemas } from 'vs/base/common/network'; export const IUntitledEditorService = createDecorator('untitledEditorService'); -export const UNTITLED_SCHEMA = 'untitled'; - export interface IModelLoadOrCreateOptions { resource?: URI; modeId?: string; @@ -204,7 +202,7 @@ export class UntitledEditorService implements IUntitledEditorService { let hasAssociatedFilePath = false; if (resource) { hasAssociatedFilePath = (resource.scheme === Schemas.file); - resource = resource.with({ scheme: UNTITLED_SCHEMA }); // ensure we have the right scheme + resource = resource.with({ scheme: Schemas.untitled }); // ensure we have the right scheme if (hasAssociatedFilePath) { this.mapResourceToAssociatedFilePath.set(resource, true); // remember for future lookups @@ -226,7 +224,7 @@ export class UntitledEditorService implements IUntitledEditorService { // Create new taking a resource URI that is not already taken let counter = this.mapResourceToInput.size + 1; do { - resource = URI.from({ scheme: UNTITLED_SCHEMA, path: `Untitled-${counter}` }); + resource = URI.from({ scheme: Schemas.untitled, path: `Untitled-${counter}` }); counter++; } while (this.mapResourceToInput.has(resource)); } diff --git a/src/vs/workbench/test/common/editor/editor.test.ts b/src/vs/workbench/test/common/editor/editor.test.ts index fecaf291d09..f1f983df23b 100644 --- a/src/vs/workbench/test/common/editor/editor.test.ts +++ b/src/vs/workbench/test/common/editor/editor.test.ts @@ -14,6 +14,7 @@ import URI from 'vs/base/common/uri'; import { IUntitledEditorService, UntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { workbenchInstantiationService } from 'vs/workbench/test/workbenchTestServices'; +import { Schemas } from 'vs/base/common/network'; class ServiceAccessor { constructor( @IUntitledEditorService public untitledEditorService: UntitledEditorService) { @@ -63,26 +64,26 @@ suite('Workbench - Editor', () => { assert.equal(toResource(untitled).toString(), untitled.getResource().toString()); assert.equal(toResource(untitled, { supportSideBySide: true }).toString(), untitled.getResource().toString()); - assert.equal(toResource(untitled, { filter: 'untitled' }).toString(), untitled.getResource().toString()); - assert.equal(toResource(untitled, { filter: ['file', 'untitled'] }).toString(), untitled.getResource().toString()); - assert.ok(!toResource(untitled, { filter: 'file' })); + assert.equal(toResource(untitled, { filter: Schemas.untitled }).toString(), untitled.getResource().toString()); + assert.equal(toResource(untitled, { filter: [Schemas.file, Schemas.untitled] }).toString(), untitled.getResource().toString()); + assert.ok(!toResource(untitled, { filter: Schemas.file })); const file = new FileEditorInput(URI.file('/some/path.txt')); assert.equal(toResource(file).toString(), file.getResource().toString()); assert.equal(toResource(file, { supportSideBySide: true }).toString(), file.getResource().toString()); - assert.equal(toResource(file, { filter: 'file' }).toString(), file.getResource().toString()); - assert.equal(toResource(file, { filter: ['file', 'untitled'] }).toString(), file.getResource().toString()); - assert.ok(!toResource(file, { filter: 'untitled' })); + assert.equal(toResource(file, { filter: Schemas.file }).toString(), file.getResource().toString()); + assert.equal(toResource(file, { filter: [Schemas.file, Schemas.untitled] }).toString(), file.getResource().toString()); + assert.ok(!toResource(file, { filter: Schemas.untitled })); const diffEditorInput = new DiffEditorInput('name', 'description', untitled, file); assert.ok(!toResource(diffEditorInput)); - assert.ok(!toResource(diffEditorInput, { filter: 'file' })); + assert.ok(!toResource(diffEditorInput, { filter: Schemas.file })); assert.ok(!toResource(diffEditorInput, { supportSideBySide: false })); assert.equal(toResource(file, { supportSideBySide: true }).toString(), file.getResource().toString()); - assert.equal(toResource(file, { supportSideBySide: true, filter: 'file' }).toString(), file.getResource().toString()); - assert.equal(toResource(file, { supportSideBySide: true, filter: ['file', 'untitled'] }).toString(), file.getResource().toString()); + assert.equal(toResource(file, { supportSideBySide: true, filter: Schemas.file }).toString(), file.getResource().toString()); + assert.equal(toResource(file, { supportSideBySide: true, filter: [Schemas.file, Schemas.untitled] }).toString(), file.getResource().toString()); }); }); \ No newline at end of file