undo & redo for file info
This commit is contained in:
1 parent
4d1d09fe80
commit
d9dbf15d30
5 files changed
+44
-15
No files matched your search
@@ -3,7 +3,9 @@
|
||||
"desc": "",
|
||||
"firstid": 1,
|
||||
"export": true,
|
||||
"import": ["vars/declare-core.json"],
|
||||
"import": [
|
||||
"vars/declare-core.json"
|
||||
],
|
||||
"declvar": [
|
||||
{
|
||||
"name": "owner",
|
||||
@@ -17,5 +19,6 @@
|
||||
"root": {
|
||||
"id": 1,
|
||||
"name": "Sequence"
|
||||
}
|
||||
},
|
||||
"group": []
|
||||
}
|
||||
@@ -18,10 +18,6 @@
|
||||
{
|
||||
"name": "target1",
|
||||
"desc": "其它目标"
|
||||
},
|
||||
{
|
||||
"name": "test",
|
||||
"desc": "测试"
|
||||
}
|
||||
],
|
||||
"root": {
|
||||
|
||||
@@ -218,6 +218,8 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
relative: state.relative,
|
||||
updateFileMeta: state.updateFileMeta,
|
||||
nodeDefs: state.nodeDefs,
|
||||
editingTree: state.editingTree,
|
||||
editingNode: state.editingNode,
|
||||
}))
|
||||
);
|
||||
|
||||
@@ -550,6 +552,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
b3util.updateUsingGroups(editor.data.group);
|
||||
b3util.updateUsingVars(collectVarDefs(editor));
|
||||
pushHistory();
|
||||
refresh();
|
||||
onChange();
|
||||
}
|
||||
@@ -584,7 +587,16 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
|
||||
const pushHistory = () => {
|
||||
editor.historyStack.length = ++editor.historyIndex;
|
||||
editor.historyStack.push(b3util.createNode(editor.root));
|
||||
editor.historyStack.push(
|
||||
JSON.stringify(
|
||||
{
|
||||
...editor.data,
|
||||
root: b3util.createNode(editor.root),
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const copyNode = () => {
|
||||
@@ -728,13 +740,23 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
editor.graph.findById(data.id)?.draw();
|
||||
};
|
||||
|
||||
const useStackData = (data: NodeModel) => {
|
||||
editor.root = createTreeData(data);
|
||||
const useStackData = (str: string) => {
|
||||
const data = JSON.parse(str) as TreeModel;
|
||||
editor.data = data;
|
||||
editor.root = createTreeData(data.root);
|
||||
editor.import = data.import.map((v) => ({ path: v, vars: [] }));
|
||||
editor.declvar = data.declvar.map((v) => ({ ...v }));
|
||||
editor.autoId = b3util.refreshTreeDataId(editor.root, editor.data.firstid);
|
||||
editor.graph.changeData(editor.root);
|
||||
editor.graph.layout();
|
||||
restoreViewport();
|
||||
onChange();
|
||||
|
||||
if (workspace.editingTree) {
|
||||
workspace.onEditingTree(editor);
|
||||
} else if (workspace.editingNode) {
|
||||
selectNode(workspace.editingNode.data.id.toString());
|
||||
}
|
||||
};
|
||||
|
||||
const updateGrahp = () => {
|
||||
@@ -744,16 +766,14 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
|
||||
const undo = () => {
|
||||
if (editor.historyIndex > 0) {
|
||||
const data = editor.historyStack[--editor.historyIndex];
|
||||
useStackData(data);
|
||||
useStackData(editor.historyStack[--editor.historyIndex]);
|
||||
updateSearchState();
|
||||
}
|
||||
};
|
||||
|
||||
const redo = () => {
|
||||
if (editor.historyIndex < editor.historyStack.length - 1) {
|
||||
const data = editor.historyStack[++editor.historyIndex];
|
||||
useStackData(data);
|
||||
useStackData(editor.historyStack[++editor.historyIndex]);
|
||||
updateSearchState();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -58,7 +58,7 @@ export class EditorStore {
|
||||
alertReload: boolean = false;
|
||||
searchingText?: string;
|
||||
|
||||
historyStack: NodeModel[] = [];
|
||||
historyStack: string[] = [];
|
||||
historyIndex: number = 0;
|
||||
selectedId?: string | null;
|
||||
|
||||
@@ -79,7 +79,16 @@ export class EditorStore {
|
||||
this.import = this.data.import.map((v) => ({ path: v, vars: [] }));
|
||||
this.declvar = this.data.declvar.map((v) => ({ ...v }));
|
||||
this.autoId = b3util.refreshTreeDataId(this.root, this.data.firstid);
|
||||
this.historyStack.push(b3util.createNode(this.root));
|
||||
this.historyStack.push(
|
||||
JSON.stringify(
|
||||
{
|
||||
...this.data,
|
||||
root: b3util.createNode(this.root),
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
);
|
||||
this.historyIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -721,6 +721,7 @@ export const loadVarDef = (list: ImportDef[]) => {
|
||||
// TODO: check file date
|
||||
// TODO: use cache
|
||||
if (entry.vars.length) {
|
||||
entry.vars.forEach((v) => all.add(v));
|
||||
continue;
|
||||
}
|
||||
const filter: Map<string, boolean> = new Map();
|
||||
|
||||
Reference in new issue
Block a user