save & save all

This commit is contained in:
zhandouxiaojiji committed 2020-11-04 10:32:39 +08:00
1 parent 3392630e6b
commit c4eb53ac68
5 files changed
+66 -5

No files matched your search

+14 -4
View File
@@ -1,17 +1,17 @@
import * as React from 'react';
import * as fs from 'fs';
import * as path from 'path';
import { Row, Col, message } from 'antd';
import NodePanel from './NodePanel';
import { INode } from '@antv/g6/lib/interface/item';
import G6, { TreeGraph, Util } from '@antv/g6';
import { TreeGraphData, IG6GraphEvent } from '@antv/g6/lib/types';
import G6, { TreeGraph } from '@antv/g6';
import { G6GraphEvent } from '@antv/g6/lib/interface/behavior';
import './Editor.css';
import * as Utils from '../../common/Utils';
import { BehaviorTreeModel, GraphNodeModel, BehaviorNodeModel } from '../../common/BehaviorTreeModel';
import TreePanel from './TreePanel';
import Settings from '../../main-process/Settings';
import './Editor.css';
export interface EditorProps {
filepath: string;
}
@@ -303,6 +303,16 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
this.graph.set('animate', true);
}
save() {
const { filepath } = this.props;
const root = Utils.createFileData(this.graph.findDataById('1') as GraphNodeModel);
fs.writeFileSync(filepath, JSON.stringify({
name: path.basename(filepath).slice(0, -5),
root,
desc: root.desc,
}));
}
render() {
const { curNodeId, treeModel, settings } = this.state;
var curNode: any;
+19 -1
View File
@@ -2,7 +2,7 @@
import * as ReactDOM from "react-dom";
import Editor from "./Editor";
import React, { Component } from "react";
import { Layout, Tabs } from 'antd';
import { Layout, Tabs, message } from 'antd';
import { ipcRenderer, remote } from 'electron';
import * as path from 'path';
@@ -39,6 +39,24 @@ export default class TreeTabs extends Component<TreeTabsProps, TreeTabsState> {
const editor = this.editors[curPath];
editor.createNode(name);
});
ipcRenderer.on(MainEventType.SAVE, (event: any) => {
const {curPath} = this.state;
if(!curPath) {
return;
}
const editor = this.editors[curPath];
editor.save();
message.success("已保存");
});
ipcRenderer.on(MainEventType.SAVE_ALL, (event: any) => {
for(let k in this.editors){
let editor = this.editors[k];
editor.save();
}
message.success("已保存所有行为树");
});
}
openFile(path: string) {