mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-01 22:12:26 +01:00
debt - merge getResource, asFileEditorInput and asFileOrUntitledEditorInput into one helper method
This commit is contained in:
@@ -11,7 +11,7 @@ import { IconLabel, IIconLabelOptions, IIconLabelCreationOptions } from 'vs/base
|
||||
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
|
||||
import { IModeService } from 'vs/editor/common/services/modeService';
|
||||
import { IEditorInput } from 'vs/platform/editor/common/editor';
|
||||
import { getResource } from 'vs/workbench/common/editor';
|
||||
import { toResource } from 'vs/workbench/common/editor';
|
||||
import { getPathLabel } from 'vs/base/common/labels';
|
||||
import { PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry';
|
||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
@@ -146,7 +146,7 @@ export class EditorLabel extends ResourceLabel {
|
||||
|
||||
public setEditor(editor: IEditorInput, options?: IResourceLabelOptions): void {
|
||||
this.setLabel({
|
||||
resource: getResource(editor),
|
||||
resource: toResource(editor, { supportSideBySide: true }),
|
||||
name: editor.getName(),
|
||||
description: editor.getDescription()
|
||||
}, options);
|
||||
|
||||
@@ -9,7 +9,7 @@ import nls = require('vs/nls');
|
||||
import { Action } from 'vs/base/common/actions';
|
||||
import { mixin } from 'vs/base/common/objects';
|
||||
import { getCodeEditor } from 'vs/editor/common/services/codeEditorService';
|
||||
import { EditorInput, getUntitledOrFileResource, TextEditorOptions, EditorOptions, IEditorIdentifier, IEditorContext, ActiveEditorMoveArguments, ActiveEditorMovePositioning, EditorCommands, ConfirmResult } from 'vs/workbench/common/editor';
|
||||
import { EditorInput, hasResource, TextEditorOptions, EditorOptions, IEditorIdentifier, IEditorContext, ActiveEditorMoveArguments, ActiveEditorMovePositioning, EditorCommands, ConfirmResult } from 'vs/workbench/common/editor';
|
||||
import { QuickOpenEntryGroup } from 'vs/base/parts/quickopen/browser/quickOpenModel';
|
||||
import { EditorQuickOpenEntry, EditorQuickOpenEntryGroup, IEditorQuickOpenEntry, QuickOpenAction } from 'vs/workbench/browser/quickopen';
|
||||
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
@@ -195,7 +195,7 @@ export class FocusFirstGroupAction extends Action {
|
||||
|
||||
// For now only support to open files from history to the side
|
||||
if (input instanceof EditorInput) {
|
||||
if (!!getUntitledOrFileResource(input)) {
|
||||
if (hasResource(input, { filter: ['file', 'untitled'] })) {
|
||||
return this.editorService.openEditor(input, null, Position.ONE);
|
||||
}
|
||||
} else {
|
||||
@@ -268,7 +268,7 @@ export abstract class BaseFocusSideGroupAction extends Action {
|
||||
|
||||
// For now only support to open files from history to the side
|
||||
if (input instanceof EditorInput) {
|
||||
if (!!getUntitledOrFileResource(input)) {
|
||||
if (hasResource(input, { filter: ['file', 'untitled'] })) {
|
||||
return this.editorService.openEditor(input, { pinned: true }, this.getTargetEditorSide());
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -24,7 +24,7 @@ import { IEditorGroupService } from 'vs/workbench/services/group/common/groupSer
|
||||
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
import { EditorInput, asFileEditorInput, IEditorGroup, IEditorStacksModel } from 'vs/workbench/common/editor';
|
||||
import { EditorInput, toResource, IEditorGroup, IEditorStacksModel } from 'vs/workbench/common/editor';
|
||||
|
||||
export class EditorPickerEntry extends QuickOpenEntryGroup {
|
||||
private stacks: IEditorStacksModel;
|
||||
@@ -62,9 +62,7 @@ export class EditorPickerEntry extends QuickOpenEntryGroup {
|
||||
}
|
||||
|
||||
public getResource(): URI {
|
||||
const fileInput = asFileEditorInput(this.editor, true);
|
||||
|
||||
return fileInput && fileInput.getResource();
|
||||
return toResource(this.editor, { supportSideBySide: true, filter: 'file' });
|
||||
}
|
||||
|
||||
public getAriaLabel(): string {
|
||||
|
||||
@@ -19,7 +19,7 @@ import { Action } from 'vs/base/common/actions';
|
||||
import { language, LANGUAGE_DEFAULT } from 'vs/base/common/platform';
|
||||
import { IMode } from 'vs/editor/common/modes';
|
||||
import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput';
|
||||
import { IFileEditorInput, EncodingMode, IEncodingSupport, asFileEditorInput, getUntitledOrFileResource } from 'vs/workbench/common/editor';
|
||||
import { IFileEditorInput, EncodingMode, IEncodingSupport, toResource, SideBySideEditorInput } from 'vs/workbench/common/editor';
|
||||
import { IDisposable, combinedDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { IMessageService, Severity } from 'vs/platform/message/common/message';
|
||||
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
|
||||
@@ -30,7 +30,7 @@ import { TrimTrailingWhitespaceAction } from 'vs/editor/contrib/linesOperations/
|
||||
import { IndentUsingSpaces, IndentUsingTabs, DetectIndentation, IndentationToSpacesAction, IndentationToTabsAction } from 'vs/workbench/parts/indentation/common/indentation';
|
||||
import { BaseBinaryResourceEditor } from 'vs/workbench/browser/parts/editor/binaryEditor';
|
||||
import { BinaryResourceDiffEditor } from 'vs/workbench/browser/parts/editor/binaryDiffEditor';
|
||||
import { IEditor as IBaseEditor } from 'vs/platform/editor/common/editor';
|
||||
import { IEditor as IBaseEditor, IEditorInput } from 'vs/platform/editor/common/editor';
|
||||
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IQuickOpenService, IPickOpenEntry, IFilePickOpenEntry } from 'vs/platform/quickOpen/common/quickOpen';
|
||||
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
|
||||
@@ -68,12 +68,21 @@ function getTextModel(editorWidget: IEditor): IModel {
|
||||
return editorWidget ? <IModel>editorWidget.getModel() : null;
|
||||
}
|
||||
|
||||
function asFileOrUntitledEditorInput(input: any): UntitledEditorInput | IFileEditorInput {
|
||||
function toEditorWithEncodingSupport(input: IEditorInput): IEncodingSupport {
|
||||
if (input instanceof SideBySideEditorInput) {
|
||||
input = input.master;
|
||||
}
|
||||
|
||||
if (input instanceof UntitledEditorInput) {
|
||||
return input;
|
||||
}
|
||||
|
||||
return asFileEditorInput(input, true /* support diff editor */);
|
||||
let encodingSupport = input as IFileEditorInput;
|
||||
if (types.areFunctions(encodingSupport.setEncoding, encodingSupport.getEncoding)) {
|
||||
return encodingSupport;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
interface IEditorSelectionStatus {
|
||||
@@ -624,8 +633,8 @@ export class EditorStatus implements IStatusbarItem {
|
||||
|
||||
// We only support text based editors
|
||||
if (getEditorWidget(e)) {
|
||||
const encodingSupport: IEncodingSupport = asFileOrUntitledEditorInput(e.input);
|
||||
if (encodingSupport && types.isFunction(encodingSupport.getEncoding)) {
|
||||
const encodingSupport: IEncodingSupport = toEditorWithEncodingSupport(e.input);
|
||||
if (encodingSupport) {
|
||||
const rawEncoding = encodingSupport.getEncoding();
|
||||
const encodingInfo = SUPPORTED_ENCODINGS[rawEncoding];
|
||||
if (encodingInfo) {
|
||||
@@ -642,7 +651,7 @@ export class EditorStatus implements IStatusbarItem {
|
||||
private onResourceEncodingChange(resource: uri): void {
|
||||
const activeEditor = this.editorService.getActiveEditor();
|
||||
if (activeEditor) {
|
||||
const activeResource = getUntitledOrFileResource(activeEditor.input, true);
|
||||
const activeResource = toResource(activeEditor.input, { supportSideBySide: true, filter: ['file', 'untitled'] });
|
||||
if (activeResource && activeResource.toString() === resource.toString()) {
|
||||
return this.onEncodingChange(<IBaseEditor>activeEditor); // only update if the encoding changed for the active resource
|
||||
}
|
||||
@@ -729,7 +738,7 @@ export class ChangeModeAction extends Action {
|
||||
}
|
||||
|
||||
const textModel = getTextModel(editorWidget);
|
||||
const fileinput = asFileEditorInput(activeEditor.input, true);
|
||||
const fileResource = toResource(activeEditor.input, { supportSideBySide: true, filter: 'file' });
|
||||
|
||||
// Compute mode
|
||||
let currentModeId: string;
|
||||
@@ -769,16 +778,15 @@ export class ChangeModeAction extends Action {
|
||||
};
|
||||
});
|
||||
|
||||
if (fileinput) {
|
||||
if (fileResource) {
|
||||
picks[0].separator = { border: true, label: nls.localize('languagesPicks', "languages (identifier)") };
|
||||
}
|
||||
|
||||
// Offer action to configure via settings
|
||||
let configureModeAssociations: IPickOpenEntry;
|
||||
let galleryAction: Action;
|
||||
if (fileinput) {
|
||||
const resource = fileinput.getResource();
|
||||
const ext = paths.extname(resource.fsPath) || paths.basename(resource.fsPath);
|
||||
if (fileResource) {
|
||||
const ext = paths.extname(fileResource.fsPath) || paths.basename(fileResource.fsPath);
|
||||
|
||||
galleryAction = this.instantiationService.createInstance(ShowLanguageExtensionsAction, ext);
|
||||
if (galleryAction.enabled) {
|
||||
@@ -793,7 +801,7 @@ export class ChangeModeAction extends Action {
|
||||
const autoDetectMode: IPickOpenEntry = {
|
||||
label: nls.localize('autoDetect', "Auto Detect")
|
||||
};
|
||||
if (fileinput) {
|
||||
if (fileResource) {
|
||||
picks.unshift(autoDetectMode);
|
||||
}
|
||||
|
||||
@@ -809,7 +817,7 @@ export class ChangeModeAction extends Action {
|
||||
|
||||
// User decided to permanently configure associations, return right after
|
||||
if (pick === configureModeAssociations) {
|
||||
this.configureFileAssociation(fileinput.getResource());
|
||||
this.configureFileAssociation(fileResource);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -833,7 +841,7 @@ export class ChangeModeAction extends Action {
|
||||
// Find mode
|
||||
let mode: TPromise<IMode>;
|
||||
if (pick === autoDetectMode) {
|
||||
mode = this.modeService.getOrCreateModeByFilenameOrFirstLine(getUntitledOrFileResource(activeEditor.input, true).fsPath, textModel.getLineContent(1));
|
||||
mode = this.modeService.getOrCreateModeByFilenameOrFirstLine(toResource(activeEditor.input, { supportSideBySide: true, filter: ['file', 'untitled'] }).fsPath, textModel.getLineContent(1));
|
||||
} else {
|
||||
mode = this.modeService.getOrCreateModeByLanguageName(pick.label);
|
||||
}
|
||||
@@ -1018,8 +1026,8 @@ export class ChangeEncodingAction extends Action {
|
||||
return this.quickOpenService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]);
|
||||
}
|
||||
|
||||
let encodingSupport: IEncodingSupport = asFileOrUntitledEditorInput(activeEditor.input);
|
||||
if (!types.areFunctions(encodingSupport.setEncoding, encodingSupport.getEncoding)) {
|
||||
let encodingSupport: IEncodingSupport = toEditorWithEncodingSupport(activeEditor.input);
|
||||
if (!encodingSupport) {
|
||||
return this.quickOpenService.pick([{ label: nls.localize('noFileEditor', "No file active at this time") }]);
|
||||
}
|
||||
|
||||
@@ -1086,8 +1094,8 @@ export class ChangeEncodingAction extends Action {
|
||||
}).then(encoding => {
|
||||
if (encoding) {
|
||||
activeEditor = this.editorService.getActiveEditor();
|
||||
encodingSupport = asFileOrUntitledEditorInput(activeEditor.input);
|
||||
if (encodingSupport && types.areFunctions(encodingSupport.setEncoding, encodingSupport.getEncoding) && encodingSupport.getEncoding() !== encoding.id) {
|
||||
encodingSupport = toEditorWithEncodingSupport(activeEditor.input);
|
||||
if (encodingSupport && encodingSupport.getEncoding() !== encoding.id) {
|
||||
encodingSupport.setEncoding(encoding.id, isReopenWithEncoding ? EncodingMode.Decode : EncodingMode.Encode); // Set new encoding
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
import 'vs/css!./media/notabstitle';
|
||||
import errors = require('vs/base/common/errors');
|
||||
import { IEditorGroup, getResource } from 'vs/workbench/common/editor';
|
||||
import { IEditorGroup, toResource } from 'vs/workbench/common/editor';
|
||||
import DOM = require('vs/base/browser/dom');
|
||||
import { TitleControl } from 'vs/workbench/browser/parts/editor/titleControl';
|
||||
import { EditorLabel } from 'vs/workbench/browser/labels';
|
||||
@@ -117,7 +117,7 @@ export class NoTabsTitleControl extends TitleControl {
|
||||
}
|
||||
|
||||
// Editor Label
|
||||
const resource = getResource(editor);
|
||||
const resource = toResource(editor, { supportSideBySide: true });
|
||||
const name = editor.getName() || '';
|
||||
const description = isActive ? (editor.getDescription() || '') : '';
|
||||
let verboseDescription = editor.getDescription(true) || '';
|
||||
|
||||
@@ -14,7 +14,7 @@ import { isMacintosh } from 'vs/base/common/platform';
|
||||
import { MIME_BINARY } from 'vs/base/common/mime';
|
||||
import { ActionRunner, IAction } from 'vs/base/common/actions';
|
||||
import { Position, IEditorInput } from 'vs/platform/editor/common/editor';
|
||||
import { IEditorGroup, asFileEditorInput, getResource } from 'vs/workbench/common/editor';
|
||||
import { IEditorGroup, toResource } from 'vs/workbench/common/editor';
|
||||
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
|
||||
import { KeyCode } from 'vs/base/common/keyCodes';
|
||||
import { EditorLabel } from 'vs/workbench/browser/labels';
|
||||
@@ -221,7 +221,7 @@ export class TabsTitleControl extends TitleControl {
|
||||
|
||||
// Label
|
||||
const tabLabel = this.editorLabels[index];
|
||||
tabLabel.setLabel({ name, description, resource: getResource(editor) }, { extraClasses: ['tab-label'], italic: !isPinned });
|
||||
tabLabel.setLabel({ name, description, resource: toResource(editor, { supportSideBySide: true }) }, { extraClasses: ['tab-label'], italic: !isPinned });
|
||||
|
||||
// Active state
|
||||
if (isActive) {
|
||||
@@ -529,9 +529,9 @@ export class TabsTitleControl extends TitleControl {
|
||||
e.dataTransfer.effectAllowed = 'copyMove';
|
||||
|
||||
// Insert transfer accordingly
|
||||
const fileInput = asFileEditorInput(editor, true);
|
||||
if (fileInput) {
|
||||
const resource = fileInput.getResource().toString();
|
||||
const fileResource = toResource(editor, { supportSideBySide: true, filter: 'file' });
|
||||
if (fileResource) {
|
||||
const resource = fileResource.toString();
|
||||
e.dataTransfer.setData('URL', resource); // enables cross window DND of tabs
|
||||
e.dataTransfer.setData('DownloadURL', [MIME_BINARY, editor.getName(), resource].join(':')); // enables support to drag a tab as file to desktop
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import { BaseEditor, IEditorInputActionContext } from 'vs/workbench/browser/part
|
||||
import { RunOnceScheduler } from 'vs/base/common/async';
|
||||
import { isCommonCodeEditor, isCommonDiffEditor } from 'vs/editor/common/editorCommon';
|
||||
import arrays = require('vs/base/common/arrays');
|
||||
import { IEditorStacksModel, IEditorGroup, IEditorIdentifier, EditorInput, IWorkbenchEditorConfiguration, IStacksModelChangeEvent, getResource } from 'vs/workbench/common/editor';
|
||||
import { IEditorStacksModel, IEditorGroup, IEditorIdentifier, EditorInput, IWorkbenchEditorConfiguration, IStacksModelChangeEvent, toResource } from 'vs/workbench/common/editor';
|
||||
import { EventType as BaseEventType } from 'vs/base/common/events';
|
||||
import { IActionItem, ActionsOrientation, Separator } from 'vs/base/browser/ui/actionbar/actionbar';
|
||||
import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
|
||||
@@ -301,7 +301,7 @@ export abstract class TitleControl implements ITitleAreaControl {
|
||||
const position = this.stacks.positionOfGroup(group);
|
||||
|
||||
// Update the resource context
|
||||
this.resourceContext.set(group && getResource(group.activeEditor));
|
||||
this.resourceContext.set(group && toResource(group.activeEditor, { supportSideBySide: true }));
|
||||
|
||||
// Editor actions require the editor control to be there, so we retrieve it via service
|
||||
const control = this.editorService.getVisibleEditors()[position];
|
||||
@@ -427,7 +427,7 @@ export abstract class TitleControl implements ITitleAreaControl {
|
||||
|
||||
// Update the resource context
|
||||
const currentContext = this.resourceContext.get();
|
||||
this.resourceContext.set(identifier.editor && getResource(identifier.editor));
|
||||
this.resourceContext.set(toResource(identifier.editor, { supportSideBySide: true }));
|
||||
|
||||
// Find target anchor
|
||||
let anchor: HTMLElement | { x: number, y: number } = node;
|
||||
|
||||
@@ -31,7 +31,7 @@ import { IResourceInput, IEditorInput } from 'vs/platform/editor/common/editor';
|
||||
import { IModeService } from 'vs/editor/common/services/modeService';
|
||||
import { getIconClasses } from 'vs/workbench/browser/labels';
|
||||
import { IModelService } from 'vs/editor/common/services/modelService';
|
||||
import { EditorInput, getUntitledOrFileResource, IWorkbenchEditorConfiguration } from 'vs/workbench/common/editor';
|
||||
import { EditorInput, toResource, IWorkbenchEditorConfiguration } from 'vs/workbench/common/editor';
|
||||
import { WorkbenchComponent } from 'vs/workbench/common/component';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { IPartService } from 'vs/workbench/services/part/common/partService';
|
||||
@@ -782,7 +782,7 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
|
||||
history.forEach(input => {
|
||||
let resource: URI;
|
||||
if (input instanceof EditorInput) {
|
||||
resource = getUntitledOrFileResource(input);
|
||||
resource = toResource(input, { filter: ['file', 'untitled'] });
|
||||
} else {
|
||||
resource = (input as IResourceInput).resource;
|
||||
}
|
||||
@@ -1088,7 +1088,7 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry {
|
||||
this.input = input;
|
||||
|
||||
if (input instanceof EditorInput) {
|
||||
this.resource = getUntitledOrFileResource(input);
|
||||
this.resource = toResource(input, { filter: ['file', 'untitled'] });
|
||||
this.label = input.getName();
|
||||
this.description = input.getDescription();
|
||||
this.dirty = input.isDirty();
|
||||
|
||||
Reference in New Issue
Block a user