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

grid.maximizeViewSize, grid.distributeViewSizes

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