提交 adf06c52 编写于 作者: B Benjamin Pasero

Allow to use editor options interface without creating EditorOptions instance (fixes #6604)

上级 d84775cd
......@@ -12,7 +12,6 @@ import labels = require('vs/base/common/labels');
import {Registry} from 'vs/platform/platform';
import {Action} from 'vs/base/common/actions';
import strings = require('vs/base/common/strings');
import {EditorOptions} from 'vs/workbench/common/editor';
import {IWorkbenchActionRegistry, Extensions} from 'vs/workbench/common/actionRegistry';
import {StringEditorInput} from 'vs/workbench/common/editor/stringEditorInput';
import {getDefaultValuesContent} from 'vs/platform/configuration/common/model';
......@@ -140,7 +139,7 @@ export class OpenGlobalSettingsAction extends BaseOpenSettingsAction {
let editorCount = this.editorService.getVisibleEditors().length;
return this.editorService.createInput({ resource: this.contextService.toResource('.vscode/settings.json') }).then((typedInput) => {
return this.editorService.openEditor(typedInput, EditorOptions.create({ pinned: true }), editorCount === 2 ? Position.RIGHT : editorCount === 1 ? Position.CENTER : void 0);
return this.editorService.openEditor(typedInput, { pinned: true }, editorCount === 2 ? Position.RIGHT : editorCount === 1 ? Position.CENTER : void 0);
});
})
]
......
......@@ -236,7 +236,7 @@ export abstract class BaseFocusSideGroupAction extends Action {
// For now only support to open files from history to the side
if (!!getUntitledOrFileResource(input)) {
return this.editorService.openEditor(input, EditorOptions.create({ pinned: true }), this.getTargetEditorSide());
return this.editorService.openEditor(input, { pinned: true }, this.getTargetEditorSide());
}
}
}
......@@ -909,7 +909,7 @@ export class ReopenClosedEditorAction extends Action {
}
if (lastClosedEditor) {
this.editorService.openEditor(lastClosedEditor, EditorOptions.create({ pinned: true }));
this.editorService.openEditor(lastClosedEditor, { pinned: true });
}
return TPromise.as(false);
......
......@@ -33,7 +33,7 @@ import {IDisposable, dispose} from 'vs/base/common/lifecycle';
import {TabsTitleControl} from 'vs/workbench/browser/parts/editor/tabsTitleControl';
import {TitleControl} from 'vs/workbench/browser/parts/editor/titleControl';
import {NoTabsTitleControl} from 'vs/workbench/browser/parts/editor/noTabsTitleControl';
import {IEditorStacksModel, IStacksModelChangeEvent, IWorkbenchEditorConfiguration, EditorOptions} from 'vs/workbench/common/editor';
import {IEditorStacksModel, IStacksModelChangeEvent, IWorkbenchEditorConfiguration} from 'vs/workbench/common/editor';
import {ITitleAreaControl} from 'vs/workbench/browser/parts/editor/titleControl';
import {extractResources} from 'vs/base/browser/dnd';
......@@ -804,7 +804,6 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
const splitEditor = (typeof splitTo === 'number'); // TODO@Ben ugly split code should benefit from empty group support once available!
const freeGroup = (stacks.groups.length === 1) ? Position.CENTER : Position.RIGHT;
const pinned = EditorOptions.create({ pinned: true });
// Check for transfer from title control
const draggedEditor = TitleControl.getDraggedEditor();
......@@ -814,13 +813,13 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
// Copy editor to new location
if (isCopy) {
if (splitEditor) {
editorService.openEditor(draggedEditor.editor, pinned, freeGroup).then(() => {
editorService.openEditor(draggedEditor.editor, { pinned: true }, freeGroup).then(() => {
if (splitTo !== freeGroup) {
groupService.moveGroup(freeGroup, splitTo);
}
}).done(null, errors.onUnexpectedError);
} else {
editorService.openEditor(draggedEditor.editor, pinned, position).done(null, errors.onUnexpectedError);
editorService.openEditor(draggedEditor.editor, { pinned: true }, position).done(null, errors.onUnexpectedError);
}
}
......@@ -831,7 +830,7 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
if (draggedEditor.group.count === 1) {
groupService.moveGroup(sourcePosition, splitTo);
} else {
editorService.openEditor(draggedEditor.editor, pinned, freeGroup).then(() => {
editorService.openEditor(draggedEditor.editor, { pinned: true }, freeGroup).then(() => {
if (splitTo !== freeGroup) {
groupService.moveGroup(freeGroup, splitTo);
}
......
......@@ -15,7 +15,7 @@ import DOM = require('vs/base/browser/dom');
import {isMacintosh} from 'vs/base/common/platform';
import {MIME_BINARY} from 'vs/base/common/mime';
import {Position} from 'vs/platform/editor/common/editor';
import {IEditorGroup, IEditorIdentifier, asFileEditorInput, EditorOptions} from 'vs/workbench/common/editor';
import {IEditorGroup, IEditorIdentifier, asFileEditorInput} from 'vs/workbench/common/editor';
import {ToolBar} from 'vs/base/browser/ui/toolbar/toolbar';
import {StandardKeyboardEvent} from 'vs/base/browser/keyboardEvent';
import {CommonKeybindings as Kb, KeyCode} from 'vs/base/common/keyCodes';
......@@ -97,7 +97,7 @@ export class TabsTitleControl extends TitleControl {
if (target instanceof HTMLElement && target.className.indexOf('tabs-container') === 0) {
DOM.EventHelper.stop(e);
return this.editorService.openEditor(this.untitledEditorService.createOrGet(), EditorOptions.create({ pinned: true })); // untitled are always pinned
return this.editorService.openEditor(this.untitledEditorService.createOrGet(), { pinned: true }); // untitled are always pinned
}
}));
......@@ -165,7 +165,7 @@ export class TabsTitleControl extends TitleControl {
// Copy: just open editor at target index
else {
this.editorService.openEditor(draggedEditor.editor, EditorOptions.create({ pinned: true, index: targetIndex }), targetPosition).done(null, errors.onUnexpectedError);
this.editorService.openEditor(draggedEditor.editor, { pinned: true, index: targetIndex }, targetPosition).done(null, errors.onUnexpectedError);
}
this.onEditorDragEnd();
......@@ -433,7 +433,7 @@ export class TabsTitleControl extends TitleControl {
const target = group.getEditor(targetIndex);
if (target) {
handled = true;
this.editorService.openEditor(target, EditorOptions.create({ preserveFocus: true }), position).done(null, errors.onUnexpectedError);
this.editorService.openEditor(target, { preserveFocus: true }, position).done(null, errors.onUnexpectedError);
(<HTMLElement>this.tabsContainer.childNodes[targetIndex]).focus();
}
}
......@@ -508,7 +508,7 @@ export class TabsTitleControl extends TitleControl {
// Copy: just open editor at target index
else {
this.editorService.openEditor(draggedEditor.editor, EditorOptions.create({ pinned: true, index: targetIndex }), targetPosition).done(null, errors.onUnexpectedError);
this.editorService.openEditor(draggedEditor.editor, { pinned: true, index: targetIndex }, targetPosition).done(null, errors.onUnexpectedError);
}
this.onEditorDragEnd();
......
......@@ -22,7 +22,7 @@ import {ITree, IElementCallback} from 'vs/base/parts/tree/browser/tree';
import labels = require('vs/base/common/labels');
import paths = require('vs/base/common/paths');
import {Registry} from 'vs/platform/platform';
import {EditorInput, EditorOptions, getUntitledOrFileResource, IWorkbenchEditorConfiguration} from 'vs/workbench/common/editor';
import {EditorInput, getUntitledOrFileResource, IWorkbenchEditorConfiguration} from 'vs/workbench/common/editor';
import {WorkbenchComponent} from 'vs/workbench/common/component';
import Event, {Emitter} from 'vs/base/common/event';
import {Identifiers} from 'vs/workbench/common/constants';
......@@ -1025,7 +1025,7 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry {
const sideBySide = !context.quickNavigateConfiguration && context.keymods.indexOf(KeyMod.CtrlCmd) >= 0;
const pinned = !this.configurationService.getConfiguration<IWorkbenchEditorConfiguration>().workbench.editor.enablePreviewFromQuickOpen;
this.editorService.openEditor(this.input, EditorOptions.create({ pinned }), sideBySide).done(null, errors.onUnexpectedError);
this.editorService.openEditor(this.input, { pinned }, sideBySide).done(null, errors.onUnexpectedError);
return true;
}
......
......@@ -9,8 +9,8 @@ import {EventEmitter} from 'vs/base/common/eventEmitter';
import Event, {Emitter} from 'vs/base/common/event';
import types = require('vs/base/common/types');
import URI from 'vs/base/common/uri';
import {IEditor, IEditorViewState, IRange} from 'vs/editor/common/editorCommon';
import {IEditorInput, IEditorModel, IEditorOptions, IResourceInput, Position} from 'vs/platform/editor/common/editor';
import {IEditor, IEditorViewState} from 'vs/editor/common/editorCommon';
import {IEditorInput, IEditorModel, IEditorOptions, IEditorOptionsBag, ITextEditorOptions, IResourceInput, Position} from 'vs/platform/editor/common/editor';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {Event as BaseEvent} from 'vs/base/common/events';
import {IEditorGroupService} from 'vs/workbench/services/group/common/groupService';
......@@ -332,13 +332,7 @@ export class EditorOptions implements IEditorOptions {
/**
* Helper to create EditorOptions inline.
*/
public static create(settings: {
preserveFocus?: boolean;
forceOpen?: boolean;
pinned?: boolean,
index?: number,
inactive?: boolean
}): EditorOptions {
public static create(settings: IEditorOptionsBag): EditorOptions {
let options = new EditorOptions();
options.preserveFocus = settings.preserveFocus;
options.forceOpen = settings.forceOpen;
......@@ -439,13 +433,7 @@ export class TextEditorOptions extends EditorOptions {
/**
* Helper to create TextEditorOptions inline.
*/
public static create(settings: {
preserveFocus?: boolean;
forceOpen?: boolean;
pinned?: boolean;
index?: number;
selection?: IRange
}): TextEditorOptions {
public static create(settings: ITextEditorOptions): TextEditorOptions {
let options = new TextEditorOptions();
options.preserveFocus = settings.preserveFocus;
options.forceOpen = settings.forceOpen;
......
......@@ -854,7 +854,7 @@ export class DebugService implements debug.IDebugService {
this.model.sourceIsUnavailable(source);
const editorInput = this.getDebugStringEditorInput(source, nls.localize('debugSourceNotAvailable', "Source {0} is not available.", source.uri.fsPath), 'text/plain');
return this.editorService.openEditor(editorInput, wbeditorcommon.TextEditorOptions.create({ preserveFocus: true }), sideBySide);
return this.editorService.openEditor(editorInput, { preserveFocus: true }, sideBySide);
}
public getConfigurationManager(): debug.IConfigurationManager {
......
......@@ -28,7 +28,7 @@ import {EventType as WorkbenchEventType} from 'vs/workbench/common/events';
import {LocalFileChangeEvent, VIEWLET_ID, ITextFileService, TextFileChangeEvent, EventType as FileEventType} from 'vs/workbench/parts/files/common/files';
import {IFileService, IFileStat, IImportResult} from 'vs/platform/files/common/files';
import {DiffEditorInput, toDiffLabel} from 'vs/workbench/common/editor/diffEditorInput';
import {asFileEditorInput, getUntitledOrFileResource, EditorOptions, UntitledEditorInput, ConfirmResult, IEditorIdentifier} from 'vs/workbench/common/editor';
import {asFileEditorInput, getUntitledOrFileResource, UntitledEditorInput, ConfirmResult, IEditorIdentifier} from 'vs/workbench/common/editor';
import {FileEditorInput} from 'vs/workbench/parts/files/browser/editors/fileEditorInput';
import {FileStat, NewStatPlaceholder} from 'vs/workbench/parts/files/common/explorerViewModel';
import {ExplorerView} from 'vs/workbench/parts/files/browser/views/explorerView';
......@@ -566,7 +566,7 @@ export class GlobalNewUntitledFileAction extends Action {
public run(): TPromise<any> {
let input = this.untitledEditorService.createOrGet();
return this.editorService.openEditor(input, EditorOptions.create({ pinned: true })); // untitled are always pinned
return this.editorService.openEditor(input, { pinned: true }); // untitled are always pinned
}
}
......
......@@ -12,7 +12,7 @@ import URI from 'vs/base/common/uri';
import paths = require('vs/base/common/paths');
import arrays = require('vs/base/common/arrays');
import {DiffEditorInput} from 'vs/workbench/common/editor/diffEditorInput';
import {EditorInput, EditorOptions, IEditorStacksModel} from 'vs/workbench/common/editor';
import {EditorInput, IEditorStacksModel} from 'vs/workbench/common/editor';
import {Position} from 'vs/platform/editor/common/editor';
import {BaseEditor} from 'vs/workbench/browser/parts/editor/baseEditor';
import {BaseTextEditor} from 'vs/workbench/browser/parts/editor/textEditor';
......@@ -250,11 +250,7 @@ export class FileTracker implements IWorkbenchContribution {
// Binary file: always update
else if (editor.getId() === BINARY_FILE_EDITOR_ID) {
let editorOptions = new EditorOptions();
editorOptions.forceOpen = true;
editorOptions.preserveFocus = true;
this.editorService.openEditor(editor.input, editorOptions, editor.position).done(null, errors.onUnexpectedError);
this.editorService.openEditor(editor.input, { forceOpen: true, preserveFocus: true }, editor.position).done(null, errors.onUnexpectedError);
}
}
}
......@@ -316,17 +312,10 @@ export class FileTracker implements IWorkbenchContribution {
reopenFileResource = URI.file(paths.join(newResource.fsPath, inputResource.fsPath.substr(index + oldResource.fsPath.length + 1))); // update the path by changing the old path value to the new one
}
let editorInput: EditorInput;
let editorOptions = new EditorOptions();
editorOptions.preserveFocus = true;
editorOptions.pinned = group.isPinned(input);
editorOptions.index = group.indexOf(input);
// Reopen File Input
if (input instanceof FileEditorInput) {
editorInput = this.instantiationService.createInstance(FileEditorInput, reopenFileResource, mimeHint || MIME_UNKNOWN, void 0);
this.editorService.openEditor(editorInput, editorOptions, editor.position).done(null, errors.onUnexpectedError);
const editorInput = this.instantiationService.createInstance(FileEditorInput, reopenFileResource, mimeHint || MIME_UNKNOWN, void 0);
this.editorService.openEditor(editorInput, { preserveFocus: true, pinned: group.isPinned(input), index: group.indexOf(input) }, editor.position).done(null, errors.onUnexpectedError);
}
}
}
......
......@@ -16,7 +16,6 @@ import {Action, IActionRunner, IAction} from 'vs/base/common/actions';
import {prepareActions} from 'vs/workbench/browser/actionBarRegistry';
import {ITree} from 'vs/base/parts/tree/browser/tree';
import {Tree} from 'vs/base/parts/tree/browser/treeImpl';
import {EditorOptions} from 'vs/workbench/common/editor';
import {LocalFileChangeEvent, IFilesConfiguration} from 'vs/workbench/parts/files/common/files';
import {IFileStat, IResolveFileOptions, FileChangeType, FileChangesEvent, IFileChange, EventType as FileEventType, IFileService} from 'vs/platform/files/common/files';
import {FileImportedEvent, RefreshViewExplorerAction, NewFolderAction, NewFileAction} from 'vs/workbench/parts/files/browser/fileActions';
......@@ -308,7 +307,7 @@ export class ExplorerView extends CollapsibleViewletView {
}
// Otherwise open in active slot
return this.editorService.openEditor(input, keepFocus ? EditorOptions.create({ preserveFocus: true }) : void 0);
return this.editorService.openEditor(input, keepFocus ? { preserveFocus: true } : void 0);
}
private getActiveEditorInputResource(): URI {
......
......@@ -27,7 +27,7 @@ import {LocalFileChangeEvent, IFilesConfiguration, ITextFileService} from 'vs/wo
import {IFileOperationResult, FileOperationResult, IFileStat, IFileService} from 'vs/platform/files/common/files';
import {FileEditorInput} from 'vs/workbench/parts/files/browser/editors/fileEditorInput';
import {DuplicateFileAction, ImportFileAction, PasteFileAction, keybindingForAction, IEditableData, IFileViewletState} from 'vs/workbench/parts/files/browser/fileActions';
import {EditorOptions, ConfirmResult} from 'vs/workbench/common/editor';
import {ConfirmResult} from 'vs/workbench/common/editor';
import {IDataSource, ITree, IElementCallback, IAccessibilityProvider, IRenderer, ContextMenuEvent, ISorter, IFilter, IDragAndDrop, IDragAndDropData, IDragOverReaction, DRAG_OVER_ACCEPT_BUBBLE_DOWN, DRAG_OVER_ACCEPT_BUBBLE_DOWN_COPY, DRAG_OVER_ACCEPT_BUBBLE_UP, DRAG_OVER_ACCEPT_BUBBLE_UP_COPY, DRAG_OVER_REJECT} from 'vs/base/parts/tree/browser/tree';
import labels = require('vs/base/common/labels');
import {DesktopDragAndDropData, ExternalElementsDragAndDropData} from 'vs/base/parts/tree/browser/treeDnd';
......@@ -593,12 +593,10 @@ export class FileController extends DefaultController {
private openEditor(stat: FileStat, preserveFocus: boolean, sideBySide: boolean, pinned = false): void {
if (stat && !stat.isDirectory) {
let editorInput = this.instantiationService.createInstance(FileEditorInput, stat.resource, stat.mime, void 0);
let editorOptions = EditorOptions.create({ preserveFocus, pinned });
this.telemetryService.publicLog('workbenchActionExecuted', { id: 'workbench.files.openFile', from: 'explorer' });
this.editorService.openEditor(editorInput, editorOptions, sideBySide).done(null, errors.onUnexpectedError);
const editorInput = this.instantiationService.createInstance(FileEditorInput, stat.resource, stat.mime, void 0);
this.editorService.openEditor(editorInput, { preserveFocus, pinned }, sideBySide).done(null, errors.onUnexpectedError);
}
}
......
......@@ -23,7 +23,7 @@ import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IEditorGroupService} from 'vs/workbench/services/group/common/groupService';
import {IContextMenuService} from 'vs/platform/contextview/browser/contextView';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
import {EditorOptions, UntitledEditorInput, IEditorGroup, IEditorStacksModel} from 'vs/workbench/common/editor';
import {UntitledEditorInput, IEditorGroup, IEditorStacksModel} from 'vs/workbench/common/editor';
import {ITextFileService, AutoSaveMode, FileEditorInput, asFileResource} from 'vs/workbench/parts/files/common/files';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {EditorStacksModel, EditorGroup} from 'vs/workbench/common/editor/editorStacksModel';
......@@ -344,7 +344,7 @@ export class Controller extends treedefaults.DefaultController {
this.editorGroupService.pinEditor(position, element.editorInput);
}
this.editorGroupService.activateGroup(position);
this.editorService.openEditor(element.editorInput, EditorOptions.create({ preserveFocus: !pinEditor }), position)
this.editorService.openEditor(element.editorInput, { preserveFocus: !pinEditor }, position)
.done(() => this.editorGroupService.activateGroup(position), errors.onUnexpectedError);
}
}
......
......@@ -99,6 +99,10 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
// Workbench Input Support
if (input instanceof EditorInput) {
if (!(arg2 instanceof EditorOptions)) {
arg2 = EditorOptions.create(arg2);
}
return this.doOpenEditor(input, <EditorOptions>arg2, arg3);
}
......@@ -137,9 +141,14 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
public openEditors(editors: any[]): TPromise<IEditor[]> {
return TPromise.join(editors.map(editor => this.createInput(editor.input))).then(inputs => {
const typedInputs: { input: EditorInput, position: Position, options?: EditorOptions }[] = inputs.map((input, index) => {
let options = editors[index].input instanceof EditorInput ? editors[index].options : TextEditorOptions.from(editors[index].input);
if (!(options instanceof EditorOptions)) {
options = EditorOptions.create(options);
}
return {
input,
options: editors[index].input instanceof EditorInput ? editors[index].options : TextEditorOptions.from(editors[index].input),
options,
position: editors[index].position
};
});
......@@ -149,15 +158,20 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
}
public replaceEditors(editors: { toReplace: IResourceInput, replaceWith: IResourceInput }[]): TPromise<BaseEditor[]>;
public replaceEditors(editors: { toReplace: EditorInput, replaceWith: EditorInput, options?: EditorOptions }[]): TPromise<BaseEditor[]>;
public replaceEditors(editors: { toReplace: EditorInput, replaceWith: EditorInput, options?: IEditorOptions }[]): TPromise<BaseEditor[]>;
public replaceEditors(editors: any[]): TPromise<BaseEditor[]> {
return TPromise.join(editors.map(editor => this.createInput(editor.toReplace))).then(toReplaceInputs => {
return TPromise.join(editors.map(editor => this.createInput(editor.replaceWith))).then(replaceWithInputs => {
const typedReplacements: { toReplace: EditorInput, replaceWith: EditorInput, options?: EditorOptions }[] = editors.map((editor, index) => {
let options = editor.toReplace instanceof EditorInput ? editor.options : TextEditorOptions.from(editor.replaceWith);
if (!(options instanceof EditorOptions)) {
options = EditorOptions.create(options);
}
return {
toReplace: toReplaceInputs[index],
replaceWith: replaceWithInputs[index],
options: editor.toReplace instanceof EditorInput ? editor.options : TextEditorOptions.from(editor.replaceWith)
options
};
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册