提交 f3a9380c 编写于 作者: I isidor

reduce hacks in getMultiSelectedEditorContexts

上级 2404eeaf
......@@ -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);
}
}
......
......@@ -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 {
......
......@@ -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<IEditorGroup, IEditorGroupTemplat
const model = this.editorGroupService.getStacksModel();
const positionOfTargetGroup = model.positionOfGroup(editorGroupTemplate.editorGroup);
OpenEditorRenderer.DRAGGED_OPEN_EDITORS.forEach(oe =>
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<OpenEditor, IOpenEditorTemplateDat
const dragImage = document.createElement('div');
e.dataTransfer.effectAllowed = 'copyMove';
dragImage.className = 'monaco-tree-drag-image';
dragImage.textContent = editorTemplate.openEditor.editorInput.getName();
dragImage.textContent = editorTemplate.openEditor.editor.getName();
document.body.appendChild(dragImage);
e.dataTransfer.setDragImage(dragImage, -10, -10);
setTimeout(() => document.body.removeChild(dragImage), 0);
......@@ -547,7 +547,7 @@ class OpenEditorRenderer implements IRenderer<OpenEditor, IOpenEditorTemplateDat
const dragged = <OpenEditor[]>this.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<OpenEditor, IOpenEditorTemplateDat
dom.removeClass(container, 'focused');
if (OpenEditorRenderer.DRAGGED_OPEN_EDITORS) {
const model = this.editorGroupService.getStacksModel();
const positionOfTargetGroup = model.positionOfGroup(editorTemplate.openEditor.editorGroup);
const index = editorTemplate.openEditor.editorGroup.indexOf(editorTemplate.openEditor.editorInput);
const positionOfTargetGroup = model.positionOfGroup(editorTemplate.openEditor.group);
const index = editorTemplate.openEditor.group.indexOf(editorTemplate.openEditor.editor);
OpenEditorRenderer.DRAGGED_OPEN_EDITORS.forEach(oe =>
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<OpenEditor, IOpenEditorTemplateDat
renderElement(editor: OpenEditor, index: number, templateData: IOpenEditorTemplateData): void {
templateData.openEditor = editor;
editor.isDirty() ? dom.addClass(templateData.container, 'dirty') : dom.removeClass(templateData.container, 'dirty');
templateData.root.setEditor(editor.editorInput, {
templateData.root.setEditor(editor.editor, {
italic: editor.isPreview(),
extraClasses: ['open-editor'],
fileDecorations: this.configurationService.getValue<IFilesConfiguration>().explorer.decorations
});
templateData.actionBar.context = { group: editor.editorGroup, editor: editor.editorInput };
templateData.actionBar.context = { group: editor.group, editor: editor.editor };
}
disposeTemplate(templateData: IOpenEditorTemplateData): void {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册