From f3a9380c481f8ce218bebe9a67125523a1c42de7 Mon Sep 17 00:00:00 2001 From: isidor Date: Thu, 18 Jan 2018 16:20:28 +0100 Subject: [PATCH] reduce hacks in getMultiSelectedEditorContexts --- .../browser/parts/editor/editorCommands.ts | 12 ++++---- .../parts/files/common/explorerModel.ts | 14 +++++----- .../electron-browser/views/openEditorsView.ts | 28 +++++++++---------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/vs/workbench/browser/parts/editor/editorCommands.ts b/src/vs/workbench/browser/parts/editor/editorCommands.ts index d8c491c64e7..42d2ed951c4 100644 --- a/src/vs/workbench/browser/parts/editor/editorCommands.ts +++ b/src/vs/workbench/browser/parts/editor/editorCommands.ts @@ -13,7 +13,7 @@ import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/edi import { IEditor, Position, POSITIONS, Direction, IEditorInput } from 'vs/platform/editor/common/editor'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { TextDiffEditor } from 'vs/workbench/browser/parts/editor/textDiffEditor'; -import { EditorStacksModel } from 'vs/workbench/common/editor/editorStacksModel'; +import { EditorStacksModel, EditorGroup } from 'vs/workbench/common/editor/editorStacksModel'; import { KeyMod, KeyCode, KeyChord } from 'vs/base/common/keyCodes'; import { TPromise } from 'vs/base/common/winjs.base'; import URI from 'vs/base/common/uri'; @@ -496,21 +496,21 @@ function positionAndInput(editorGroupService: IEditorGroupService, editorService } export function getMultiSelectedEditorContexts(editorContext: IEditorIdentifier, listService: IListService): IEditorIdentifier[] { - // TODO@Isidor this method is not nice since it assumes it is working on open editors view and maps elements on top of that const list = listService.lastFocusedList; // Mapping for open editors view - const elementToContext = element => element && element.editorGroup && element.editorInput ? { group: element.editorGroup, editor: element.editorInput } : { group: element, editor: undefined }; + const isEditorIdentifier = (element: any) => 'group' in element && 'editor' in element; + const elementToContext = (element: IEditorIdentifier | EditorGroup) => element instanceof EditorGroup ? { group: element, editor: undefined } : element; if (list instanceof List && list.isDOMFocused()) { const selection = list.getSelectedElements(); const focus = list.getFocusedElements(); // Only respect selection if it contains focused element if (focus.length && selection && selection.indexOf(focus[0]) >= 0) { - return list.getSelectedElements().map(elementToContext); + return list.getSelectedElements().filter(e => e instanceof EditorGroup || isEditorIdentifier(e)).map(elementToContext); } - if (focus) { - return focus.map(elementToContext); + if (focus.length) { + return focus.filter(e => e instanceof EditorGroup || isEditorIdentifier(e)).map(elementToContext); } } diff --git a/src/vs/workbench/parts/files/common/explorerModel.ts b/src/vs/workbench/parts/files/common/explorerModel.ts index 14a2a7a7489..1b5c744e122 100644 --- a/src/vs/workbench/parts/files/common/explorerModel.ts +++ b/src/vs/workbench/parts/files/common/explorerModel.ts @@ -12,7 +12,7 @@ import { isLinux } from 'vs/base/common/platform'; import { IFileStat, isParent } from 'vs/platform/files/common/files'; import { IEditorInput } from 'vs/platform/editor/common/editor'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; -import { IEditorGroup, toResource } from 'vs/workbench/common/editor'; +import { IEditorGroup, toResource, IEditorIdentifier } from 'vs/workbench/common/editor'; import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { getPathLabel } from 'vs/base/common/labels'; @@ -369,18 +369,18 @@ export class NewStatPlaceholder extends FileStat { } } -export class OpenEditor { +export class OpenEditor implements IEditorIdentifier { - constructor(private editor: IEditorInput, private group: IEditorGroup) { + constructor(private _editor: IEditorInput, private _group: IEditorGroup) { // noop } - public get editorInput() { - return this.editor; + public get editor() { + return this._editor; } - public get editorGroup() { - return this.group; + public get group() { + return this._group; } public getId(): string { diff --git a/src/vs/workbench/parts/files/electron-browser/views/openEditorsView.ts b/src/vs/workbench/parts/files/electron-browser/views/openEditorsView.ts index fb55f5d1ce7..fa163df1bb8 100644 --- a/src/vs/workbench/parts/files/electron-browser/views/openEditorsView.ts +++ b/src/vs/workbench/parts/files/electron-browser/views/openEditorsView.ts @@ -276,8 +276,8 @@ export class OpenEditorsView extends ViewsViewletPanel { } if (event.browserEvent && event.browserEvent.button === 1 /* Middle Button */) { - const position = this.model.positionOfGroup(element.editorGroup); - this.editorService.closeEditor(position, element.editorInput).done(null, errors.onUnexpectedError); + const position = this.model.positionOfGroup(element.group); + this.editorService.closeEditor(position, element.editor).done(null, errors.onUnexpectedError); } else { this.openEditor(element, { preserveFocus: !isDoubleClick, pinned: isDoubleClick, sideBySide: event.browserEvent.altKey }); } @@ -292,12 +292,12 @@ export class OpenEditorsView extends ViewsViewletPanel { } */ this.telemetryService.publicLog('workbenchActionExecuted', { id: 'workbench.files.openFile', from: 'openEditors' }); - let position = this.model.positionOfGroup(element.editorGroup); + let position = this.model.positionOfGroup(element.group); if (options.sideBySide && position !== Position.THREE) { position++; } this.editorGroupService.activateGroup(this.model.groupAt(position)); - this.editorService.openEditor(element.editorInput, options, position) + this.editorService.openEditor(element.editor, options, position) .done(() => this.editorGroupService.activateGroup(this.model.groupAt(position)), errors.onUnexpectedError); } } @@ -308,10 +308,10 @@ export class OpenEditorsView extends ViewsViewletPanel { getAnchor: () => e.anchor, getActions: () => { const actions = []; - fillInActions(this.contributedContextMenu, { shouldForwardArgs: true, arg: element instanceof OpenEditor ? element.editorInput.getResource() : {} }, actions, this.contextMenuService); + fillInActions(this.contributedContextMenu, { shouldForwardArgs: true, arg: element instanceof OpenEditor ? element.editor.getResource() : {} }, actions, this.contextMenuService); return TPromise.as(actions); }, - getActionsContext: () => element instanceof OpenEditor ? { group: element.editorGroup, editor: element.editorInput } : { group: element } + getActionsContext: () => element instanceof OpenEditor ? { group: element.group, editor: element.editor } : { group: element } }); } @@ -482,7 +482,7 @@ class EditorGroupRenderer implements IRenderer - this.editorGroupService.moveEditor(oe.editorInput, model.positionOfGroup(oe.editorGroup), positionOfTargetGroup, { preserveFocus: true })); + this.editorGroupService.moveEditor(oe.editor, model.positionOfGroup(oe.group), positionOfTargetGroup, { preserveFocus: true })); this.editorGroupService.activateGroup(positionOfTargetGroup); } })); @@ -539,7 +539,7 @@ class OpenEditorRenderer implements IRenderer document.body.removeChild(dragImage), 0); @@ -547,7 +547,7 @@ class OpenEditorRenderer implements IRendererthis.getSelectedElements().filter(e => e instanceof OpenEditor); OpenEditorRenderer.DRAGGED_OPEN_EDITORS = dragged; - if (editorTemplate.openEditor && editorTemplate.openEditor.editorInput) { + if (editorTemplate.openEditor && editorTemplate.openEditor.editor) { // enables dropping editor resource path into text controls e.dataTransfer.setData(DataTransfers.TEXT, dragged.map(d => d.getResource()).map(resource => resource.scheme === 'file' ? getPathLabel(resource) : resource.toString()).join('\n')); @@ -574,11 +574,11 @@ class OpenEditorRenderer implements IRenderer - this.editorGroupService.moveEditor(oe.editorInput, model.positionOfGroup(oe.editorGroup), positionOfTargetGroup, { index, preserveFocus: true })); + this.editorGroupService.moveEditor(oe.editor, model.positionOfGroup(oe.group), positionOfTargetGroup, { index, preserveFocus: true })); this.editorGroupService.activateGroup(positionOfTargetGroup); } })); @@ -592,12 +592,12 @@ class OpenEditorRenderer implements IRenderer().explorer.decorations }); - templateData.actionBar.context = { group: editor.editorGroup, editor: editor.editorInput }; + templateData.actionBar.context = { group: editor.group, editor: editor.editor }; } disposeTemplate(templateData: IOpenEditorTemplateData): void { -- GitLab