Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
f59d7adb
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,发现更多精彩内容 >>
提交
f59d7adb
编写于
4月 23, 2018
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
grid view: get views
上级
f3a71463
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
52 addition
and
26 deletion
+52
-26
src/vs/base/browser/ui/grid/gridview.ts
src/vs/base/browser/ui/grid/gridview.ts
+52
-26
未找到文件。
src/vs/base/browser/ui/grid/gridview.ts
浏览文件 @
f59d7adb
...
@@ -15,14 +15,24 @@ function orthogonal(orientation: Orientation): Orientation {
...
@@ -15,14 +15,24 @@ function orthogonal(orientation: Orientation): Orientation {
return
orientation
===
Orientation
.
VERTICAL
?
Orientation
.
HORIZONTAL
:
Orientation
.
VERTICAL
;
return
orientation
===
Orientation
.
VERTICAL
?
Orientation
.
HORIZONTAL
:
Orientation
.
VERTICAL
;
}
}
export
interface
IGrid
{
export
interface
ILeafNode
<
T
extends
IView
>
{
view
:
T
;
}
export
interface
IBranchNode
<
T
extends
IView
>
{
children
:
IGridNode
<
T
>
[];
}
export
type
IGridNode
<
T
extends
IView
>
=
ILeafNode
<
T
>
|
IBranchNode
<
T
>
;
export
interface
IGrid
<
T
extends
IView
>
{
layout
(
width
:
number
,
height
:
number
):
void
;
layout
(
width
:
number
,
height
:
number
):
void
;
addView
(
view
:
IView
,
size
:
number
,
location
:
number
[]):
void
;
addView
(
view
:
IView
,
size
:
number
,
location
:
number
[]):
void
;
removeView
(
location
:
number
[]):
void
;
removeView
(
location
:
number
[]):
void
;
moveView
(
from
:
number
[],
to
:
number
[]):
void
;
moveView
(
from
:
number
[],
to
:
number
[]):
void
;
resizeView
(
location
:
number
[],
size
:
number
):
void
;
resizeView
(
location
:
number
[],
size
:
number
):
void
;
getViewSize
(
location
:
number
[]):
number
;
getViewSize
(
location
:
number
[]):
number
;
// getViews(): ITreeNode<T>[]
;
getViews
():
IBranchNode
<
T
>
;
}
}
function
tail
<
T
>
(
arr
:
T
[]):
[
T
[],
T
]
{
function
tail
<
T
>
(
arr
:
T
[]):
[
T
[],
T
]
{
...
@@ -49,9 +59,9 @@ abstract class AbstractNode implements IView {
...
@@ -49,9 +59,9 @@ abstract class AbstractNode implements IView {
}
}
}
}
class
BranchNode
extends
AbstractNode
{
class
BranchNode
<
T
extends
IView
>
extends
AbstractNode
{
private
children
:
Node
[]
=
[];
readonly
children
:
Node
<
T
>
[]
=
[];
private
splitview
:
SplitView
;
private
splitview
:
SplitView
;
get
minimumSize
():
number
{
get
minimumSize
():
number
{
...
@@ -86,10 +96,6 @@ class BranchNode extends AbstractNode {
...
@@ -86,10 +96,6 @@ class BranchNode extends AbstractNode {
return
result
;
return
result
;
}
}
get
length
():
number
{
return
this
.
children
.
length
;
}
private
_onDidChange
=
new
Emitter
<
number
|
undefined
>
();
private
_onDidChange
=
new
Emitter
<
number
|
undefined
>
();
get
onDidChange
():
Event
<
number
|
undefined
>
{
return
this
.
_onDidChange
.
event
;
}
get
onDidChange
():
Event
<
number
|
undefined
>
{
return
this
.
_onDidChange
.
event
;
}
private
_onDidChangeDisposable
:
IDisposable
=
EmptyDisposable
;
private
_onDidChangeDisposable
:
IDisposable
=
EmptyDisposable
;
...
@@ -117,17 +123,13 @@ class BranchNode extends AbstractNode {
...
@@ -117,17 +123,13 @@ class BranchNode extends AbstractNode {
this
.
orthogonalLayout
(
this
.
orthogonalSize
);
this
.
orthogonalLayout
(
this
.
orthogonalSize
);
}
}
getChild
(
index
:
number
):
Node
{
addChild
(
node
:
Node
<
T
>
,
size
:
number
,
index
:
number
):
void
{
return
this
.
children
[
index
];
}
addChild
(
node
:
Node
,
size
:
number
,
index
:
number
):
void
{
this
.
splitview
.
addView
(
node
,
size
,
index
);
this
.
splitview
.
addView
(
node
,
size
,
index
);
this
.
children
.
splice
(
index
,
0
,
node
);
this
.
children
.
splice
(
index
,
0
,
node
);
this
.
onDidChildrenChange
();
this
.
onDidChildrenChange
();
}
}
removeChild
(
index
:
number
):
Node
{
removeChild
(
index
:
number
):
Node
<
T
>
{
const
child
=
this
.
children
[
index
];
const
child
=
this
.
children
[
index
];
this
.
splitview
.
removeView
(
index
);
this
.
splitview
.
removeView
(
index
);
this
.
children
.
splice
(
index
,
1
);
this
.
children
.
splice
(
index
,
1
);
...
@@ -142,9 +144,9 @@ class BranchNode extends AbstractNode {
...
@@ -142,9 +144,9 @@ class BranchNode extends AbstractNode {
}
}
}
}
class
LeafNode
extends
AbstractNode
{
class
LeafNode
<
T
extends
IView
>
extends
AbstractNode
{
constructor
(
private
view
:
IView
,
readonly
orientation
:
Orientation
)
{
constructor
(
readonly
view
:
T
,
readonly
orientation
:
Orientation
)
{
super
();
super
();
}
}
...
@@ -162,7 +164,7 @@ class LeafNode extends AbstractNode {
...
@@ -162,7 +164,7 @@ class LeafNode extends AbstractNode {
}
}
}
}
type
Node
=
BranchNode
|
LeafNode
;
type
Node
<
T
extends
IView
>
=
BranchNode
<
T
>
|
LeafNode
<
T
>
;
/**
/**
* Explanation:
* Explanation:
...
@@ -176,19 +178,19 @@ type Node = BranchNode | LeafNode;
...
@@ -176,19 +178,19 @@ type Node = BranchNode | LeafNode;
* | C \---C
* | C \---C
*/
*/
export
class
GridView
{
export
class
GridView
<
T
extends
IView
>
implements
IGrid
<
T
>
{
private
root
:
BranchNode
;
private
root
:
BranchNode
<
T
>
;
constructor
(
container
:
HTMLElement
)
{
constructor
(
container
:
HTMLElement
)
{
this
.
root
=
new
BranchNode
(
Orientation
.
VERTICAL
);
this
.
root
=
new
BranchNode
(
Orientation
.
VERTICAL
);
this
.
root
.
render
(
container
);
this
.
root
.
render
(
container
);
}
}
addView
(
view
:
IView
,
size
:
number
,
location
:
number
[]):
void
{
addView
(
view
:
T
,
size
:
number
,
location
:
number
[]):
void
{
const
[
rest
,
index
]
=
tail
(
location
);
const
[
rest
,
index
]
=
tail
(
location
);
const
[
pathToParent
,
parent
]
=
this
.
getNode
(
rest
);
const
[
pathToParent
,
parent
]
=
this
.
getNode
(
rest
);
const
node
=
new
LeafNode
(
view
,
orthogonal
(
parent
.
orientation
));
const
node
=
new
LeafNode
<
T
>
(
view
,
orthogonal
(
parent
.
orientation
));
if
(
parent
instanceof
BranchNode
)
{
if
(
parent
instanceof
BranchNode
)
{
parent
.
addChild
(
node
,
size
,
index
);
parent
.
addChild
(
node
,
size
,
index
);
...
@@ -199,7 +201,7 @@ export class GridView {
...
@@ -199,7 +201,7 @@ export class GridView {
// 1. remove parent from grandparent
// 1. remove parent from grandparent
grandParent
.
removeChild
(
parentIndex
);
grandParent
.
removeChild
(
parentIndex
);
// 2. convert parent to Branch Node
// 2. convert parent to Branch Node
const
newParent
=
new
BranchNode
(
parent
.
orientation
);
const
newParent
=
new
BranchNode
<
T
>
(
parent
.
orientation
);
// 3. add parent to grandparent
// 3. add parent to grandparent
grandParent
.
addChild
(
newParent
,
20
,
parentIndex
);
grandParent
.
addChild
(
newParent
,
20
,
parentIndex
);
// 4. add node to parent
// 4. add node to parent
...
@@ -217,11 +219,11 @@ export class GridView {
...
@@ -217,11 +219,11 @@ export class GridView {
parent
.
removeChild
(
index
);
parent
.
removeChild
(
index
);
if
(
parent
.
length
===
0
)
{
if
(
parent
.
children
.
length
===
0
)
{
throw
new
Error
(
'
Invalid grid state
'
);
throw
new
Error
(
'
Invalid grid state
'
);
}
}
if
(
parent
.
length
>
1
)
{
if
(
parent
.
children
.
length
>
1
)
{
return
;
return
;
}
}
...
@@ -242,7 +244,31 @@ export class GridView {
...
@@ -242,7 +244,31 @@ export class GridView {
this
.
root
.
orthogonalLayout
(
height
);
this
.
root
.
orthogonalLayout
(
height
);
}
}
private
getNode
(
location
:
number
[],
node
:
Node
=
this
.
root
,
path
:
BranchNode
[]
=
[]):
[
BranchNode
[],
Node
]
{
moveView
(
from
:
number
[],
to
:
number
[]):
void
{
throw
new
Error
(
'
Method not implemented.
'
);
}
resizeView
(
location
:
number
[],
size
:
number
):
void
{
throw
new
Error
(
'
Method not implemented.
'
);
}
getViewSize
(
location
:
number
[]):
number
{
throw
new
Error
(
'
Method not implemented.
'
);
}
getViews
():
IBranchNode
<
T
>
{
return
this
.
_getViews
(
this
.
root
)
as
IBranchNode
<
T
>
;
}
private
_getViews
(
node
:
Node
<
T
>
):
IGridNode
<
T
>
{
if
(
node
instanceof
BranchNode
)
{
return
{
children
:
node
.
children
.
map
(
c
=>
this
.
_getViews
(
c
))
};
}
else
{
return
{
view
:
node
.
view
};
}
}
private
getNode
(
location
:
number
[],
node
:
Node
<
T
>
=
this
.
root
,
path
:
BranchNode
<
T
>
[]
=
[]):
[
BranchNode
<
T
>
[],
Node
<
T
>
]
{
if
(
location
.
length
===
0
)
{
if
(
location
.
length
===
0
)
{
return
[
path
,
node
];
return
[
path
,
node
];
}
}
...
@@ -252,7 +278,7 @@ export class GridView {
...
@@ -252,7 +278,7 @@ export class GridView {
}
}
const
[
index
,
...
rest
]
=
location
;
const
[
index
,
...
rest
]
=
location
;
const
child
=
node
.
getChild
(
index
)
;
const
child
=
node
.
children
[
index
]
;
path
.
push
(
node
);
path
.
push
(
node
);
return
this
.
getNode
(
rest
,
child
,
path
);
return
this
.
getNode
(
rest
,
child
,
path
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录