Godot-Simple-TODO/addons/SimpleTODO/TODO.gd

70 lines
2.2 KiB
GDScript3
Raw Normal View History

2022-09-29 00:18:13 +02:00
@tool
extends Control
2022-02-01 00:56:02 +01:00
2022-09-29 00:18:13 +02:00
@onready var column_container: Control = %Columns
@onready var column_mirror: Control = %ColumnMirror
@onready var scroll_container: ScrollContainer = %ScrollContainer
var plugin: EditorPlugin
2022-09-25 20:35:51 +02:00
2022-02-01 00:56:02 +01:00
var undo_redo: UndoRedo
2022-09-29 00:18:13 +02:00
var item_placement_holder: Panel
2022-02-01 00:56:02 +01:00
func _ready() -> void:
undo_redo = UndoRedo.new()
2022-09-29 00:18:13 +02:00
item_placement_holder = create_drag_placement_holder()
scroll_container.get_v_scroll_bar().value_changed.connect(update_mirror)
2022-09-25 20:35:51 +02:00
func update_mirror(v: float):
2022-09-29 00:18:13 +02:00
column_mirror.visible = v > column_mirror.get_child(0).size.y
2022-09-25 20:35:51 +02:00
2022-09-29 00:18:13 +02:00
func connect_scrollbar(to_method: Callable):
scroll_container.get_h_scroll_bar().value_changed.connect(to_method)
scroll_container.get_v_scroll_bar().value_changed.connect(to_method)
2022-02-01 00:56:02 +01:00
func create_drag_placement_holder() -> Panel:
2022-09-29 00:18:13 +02:00
var new_holder: Panel = preload("res://addons/SimpleTODO/ItemPlacementHolder.tscn").instantiate()
new_holder.visible = false
add_child(new_holder)
return new_holder
2022-02-01 00:56:02 +01:00
func add_column(from_button := false) -> Control:
2022-09-29 00:18:13 +02:00
var column = preload("res://addons/SimpleTODO/TODOColumn.tscn").instantiate()
column.main = self
2022-09-29 00:18:13 +02:00
column.plugin = plugin
2022-02-01 00:56:02 +01:00
column.undo_redo = undo_redo
2022-09-29 00:18:13 +02:00
column.delete.connect(delete_column.bind(column))
2022-02-01 00:56:02 +01:00
undo_redo.create_action("Add Column")
2022-09-29 00:18:13 +02:00
undo_redo.add_do_method(column_container.add_child.bind(column))
2022-02-01 00:56:02 +01:00
undo_redo.add_do_reference(column)
2022-09-29 00:18:13 +02:00
undo_redo.add_do_method(request_save)
undo_redo.add_undo_method(column_container.remove_child.bind(column))
undo_redo.add_undo_method(request_save)
2022-02-01 00:56:02 +01:00
undo_redo.commit_action()
if from_button:
2022-09-29 00:18:13 +02:00
column.header.name_edit.grab_focus.call_deferred()
column.header.name_edit.select_all.call_deferred()
get_tree().create_timer(0.1).timeout.connect(scroll_container.ensure_control_visible.bind(column))
2022-02-01 00:56:02 +01:00
return column
func delete_column(column):
undo_redo.create_action("Delete Column")
2022-09-29 00:18:13 +02:00
undo_redo.add_do_method(column_container.remove_child.bind(column))
undo_redo.add_do_method(request_save)
undo_redo.add_undo_method(column_container.add_child.bind(column))
2022-02-01 00:56:02 +01:00
undo_redo.add_undo_reference(column)
2022-09-29 00:18:13 +02:00
undo_redo.add_undo_method(request_save)
2022-02-01 00:56:02 +01:00
undo_redo.commit_action()
func request_save() -> void:
2022-09-29 00:18:13 +02:00
plugin.save_data()
2022-09-25 20:35:51 +02:00
func refresh_mirrors():
for column in column_container.get_children():
2022-09-29 00:18:13 +02:00
column.update_mirror.call_deferred(0)