Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/ui_parts/settings_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ func get_content(index: TabIndex) -> Control:
match index:
TabIndex.FORMATTING:
current_content = SettingsContentGeneric.instantiate()
current_content.undo_redo = undo_redo
current_content.setup([Configs.savedata.editor_formatter,
Configs.savedata.export_formatter] as Array[ConfigResource], current_content.setup_formatting_content)
current_content.preview_changed.connect(set_preview)
TabIndex.OPTIMIZER:
current_content = SettingsContentGeneric.instantiate()
current_content.undo_redo = undo_redo
current_content.setup([Configs.savedata.default_optimizer] as Array[ConfigResource], current_content.setup_optimizer_content)
TabIndex.PALETTES:
current_content = SettingsContentPalettes.instantiate()
Expand All @@ -87,6 +89,7 @@ func get_content(index: TabIndex) -> Control:
settings_tab_container.select_tab.bind(TabIndex.SHORTCUTS))
TabIndex.THEMING, TabIndex.TAB_BAR, TabIndex.OTHER:
current_content = SettingsContentGeneric.instantiate()
current_content.undo_redo = undo_redo
var callback := Callable()
match index:
TabIndex.THEMING: callback = current_content.setup_theming_content
Expand Down
7 changes: 5 additions & 2 deletions src/ui_widgets/UndoRedoRef.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ var _undo_redo := UndoRedo.new()
func _init() -> void:
_undo_redo.version_changed.connect(version_changed.emit)

func create_action(name := "") -> void:
_undo_redo.create_action(name)
func create_action(name := "", merge_mode := UndoRedo.MERGE_DISABLE, backward_undo_ops := false) -> void:
_undo_redo.create_action(name, merge_mode, backward_undo_ops)

func add_do_method(callable: Callable) -> void:
_undo_redo.add_do_method(callable)
Expand Down Expand Up @@ -47,6 +47,9 @@ func has_undo() -> bool:
func has_redo() -> bool:
return _undo_redo.has_redo()

func is_committing_action() -> bool:
return _undo_redo.is_committing_action()

func clear_history() -> void:
_undo_redo.clear_history()

Expand Down
15 changes: 14 additions & 1 deletion src/ui_widgets/settings_content_generic.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const ProfileFrameScene = preload("res://src/ui_widgets/profile_frame.tscn")
var current_setup_resources: Array[ConfigResource]
var setup_method: Callable

var undo_redo: UndoRedoRef

var current_setup_setting := ""
var current_setup_resource_index := 0
var current_setup_container: VBoxContainer
Expand Down Expand Up @@ -75,6 +77,8 @@ class SettingCanvasPreview:

func _ready() -> void:
Configs.language_changed.connect(setup_content)
undo_redo.version_changed.connect(_on_undo_redo_version_changed)
tree_exiting.connect(undo_redo.version_changed.disconnect.bind(_on_undo_redo_version_changed), CONNECT_ONE_SHOT)
if current_setup_resources.size() > 1:
var categories := HFlowContainer.new()
categories.alignment = FlowContainer.ALIGNMENT_CENTER
Expand Down Expand Up @@ -120,6 +124,10 @@ func setup_content() -> void:
setup_method.call()
HandlerGUI.throw_mouse_motion_event()

func _on_undo_redo_version_changed() -> void:
if not undo_redo.is_committing_action():
setup_content()

func setup_formatting_content() -> void:
var current_setup_resource: Formatter = _get_current_setup_resource()

Expand Down Expand Up @@ -829,7 +837,12 @@ func _add_file_path_edit(text: String, extensions_list: PackedStringArray) -> Co
func setup_frame(frame: Control, has_default := true) -> void:
var bind := current_setup_setting
var resource_ref := _get_current_setup_resource()
frame.setter = func(p: Variant) -> void: resource_ref.set(bind, p)
frame.setter = func(p: Variant) -> void:
if resource_ref.get(bind) != p:
undo_redo.create_action(bind, UndoRedo.MERGE_ENDS, false)
undo_redo.add_do_method(resource_ref.set.bind(bind, p))
undo_redo.add_undo_method(resource_ref.set.bind(bind, resource_ref.get(bind)))
undo_redo.commit_action()
frame.getter = resource_ref.get.bind(bind)
if has_default:
frame.default = resource_ref.get_setting_default(current_setup_setting)
Expand Down