提交 8b453ea8 编写于 作者: J Joao Moreno

grid.maximizeViewSize, grid.distributeViewSizes

fixes #50947
上级 dee27453
......@@ -280,20 +280,17 @@ export class Grid<T extends IView> implements IDisposable {
return getLocationOrientation(this.orientation, location) === Orientation.HORIZONTAL ? viewSize.width : viewSize.height;
}
getViews(): GridBranchNode<T> {
return this.gridview.getViews() as GridBranchNode<T>;
}
getOrientation(view: T): Orientation {
maximizeViewSize(view: T): void {
const location = this.getViewLocation(view);
return getLocationOrientation(this.orientation, location);
this.gridview.maximizeViewSize(location);
}
resetViewSize(view: T): void {
const location = this.getViewLocation(view);
distributeViewSizes(): void {
this.gridview.distributeViewSizes();
}
this.doResetViewSize(location);
getViews(): GridBranchNode<T> {
return this.gridview.getViews() as GridBranchNode<T>;
}
getNeighborViews(view: T, direction: Direction, wrap: boolean = false): T[] {
......
......@@ -256,8 +256,16 @@ class BranchNode implements ISplitView, IDisposable {
this.splitview.resizeView(index, size);
}
distributeViewSizes(): void {
distributeViewSizes(recursive = false): void {
this.splitview.distributeViewSizes();
if (recursive) {
for (const child of this.children) {
if (child instanceof BranchNode) {
child.distributeViewSizes(true);
}
}
}
}
getChildSize(index: number): number {
......@@ -622,19 +630,36 @@ export class GridView implements IDisposable {
parent.resizeChild(index, size);
}
distributeViewSizes(location: number[]): void {
getViewSize(location: number[]): { width: number; height: number; } {
const [, node] = this.getNode(location);
return { width: node.width, height: node.height };
}
if (!(node instanceof BranchNode)) {
maximizeViewSize(location: number[]): void {
const [ancestors, node] = this.getNode(location);
if (!(node instanceof LeafNode)) {
throw new Error('Invalid location');
}
node.distributeViewSizes();
for (let i = 0; i < ancestors.length; i++) {
ancestors[i].resizeChild(location[i], Number.POSITIVE_INFINITY);
}
}
getViewSize(location: number[]): { width: number; height: number; } {
distributeViewSizes(location?: number[]): void {
if (!location) {
this.root.distributeViewSizes(true);
return;
}
const [, node] = this.getNode(location);
return { width: node.width, height: node.height };
if (!(node instanceof BranchNode)) {
throw new Error('Invalid location');
}
node.distributeViewSizes();
}
getViews(): GridBranchNode {
......
......@@ -72,9 +72,6 @@ suite('Grid', function () {
grid.addView(view2, 200, view1, Direction.Up);
assert.deepEqual(view1.size, [800, 400]);
assert.deepEqual(view2.size, [800, 200]);
assert.equal(grid.getOrientation(view1), Orientation.VERTICAL);
assert.equal(grid.getOrientation(view2), Orientation.VERTICAL);
});
test('two views horizontally', function () {
......@@ -87,9 +84,6 @@ suite('Grid', function () {
grid.addView(view2, 300, view1, Direction.Right);
assert.deepEqual(view1.size, [500, 600]);
assert.deepEqual(view2.size, [300, 600]);
assert.equal(grid.getOrientation(view1), Orientation.HORIZONTAL);
assert.equal(grid.getOrientation(view2), Orientation.HORIZONTAL);
});
test('simple layout', function () {
......
......@@ -18,7 +18,7 @@ import { GroupIdentifier, IWorkbenchEditorConfiguration } from 'vs/workbench/com
import { values } from 'vs/base/common/map';
import { EDITOR_GROUP_BORDER } from 'vs/workbench/common/theme';
import { distinct } from 'vs/base/common/arrays';
import { IEditorGroupsAccessor, IEditorGroupView, IEditorPartOptions, getEditorPartOptions, impactsEditorPartOptions, IEditorPartOptionsChangeEvent, EDITOR_MAX_DIMENSIONS, EDITOR_MIN_DIMENSIONS, EditorGroupsServiceImpl } from 'vs/workbench/browser/parts/editor/editor';
import { IEditorGroupsAccessor, IEditorGroupView, IEditorPartOptions, getEditorPartOptions, impactsEditorPartOptions, IEditorPartOptionsChangeEvent, EditorGroupsServiceImpl } from 'vs/workbench/browser/parts/editor/editor';
import { EditorGroupView } from 'vs/workbench/browser/parts/editor/editorGroupView';
import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
import { IDisposable, dispose, toDisposable } from 'vs/base/common/lifecycle';
......@@ -294,25 +294,12 @@ export class EditorPart extends Part implements EditorGroupsServiceImpl, IEditor
// Even all group sizes
if (arrangement === GroupsArrangement.EVEN) {
this.groups.forEach(group => {
this.gridWidget.resetViewSize(group);
});
this.gridWidget.distributeViewSizes();
}
// Maximize the current active group
else {
this.groups.forEach(group => {
const orientation = this.gridWidget.getOrientation(group);
let newSize: number;
if (this.activeGroup === group) {
newSize = orientation === Orientation.HORIZONTAL ? EDITOR_MAX_DIMENSIONS.width : EDITOR_MAX_DIMENSIONS.height;
} else {
newSize = orientation === Orientation.HORIZONTAL ? EDITOR_MIN_DIMENSIONS.width : EDITOR_MIN_DIMENSIONS.height;
}
this.gridWidget.resizeView(group, newSize);
});
this.gridWidget.maximizeViewSize(this.activeGroup);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册