Godot-Simple-TODO/addons/SimpleTODO/TODO.gd
2022-10-02 04:09:33 +02:00

70 lines
2.2 KiB
GDScript

@tool
extends Control
@onready var column_container: Control = %Columns
@onready var column_mirror: Control = %ColumnMirror
@onready var scroll_container: ScrollContainer = %ScrollContainer
var plugin: EditorPlugin
var undo_redo: UndoRedo
var item_placement_holder: Panel
func _ready() -> void:
undo_redo = UndoRedo.new()
item_placement_holder = create_drag_placement_holder()
scroll_container.get_v_scroll_bar().value_changed.connect(update_mirror)
func update_mirror(v: float):
column_mirror.visible = v > column_mirror.get_child(0).size.y
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)
func create_drag_placement_holder() -> Panel:
var new_holder: Panel = preload("res://addons/SimpleTODO/ItemPlacementHolder.tscn").instantiate()
new_holder.visible = false
add_child(new_holder)
return new_holder
func add_column(from_button := false) -> Control:
var column = preload("res://addons/SimpleTODO/TODOColumn.tscn").instantiate()
column.main = self
column.plugin = plugin
column.undo_redo = undo_redo
column.delete.connect(delete_column.bind(column))
undo_redo.create_action("Add Column")
undo_redo.add_do_method(column_container.add_child.bind(column))
undo_redo.add_do_reference(column)
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)
undo_redo.commit_action()
if from_button:
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))
return column
func delete_column(column):
undo_redo.create_action("Delete Column")
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))
undo_redo.add_undo_reference(column)
undo_redo.add_undo_method(request_save)
undo_redo.commit_action()
func request_save() -> void:
plugin.save_data()
func refresh_mirrors():
for column in column_container.get_children():
column.update_mirror.call_deferred(0)