提交 5e271907 编写于 作者: B Benjamin Pasero

grid - allow to get groups in grid order

上级 efd80fa8
......@@ -11,9 +11,9 @@ import { Part } from 'vs/workbench/browser/part';
import { Dimension, isAncestor, toggleClass, addClass, clearNode } from 'vs/base/browser/dom';
import { Event, Emitter, once } from 'vs/base/common/event';
import { contrastBorder, editorBackground } from 'vs/platform/theme/common/colorRegistry';
import { INextEditorGroupsService, GroupDirection, IAddGroupOptions, GroupsArrangement, GroupOrientation, IMergeGroupOptions, MergeGroupMode, ICopyEditorOptions } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { INextEditorGroupsService, GroupDirection, IAddGroupOptions, GroupsArrangement, GroupOrientation, IMergeGroupOptions, MergeGroupMode, ICopyEditorOptions, GroupsOrder } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Direction, SerializableGrid, Sizing, ISerializedGrid, Orientation, ISerializedNode } from 'vs/base/browser/ui/grid/grid';
import { Direction, SerializableGrid, Sizing, ISerializedGrid, Orientation, ISerializedNode, GridBranchNode, isGridBranchNode, GridNode } from 'vs/base/browser/ui/grid/grid';
import { GroupIdentifier, IWorkbenchEditorConfiguration } from 'vs/workbench/common/editor';
import { values } from 'vs/base/common/map';
import { EDITOR_GROUP_BORDER } from 'vs/workbench/common/theme';
......@@ -168,16 +168,32 @@ export class NextEditorPart extends Part implements INextEditorGroupsService, IN
return this.gridWidget.orientation === Orientation.VERTICAL ? GroupOrientation.VERTICAL : GroupOrientation.HORIZONTAL;
}
getGroups(sortByMostRecentlyActive?: boolean): INextEditorGroupView[] {
if (!sortByMostRecentlyActive) {
return this.groups;
}
getGroups(order?: GroupsOrder): INextEditorGroupView[] {
switch (order) {
case GroupsOrder.MOST_RECENTLY_ACTIVE:
const mostRecentActive = this.mostRecentActiveGroups.map(groupId => this.getGroup(groupId));
// there can be groups that got never active, even though they exist. in this case
// make sure to ust append them at the end so that all groups are returned properly
return distinct([...mostRecentActive, ...this.groups]);
case GroupsOrder.GRID_ORDER:
const views: INextEditorGroupView[] = [];
this.fillGridNodes(views, this.gridWidget.getViews());
return views;
const mostRecentActive = this.mostRecentActiveGroups.map(groupId => this.getGroup(groupId));
default:
return this.groups;
}
}
// there can be groups that got never active, even though they exist. in this case
// make sure to ust append them at the end so that all groups are returned properly
return distinct([...mostRecentActive, ...this.groups]);
private fillGridNodes(target: INextEditorGroupView[], node: GridBranchNode<INextEditorGroupView> | GridNode<INextEditorGroupView>): void {
if (isGridBranchNode(node)) {
node.children.forEach(child => this.fillGridNodes(target, child));
} else {
target.push(node.view);
}
}
getGroup(identifier: GroupIdentifier): INextEditorGroupView {
......@@ -377,7 +393,7 @@ export class NextEditorPart extends Part implements INextEditorGroupsService, IN
}
private doRemoveGroupWithEditors(groupView: INextEditorGroupView): void {
const mostRecentlyActiveGroups = this.getGroups(true);
const mostRecentlyActiveGroups = this.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE);
let lastActiveGroup: INextEditorGroupView;
if (this._activeGroup === groupView) {
......@@ -396,7 +412,7 @@ export class NextEditorPart extends Part implements INextEditorGroupsService, IN
// Activate next group if the removed one was active
if (this._activeGroup === groupView) {
const mostRecentlyActiveGroups = this.getGroups(true);
const mostRecentlyActiveGroups = this.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE);
const nextActiveGroup = mostRecentlyActiveGroups[1]; // [0] will be the current group we are about to dispose
this.activateGroup(nextActiveGroup);
}
......
......@@ -24,7 +24,7 @@ import { basename } from 'vs/base/common/paths';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import { localize } from 'vs/nls';
import { TPromise } from 'vs/base/common/winjs.base';
import { INextEditorGroupsService, INextEditorGroup, GroupDirection } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { INextEditorGroupsService, INextEditorGroup, GroupDirection, GroupsOrder } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { INextEditorService, IResourceEditor, ACTIVE_GROUP_TYPE, SIDE_GROUP_TYPE, SIDE_GROUP, ACTIVE_GROUP } from 'vs/workbench/services/editor/common/nextEditorService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
......@@ -217,7 +217,7 @@ export class NextEditorService extends Disposable implements INextEditorService
// Group: Unspecified without a specific index to open
else if (!options || typeof options.index !== 'number') {
const groupsByLastActive = this.nextEditorGroupsService.getGroups(true);
const groupsByLastActive = this.nextEditorGroupsService.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE);
// Respect option to reveal an editor if it is already visible in any group
if (options && options.revealIfVisible) {
......
......@@ -73,6 +73,11 @@ export interface IEditorReplacement {
options?: IEditorOptions;
}
export enum GroupsOrder {
MOST_RECENTLY_ACTIVE,
GRID_ORDER
}
export interface INextEditorGroupsService {
_serviceBrand: ServiceIdentifier<any>;
......@@ -120,9 +125,9 @@ export interface INextEditorGroupsService {
/**
* Get all groups that are currently visible in the editor area optionally
* sorted by being most recent active.
* sorted by being most recent active or grid order.
*/
getGroups(sortByMostRecentlyActive?: boolean): ReadonlyArray<INextEditorGroup>;
getGroups(order?: GroupsOrder): ReadonlyArray<INextEditorGroup>;
/**
* Allows to convert a group identifier to a group.
......
......@@ -8,7 +8,7 @@
import * as assert from 'assert';
import { NextEditorPart } from 'vs/workbench/browser/parts/editor2/nextEditorPart';
import { workbenchInstantiationService } from 'vs/workbench/test/workbenchTestServices';
import { GroupDirection } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { GroupDirection, GroupsOrder } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { Dimension } from 'vs/base/browser/dom';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { INextEditorPartOptions } from 'vs/workbench/browser/parts/editor2/editor2';
......@@ -121,7 +121,7 @@ suite('Next editor2 part tests', () => {
assert.equal(rootGroup, part.getGroup(rootGroup.id));
assert.ok(part.activeGroup === rootGroup);
let mru = part.getGroups(true);
let mru = part.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE);
assert.equal(mru.length, 1);
assert.equal(mru[0], rootGroup);
......@@ -132,7 +132,7 @@ suite('Next editor2 part tests', () => {
assert.equal(part.count, 2);
assert.ok(part.activeGroup === rootGroup);
mru = part.getGroups(true);
mru = part.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE);
assert.equal(mru.length, 2);
assert.equal(mru[0], rootGroup);
assert.equal(mru[1], rightGroup);
......@@ -143,7 +143,7 @@ suite('Next editor2 part tests', () => {
assert.ok(part.activeGroup === rightGroup);
assert.equal(activeGroupChangeCounter, 1);
mru = part.getGroups(true);
mru = part.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE);
assert.equal(mru.length, 2);
assert.equal(mru[0], rightGroup);
assert.equal(mru[1], rootGroup);
......@@ -158,12 +158,18 @@ suite('Next editor2 part tests', () => {
assert.ok(part.activeGroup === rightGroup);
assert.ok(!downGroup.activeControl);
mru = part.getGroups(true);
mru = part.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE);
assert.equal(mru.length, 3);
assert.equal(mru[0], rightGroup);
assert.equal(mru[1], rootGroup);
assert.equal(mru[2], downGroup);
const gridOrder = part.getGroups(GroupsOrder.GRID_ORDER);
assert.equal(gridOrder.length, 3);
assert.equal(gridOrder[0], rootGroup);
assert.equal(gridOrder[1], rightGroup);
assert.equal(gridOrder[2], downGroup);
part.moveGroup(downGroup, rightGroup, GroupDirection.DOWN);
assert.equal(groupMovedCounter, 1);
......@@ -174,7 +180,7 @@ suite('Next editor2 part tests', () => {
assert.equal(part.groups.length, 2);
assert.ok(part.activeGroup === rightGroup);
mru = part.getGroups(true);
mru = part.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE);
assert.equal(mru.length, 2);
assert.equal(mru[0], rightGroup);
assert.equal(mru[1], rootGroup);
......@@ -198,7 +204,7 @@ suite('Next editor2 part tests', () => {
assert.equal(part.groups.length, 1);
assert.ok(part.activeGroup === rootGroup);
mru = part.getGroups(true);
mru = part.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE);
assert.equal(mru.length, 1);
assert.equal(mru[0], rootGroup);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册