提交 24c4f221 编写于 作者: B Benjamin Pasero

remote - fix more places where we assume file schema or add todos

上级 8af49e11
......@@ -204,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 === Schemas.file) {
if (root.uri.scheme === Schemas.file) { // todo@remote signal remote folders?
folders.push(root.uri.fsPath);
}
});
......
......@@ -178,9 +178,9 @@ export class ResourcesDropHandler {
}
// Add external ones to recently open list unless dropped resource is a workspace
const resourcesToAddToHistory = untitledOrFileResources.filter(d => d.isExternal && d.resource.scheme === Schemas.file).map(d => d.resource);
if (resourcesToAddToHistory.length) {
this.windowsService.addRecentlyOpened(resourcesToAddToHistory.map(resource => resource.fsPath));
const filesToAddToHistory = untitledOrFileResources.filter(d => d.isExternal && d.resource.scheme === Schemas.file).map(d => d.resource);
if (filesToAddToHistory.length) {
this.windowsService.addRecentlyOpened(filesToAddToHistory.map(resource => resource.fsPath));
}
// Open in Editor
......
......@@ -94,7 +94,7 @@ export class ResourceLabel extends IconLabel {
return; // we need the resource to compare
}
if (e.model.uri.scheme === Schemas.file && e.oldModeId === PLAINTEXT_MODE_ID) {
if (e.model.uri.scheme === Schemas.file && e.oldModeId === PLAINTEXT_MODE_ID) { // todo@remote does this apply?
return; // ignore transitions in files from no mode to specific mode because this happens each time a model is created
}
......
......@@ -41,6 +41,7 @@ import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRe
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { isMacintosh } from 'vs/base/common/platform';
import { GroupOnePicker, GroupTwoPicker, GroupThreePicker, AllEditorsPicker } from 'vs/workbench/browser/parts/editor/editorPicker';
import { Schemas } from 'vs/base/common/network';
// Register String Editor
Registry.as<IEditorRegistry>(EditorExtensions.Editors).registerEditor(
......@@ -131,7 +132,7 @@ class UntitledEditorInputFactory implements IEditorInputFactory {
return instantiationService.invokeFunction<UntitledEditorInput>(accessor => {
const deserialized: ISerializedUntitledEditorInput = JSON.parse(serializedEditorInput);
const resource = !!deserialized.resourceJSON ? URI.revive(deserialized.resourceJSON) : URI.parse(deserialized.resource);
const filePath = resource.scheme === 'file' ? resource.fsPath : void 0;
const filePath = resource.scheme === Schemas.file ? resource.fsPath : void 0;
const language = deserialized.modeId;
const encoding = deserialized.encoding;
......
......@@ -156,7 +156,7 @@ export class ResourceViewer {
private static getMime(descriptor: IResourceDescriptor): string {
let mime = descriptor.mime;
if (!mime && descriptor.resource.scheme === Schemas.file) {
if (!mime && descriptor.resource.scheme !== Schemas.data) {
const ext = paths.extname(descriptor.resource.toString());
if (ext) {
mime = mapExtToMediaMimes[ext.toLowerCase()];
......
......@@ -17,6 +17,7 @@ import { Position, IResourceInput, IUntitledResourceInput } from 'vs/platform/ed
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { Schemas } from 'vs/base/common/network';
import { ILifecycleService, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { IFileService } from 'vs/platform/files/common/files';
export class BackupRestorer implements IWorkbenchContribution {
......@@ -28,7 +29,8 @@ export class BackupRestorer implements IWorkbenchContribution {
@IBackupFileService private backupFileService: IBackupFileService,
@ITextFileService private textFileService: ITextFileService,
@IEditorGroupService private groupService: IEditorGroupService,
@ILifecycleService private lifecycleService: ILifecycleService
@ILifecycleService private lifecycleService: ILifecycleService,
@IFileService private fileService: IFileService
) {
this.restoreBackups();
}
......@@ -67,7 +69,7 @@ export class BackupRestorer implements IWorkbenchContribution {
backups.forEach(backup => {
if (stacks.isOpen(backup)) {
if (backup.scheme === Schemas.file) {
if (this.fileService.canHandleResource(backup)) {
restorePromises.push(this.textFileService.models.loadOrCreate(backup).then(null, () => unresolved.push(backup)));
} else if (backup.scheme === Schemas.untitled) {
restorePromises.push(this.untitledEditorService.loadOrCreate({ resource: backup }).then(null, () => unresolved.push(backup)));
......
......@@ -11,6 +11,7 @@ import * as resources from 'vs/base/common/resources';
import { DEBUG_SCHEME } from 'vs/workbench/parts/debug/common/debug';
import { IRange } from 'vs/editor/common/core/range';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { Schemas } from 'vs/base/common/network';
const UNKNOWN_SOURCE_LABEL = nls.localize('unknownSource', "Unknown Source");
......@@ -76,7 +77,7 @@ export class Source {
let processId: string;
switch (modelUri.scheme) {
case 'file':
case Schemas.file:
path = paths.normalize(modelUri.fsPath, true);
break;
case DEBUG_SCHEME:
......
......@@ -26,6 +26,7 @@ import { IFileService } from 'vs/platform/files/common/files';
import { IListService } from 'vs/platform/list/browser/listService';
import { getResourceForCommand } from 'vs/workbench/parts/files/browser/files';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { Schemas } from 'vs/base/common/network';
if (env.isWindows) {
registerSingleton(ITerminalService, WinTerminalService);
......@@ -111,7 +112,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
handler: (accessor) => {
const historyService = accessor.get(IHistoryService);
const terminalService = accessor.get(ITerminalService);
const root = historyService.getLastActiveWorkspaceRoot('file');
const root = historyService.getLastActiveWorkspaceRoot(Schemas.file);
if (root) {
terminalService.openTerminal(root.fsPath);
}
......@@ -135,12 +136,12 @@ MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
group: 'navigation',
order: 30,
command: openConsoleCommand,
when: ResourceContextKey.Scheme.isEqualTo('file')
when: ResourceContextKey.Scheme.isEqualTo(Schemas.file)
});
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
group: 'navigation',
order: 30,
command: openConsoleCommand,
when: ResourceContextKey.Scheme.isEqualTo('file')
when: ResourceContextKey.Scheme.isEqualTo(Schemas.file)
});
......@@ -52,6 +52,7 @@ import { ICommandService, CommandsRegistry } from 'vs/platform/commands/common/c
import { IListService, ListWidget } from 'vs/platform/list/browser/listService';
import { RawContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { distinctParents, basenameOrAuthority } from 'vs/base/common/resources';
import { Schemas } from 'vs/base/common/network';
export interface IEditableData {
action: IAction;
......@@ -1344,7 +1345,7 @@ export class ShowOpenedFileInNewWindow extends Action {
}
public run(): TPromise<any> {
const fileResource = toResource(this.editorService.getActiveEditorInput(), { supportSideBySide: true, filter: 'file' });
const fileResource = toResource(this.editorService.getActiveEditorInput(), { supportSideBySide: true, filter: Schemas.file /* todo@remote */ });
if (fileResource) {
this.windowsService.openWindow([fileResource.fsPath], { forceNewWindow: true, forceOpenWorkspaceAsFile: true });
} else {
......@@ -1449,6 +1450,7 @@ export class CompareWithClipboardAction extends Action {
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IInstantiationService private instantiationService: IInstantiationService,
@ITextModelService private textModelService: ITextModelService,
@IFileService private fileService: IFileService
) {
super(id, label);
......@@ -1456,11 +1458,10 @@ export class CompareWithClipboardAction extends Action {
}
public run(): TPromise<any> {
const resource: URI = toResource(this.editorService.getActiveEditorInput(), { supportSideBySide: true, filter: 'file' });
const provider = this.instantiationService.createInstance(ClipboardContentProvider);
if (resource) {
const resource: URI = toResource(this.editorService.getActiveEditorInput(), { supportSideBySide: true });
if (resource && (this.fileService.canHandleResource(resource) || resource.scheme === Schemas.untitled)) {
if (!this.registrationDisposal) {
const provider = this.instantiationService.createInstance(ClipboardContentProvider);
this.registrationDisposal = this.textModelService.registerTextModelContentProvider(CompareWithClipboardAction.SCHEME, provider);
}
......
......@@ -92,7 +92,7 @@ function save(resource: URI, isSaveAs: boolean, editorService: IWorkbenchEditorS
let encodingOfSource: string;
if (resource.scheme === Schemas.untitled) {
encodingOfSource = untitledEditorService.getEncoding(resource);
} else if (resource.scheme === 'file') {
} else if (fileService.canHandleResource(resource)) {
const textModel = textFileService.models.get(resource);
encodingOfSource = textModel && textModel.getEncoding(); // text model can be null e.g. if this is a binary file!
}
......@@ -319,7 +319,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
const editorService = accessor.get(IWorkbenchEditorService);
resource = getResourceForCommand(resource, accessor.get(IListService), editorService);
if (resource && resource.scheme === 'file') {
if (resource && resource.scheme === Schemas.file /* only files on disk supported for now */) {
const name = paths.basename(resource.fsPath);
const editorLabel = nls.localize('modifiedLabel', "{0} (on disk) ↔ {1}", name, name);
......
......@@ -51,6 +51,7 @@ import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/edi
import { IFileService } from 'vs/platform/files/common/files';
import { distinct } from 'vs/base/common/arrays';
import { getMultiSelectedResources } from 'vs/workbench/parts/files/browser/files';
import { Schemas } from 'vs/base/common/network';
registerSingleton(ISearchWorkbenchService, SearchWorkbenchService);
replaceContributions();
......@@ -233,7 +234,7 @@ MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
id: FIND_IN_FOLDER_ID,
title: nls.localize('findInFolder', "Find in Folder...")
},
when: ContextKeyExpr.and(ExplorerFolderContext, ResourceContextKey.Scheme.isEqualTo('file')) // todo@remote
when: ContextKeyExpr.and(ExplorerFolderContext, ResourceContextKey.Scheme.isEqualTo(Schemas.file)) // todo@remote
});
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
......
......@@ -10,7 +10,7 @@ import { createDecorator, ServiceIdentifier, IInstantiationService } from 'vs/pl
import { IEditorService, IEditor, IEditorInput, IEditorOptions, ITextEditorOptions, Position, Direction, IResourceInput, IResourceDiffInput, IResourceSideBySideInput, IUntitledResourceInput } from 'vs/platform/editor/common/editor';
import URI from 'vs/base/common/uri';
import { Registry } from 'vs/platform/registry/common/platform';
import { basename, dirname } from 'vs/base/common/paths';
import { basename } 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 } from 'vs/workbench/services/untitled/common/untitledEditorService';
......@@ -318,24 +318,10 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
return this.untitledEditorService.createOrGet(untitledInput.filePath ? URI.file(untitledInput.filePath) : untitledInput.resource, untitledInput.language, untitledInput.contents, untitledInput.encoding);
}
// Resource Editor Support
const resourceInput = <IResourceInput>input;
// Files / Data URI support
if (resourceInput.resource instanceof URI && (resourceInput.resource.scheme === Schemas.file || resourceInput.resource.scheme === Schemas.data)) {
return this.createOrGet(resourceInput.resource, this.instantiationService, resourceInput.label, resourceInput.description, resourceInput.encoding);
}
// Any other resource
else if (resourceInput.resource instanceof URI) {
const label = resourceInput.label || basename(resourceInput.resource.fsPath);
let description: string;
if (typeof resourceInput.description === 'string') {
description = resourceInput.description;
} else if (resourceInput.resource.scheme === Schemas.file) {
description = dirname(resourceInput.resource.fsPath);
}
return this.createOrGet(resourceInput.resource, this.instantiationService, label, description);
if (resourceInput.resource instanceof URI) {
return this.createOrGet(resourceInput.resource, this.instantiationService, resourceInput.label || basename(resourceInput.resource.fsPath), resourceInput.description, resourceInput.encoding);
}
return null;
......
......@@ -231,7 +231,7 @@ export abstract class TextFileService implements ITextFileService {
const filesToBackup: ITextFileEditorModel[] = [];
const untitledToBackup: URI[] = [];
dirtyToBackup.forEach(s => {
if (s.scheme === Schemas.file) {
if (this.fileService.canHandleResource(s)) {
filesToBackup.push(textFileEditorModelManager.get(s));
} else if (s.scheme === Schemas.untitled) {
untitledToBackup.push(s);
......@@ -390,7 +390,7 @@ export abstract class TextFileService implements ITextFileService {
public save(resource: URI, options?: ISaveOptions): TPromise<boolean> {
// Run a forced save if we detect the file is not dirty so that save participants can still run
if (options && options.force && resource.scheme === Schemas.file && !this.isDirty(resource)) {
if (options && options.force && this.fileService.canHandleResource(resource) && !this.isDirty(resource)) {
const model = this._models.get(resource);
if (model) {
model.save({ force: true, reason: SaveReason.EXPLICIT }).then(() => !model.isDirty());
......@@ -572,7 +572,7 @@ export abstract class TextFileService implements ITextFileService {
// Retrieve text model from provided resource if any
let modelPromise: TPromise<ITextFileEditorModel | UntitledEditorModel> = TPromise.as(null);
if (resource.scheme === Schemas.file) {
if (this.fileService.canHandleResource(resource)) {
modelPromise = TPromise.as(this._models.get(resource));
} else if (resource.scheme === Schemas.untitled && this.untitledEditorService.exists(resource)) {
modelPromise = this.untitledEditorService.loadOrCreate({ resource });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册