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

106 lines
2.7 KiB
GDScript3
Raw Normal View History

2022-09-29 00:18:13 +02:00
@tool
2022-02-01 00:56:02 +01:00
extends EditorPlugin
const DATA_FILE = "res://TODO.cfg"
var todo_screen: Control
var is_loading: bool
2022-09-29 00:18:13 +02:00
func _get_plugin_name():
2022-02-01 00:56:02 +01:00
return "TODO"
2022-09-29 00:18:13 +02:00
func _get_plugin_icon():
return get_editor_interface().get_base_control().get_theme_icon(&"CheckBox", &"EditorIcons")
2022-02-01 00:56:02 +01:00
2022-09-29 00:18:13 +02:00
func _has_main_screen() -> bool:
2022-02-01 00:56:02 +01:00
return true
func _enter_tree():
2022-09-29 00:18:13 +02:00
todo_screen = preload("res://addons/SimpleTODO/TODO.tscn").instantiate()
todo_screen.plugin = self
2022-02-01 00:56:02 +01:00
todo_screen.hide()
2022-09-29 00:18:13 +02:00
get_editor_interface().get_editor_main_screen().add_child(todo_screen)
2022-02-01 00:56:02 +01:00
load_data()
print("TODO loaded")
2022-02-01 00:56:02 +01:00
func _ready() -> void:
set_process_input(false)
2022-09-29 00:18:13 +02:00
func _set_window_layout(configuration: ConfigFile):
if configuration.has_section("SimpleTODO"):
var minimized_tabs = configuration.get_value("SimpleTODO", "minimized_tabs")
if minimized_tabs.size() <= 0:
return
for i in todo_screen.column_container.get_child_count():
2022-09-29 00:18:13 +02:00
var column: PanelContainer = todo_screen.column_container.get_child(i)
column.set_minimized.call_deferred(minimized_tabs[i])
2022-09-29 00:18:13 +02:00
func _get_window_layout(configuration: ConfigFile):
var new_minimized_tabs = []
2022-09-29 00:18:13 +02:00
for column in todo_screen.column_container.get_children():
2022-09-29 00:18:13 +02:00
if not column is PanelContainer:
continue
new_minimized_tabs.append(column.minimized)
configuration.set_value("SimpleTODO", "minimized_tabs", new_minimized_tabs)
2022-02-01 00:56:02 +01:00
func _exit_tree():
todo_screen.queue_free()
2022-09-29 00:18:13 +02:00
func _make_visible(visible: bool) -> void:
2022-02-01 00:56:02 +01:00
todo_screen.visible = visible
set_process_input(visible)
func _input(event: InputEvent) -> void:
if event is InputEventKey:
if event.pressed:
2022-09-29 00:18:13 +02:00
if event.is_command_or_control_pressed():
if event.keycode == KEY_Z:
2022-02-01 00:56:02 +01:00
todo_screen.undo_redo.undo()
get_viewport().set_input_as_handled()
2022-09-29 00:18:13 +02:00
elif event.keycode == KEY_Y:
2022-02-01 00:56:02 +01:00
todo_screen.undo_redo.redo()
get_viewport().set_input_as_handled()
func save_data():
if is_loading:
return
2022-09-29 00:18:13 +02:00
var data := ConfigFile.new()
2022-02-01 00:56:02 +01:00
for column in todo_screen.column_container.get_children():
2022-09-29 00:18:13 +02:00
var section = column.header.name_edit.text
2022-02-01 00:56:02 +01:00
if column.item_container.get_child_count() > 0:
for item in column.item_container.get_children():
data.set_value(section, str("item", item.id), item.text_field.text)
2022-02-01 00:56:02 +01:00
else:
data.set_value(section, "__none__", "null")
data.save(DATA_FILE)
func load_data():
2022-09-29 00:18:13 +02:00
var data := ConfigFile.new()
2022-02-01 00:56:02 +01:00
data.load(DATA_FILE)
is_loading = true
for section in data.get_sections():
var column = todo_screen.add_column()
2022-09-25 20:35:51 +02:00
column.set_name(section)
2022-09-29 00:18:13 +02:00
2022-02-01 00:56:02 +01:00
for item in data.get_section_keys(section):
if item == "__none__":
continue
var column_item = column.add_item()
column_item.text_field.text = data.get_value(section, item)
column_item.id = item.to_int()
2022-02-01 00:56:02 +01:00
todo_screen.undo_redo.clear_history()
is_loading = false