sidebar和tree viewer
sidebar配置
在 package.json 的 contributes 中添加:
json
"viewsContainers": {
"activitybar": [
{
"id":"sidebar_xybank",
"title": "兴业插件市场",
"icon": "./img/xybank.png"
}
]
}1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
sidebar展示内容
json
"views": {
"sidebar_xybank":[
{
"id":"sidebar_plugin",
"name":"插件中心",
"icon": "./img/yu.svg"
},
{
"id":"sidebar_wuliao",
"name":"物料中心",
"icon": "./img/xybank.png"
}
]
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
treeview
item树节点
实现一个继承父类vscode.TreeItem
ts
export class ConfigEntryItem extends vscode.TreeItem
{
parentPath?: string;
}1
2
3
4
2
3
4
树的内容组织管理
ts
export class ProjEntryList implements vscode.TreeDataProvider<ConfigEntryItem>
{
proj?: string ;
constructor(proj?: string) {
this.proj = proj;
}
onDidChangeTreeData?: vscode.Event<void | ConfigEntryItem | null | undefined> | undefined;
getTreeItem(element: ConfigEntryItem): vscode.TreeItem | Thenable<vscode.TreeItem> {
return element;
}
getChildren(element?: ConfigEntryItem): vscode.ProviderResult<ConfigEntryItem[]> {
console.log("sidebar by proj");
if (element) {//子节点
console.log(element);
var el = element.label?.toString();
if(!el){
el = "";
}
var pp = element.parentPath;
if(!pp){
pp = "";
}
var srcPath = path.join(pp, el);
var childs2 = this.getChilds(srcPath);
return childs2;
} else { //根节点
var srcDir = "";
if (this.proj === "yuemacs"){
srcDir = "/opt/dir/yuemacs";
}else if (this.proj === "yunvim"){
srcDir = "/opt/dir/yulove/etc/nvim2";
}
var childs = this.getChilds(srcDir);
return childs;
}
}
getChilds(srcDir:string): vscode.ProviderResult<ConfigEntryItem[]> {
var childs:ConfigEntryItem[] = [];
var files = fs.readdirSync(srcDir);
files.forEach( f =>{
if(f === ".git" || f === ".gitignore" || f === ".cache" || f=== ".lsp-session-v1" || f===".yu"){
return;
}
var srcPath = path.join(srcDir, f);
const isDir = fs.lstatSync(srcPath).isDirectory();
if (!isDir) {
var item = new ConfigEntryItem(f,vscode.TreeItemCollapsibleState.None);
item.iconPath= path.join(pub.Info.iconsPath, "file_type_affinitydesigner.svg");
item.command = {command:"yuvscode.yuopen", //命令id
arguments:[srcPath] //命令接收的参数
};
childs.push(item);
}else{
var item = new ConfigEntryItem(f,vscode.TreeItemCollapsibleState.Collapsed);
item.parentPath = srcDir;
item.iconPath= path.join(pub.Info.iconsPath, "default_folder.svg");
childs.push(item);
}
});
return childs;
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
- getChildren方法是最重要的方法,
- 入参是element: 返回值是TreeItem数组,代表这一层级的所有的元素集合。就是点击各个子目录传递的element
- 入参是undefined: 说明是根结点。
- vscode.TreeItem
- iconPath 图标
- command 点击执行的命令