Skip to content

Commit 979beff

Browse files
committed
Main canvas: Add undo-redo functionality
Use the inner properties of the block script (block_trees and generated_script) for the do / undo. Connect to the EditorUndoRedoManager version_changed signal to reload the canvas.
1 parent b1aca57 commit 979beff

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

addons/block_code/ui/main_panel.gd

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ func _ready():
2828

2929
# Setup block scripting environment
3030
block_code_tab = eia.Utils.find_child_by_name(eia.context_switcher, "Block Code")
31+
undo_redo.version_changed.connect(_on_undo_redo_version_changed)
32+
33+
34+
func _on_undo_redo_version_changed():
35+
if _current_block_code_node == null:
36+
return
37+
38+
var block_script: BlockScriptData = _current_block_code_node.block_script
39+
_picker.bsd_selected(block_script)
40+
_title_bar.bsd_selected(block_script)
41+
_block_canvas.bsd_selected(block_script)
3142

3243

3344
func _on_button_pressed():
@@ -56,14 +67,16 @@ func save_script():
5667
var block_script: BlockScriptData = _current_block_code_node.block_script
5768

5869
undo_redo.create_action("Modify %s's block code script" % _current_block_code_node.get_parent().name)
59-
undo_redo.add_undo_property(_current_block_code_node, "block_script", block_script)
70+
undo_redo.add_undo_property(_current_block_code_node.block_script, "block_trees", _current_block_code_node.block_script.block_trees)
71+
undo_redo.add_undo_property(_current_block_code_node.block_script, "generated_script", _current_block_code_node.block_script.generated_script)
6072

6173
var block_trees := _block_canvas.get_canvas_block_trees()
6274
var generated_script = _block_canvas.generate_script_from_current_window(block_script.script_inherits)
6375
block_script.block_trees = block_trees
6476
block_script.generated_script = generated_script
6577

66-
undo_redo.add_do_property(_current_block_code_node, "block_script", block_script)
78+
undo_redo.add_do_property(_current_block_code_node.block_script, "block_trees", block_trees)
79+
undo_redo.add_do_property(_current_block_code_node.block_script, "generated_script", generated_script)
6780
undo_redo.commit_action()
6881

6982

0 commit comments

Comments
 (0)