Properties load files
This commit is contained in:
1 parent
23f4795562
commit
3a68247afd
3 files changed
+62
-10
No files matched your search
@@ -1,6 +1,7 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { Menu, Input } from "antd";
|
import { Menu, Input } from "antd";
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
import * as path from 'path';
|
||||||
import { BehaviorTreeModel } from "../../common/BehaviorTreeModel";
|
import { BehaviorTreeModel } from "../../common/BehaviorTreeModel";
|
||||||
import { remote } from 'electron';
|
import { remote } from 'electron';
|
||||||
import { MainProcess } from "../../main-process/MainProcess";
|
import { MainProcess } from "../../main-process/MainProcess";
|
||||||
@@ -8,28 +9,60 @@ import Settings from "../../main-process/Settings";
|
|||||||
|
|
||||||
const { Search } = Input;
|
const { Search } = Input;
|
||||||
|
|
||||||
|
interface TreeFile {
|
||||||
|
name: string;
|
||||||
|
path: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface PropertiesProps {
|
export interface PropertiesProps {
|
||||||
workspace: string;
|
workspace: string;
|
||||||
onOpenTree: (path: string) => void;
|
onOpenTree: (path: string) => void;
|
||||||
trees: BehaviorTreeModel[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PropertiesState {
|
interface PropertiesState {
|
||||||
|
treeList: TreeFile[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Properties extends Component<PropertiesProps> {
|
export default class Properties extends Component<PropertiesProps> {
|
||||||
state: PropertiesState = {
|
state: PropertiesState = {
|
||||||
|
treeList: []
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
var workspace = this.props.workspace;
|
||||||
|
if (workspace == '') {
|
||||||
|
workspace = this.getLastWorkspace();
|
||||||
|
}
|
||||||
|
this.setState({ treeList: this.getTreeList(workspace) });
|
||||||
|
}
|
||||||
|
|
||||||
|
getLastWorkspace() {
|
||||||
const settings: Settings = remote.getGlobal("settings");
|
const settings: Settings = remote.getGlobal("settings");
|
||||||
const lastWorkspace = settings.recentWorkspaces[0];
|
return settings.recentWorkspaces[0];
|
||||||
console.log("&&&&&& last workspace", lastWorkspace);
|
}
|
||||||
|
|
||||||
|
getTreeList(workspace: string) {
|
||||||
|
if (workspace == '' || !fs.existsSync(workspace)) {
|
||||||
|
console.log("workspace not exist", workspace);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const files = fs.readdirSync(workspace);
|
||||||
|
const list: TreeFile[] = [];
|
||||||
|
files.forEach((filename) => {
|
||||||
|
const stat = fs.statSync(path.join(workspace, filename))
|
||||||
|
if (stat.isFile()) {
|
||||||
|
list.push({
|
||||||
|
name: filename.slice(0, -5),
|
||||||
|
path: workspace + '/' + name + '.json'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { treeList } = this.state;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Search
|
<Search
|
||||||
@@ -38,10 +71,16 @@ export default class Properties extends Component<PropertiesProps> {
|
|||||||
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Menu
|
<Menu
|
||||||
mode="inline"
|
mode="inline"
|
||||||
>
|
>
|
||||||
<Menu.Item>test</Menu.Item>
|
{treeList.map((tree) => (
|
||||||
|
<Menu.Item
|
||||||
|
key={tree.name}
|
||||||
|
>
|
||||||
|
{tree.name}
|
||||||
|
</Menu.Item>
|
||||||
|
))}
|
||||||
</Menu>
|
</Menu>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -34,10 +34,8 @@ export default class Editor extends Component {
|
|||||||
ipcRenderer.on(MainEventType.OPEN_WORKSPACE, (event: any, workspace: any) => {
|
ipcRenderer.on(MainEventType.OPEN_WORKSPACE, (event: any, workspace: any) => {
|
||||||
console.log("on open workspace", workspace);
|
console.log("on open workspace", workspace);
|
||||||
this.setState({ workspace });
|
this.setState({ workspace });
|
||||||
this.loadAllTrees();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.loadAllTrees();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadAllTrees() {
|
loadAllTrees() {
|
||||||
@@ -89,7 +87,6 @@ export default class Editor extends Component {
|
|||||||
onOpenTree={(path) => {
|
onOpenTree={(path) => {
|
||||||
console.log("open tree", path);
|
console.log("open tree", path);
|
||||||
}}
|
}}
|
||||||
trees={trees}
|
|
||||||
/>
|
/>
|
||||||
</Sider>
|
</Sider>
|
||||||
<Content className="content">
|
<Content className="content">
|
||||||
|
|||||||
@@ -2,3 +2,19 @@ body {
|
|||||||
background-color: #242424;
|
background-color: #242424;
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar
|
||||||
|
{
|
||||||
|
background-color: #a0a0a0;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-track
|
||||||
|
{
|
||||||
|
background-color:#1d1d1d;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-thumb
|
||||||
|
{
|
||||||
|
height:50px;
|
||||||
|
background-color:#818181;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user