Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
0bc81da1
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0bc81da1
编写于
6月 01, 2018
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
💄
grid, cleanup getViews()
上级
533dc643
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
85 addition
and
102 deletion
+85
-102
src/vs/base/browser/ui/grid/grid.ts
src/vs/base/browser/ui/grid/grid.ts
+55
-93
src/vs/base/browser/ui/grid/gridview.ts
src/vs/base/browser/ui/grid/gridview.ts
+29
-8
src/vs/base/test/browser/ui/grid/gridview.test.ts
src/vs/base/test/browser/ui/grid/gridview.test.ts
+1
-1
未找到文件。
src/vs/base/browser/ui/grid/grid.ts
浏览文件 @
0bc81da1
...
...
@@ -9,7 +9,7 @@ import 'vs/css!./gridview';
import
{
Orientation
}
from
'
vs/base/browser/ui/sash/sash
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
tail2
as
tail
}
from
'
vs/base/common/arrays
'
;
import
{
orthogonal
,
IView
,
GridView
,
Sizing
as
GridViewSizing
}
from
'
./gridview
'
;
import
{
orthogonal
,
IView
,
GridView
,
Sizing
as
GridViewSizing
,
Box
}
from
'
./gridview
'
;
export
{
Orientation
}
from
'
./gridview
'
;
...
...
@@ -31,12 +31,12 @@ function oppositeDirection(direction: Direction): Direction {
export
interface
GridLeafNode
<
T
extends
IView
>
{
readonly
view
:
T
;
readonly
size
:
number
;
readonly
box
:
Box
;
}
export
interface
GridBranchNode
<
T
extends
IView
>
{
readonly
children
:
GridNode
<
T
>
[];
readonly
size
:
number
;
readonly
box
:
Box
;
}
export
type
GridNode
<
T
extends
IView
>
=
GridLeafNode
<
T
>
|
GridBranchNode
<
T
>
;
...
...
@@ -45,63 +45,17 @@ export function isGridBranchNode<T extends IView>(node: GridNode<T>): node is Gr
return
!!
(
node
as
any
).
children
;
}
interface
Box
{
top
:
number
;
left
:
number
;
width
:
number
;
height
:
number
;
}
interface
BoxLeafNode
<
T
extends
IView
>
{
readonly
node
:
GridLeafNode
<
T
>
;
readonly
box
:
Box
;
}
interface
BoxBranchNode
<
T
extends
IView
>
{
readonly
children
:
BoxNode
<
T
>
[];
readonly
box
:
Box
;
}
// TODO@Joao: should GridNodes already contain Box information? that would save us some memory here
type
BoxNode
<
T
extends
IView
>
=
BoxLeafNode
<
T
>
|
BoxBranchNode
<
T
>
;
function
isBoxBranchNode
<
T
extends
IView
>
(
node
:
BoxNode
<
T
>
):
node
is
BoxBranchNode
<
T
>
{
return
!!
(
node
as
any
).
children
;
}
function
toBoxNode
<
T
extends
IView
>
(
node
:
GridNode
<
T
>
,
orientation
:
Orientation
,
box
:
Box
):
BoxNode
<
T
>
{
if
(
!
isGridBranchNode
(
node
))
{
return
{
node
,
box
};
}
const
children
:
BoxNode
<
T
>
[]
=
[];
let
offset
=
0
;
for
(
let
i
=
0
;
i
<
node
.
children
.
length
;
i
++
)
{
const
child
=
node
.
children
[
i
];
const
childOrientation
=
orthogonal
(
orientation
);
const
childBox
:
Box
=
orientation
===
Orientation
.
HORIZONTAL
?
{
top
:
box
.
top
,
left
:
box
.
left
+
offset
,
width
:
child
.
size
,
height
:
box
.
height
}
:
{
top
:
box
.
top
+
offset
,
left
:
box
.
left
,
width
:
box
.
width
,
height
:
child
.
size
};
children
.
push
(
toBoxNode
(
child
,
childOrientation
,
childBox
));
offset
+=
child
.
size
;
}
return
{
children
,
box
};
}
function
getBoxNode
<
T
extends
IView
>
(
node
:
BoxNode
<
T
>
,
location
:
number
[]):
BoxNode
<
T
>
{
function
getGridNode
<
T
extends
IView
>
(
node
:
GridNode
<
T
>
,
location
:
number
[]):
GridNode
<
T
>
{
if
(
location
.
length
===
0
)
{
return
node
;
}
if
(
!
is
Box
BranchNode
(
node
))
{
if
(
!
is
Grid
BranchNode
(
node
))
{
throw
new
Error
(
'
Invalid location
'
);
}
const
[
index
,
...
rest
]
=
location
;
return
get
Box
Node
(
node
.
children
[
index
],
rest
);
return
get
Grid
Node
(
node
.
children
[
index
],
rest
);
}
interface
Range
{
...
...
@@ -133,11 +87,11 @@ function getBoxBoundary(box: Box, direction: Direction): Boundary {
return
{
offset
,
range
};
}
function
findAdjacentBoxLeafNodes
<
T
extends
IView
>
(
boxNode
:
BoxNode
<
T
>
,
direction
:
Direction
,
boundary
:
Boundary
):
Box
LeafNode
<
T
>
[]
{
const
result
:
Box
LeafNode
<
T
>
[]
=
[];
function
findAdjacentBoxLeafNodes
<
T
extends
IView
>
(
boxNode
:
GridNode
<
T
>
,
direction
:
Direction
,
boundary
:
Boundary
):
Grid
LeafNode
<
T
>
[]
{
const
result
:
Grid
LeafNode
<
T
>
[]
=
[];
function
_
(
boxNode
:
Box
Node
<
T
>
,
direction
:
Direction
,
boundary
:
Boundary
):
void
{
if
(
is
Box
BranchNode
(
boxNode
))
{
function
_
(
boxNode
:
Grid
Node
<
T
>
,
direction
:
Direction
,
boundary
:
Boundary
):
void
{
if
(
is
Grid
BranchNode
(
boxNode
))
{
for
(
const
child
of
boxNode
.
children
)
{
_
(
child
,
direction
,
boundary
);
}
...
...
@@ -335,24 +289,23 @@ export class Grid<T extends IView> implements IDisposable {
getNeighborViews
(
view
:
T
,
direction
:
Direction
,
wrap
:
boolean
=
false
):
T
[]
{
const
location
=
this
.
getViewLocation
(
view
);
const
root
=
this
.
getViews
();
const
boxRoot
=
toBoxNode
(
root
,
this
.
orientation
,
{
top
:
0
,
left
:
0
,
width
:
this
.
width
,
height
:
this
.
height
});
const
boxNode
=
getBoxNode
(
boxRoot
,
location
);
let
boundary
=
getBoxBoundary
(
boxNode
.
box
,
direction
);
const
node
=
getGridNode
(
root
,
location
);
let
boundary
=
getBoxBoundary
(
node
.
box
,
direction
);
if
(
wrap
)
{
if
(
direction
===
Direction
.
Up
&&
boxN
ode
.
box
.
top
===
0
)
{
boundary
=
{
offset
:
boxRoot
.
box
.
top
+
boxR
oot
.
box
.
height
,
range
:
boundary
.
range
};
}
else
if
(
direction
===
Direction
.
Right
&&
boxNode
.
box
.
left
+
boxNode
.
box
.
width
===
boxR
oot
.
box
.
width
)
{
if
(
direction
===
Direction
.
Up
&&
n
ode
.
box
.
top
===
0
)
{
boundary
=
{
offset
:
root
.
box
.
top
+
r
oot
.
box
.
height
,
range
:
boundary
.
range
};
}
else
if
(
direction
===
Direction
.
Right
&&
node
.
box
.
left
+
node
.
box
.
width
===
r
oot
.
box
.
width
)
{
boundary
=
{
offset
:
0
,
range
:
boundary
.
range
};
}
else
if
(
direction
===
Direction
.
Down
&&
boxNode
.
box
.
top
+
boxNode
.
box
.
height
===
boxR
oot
.
box
.
height
)
{
}
else
if
(
direction
===
Direction
.
Down
&&
node
.
box
.
top
+
node
.
box
.
height
===
r
oot
.
box
.
height
)
{
boundary
=
{
offset
:
0
,
range
:
boundary
.
range
};
}
else
if
(
direction
===
Direction
.
Left
&&
boxN
ode
.
box
.
left
===
0
)
{
boundary
=
{
offset
:
boxRoot
.
box
.
left
+
boxR
oot
.
box
.
width
,
range
:
boundary
.
range
};
}
else
if
(
direction
===
Direction
.
Left
&&
n
ode
.
box
.
left
===
0
)
{
boundary
=
{
offset
:
root
.
box
.
left
+
r
oot
.
box
.
width
,
range
:
boundary
.
range
};
}
}
return
findAdjacentBoxLeafNodes
(
boxR
oot
,
oppositeDirection
(
direction
),
boundary
)
.
map
(
boxNode
=>
boxNode
.
node
.
view
);
return
findAdjacentBoxLeafNodes
(
r
oot
,
oppositeDirection
(
direction
),
boundary
)
.
map
(
node
=>
node
.
view
);
}
private
getViewLocation
(
view
:
T
):
number
[]
{
...
...
@@ -414,15 +367,17 @@ export interface ISerializedGrid {
export
class
SerializableGrid
<
T
extends
ISerializableView
>
extends
Grid
<
T
>
{
private
static
serializeNode
<
T
extends
ISerializableView
>
(
node
:
GridNode
<
T
>
):
ISerializedNode
{
if
(
isGridBranchNode
(
node
))
{
return
{
type
:
'
branch
'
,
data
:
node
.
children
.
map
(
c
=>
SerializableGrid
.
serializeNode
(
c
)),
size
:
node
.
size
};
}
else
{
return
{
type
:
'
leaf
'
,
data
:
node
.
view
.
toJSON
(),
size
:
node
.
size
};
private
static
serializeNode
<
T
extends
ISerializableView
>
(
node
:
GridNode
<
T
>
,
orientation
:
Orientation
):
ISerializedNode
{
const
size
=
orientation
===
Orientation
.
VERTICAL
?
node
.
box
.
width
:
node
.
box
.
height
;
if
(
!
isGridBranchNode
(
node
))
{
return
{
type
:
'
leaf
'
,
data
:
node
.
view
.
toJSON
(),
size
};
}
return
{
type
:
'
branch
'
,
data
:
node
.
children
.
map
(
c
=>
SerializableGrid
.
serializeNode
(
c
,
orthogonal
(
orientation
))),
size
};
}
private
static
deserializeNode
<
T
extends
ISerializableView
>
(
json
:
ISerializedNode
,
deserializer
:
IViewDeserializer
<
T
>
):
GridNode
<
T
>
{
private
static
deserializeNode
<
T
extends
ISerializableView
>
(
json
:
ISerializedNode
,
orientation
:
Orientation
,
box
:
Box
,
deserializer
:
IViewDeserializer
<
T
>
):
GridNode
<
T
>
{
if
(
!
json
||
typeof
json
!==
'
object
'
)
{
throw
new
Error
(
'
Invalid JSON
'
);
}
...
...
@@ -433,25 +388,29 @@ export class SerializableGrid<T extends ISerializableView> extends Grid<T> {
if
(
type
===
'
branch
'
)
{
if
(
!
Array
.
isArray
(
data
))
{
throw
new
Error
(
'
Invalid JSON:
\'
data
\'
property of branch must be an array.
'
);
}
else
if
(
typeof
json
.
size
!==
'
number
'
)
{
throw
new
Error
(
'
Invalid JSON:
\'
size
\'
property of branch must be a number.
'
);
}
const
nodes
=
data
as
ISerializedNode
[];
const
children
=
nodes
.
map
(
c
=>
SerializableGrid
.
deserializeNode
(
c
,
deserializer
));
const
size
=
json
.
size
as
number
;
const
children
:
GridNode
<
T
>
[]
=
[];
let
offset
=
0
;
return
{
children
,
size
};
for
(
const
child
of
data
)
{
if
(
typeof
child
.
size
!==
'
number
'
)
{
throw
new
Error
(
'
Invalid JSON:
\'
size
\'
property of node must be a number.
'
);
}
}
else
if
(
type
===
'
leaf
'
)
{
if
(
typeof
json
.
size
!==
'
number
'
)
{
throw
new
Error
(
'
Invalid JSON:
\'
size
\'
property of leaf must be a number.
'
);
const
childBox
:
Box
=
orientation
===
Orientation
.
HORIZONTAL
?
{
top
:
box
.
top
,
left
:
box
.
left
+
offset
,
width
:
child
.
size
,
height
:
box
.
height
}
:
{
top
:
box
.
top
+
offset
,
left
:
box
.
left
,
width
:
box
.
width
,
height
:
child
.
size
};
children
.
push
(
SerializableGrid
.
deserializeNode
(
child
,
orthogonal
(
orientation
),
childBox
,
deserializer
));
offset
+=
child
.
size
;
}
const
view
=
deserializer
.
fromJSON
(
data
)
as
T
;
const
size
=
json
.
size
as
number
;
return
{
children
,
box
};
return
{
view
,
size
};
}
else
if
(
type
===
'
leaf
'
)
{
const
view
=
deserializer
.
fromJSON
(
data
)
as
T
;
return
{
view
,
box
};
}
throw
new
Error
(
'
Invalid JSON:
\'
type
\'
property must be either
\'
branch
\'
or
\'
leaf
\'
.
'
);
...
...
@@ -474,17 +433,18 @@ export class SerializableGrid<T extends ISerializableView> extends Grid<T> {
throw
new
Error
(
'
Invalid JSON:
\'
height
\'
property must be a number.
'
);
}
const
root
=
SerializableGrid
.
deserializeNode
(
json
.
root
,
deserializer
)
as
GridBranchNode
<
T
>
;
const
orientation
=
json
.
orientation
as
Orientation
;
const
width
=
json
.
width
as
number
;
const
height
=
json
.
height
as
number
;
const
box
:
Box
=
{
top
:
0
,
left
:
0
,
width
,
height
};
const
root
=
SerializableGrid
.
deserializeNode
(
json
.
root
,
orientation
,
box
,
deserializer
)
as
GridBranchNode
<
T
>
;
const
firstLeaf
=
SerializableGrid
.
getFirstLeaf
(
root
);
if
(
!
firstLeaf
)
{
throw
new
Error
(
'
Invalid serialized state, first leaf not found
'
);
}
const
orientation
=
json
.
orientation
as
Orientation
;
const
width
=
json
.
width
as
number
;
const
height
=
json
.
height
as
number
;
const
result
=
new
SerializableGrid
<
T
>
(
container
,
firstLeaf
.
view
);
result
.
orientation
=
orientation
;
result
.
restoreViews
(
firstLeaf
.
view
,
orientation
,
root
);
...
...
@@ -501,7 +461,7 @@ export class SerializableGrid<T extends ISerializableView> extends Grid<T> {
serialize
():
ISerializedGrid
{
return
{
root
:
SerializableGrid
.
serializeNode
(
this
.
getViews
()),
root
:
SerializableGrid
.
serializeNode
(
this
.
getViews
()
,
this
.
orientation
),
orientation
:
this
.
orientation
,
width
:
this
.
width
,
height
:
this
.
height
...
...
@@ -532,7 +492,8 @@ export class SerializableGrid<T extends ISerializableView> extends Grid<T> {
const
firstLeaves
=
node
.
children
.
map
(
c
=>
SerializableGrid
.
getFirstLeaf
(
c
));
for
(
let
i
=
1
;
i
<
firstLeaves
.
length
;
i
++
)
{
this
.
addView
(
firstLeaves
[
i
].
view
,
firstLeaves
[
i
].
size
,
referenceView
,
direction
);
const
size
=
orientation
===
Orientation
.
VERTICAL
?
firstLeaves
[
i
].
box
.
height
:
firstLeaves
[
i
].
box
.
width
;
this
.
addView
(
firstLeaves
[
i
].
view
,
size
,
referenceView
,
direction
);
referenceView
=
firstLeaves
[
i
].
view
;
}
...
...
@@ -557,7 +518,8 @@ export class SerializableGrid<T extends ISerializableView> extends Grid<T> {
const
childLocation
=
[...
location
,
i
];
if
(
i
<
node
.
children
.
length
-
1
)
{
this
.
gridview
.
resizeView
(
childLocation
,
Math
.
floor
(
child
.
size
*
scale
));
const
size
=
orientation
===
Orientation
.
VERTICAL
?
child
.
box
.
height
:
child
.
box
.
width
;
this
.
gridview
.
resizeView
(
childLocation
,
Math
.
floor
(
size
*
scale
));
}
this
.
restoreViewsSize
(
childLocation
,
child
,
orthogonal
(
orientation
),
widthScale
,
heightScale
);
...
...
src/vs/base/browser/ui/grid/gridview.ts
浏览文件 @
0bc81da1
...
...
@@ -38,14 +38,21 @@ export function orthogonal(orientation: Orientation): Orientation {
return
orientation
===
Orientation
.
VERTICAL
?
Orientation
.
HORIZONTAL
:
Orientation
.
VERTICAL
;
}
export
interface
Box
{
top
:
number
;
left
:
number
;
width
:
number
;
height
:
number
;
}
export
interface
GridLeafNode
{
readonly
view
:
IView
;
readonly
size
:
number
;
readonly
box
:
Box
;
}
export
interface
GridBranchNode
{
readonly
children
:
GridNode
[];
readonly
size
:
number
;
readonly
box
:
Box
;
}
export
type
GridNode
=
GridLeafNode
|
GridBranchNode
;
...
...
@@ -559,15 +566,29 @@ export class GridView implements IDisposable {
}
getViews
():
GridBranchNode
{
return
this
.
_getViews
(
this
.
root
)
as
GridBranchNode
;
return
this
.
_getViews
(
this
.
root
,
this
.
orientation
,
{
top
:
0
,
left
:
0
,
width
:
this
.
width
,
height
:
this
.
height
}
)
as
GridBranchNode
;
}
private
_getViews
(
node
:
Node
):
GridNode
{
if
(
node
instanceof
BranchNode
)
{
return
{
children
:
node
.
children
.
map
(
c
=>
this
.
_getViews
(
c
)),
size
:
node
.
orthogonalSize
};
}
else
{
return
{
view
:
node
.
view
,
size
:
node
.
size
};
private
_getViews
(
node
:
Node
,
orientation
:
Orientation
,
box
:
Box
):
GridNode
{
if
(
node
instanceof
LeafNode
)
{
return
{
view
:
node
.
view
,
box
};
}
const
children
:
GridNode
[]
=
[];
let
offset
=
0
;
for
(
let
i
=
0
;
i
<
node
.
children
.
length
;
i
++
)
{
const
child
=
node
.
children
[
i
];
const
childOrientation
=
orthogonal
(
orientation
);
const
childBox
:
Box
=
orientation
===
Orientation
.
HORIZONTAL
?
{
top
:
box
.
top
,
left
:
box
.
left
+
offset
,
width
:
child
.
width
,
height
:
box
.
height
}
:
{
top
:
box
.
top
+
offset
,
left
:
box
.
left
,
width
:
box
.
width
,
height
:
child
.
height
};
children
.
push
(
this
.
_getViews
(
child
,
childOrientation
,
childBox
));
offset
+=
orientation
===
Orientation
.
HORIZONTAL
?
child
.
width
:
child
.
height
;
}
return
{
children
,
box
};
}
private
getNode
(
location
:
number
[],
node
:
Node
=
this
.
root
,
path
:
BranchNode
[]
=
[]):
[
BranchNode
[],
Node
]
{
...
...
src/vs/base/test/browser/ui/grid/gridview.test.ts
浏览文件 @
0bc81da1
...
...
@@ -23,7 +23,7 @@ suite('Gridview', function () {
test
(
'
empty gridview is empty
'
,
function
()
{
const
gridview
=
new
GridView
(
container
);
assert
.
deepEqual
(
gridview
.
getViews
(),
{
children
:
[],
size
:
0
}
);
assert
.
deepEqual
(
nodesToArrays
(
gridview
.
getViews
()),
[]
);
gridview
.
dispose
();
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录