提交 e9fa946e 编写于 作者: I isidor

open editors: inital adoption to grid

上级 e16a0519
......@@ -124,8 +124,8 @@ export class BaseSplitEditorGroupAction extends Action {
public run(context?: IEditorIdentifier): TPromise<any> {
let group: INextEditorGroup;
if (context && context.group) {
group = this.nextEditorGroupsService.getGroup(context.group);
if (context && context.groupId) {
group = this.nextEditorGroupsService.getGroup(context.groupId);
}
if (!group) {
......@@ -237,7 +237,7 @@ export class JoinTwoGroupsAction extends Action {
// Joining group is from context, or the active group
if (context) {
fromPosition = editorStacksModel.positionOfGroup(editorStacksModel.getGroup(context.group));
fromPosition = editorStacksModel.positionOfGroup(editorStacksModel.getGroup(context.groupId));
} else {
fromPosition = editorStacksModel.positionOfGroup(editorStacksModel.activeGroup);
}
......@@ -808,7 +808,7 @@ export class CloseEditorsInOtherGroupsAction extends Action {
}
public run(context?: IEditorIdentifier): TPromise<any> {
let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(this.editorGroupService.getStacksModel().getGroup(context.group)) : null;
let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(this.editorGroupService.getStacksModel().getGroup(context.groupId)) : null;
if (typeof position !== 'number') {
const activeEditor = this.editorService.getActiveEditor();
if (activeEditor) {
......@@ -839,7 +839,7 @@ export class MoveGroupLeftAction extends Action {
}
public run(context?: IEditorIdentifier): TPromise<any> {
let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(this.editorGroupService.getStacksModel().getGroup(context.group)) : null;
let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(this.editorGroupService.getStacksModel().getGroup(context.groupId)) : null;
if (typeof position !== 'number') {
const activeEditor = this.editorService.getActiveEditor();
if (activeEditor && (activeEditor.group === Position.TWO || activeEditor.group === Position.THREE)) {
......@@ -873,7 +873,7 @@ export class MoveGroupRightAction extends Action {
}
public run(context?: IEditorIdentifier): TPromise<any> {
let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(this.editorGroupService.getStacksModel().getGroup(context.group)) : null;
let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(this.editorGroupService.getStacksModel().getGroup(context.groupId)) : null;
if (typeof position !== 'number') {
const activeEditor = this.editorService.getActiveEditor();
const editors = this.editorService.getVisibleEditors();
......@@ -954,7 +954,7 @@ export class MaximizeGroupAction extends Action {
function getTarget(editorService: IWorkbenchEditorService, editorGroupService: IEditorGroupService, context?: IEditorIdentifier): { input: IEditorInput, position: Position } {
if (context) {
return { input: context.editor, position: editorGroupService.getStacksModel().positionOfGroup(editorGroupService.getStacksModel().getGroup(context.group)) };
return { input: context.editor, position: editorGroupService.getStacksModel().positionOfGroup(editorGroupService.getStacksModel().getGroup(context.groupId)) };
}
const activeEditor = editorService.getActiveEditor();
......@@ -980,7 +980,7 @@ export abstract class BaseNavigateEditorAction extends Action {
const model = this.editorGroupService.getStacksModel();
const result = this.navigate();
if (result) {
return this.editorService.openEditor(result.editor, null, model.positionOfGroup(this.editorGroupService.getStacksModel().getGroup(result.group)));
return this.editorService.openEditor(result.editor, null, model.positionOfGroup(this.editorGroupService.getStacksModel().getGroup(result.groupId)));
}
return TPromise.as(false);
......
......@@ -552,7 +552,7 @@ export function getMultiSelectedEditorContexts(editorContext: IEditorCommandsCon
const list = listService.lastFocusedList;
if (list instanceof List && list.isDOMFocused()) {
const elementToContext = (element: IEditorIdentifier | EditorGroup) =>
element instanceof EditorGroup ? { groupId: element.id, editorIndex: undefined } : { groupId: element.group, editorIndex: editorGroupService.getGroup(element.group).getIndexOfEditor(element.editor) };
element instanceof EditorGroup ? { groupId: element.id, editorIndex: undefined } : { groupId: element.groupId, editorIndex: editorGroupService.getGroup(element.groupId).getIndexOfEditor(element.editor) };
const onlyEditorGroupAndEditor = (e: IEditorIdentifier | EditorGroup) => e instanceof EditorGroup || ('editor' in e && 'group' in e);
const focusedElements: (IEditorIdentifier | EditorGroup)[] = list.getFocusedElements().filter(onlyEditorGroupAndEditor);
......@@ -562,7 +562,7 @@ export function getMultiSelectedEditorContexts(editorContext: IEditorCommandsCon
if (focus) {
const selection: (IEditorIdentifier | EditorGroup)[] = list.getSelectedElements().filter(onlyEditorGroupAndEditor);
// Only respect selection if it contains focused element
if (selection && selection.some(s => s instanceof EditorGroup ? s.id === focus.groupId : s.group === focus.groupId && editorGroupService.getGroup(s.group).getIndexOfEditor(s.editor) === focus.editorIndex)) {
if (selection && selection.some(s => s instanceof EditorGroup ? s.id === focus.groupId : s.groupId === focus.groupId && editorGroupService.getGroup(s.groupId).getIndexOfEditor(s.editor) === focus.editorIndex)) {
return selection.map(elementToContext);
}
......
......@@ -1135,7 +1135,7 @@ export class EditorGroupsControl extends Themable implements IEditorGroupsContro
let options = EditorOptions.create({ pinned: true });
const activeEditor = $this.editorService.getActiveEditor();
const editor = getCodeEditor(activeEditor);
if (editor && activeEditor.group === stacks.positionOfGroup(stacks.getGroup(identifier.group)) && identifier.editor.matches(activeEditor.input)) {
if (editor && activeEditor.group === stacks.positionOfGroup(stacks.getGroup(identifier.groupId)) && identifier.editor.matches(activeEditor.input)) {
options = TextEditorOptions.fromEditor(editor, { pinned: true });
}
......@@ -1181,7 +1181,7 @@ export class EditorGroupsControl extends Themable implements IEditorGroupsContro
// Move editor to new location
else {
const draggedGroup = stacks.getGroup(draggedEditor.group);
const draggedGroup = stacks.getGroup(draggedEditor.groupId);
const sourcePosition = stacks.positionOfGroup(draggedGroup);
if (splitEditor) {
if (draggedGroup.count === 1) {
......@@ -1229,7 +1229,7 @@ export class EditorGroupsControl extends Themable implements IEditorGroupsContro
let splitTarget: Position;
const draggedGroup = stacks.getGroup(draggedEditor.group);
const draggedGroup = stacks.getGroup(draggedEditor.groupId);
// No splitting if we reached maximum group count
if (groups === POSITIONS.length) {
......
......@@ -20,7 +20,7 @@ import { toErrorMessage } from 'vs/base/common/errorMessage';
import { Scope as MementoScope } from 'vs/workbench/common/memento';
import { Part } from 'vs/workbench/browser/part';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { EditorInput, EditorOptions, ConfirmResult, IWorkbenchEditorConfiguration, TextEditorOptions, SideBySideEditorInput, TextCompareEditorVisibleContext, TEXT_DIFF_EDITOR_ID, IEditorOpeningEvent, GroupIdentifier, CloseDirection, IEditor } from 'vs/workbench/common/editor';
import { EditorInput, EditorOptions, ConfirmResult, IWorkbenchEditorConfiguration, TextEditorOptions, SideBySideEditorInput, TextCompareEditorVisibleContext, TEXT_DIFF_EDITOR_ID, IEditorOpeningEvent, CloseDirection, IEditor } from 'vs/workbench/common/editor';
import { EditorGroupsControl, Rochade, IEditorGroupsControl, ProgressState } from 'vs/workbench/browser/parts/editor/editorGroupsControl';
import { ScopedProgressService } from 'vs/workbench/services/progress/browser/progressService';
import { IEditorGroupService, GroupOrientation, GroupArrangement, IEditorTabOptions, IMoveOptions } from 'vs/workbench/services/group/common/groupService';
......@@ -189,7 +189,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
editor.options = EditorOptions.create({ index });
}
const replacement = { group: group.id, editor: editor.toReplace, replaceWith: editor.replaceWith, options: editor.options };
const replacement = { groupId: group.id, editor: editor.toReplace, replaceWith: editor.replaceWith, options: editor.options };
if (group.activeEditor.matches(editor.toReplace)) {
activeReplacements.push(replacement);
} else {
......@@ -202,7 +202,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
// Deal with hidden replacements first
hiddenReplacements.forEach(replacement => {
const group = this.stacks.getGroup(replacement.group);
const group = this.stacks.getGroup(replacement.groupId);
group.openEditor(replacement.replaceWith, { active: false, pinned: true, index: replacement.options.index });
group.closeEditor(replacement.editor);
......@@ -210,7 +210,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
// Now deal with active editors to be opened
const res = this.openEditors(activeReplacements.map(replacement => {
const group = this.stacks.getGroup(replacement.group);
const group = this.stacks.getGroup(replacement.groupId);
return {
input: replacement.replaceWith,
......@@ -221,7 +221,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
// Close active editors to be replaced now (they are no longer active)
activeReplacements.forEach(replacement => {
this.doCloseEditor(this.stacks.getGroup(replacement.group), replacement.editor, false);
this.doCloseEditor(this.stacks.getGroup(replacement.groupId), replacement.editor, false);
});
return res;
......@@ -797,22 +797,22 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
const visibleEditors: EditorIdentifier[] = [];
const hiddenEditors: EditorIdentifier[] = [];
this.pendingEditorInputsToClose.forEach(identifier => {
const { group, editor } = identifier;
const { groupId, editor } = identifier;
if (this.stacks.getGroup(group).isActive(editor)) {
if (this.stacks.getGroup(groupId).isActive(editor)) {
visibleEditors.push(identifier);
} else if (this.stacks.getGroup(group).contains(editor)) {
} else if (this.stacks.getGroup(groupId).contains(editor)) {
hiddenEditors.push(identifier);
}
});
// Close all hidden first
hiddenEditors.forEach(hidden => this.doCloseEditor(this.stacks.getGroup(hidden.group), hidden.editor, false));
hiddenEditors.forEach(hidden => this.doCloseEditor(this.stacks.getGroup(hidden.groupId), hidden.editor, false));
// Close visible ones second
visibleEditors
.sort((a1, a2) => this.stacks.positionOfGroup(this.stacks.getGroup(a2.group)) - this.stacks.positionOfGroup(this.stacks.getGroup(a1.group))) // reduce layout work by starting right/bottom first
.forEach(visible => this.doCloseEditor(this.stacks.getGroup(visible.group), visible.editor, false));
.sort((a1, a2) => this.stacks.positionOfGroup(this.stacks.getGroup(a2.groupId)) - this.stacks.positionOfGroup(this.stacks.getGroup(a1.groupId))) // reduce layout work by starting right/bottom first
.forEach(visible => this.doCloseEditor(this.stacks.getGroup(visible.groupId), visible.editor, false));
// Reset
this.pendingEditorInputCloseTimeout = null;
......@@ -891,7 +891,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
private onEditorDirty(identifier: EditorIdentifier): void {
// we pin every editor that becomes dirty
this.pinEditor(identifier.group, identifier.editor);
this.pinEditor(identifier.groupId, identifier.editor);
}
private onEditorGroupOpenedOrClosed(): void {
......@@ -1240,7 +1240,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
}
// Check for dirty and veto
return this.handleDirty([{ group: group.id, editor: input }], true /* ignore if opened in other group */).then(veto => {
return this.handleDirty([{ groupId: group.id, editor: input }], true /* ignore if opened in other group */).then(veto => {
if (veto) {
return;
}
......@@ -1356,7 +1356,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
const { editor } = identifier;
// Switch to editor that we want to handle
return this.openEditor(identifier.editor, null, this.stacks.positionOfGroup(this.stacks.getGroup(identifier.group))).then(() => {
return this.openEditor(identifier.editor, null, this.stacks.positionOfGroup(this.stacks.getGroup(identifier.groupId))).then(() => {
return editor.confirmSave().then(res => {
// It could be that the editor saved meanwhile, so we check again
......@@ -1742,8 +1742,6 @@ interface IEditorPartUIState {
}
interface IEditorReplacement extends EditorIdentifier {
group: GroupIdentifier;
editor: EditorInput;
replaceWith: EditorInput;
options?: EditorOptions;
}
......@@ -1765,4 +1763,4 @@ class ProgressMonitor {
}
}
//#endregion
\ No newline at end of file
//#endregion
......@@ -154,7 +154,7 @@ class DropOverlay extends Themable {
// Check for editor transfer
else if (this.editorTransfer.hasData(DraggedEditorIdentifier.prototype)) {
return this.accessor.getGroup(this.editorTransfer.getData(DraggedEditorIdentifier.prototype)[0].identifier.group);
return this.accessor.getGroup(this.editorTransfer.getData(DraggedEditorIdentifier.prototype)[0].identifier.groupId);
}
return void 0;
......@@ -213,7 +213,7 @@ class DropOverlay extends Themable {
const targetGroup = ensureTargetGroup();
// Return if the drop is a no-op
const sourceGroup = this.accessor.getGroup(draggedEditor.group);
const sourceGroup = this.accessor.getGroup(draggedEditor.groupId);
if (sourceGroup === targetGroup) {
return;
}
......@@ -454,4 +454,4 @@ export class NextEditorDropTarget extends Themable {
this._overlay = void 0;
}
}
}
\ No newline at end of file
}
......@@ -1203,7 +1203,7 @@ class EditorOpeningEvent implements IEditorOpeningEvent {
) {
}
get group(): GroupIdentifier {
get groupId(): GroupIdentifier {
return this._group;
}
......
......@@ -180,7 +180,7 @@ export class NextTabsTitleControl extends NextTitleControl {
isLocalDragAndDrop = true;
const localDraggedEditor = this.editorTransfer.getData(DraggedEditorIdentifier.prototype)[0].identifier;
if (this.group.id === localDraggedEditor.group && this.group.getIndexOfEditor(localDraggedEditor.editor) === this.group.count - 1) {
if (this.group.id === localDraggedEditor.groupId && this.group.getIndexOfEditor(localDraggedEditor.editor) === this.group.count - 1) {
e.dataTransfer.dropEffect = 'none';
return;
}
......@@ -525,7 +525,7 @@ export class NextTabsTitleControl extends NextTitleControl {
// Drag support
disposables.push(addDisposableListener(tab, EventType.DRAG_START, (e: DragEvent) => {
const editor = this.group.getEditor(index);
this.editorTransfer.setData([new DraggedEditorIdentifier({ editor, group: this.group.id })], DraggedEditorIdentifier.prototype);
this.editorTransfer.setData([new DraggedEditorIdentifier({ editor, groupId: this.group.id })], DraggedEditorIdentifier.prototype);
e.dataTransfer.effectAllowed = 'copyMove';
......@@ -559,7 +559,7 @@ export class NextTabsTitleControl extends NextTitleControl {
isLocalDragAndDrop = true;
const localDraggedEditor = this.editorTransfer.getData(DraggedEditorIdentifier.prototype)[0].identifier;
if (localDraggedEditor.editor === this.group.getEditor(index) && localDraggedEditor.group === this.group.id) {
if (localDraggedEditor.editor === this.group.getEditor(index) && localDraggedEditor.groupId === this.group.id) {
e.dataTransfer.dropEffect = 'none';
return;
}
......@@ -966,10 +966,10 @@ export class NextTabsTitleControl extends NextTitleControl {
// Local DND
const draggedEditor = this.editorTransfer.hasData(DraggedEditorIdentifier.prototype) ? this.editorTransfer.getData(DraggedEditorIdentifier.prototype)[0].identifier : void 0;
if (draggedEditor) {
const sourceGroup = this.accessor.getGroup(draggedEditor.group);
const sourceGroup = this.accessor.getGroup(draggedEditor.groupId);
// Move editor to target position and index
if (this.isMoveOperation(e, draggedEditor.group)) {
if (this.isMoveOperation(e, draggedEditor.groupId)) {
sourceGroup.moveEditor(draggedEditor.editor, this.group, { index: targetIndex });
}
......
......@@ -890,7 +890,7 @@ export class TextEditorOptions extends EditorOptions {
}
export interface IEditorIdentifier {
group: GroupIdentifier;
groupId: GroupIdentifier;
editor: IEditorInput;
}
......@@ -1204,4 +1204,4 @@ export interface IEditorGroup {
isPinned(editor: IEditorInput): boolean;
}
//#endregion
\ No newline at end of file
//#endregion
......@@ -28,7 +28,7 @@ export interface EditorCloseEvent extends IEditorCloseEvent {
}
export interface EditorIdentifier extends IEditorIdentifier {
group: GroupIdentifier;
groupId: GroupIdentifier;
editor: EditorInput;
}
......@@ -354,7 +354,7 @@ export class EditorGroup extends Disposable implements IEditorGroup {
this.splice(index, true);
// Event
return { editor, replaced, index, group: this.id };
return { editor, replaced, index, groupId: this.id };
}
closeEditors(except: EditorInput, direction?: CloseDirection): void {
......@@ -1264,4 +1264,4 @@ export class EditorGroup extends Disposable implements IEditorGroup {
// }
// }
// //#endregion
\ No newline at end of file
// //#endregion
......@@ -72,7 +72,7 @@ export class TextFileEditor extends BaseTextEditor {
}
private onWillCloseEditor(e: IEditorIdentifier): void {
if (e.editor === this.input && this.group === e.group) {
if (e.editor === this.input && this.group === e.groupId) {
this.doSaveTextEditorViewState(this.input);
}
}
......
......@@ -12,11 +12,12 @@ import { ResourceMap } from 'vs/base/common/map';
import { isLinux } from 'vs/base/common/platform';
import { IFileStat } from 'vs/platform/files/common/files';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IEditorGroup, toResource, IEditorIdentifier, IEditorInput } from 'vs/workbench/common/editor';
import { toResource, IEditorIdentifier, IEditorInput } from 'vs/workbench/common/editor';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { getPathLabel } from 'vs/base/common/labels';
import { Schemas } from 'vs/base/common/network';
import { startsWith, startsWithIgnoreCase, rtrim } from 'vs/base/common/strings';
import { INextEditorGroup } from 'vs/workbench/services/group/common/nextEditorGroupsService';
export class Model {
......@@ -451,7 +452,7 @@ export class NewStatPlaceholder extends ExplorerItem {
export class OpenEditor implements IEditorIdentifier {
constructor(private _editor: IEditorInput, private _group: IEditorGroup) {
constructor(private _editor: IEditorInput, private _group: INextEditorGroup) {
// noop
}
......@@ -460,23 +461,23 @@ export class OpenEditor implements IEditorIdentifier {
}
public get editorIndex() {
return this.legacyGroup.indexOf(this.editor);
return this._group.getIndexOfEditor(this.editor);
}
public get group() {
return this._group.id;
return this._group;
}
public get legacyGroup() {
return this._group;
public get groupId() {
return this._group.id;
}
public getId(): string {
return `openeditor:${this.group}:${this.legacyGroup.indexOf(this.editor)}:${this.editor.getName()}:${this.editor.getDescription()}`;
return `openeditor:${this.groupId}:${this.editorIndex}:${this.editor.getName()}:${this.editor.getDescription()}`;
}
public isPreview(): boolean {
return this.legacyGroup.isPreview(this.editor);
return this._group.previewEditor === this.editor;
}
public isUntitled(): boolean {
......
......@@ -128,7 +128,7 @@ function save(resource: URI, isSaveAs: boolean, editorService: INextEditorServic
return void 0; // save canceled or same resource used
}
const replaceWith: IResourceInput = {
const replacement: IResourceInput = {
resource: target,
encoding: encodingOfSource,
options: {
......@@ -136,13 +136,12 @@ function save(resource: URI, isSaveAs: boolean, editorService: INextEditorServic
viewState: viewStateOfSource
}
};
console.log(replaceWith);
// TODO@Isidor
// return editorService.replaceEditors([{
// toReplace: { resource: resource },
// replaceWith
// }]).then(() => true);
// TODO@isidor
return editorService.replaceEditors([{
editor: { resource },
replacement
}], undefined).then(() => true);
});
}
......
......@@ -10,11 +10,10 @@ import { IAction } from 'vs/base/common/actions';
import * as dom from 'vs/base/browser/dom';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { INextEditorGroupsService, INextEditorGroup, GroupDirection } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { Position } from 'vs/platform/editor/common/editor';
import { IEditorStacksModel, IStacksModelChangeEvent, IEditorGroup, IEditorInput } from 'vs/workbench/common/editor';
import { IEditorInput } from 'vs/workbench/common/editor';
import { SaveAllAction, SaveAllInGroupAction } from 'vs/workbench/parts/files/electron-browser/fileActions';
import { IViewletViewOptions, IViewOptions, ViewsViewletPanel } from 'vs/workbench/browser/parts/views/viewsViewlet';
import { OpenEditorsFocusedContext, ExplorerFocusedContext, IFilesConfiguration } from 'vs/workbench/parts/files/common/files';
......@@ -24,7 +23,6 @@ import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/un
import { CloseAllEditorsAction, CloseEditorAction } from 'vs/workbench/browser/parts/editor/editorActions';
import { ToggleEditorLayoutAction } from 'vs/workbench/browser/actions/toggleEditorLayout';
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { EditorGroup } from 'vs/workbench/common/editor/editorGroup';
import { attachStylerCallback } from 'vs/platform/theme/common/styler';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { badgeBackground, badgeForeground, contrastBorder } from 'vs/platform/theme/common/colorRegistry';
......@@ -34,7 +32,7 @@ import { EditorLabel } from 'vs/workbench/browser/labels';
import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
import { TPromise } from 'vs/base/common/winjs.base';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { fillInActions } from 'vs/platform/actions/browser/menuItemActionItem';
import { IMenuService, MenuId, IMenu } from 'vs/platform/actions/common/actions';
......@@ -50,11 +48,10 @@ export class OpenEditorsView extends ViewsViewletPanel {
static readonly ID = 'workbench.explorer.openEditorsView';
static NAME = nls.localize({ key: 'openEditors', comment: ['Open is an adjective'] }, "Open Editors");
private model: IEditorStacksModel;
private dirtyCountElement: HTMLElement;
private listRefreshScheduler: RunOnceScheduler;
private structuralRefreshDelay: number;
private list: WorkbenchList<OpenEditor | IEditorGroup>;
private list: WorkbenchList<OpenEditor | INextEditorGroup>;
private contributedContextMenu: IMenu;
private needsRefresh: boolean;
private resourceContext: ResourceContextKey;
......@@ -66,8 +63,8 @@ export class OpenEditorsView extends ViewsViewletPanel {
@IInstantiationService private instantiationService: IInstantiationService,
@IContextMenuService contextMenuService: IContextMenuService,
@ITextFileService private textFileService: ITextFileService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IEditorGroupService private editorGroupService: IEditorGroupService,
@INextEditorService private editorService: INextEditorService,
@INextEditorGroupsService private editorGroupService: INextEditorGroupsService,
@IConfigurationService configurationService: IConfigurationService,
@IKeybindingService keybindingService: IKeybindingService,
@IUntitledEditorService private untitledEditorService: IUntitledEditorService,
......@@ -81,8 +78,6 @@ export class OpenEditorsView extends ViewsViewletPanel {
ariaHeaderLabel: nls.localize({ key: 'openEditosrSection', comment: ['Open is an adjective'] }, "Open Editors Section"),
}, keybindingService, contextMenuService, configurationService);
this.model = editorGroupService.getStacksModel();
this.structuralRefreshDelay = 0;
this.listRefreshScheduler = new RunOnceScheduler(() => {
const previousLength = this.list.length;
......@@ -95,7 +90,8 @@ export class OpenEditorsView extends ViewsViewletPanel {
}, this.structuralRefreshDelay);
// update on model changes
this.disposables.push(this.model.onModelChanged(e => this.onEditorStacksModelChanged(e)));
// TODO@Isidor handle model change events
// this.disposables.push(this.model.onModelChanged(e => this.onEditorStacksModelChanged(e)));
// Also handle configuration updates
this.disposables.push(this.configurationService.onDidChangeConfiguration(e => this.onConfigurationChange(e)));
......@@ -149,9 +145,9 @@ export class OpenEditorsView extends ViewsViewletPanel {
new EditorGroupRenderer(this.keybindingService, this.instantiationService, this.editorGroupService),
new OpenEditorRenderer(getSelectedElements, this.instantiationService, this.keybindingService, this.configurationService, this.editorGroupService)
], {
identityProvider: (element: OpenEditor | EditorGroup) => element instanceof OpenEditor ? element.getId() : element.id.toString(),
identityProvider: (element: OpenEditor | INextEditorGroup) => element instanceof OpenEditor ? element.getId() : element.id.toString(),
selectOnMouseDown: false /* disabled to better support DND */
}) as WorkbenchList<OpenEditor | IEditorGroup>;
}) as WorkbenchList<OpenEditor | INextEditorGroup>;
this.contributedContextMenu = this.menuService.createMenu(MenuId.OpenEditorsContext, this.list.contextKeyService);
this.disposables.push(this.contributedContextMenu);
......@@ -199,8 +195,7 @@ export class OpenEditorsView extends ViewsViewletPanel {
const element = focused.length ? focused[0] : undefined;
if (element instanceof OpenEditor) {
if (isMiddleClick) {
const position = this.model.positionOfGroup(element.legacyGroup);
this.editorService.closeEditor(position, element.editor).done(null, errors.onUnexpectedError);
this.editorService.closeEditor(element.editor, element.groupId).done(null, errors.onUnexpectedError);
} else {
this.openEditor(element, { preserveFocus: isSingleClick, pinned: isDoubleClick, sideBySide: openToSide });
}
......@@ -238,7 +233,7 @@ export class OpenEditorsView extends ViewsViewletPanel {
this.list.domFocus();
}
public getList(): WorkbenchList<OpenEditor | IEditorGroup> {
public getList(): WorkbenchList<OpenEditor | INextEditorGroup> {
return this.list;
}
......@@ -249,28 +244,28 @@ export class OpenEditorsView extends ViewsViewletPanel {
}
private get showGroups(): boolean {
return this.model.groups.length > 1;
return this.editorGroupService.groups.length > 1;
}
private get elements(): (IEditorGroup | OpenEditor)[] {
const result: (IEditorGroup | OpenEditor)[] = [];
this.model.groups.forEach(g => {
private get elements(): (INextEditorGroup | OpenEditor)[] {
const result: (INextEditorGroup | OpenEditor)[] = [];
this.editorGroupService.groups.forEach(g => {
if (this.showGroups) {
result.push(g);
}
result.push(...g.getEditors().map(ei => new OpenEditor(ei, g)));
result.push(...g.editors.map(ei => new OpenEditor(ei, g)));
});
return result;
}
private getIndex(group: IEditorGroup, editor: IEditorInput): number {
let index = editor ? group.indexOf(editor) : 0;
private getIndex(group: INextEditorGroup, editor: IEditorInput): number {
let index = editor ? group.getIndexOfEditor(editor) : 0;
if (!this.showGroups) {
return index;
}
for (let g of this.model.groups) {
for (let g of this.editorGroupService.groups) {
if (g.id === group.id) {
return index + (!!editor ? 1 : 0);
} else {
......@@ -291,24 +286,20 @@ export class OpenEditorsView extends ViewsViewletPanel {
*/
this.telemetryService.publicLog('workbenchActionExecuted', { id: 'workbench.files.openFile', from: 'openEditors' });
let position = this.model.positionOfGroup(element.legacyGroup);
if (options.sideBySide && position !== Position.THREE) {
position++;
}
const groupWhereToOpen = options.sideBySide ? this.editorGroupService.findNeighbourGroup(element.groupId, GroupDirection.RIGHT) : element.groupId;
const preserveActivateGroup = options.sideBySide && options.preserveFocus; // needed for https://github.com/Microsoft/vscode/issues/42399
if (!preserveActivateGroup) {
this.editorGroupService.activateGroup(this.model.groupAt(position)); // needed for https://github.com/Microsoft/vscode/issues/6672
this.editorGroupService.activateGroup(element.groupId); // needed for https://github.com/Microsoft/vscode/issues/6672
}
this.editorService.openEditor(element.editor, options, position).done(() => {
this.editorService.openEditor(element.editor, options, groupWhereToOpen).done(() => {
if (!preserveActivateGroup) {
this.editorGroupService.activateGroup(this.model.groupAt(position));
this.editorGroupService.activateGroup(groupWhereToOpen);
}
}, errors.onUnexpectedError);
}
}
private onListContextMenu(e: IListContextMenuEvent<OpenEditor | IEditorGroup>): void {
private onListContextMenu(e: IListContextMenuEvent<OpenEditor | INextEditorGroup>): void {
const element = e.element;
this.contextMenuService.showContextMenu({
getAnchor: () => e.anchor,
......@@ -317,38 +308,38 @@ export class OpenEditorsView extends ViewsViewletPanel {
fillInActions(this.contributedContextMenu, { shouldForwardArgs: true, arg: element instanceof OpenEditor ? element.editor.getResource() : {} }, actions, this.contextMenuService);
return TPromise.as(actions);
},
getActionsContext: () => element instanceof OpenEditor ? { groupId: element.group, editorIndex: element.editorIndex } : { groupId: element.id }
getActionsContext: () => element instanceof OpenEditor ? { groupId: element.groupId, editorIndex: element.editorIndex } : { groupId: element.id }
});
}
private onEditorStacksModelChanged(e: IStacksModelChangeEvent): void {
if (!this.isVisible() || !this.list || !this.isExpanded()) {
this.needsRefresh = true;
return;
}
// private onEditorStacksModelChanged(e: IStacksModelChangeEvent): void {
// if (!this.isVisible() || !this.list || !this.isExpanded()) {
// this.needsRefresh = true;
// return;
// }
// Do a minimal list update based on if the change is structural or not #6670
if (e.structural) {
this.listRefreshScheduler.schedule(this.structuralRefreshDelay);
} else if (!this.listRefreshScheduler.isScheduled()) {
// // Do a minimal list update based on if the change is structural or not #6670
// if (e.structural) {
// this.listRefreshScheduler.schedule(this.structuralRefreshDelay);
// } else if (!this.listRefreshScheduler.isScheduled()) {
const newElement = e.editor ? new OpenEditor(e.editor, e.group) : this.showGroups ? e.group : undefined;
if (newElement) {
const index = this.getIndex(e.group, e.editor);
const previousLength = this.list.length;
this.list.splice(index, 1, [newElement]);
// const newElement = e.editor ? new OpenEditor(e.editor, e.group) : this.showGroups ? e.group : undefined;
// if (newElement) {
// const index = this.getIndex(e.group, e.editor);
// const previousLength = this.list.length;
// this.list.splice(index, 1, [newElement]);
if (previousLength !== this.list.length) {
this.updateSize();
}
this.focusActiveEditor();
}
}
}
// if (previousLength !== this.list.length) {
// this.updateSize();
// }
// this.focusActiveEditor();
// }
// }
// }
private focusActiveEditor(): void {
if (this.model.activeGroup && this.model.activeGroup.activeEditor /* could be empty */) {
const index = this.getIndex(this.model.activeGroup, this.model.activeGroup.activeEditor);
if (this.editorGroupService.activeGroup && this.editorGroupService.activeGroup.activeEditor /* could be empty */) {
const index = this.getIndex(this.editorGroupService.activeGroup, this.editorGroupService.activeGroup.activeEditor);
this.list.setFocus([index]);
this.list.setSelection([index]);
this.list.reveal(index);
......@@ -384,8 +375,8 @@ export class OpenEditorsView extends ViewsViewletPanel {
}
private get elementCount(): number {
return this.model.groups.map(g => g.count)
.reduce((first, second) => first + second, this.showGroups ? this.model.groups.length : 0);
return this.editorGroupService.groups.map(g => g.count)
.reduce((first, second) => first + second, this.showGroups ? this.editorGroupService.groups.length : 0);
}
private getMaxExpandedBodySize(): number {
......@@ -430,28 +421,28 @@ interface IEditorGroupTemplateData {
root: HTMLElement;
name: HTMLSpanElement;
actionBar: ActionBar;
editorGroup: IEditorGroup;
editorGroup: INextEditorGroup;
toDispose: IDisposable[];
}
class OpenEditorsDelegate implements IDelegate<OpenEditor | IEditorGroup> {
class OpenEditorsDelegate implements IDelegate<OpenEditor | INextEditorGroup> {
public static readonly ITEM_HEIGHT = 22;
getHeight(element: OpenEditor | IEditorGroup): number {
getHeight(element: OpenEditor | INextEditorGroup): number {
return OpenEditorsDelegate.ITEM_HEIGHT;
}
getTemplateId(element: OpenEditor | IEditorGroup): string {
if (element instanceof EditorGroup) {
return EditorGroupRenderer.ID;
getTemplateId(element: OpenEditor | INextEditorGroup): string {
if (element instanceof OpenEditor) {
return OpenEditorRenderer.ID;
}
return OpenEditorRenderer.ID;
return EditorGroupRenderer.ID;
}
}
class EditorGroupRenderer implements IRenderer<IEditorGroup, IEditorGroupTemplateData> {
class EditorGroupRenderer implements IRenderer<INextEditorGroup, IEditorGroupTemplateData> {
static readonly ID = 'editorgroup';
private transfer = LocalSelectionTransfer.getInstance<OpenEditor>();
......@@ -459,7 +450,7 @@ class EditorGroupRenderer implements IRenderer<IEditorGroup, IEditorGroupTemplat
constructor(
private keybindingService: IKeybindingService,
private instantiationService: IInstantiationService,
private editorGroupService: IEditorGroupService
private editorGroupService: INextEditorGroupsService
) {
// noop
}
......@@ -488,23 +479,21 @@ class EditorGroupRenderer implements IRenderer<IEditorGroup, IEditorGroupTemplat
editorGroupTemplate.toDispose.push(dom.addDisposableListener(container, dom.EventType.DROP, e => {
dom.removeClass(container, 'focused');
const model = this.editorGroupService.getStacksModel();
const positionOfTargetGroup = model.positionOfGroup(editorGroupTemplate.editorGroup);
if (this.transfer.hasData(OpenEditor.prototype)) {
this.transfer.getData(OpenEditor.prototype).forEach(oe =>
this.editorGroupService.moveEditor(oe.editor, model.positionOfGroup(oe.legacyGroup), positionOfTargetGroup, { preserveFocus: true }));
this.editorGroupService.activateGroup(positionOfTargetGroup);
oe.group.moveEditor(oe.editor, editorGroupTemplate.editorGroup, { preserveFocus: true }));
this.editorGroupService.activateGroup(editorGroupTemplate.editorGroup);
} else {
const dropHandler = this.instantiationService.createInstance(ResourcesDropHandler, { allowWorkspaceOpen: false });
dropHandler.handleDrop(e, () => this.editorGroupService.activateGroup(positionOfTargetGroup), () => positionOfTargetGroup);
dropHandler.handleDrop(e, () => this.editorGroupService.activateGroup(editorGroupTemplate.editorGroup), () => editorGroupTemplate.editorGroup.id);
}
}));
return editorGroupTemplate;
}
renderElement(editorGroup: IEditorGroup, index: number, templateData: IEditorGroupTemplateData): void {
renderElement(editorGroup: INextEditorGroup, index: number, templateData: IEditorGroupTemplateData): void {
templateData.editorGroup = editorGroup;
templateData.name.textContent = `Group <${editorGroup.id}>`;
templateData.actionBar.context = { groupId: editorGroup.id };
......@@ -522,11 +511,11 @@ class OpenEditorRenderer implements IRenderer<OpenEditor, IOpenEditorTemplateDat
private transfer = LocalSelectionTransfer.getInstance<OpenEditor>();
constructor(
private getSelectedElements: () => (OpenEditor | IEditorGroup)[],
private getSelectedElements: () => (OpenEditor | INextEditorGroup)[],
private instantiationService: IInstantiationService,
private keybindingService: IKeybindingService,
private configurationService: IConfigurationService,
private editorGroupService: IEditorGroupService
private editorGroupService: INextEditorGroupsService
) {
// noop
}
......@@ -574,17 +563,15 @@ class OpenEditorRenderer implements IRenderer<OpenEditor, IOpenEditorTemplateDat
}));
editorTemplate.toDispose.push(dom.addDisposableListener(container, dom.EventType.DROP, (e: DragEvent) => {
dom.removeClass(container, 'focused');
const model = this.editorGroupService.getStacksModel();
const positionOfTargetGroup = model.positionOfGroup(editorTemplate.openEditor.legacyGroup);
const index = editorTemplate.openEditor.legacyGroup.indexOf(editorTemplate.openEditor.editor);
const index = editorTemplate.openEditor.group.getIndexOfEditor(editorTemplate.openEditor.editor);
if (this.transfer.hasData(OpenEditor.prototype)) {
this.transfer.getData(OpenEditor.prototype).forEach((oe, offset) =>
this.editorGroupService.moveEditor(oe.editor, model.positionOfGroup(oe.legacyGroup), positionOfTargetGroup, { index: index + offset, preserveFocus: true }));
this.editorGroupService.activateGroup(positionOfTargetGroup);
oe.group.moveEditor(oe.editor, editorTemplate.openEditor.group, { index: index + offset, preserveFocus: true }));
this.editorGroupService.activateGroup(editorTemplate.openEditor.group);
} else {
const dropHandler = this.instantiationService.createInstance(ResourcesDropHandler, { allowWorkspaceOpen: false });
dropHandler.handleDrop(e, () => this.editorGroupService.activateGroup(positionOfTargetGroup), () => positionOfTargetGroup, index);
dropHandler.handleDrop(e, () => this.editorGroupService.activateGroup(editorTemplate.openEditor.group), () => editorTemplate.openEditor.group.id, index);
}
}));
editorTemplate.toDispose.push(dom.addDisposableListener(container, dom.EventType.DRAG_END, () => {
......@@ -602,7 +589,7 @@ class OpenEditorRenderer implements IRenderer<OpenEditor, IOpenEditorTemplateDat
extraClasses: ['open-editor'],
fileDecorations: this.configurationService.getValue<IFilesConfiguration>().explorer.decorations
});
templateData.actionBar.context = { groupId: editor.group, editorIndex: editor.editorIndex };
templateData.actionBar.context = { groupId: editor.groupId, editorIndex: editor.editorIndex };
}
disposeTemplate(templateData: IOpenEditorTemplateData): void {
......
......@@ -74,7 +74,7 @@ export class PreferencesContribution implements IWorkbenchContribution {
// If the file resource was already opened before in the group, do not prevent
// the opening of that resource. Otherwise we would have the same settings
// opened twice (https://github.com/Microsoft/vscode/issues/36447)
const group = this.nextEditorGroupService.getGroup(event.group);
const group = this.nextEditorGroupService.getGroup(event.groupId);
if (group.isOpened(event.editor)) {
return;
}
......
......@@ -112,11 +112,11 @@ export class NextEditorService extends Disposable implements INextEditorService,
}));
groupDisposeables.push(group.onWillCloseEditor(editor => {
this._onWillCloseEditor.fire({ editor, group: group.id });
this._onWillCloseEditor.fire({ editor, groupId: group.id });
}));
groupDisposeables.push(group.onDidCloseEditor(editor => {
this._onDidCloseEditor.fire({ editor, group: group.id });
this._onDidCloseEditor.fire({ editor, groupId: group.id });
}));
groupDisposeables.push(group.onWillOpenEditor(editor => {
......@@ -124,7 +124,7 @@ export class NextEditorService extends Disposable implements INextEditorService,
}));
groupDisposeables.push(group.onDidOpenEditorFail(editor => {
this._onDidOpenEditorFail.fire({ editor, group: group.id });
this._onDidOpenEditorFail.fire({ editor, groupId: group.id });
}));
once(group.onWillDispose)(() => {
......@@ -608,4 +608,4 @@ export class DelegatingWorkbenchEditorService extends NextEditorService {
return super.doOpenEditor(group, editor, options);
});
}
}
\ No newline at end of file
}
......@@ -175,7 +175,7 @@ export class HistoryService implements IHistoryService {
}
// Remember as last active editor (can be undefined if none opened)
this.lastActiveEditor = activeEditor ? { editor: activeEditor.input, group: activeEditor.group } : void 0;
this.lastActiveEditor = activeEditor ? { editor: activeEditor.input, groupId: activeEditor.group } : void 0;
// Dispose old listeners
dispose(this.activeEditorListeners);
......@@ -202,7 +202,7 @@ export class HistoryService implements IHistoryService {
return false;
}
if (identifier.group !== editor.group) {
if (identifier.groupId !== editor.group) {
return false;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册