Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
185c58e1
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,发现更多精彩内容 >>
提交
185c58e1
编写于
4月 23, 2018
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
grid view: finish addView
上级
b08db010
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
39 addition
and
24 deletion
+39
-24
src/vs/base/browser/ui/grid/gridview.ts
src/vs/base/browser/ui/grid/gridview.ts
+39
-24
未找到文件。
src/vs/base/browser/ui/grid/gridview.ts
浏览文件 @
185c58e1
...
...
@@ -29,7 +29,7 @@ function tail<T>(arr: T[]): [T[], T] {
return
[
arr
.
slice
(
0
,
arr
.
length
-
1
),
arr
[
length
-
1
]];
}
abstract
class
Node
implements
IView
{
abstract
class
Abstract
Node
implements
IView
{
abstract
minimumSize
:
number
;
abstract
maximumSize
:
number
;
...
...
@@ -49,9 +49,9 @@ abstract class Node implements IView {
}
}
class
BranchNode
extends
Node
{
class
BranchNode
extends
Abstract
Node
{
readonly
children
:
Node
[]
=
[];
private
children
:
Node
[]
=
[];
private
splitview
:
SplitView
;
constructor
(
readonly
orientation
:
Orientation
)
{
...
...
@@ -113,21 +113,30 @@ class BranchNode extends Node {
this
.
orthogonalLayout
(
this
.
orthogonalSize
);
}
getChild
(
index
:
number
):
Node
{
return
this
.
children
[
index
];
}
addChild
(
node
:
Node
,
size
:
number
,
index
:
number
):
void
{
this
.
splitview
.
addView
(
node
,
size
,
index
);
this
.
children
.
splice
(
index
,
0
,
node
);
this
.
onDidChildrenChange
();
}
removeChild
(
index
:
number
):
void
{
this
.
splitview
.
removeView
(
index
);
this
.
children
.
splice
(
index
,
1
);
this
.
onDidChildrenChange
();
}
private
onDidChildrenChange
():
void
{
const
onDidChildrenChange
=
anyEvent
(...
this
.
children
.
map
(
c
=>
c
.
onDidChange
));
this
.
_onDidChangeDisposable
.
dispose
();
this
.
_onDidChangeDisposable
=
onDidChildrenChange
(
this
.
_onDidChange
.
fire
,
this
.
_onDidChange
);
}
removeChild
(
index
:
number
):
void
{
// TODO
}
}
class
LeafNode
extends
Node
{
class
LeafNode
extends
Abstract
Node
{
constructor
(
private
view
:
IView
,
readonly
orientation
:
Orientation
)
{
super
();
...
...
@@ -147,14 +156,21 @@ class LeafNode extends Node {
}
}
type
Node
=
BranchNode
|
LeafNode
;
/**
* Explanation:
*
* it appears at first that grid nodes should be treated as tree nodes, but that's not the case
* it appears at first that grid nodes should be treated as tree nodes,
* but that's not the case.
* the tree is composed of two types of nodes: branch nodes and leaf nodes!
*
* | B *---A
* A |--- => \---*---B
* | C \---C
*/
export
class
Grid
2
{
export
class
Grid
View
{
private
root
:
BranchNode
;
...
...
@@ -164,20 +180,24 @@ export class Grid2 {
}
addView
(
view
:
IView
,
size
:
number
,
location
:
number
[]):
void
{
const
[
rest
,
index
]
=
tail
(
location
);
const
[
pathToParent
,
parent
]
=
this
.
getNode
(
rest
);
const
[
rest
,
index
]
=
tail
(
location
);
// [[], 0]
const
[
pathToParent
,
parent
]
=
this
.
getNode
(
rest
);
// [[], this.root]
const
node
=
new
LeafNode
(
view
,
orthogonal
(
parent
.
orientation
));
if
(
parent
instanceof
BranchNode
)
{
parent
.
addChild
(
node
,
size
,
index
);
}
else
{
const
[,
grandParent
]
=
tail
(
pathToParent
);
// we must split!
const
[,
grandParent
]
=
tail
(
pathToParent
);
const
[,
parentIndex
]
=
tail
(
rest
);
// 1. remove parent from grandparent
grandParent
.
removeChild
(
parentIndex
);
// 2. convert parent to Branch Node
const
newParent
=
new
BranchNode
(
parent
.
orientation
);
// 3. add parent to grandparent
grandParent
.
addChild
(
newParent
,
20
,
parentIndex
);
// 4. add node to parent
newParent
.
addChild
(
node
,
size
,
index
);
}
}
...
...
@@ -190,16 +210,8 @@ export class Grid2 {
this
.
root
.
orthogonalLayout
(
height
);
}
private
getNode
(
location
:
number
[],
path
:
BranchNode
[]
=
[
this
.
root
]):
[
BranchNode
[],
Node
]
{
private
getNode
(
location
:
number
[],
node
:
Node
=
this
.
root
,
path
:
BranchNode
[]
=
[
]):
[
BranchNode
[],
Node
]
{
if
(
location
.
length
===
0
)
{
throw
new
Error
(
'
Invalid location
'
);
}
const
parentNode
=
path
[
path
.
length
-
1
];
const
[
index
,
...
rest
]
=
location
;
const
node
=
parentNode
.
children
[
index
];
if
(
rest
.
length
===
0
)
{
return
[
path
,
node
];
}
...
...
@@ -207,7 +219,10 @@ export class Grid2 {
throw
new
Error
(
'
Invalid location
'
);
}
const
[
index
,
...
rest
]
=
location
;
const
child
=
node
.
getChild
(
index
);
path
.
push
(
node
);
return
this
.
getNode
(
rest
,
path
);
return
this
.
getNode
(
rest
,
child
,
path
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录