2023-01-07 20:26:17 +01:00
|
|
|
extends Control
|
|
|
|
@tool
|
|
|
|
|
|
|
|
var _interface = null
|
2023-01-20 23:34:39 +01:00
|
|
|
var _utils = load("res://addons/gut/utils.gd").new()
|
2023-01-07 20:26:17 +01:00
|
|
|
var _hide_passing = true
|
|
|
|
var _font = null
|
|
|
|
var _font_size = null
|
|
|
|
var _root = null
|
|
|
|
var _max_icon_width = 10
|
2023-01-20 23:34:39 +01:00
|
|
|
var _editors = null # script_text_editor_controls.gd
|
2023-01-07 20:26:17 +01:00
|
|
|
var _show_orphans = true
|
|
|
|
var _output_control = null
|
|
|
|
|
|
|
|
const _col_1_bg_color = Color(0, 0, 0, .1)
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
var _icons = {
|
|
|
|
red = load("res://addons/gut/images/red.png"),
|
|
|
|
green = load("res://addons/gut/images/green.png"),
|
|
|
|
yellow = load("res://addons/gut/images/yellow.png"),
|
2023-01-07 20:26:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
signal search_for_text(text)
|
|
|
|
|
|
|
|
@onready var _ctrls = {
|
|
|
|
tree = $VBox/Output/Scroll/Tree,
|
|
|
|
lbl_overlay = $VBox/Output/OverlayMessage,
|
|
|
|
chk_hide_passing = $VBox/Toolbar/HidePassing,
|
2023-01-20 23:34:39 +01:00
|
|
|
toolbar =
|
|
|
|
{
|
2023-01-07 20:26:17 +01:00
|
|
|
toolbar = $VBox/Toolbar,
|
|
|
|
collapse = $VBox/Toolbar/Collapse,
|
|
|
|
collapse_all = $VBox/Toolbar/CollapseAll,
|
|
|
|
expand = $VBox/Toolbar/Expand,
|
|
|
|
expand_all = $VBox/Toolbar/ExpandAll,
|
|
|
|
hide_passing = $VBox/Toolbar/HidePassing,
|
|
|
|
show_script = $VBox/Toolbar/ShowScript,
|
|
|
|
scroll_output = $VBox/Toolbar/ScrollOutput
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
func _test_running_setup():
|
|
|
|
_hide_passing = true
|
|
|
|
_show_orphans = true
|
2023-01-20 23:34:39 +01:00
|
|
|
var _gut_config = load("res://addons/gut/gut_config.gd").new()
|
|
|
|
_gut_config.load_panel_options("res://.gut_editor_config.json")
|
2023-01-07 20:26:17 +01:00
|
|
|
set_font(
|
2023-01-20 23:34:39 +01:00
|
|
|
_gut_config.options.panel_options.font_name, _gut_config.options.panel_options.font_size
|
|
|
|
)
|
2023-01-07 20:26:17 +01:00
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
_ctrls.toolbar.hide_passing.text = "[hp]"
|
|
|
|
load_json_file("user://.gut_editor.json")
|
2023-01-07 20:26:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _set_toolbutton_icon(btn, icon_name, text):
|
2023-01-20 23:34:39 +01:00
|
|
|
if Engine.is_editor_hint():
|
|
|
|
btn.icon = get_theme_icon(icon_name, "EditorIcons")
|
2023-01-07 20:26:17 +01:00
|
|
|
else:
|
2023-01-20 23:34:39 +01:00
|
|
|
btn.text = str("[", text, "]")
|
2023-01-07 20:26:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
var f = null
|
2023-01-20 23:34:39 +01:00
|
|
|
if $FontSampler.get_label_settings() == null:
|
2023-01-07 20:26:17 +01:00
|
|
|
f = get_theme_default_font()
|
2023-01-20 23:34:39 +01:00
|
|
|
else:
|
2023-01-07 20:26:17 +01:00
|
|
|
f = $FontSampler.get_label_settings().font
|
|
|
|
var s_size = f.get_string_size("000 of 000 passed")
|
|
|
|
_root = _ctrls.tree.create_item()
|
|
|
|
_ctrls.tree.set_hide_root(true)
|
|
|
|
_ctrls.tree.columns = 2
|
|
|
|
_ctrls.tree.set_column_expand(0, true)
|
|
|
|
_ctrls.tree.set_column_expand(1, false)
|
|
|
|
_ctrls.tree.set_column_custom_minimum_width(1, s_size.x)
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
_set_toolbutton_icon(_ctrls.toolbar.collapse, "CollapseTree", "c")
|
|
|
|
_set_toolbutton_icon(_ctrls.toolbar.collapse_all, "CollapseTree", "c")
|
|
|
|
_set_toolbutton_icon(_ctrls.toolbar.expand, "ExpandTree", "e")
|
|
|
|
_set_toolbutton_icon(_ctrls.toolbar.expand_all, "ExpandTree", "e")
|
|
|
|
_set_toolbutton_icon(_ctrls.toolbar.show_script, "Script", "ss")
|
|
|
|
_set_toolbutton_icon(_ctrls.toolbar.scroll_output, "Font", "so")
|
|
|
|
|
|
|
|
(
|
|
|
|
_ctrls
|
|
|
|
. toolbar
|
|
|
|
. hide_passing
|
|
|
|
. set("custom_icons/checked", get_theme_icon("GuiVisibilityHidden", "EditorIcons"))
|
|
|
|
)
|
|
|
|
(
|
|
|
|
_ctrls
|
|
|
|
. toolbar
|
|
|
|
. hide_passing
|
|
|
|
. set("custom_icons/unchecked", get_theme_icon("GuiVisibilityVisible", "EditorIcons"))
|
|
|
|
)
|
|
|
|
|
|
|
|
if get_parent() == get_tree().root:
|
2023-01-07 20:26:17 +01:00
|
|
|
_test_running_setup()
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
call_deferred("_update_min_width")
|
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
|
|
|
|
func _update_min_width():
|
|
|
|
custom_minimum_size.x = _ctrls.toolbar.toolbar.size.x
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
func _open_file(path, line_number):
|
2023-01-20 23:34:39 +01:00
|
|
|
if _interface == null:
|
|
|
|
print("Too soon, wait a bit and try again.")
|
2023-01-07 20:26:17 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
var r = load(path)
|
2023-01-20 23:34:39 +01:00
|
|
|
if line_number != -1:
|
2023-01-07 20:26:17 +01:00
|
|
|
_interface.edit_script(r, line_number)
|
|
|
|
else:
|
|
|
|
_interface.edit_script(r)
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
if _ctrls.toolbar.show_script.pressed:
|
|
|
|
_interface.set_main_screen_editor("Script")
|
2023-01-07 20:26:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _add_script_tree_item(script_path, script_json):
|
|
|
|
var path_info = _get_path_and_inner_class_name_from_test_path(script_path)
|
|
|
|
# print('* adding script ', path_info)
|
|
|
|
var item_text = script_path
|
|
|
|
var parent = _root
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
if path_info.inner_class != "":
|
2023-01-07 20:26:17 +01:00
|
|
|
parent = _find_script_item_with_path(path_info.path)
|
|
|
|
item_text = path_info.inner_class
|
2023-01-20 23:34:39 +01:00
|
|
|
if parent == null:
|
2023-01-07 20:26:17 +01:00
|
|
|
parent = _add_script_tree_item(path_info.path, {})
|
|
|
|
|
|
|
|
var item = _ctrls.tree.create_item(parent)
|
|
|
|
item.set_text(0, item_text)
|
|
|
|
var meta = {
|
2023-01-20 23:34:39 +01:00
|
|
|
"type": "script",
|
|
|
|
"path": path_info.path,
|
|
|
|
"inner_class": path_info.inner_class,
|
|
|
|
"json": script_json
|
|
|
|
}
|
2023-01-07 20:26:17 +01:00
|
|
|
item.set_metadata(0, meta)
|
|
|
|
item.set_custom_bg_color(1, _col_1_bg_color)
|
|
|
|
|
|
|
|
return item
|
|
|
|
|
|
|
|
|
|
|
|
func _add_assert_item(text, icon, parent_item):
|
|
|
|
# print(' * adding assert')
|
|
|
|
var assert_item = _ctrls.tree.create_item(parent_item)
|
|
|
|
assert_item.set_icon_max_width(0, _max_icon_width)
|
|
|
|
assert_item.set_text(0, text)
|
2023-01-20 23:34:39 +01:00
|
|
|
assert_item.set_metadata(0, {"type": "assert"})
|
2023-01-07 20:26:17 +01:00
|
|
|
assert_item.set_icon(0, icon)
|
|
|
|
assert_item.set_custom_bg_color(1, _col_1_bg_color)
|
|
|
|
|
|
|
|
return assert_item
|
|
|
|
|
|
|
|
|
|
|
|
func _add_test_tree_item(test_name, test_json, script_item):
|
|
|
|
# print(' * adding test ', test_name)
|
|
|
|
var no_orphans_to_show = !_show_orphans or (_show_orphans and test_json.orphans == 0)
|
2023-01-20 23:34:39 +01:00
|
|
|
if _hide_passing and test_json["status"] == "pass" and no_orphans_to_show:
|
2023-01-07 20:26:17 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
var item = _ctrls.tree.create_item(script_item)
|
2023-01-20 23:34:39 +01:00
|
|
|
var status = test_json["status"]
|
|
|
|
var meta = {"type": "test", "json": test_json}
|
2023-01-07 20:26:17 +01:00
|
|
|
|
|
|
|
item.set_text(0, test_name)
|
|
|
|
item.set_text(1, status)
|
|
|
|
item.set_text_alignment(1, HORIZONTAL_ALIGNMENT_RIGHT)
|
|
|
|
item.set_custom_bg_color(1, _col_1_bg_color)
|
|
|
|
|
|
|
|
item.set_metadata(0, meta)
|
|
|
|
item.set_icon_max_width(0, _max_icon_width)
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
var orphan_text = "orphans"
|
|
|
|
if test_json.orphans == 1:
|
|
|
|
orphan_text = "orphan"
|
|
|
|
orphan_text = str(test_json.orphans, " ", orphan_text)
|
2023-01-07 20:26:17 +01:00
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
if status == "pass" and no_orphans_to_show:
|
2023-01-07 20:26:17 +01:00
|
|
|
item.set_icon(0, _icons.green)
|
2023-01-20 23:34:39 +01:00
|
|
|
elif status == "pass" and !no_orphans_to_show:
|
2023-01-07 20:26:17 +01:00
|
|
|
item.set_icon(0, _icons.yellow)
|
|
|
|
item.set_text(1, orphan_text)
|
2023-01-20 23:34:39 +01:00
|
|
|
elif status == "fail":
|
2023-01-07 20:26:17 +01:00
|
|
|
item.set_icon(0, _icons.red)
|
|
|
|
else:
|
|
|
|
item.set_icon(0, _icons.yellow)
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
if !_hide_passing:
|
2023-01-07 20:26:17 +01:00
|
|
|
for passing in test_json.passing:
|
2023-01-20 23:34:39 +01:00
|
|
|
_add_assert_item("pass: " + passing, _icons.green, item)
|
2023-01-07 20:26:17 +01:00
|
|
|
|
|
|
|
for failure in test_json.failing:
|
2023-01-20 23:34:39 +01:00
|
|
|
_add_assert_item("fail: " + failure.replace("\n", ""), _icons.red, item)
|
2023-01-07 20:26:17 +01:00
|
|
|
|
|
|
|
for pending in test_json.pending:
|
2023-01-20 23:34:39 +01:00
|
|
|
_add_assert_item("pending: " + pending.replace("\n", ""), _icons.yellow, item)
|
2023-01-07 20:26:17 +01:00
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
if status != "pass" and !no_orphans_to_show:
|
2023-01-07 20:26:17 +01:00
|
|
|
_add_assert_item(orphan_text, _icons.yellow, item)
|
|
|
|
|
|
|
|
return item
|
|
|
|
|
|
|
|
|
|
|
|
func _load_result_tree(j):
|
2023-01-20 23:34:39 +01:00
|
|
|
var scripts = j["test_scripts"]["scripts"]
|
2023-01-07 20:26:17 +01:00
|
|
|
var script_keys = scripts.keys()
|
|
|
|
# if we made it here, the json is valid and we did something, otherwise the
|
|
|
|
# 'nothing to see here' should be visible.
|
|
|
|
clear_centered_text()
|
|
|
|
|
|
|
|
var _last_script_item = null
|
|
|
|
for key in script_keys:
|
2023-01-20 23:34:39 +01:00
|
|
|
var tests = scripts[key]["tests"]
|
2023-01-07 20:26:17 +01:00
|
|
|
var test_keys = tests.keys()
|
|
|
|
var s_item = _add_script_tree_item(key, scripts[key])
|
|
|
|
var bad_count = 0
|
|
|
|
|
|
|
|
for test_key in test_keys:
|
|
|
|
var t_item = _add_test_tree_item(test_key, tests[test_key], s_item)
|
2023-01-20 23:34:39 +01:00
|
|
|
if tests[test_key].status != "pass":
|
2023-01-07 20:26:17 +01:00
|
|
|
bad_count += 1
|
2023-01-20 23:34:39 +01:00
|
|
|
elif t_item != null:
|
2023-01-07 20:26:17 +01:00
|
|
|
t_item.collapsed = true
|
|
|
|
|
|
|
|
# get_children returns the first child or null. its a dumb name.
|
2023-01-20 23:34:39 +01:00
|
|
|
if s_item.get_children() == null:
|
2023-01-07 20:26:17 +01:00
|
|
|
# var m = s_item.get_metadata(0)
|
|
|
|
# print('!! Deleting ', m.path, ' ', m.inner_class)
|
|
|
|
s_item.free()
|
|
|
|
else:
|
2023-01-20 23:34:39 +01:00
|
|
|
var total_text = str(test_keys.size(), " passed")
|
2023-01-07 20:26:17 +01:00
|
|
|
# s_item.set_text_alignment(1, s_item.ALIGN_LEFT)
|
2023-01-20 23:34:39 +01:00
|
|
|
if bad_count == 0:
|
2023-01-07 20:26:17 +01:00
|
|
|
s_item.collapsed = true
|
|
|
|
else:
|
2023-01-20 23:34:39 +01:00
|
|
|
total_text = str(test_keys.size() - bad_count, " of ", test_keys.size(), " passed")
|
2023-01-07 20:26:17 +01:00
|
|
|
s_item.set_text(1, total_text)
|
|
|
|
|
|
|
|
_free_childless_scripts()
|
|
|
|
_show_all_passed()
|
|
|
|
|
|
|
|
|
|
|
|
func _free_childless_scripts():
|
|
|
|
var items = _root.get_children()
|
|
|
|
for item in items:
|
|
|
|
var next_item = item.get_next()
|
2023-01-20 23:34:39 +01:00
|
|
|
if item.get_children() == null:
|
2023-01-07 20:26:17 +01:00
|
|
|
item.free()
|
|
|
|
item = next_item
|
|
|
|
|
|
|
|
|
|
|
|
func _find_script_item_with_path(path):
|
|
|
|
var items = _root.get_children()
|
|
|
|
var to_return = null
|
|
|
|
|
|
|
|
var idx = 0
|
2023-01-20 23:34:39 +01:00
|
|
|
while idx < items.size() and to_return == null:
|
2023-01-07 20:26:17 +01:00
|
|
|
var item = items[idx]
|
2023-01-20 23:34:39 +01:00
|
|
|
if item.get_metadata(0).path == path:
|
2023-01-07 20:26:17 +01:00
|
|
|
to_return = item
|
|
|
|
else:
|
|
|
|
idx += 1
|
|
|
|
|
|
|
|
return to_return
|
|
|
|
|
|
|
|
|
|
|
|
func _get_line_number_from_assert_msg(msg):
|
|
|
|
var line = -1
|
2023-01-20 23:34:39 +01:00
|
|
|
if msg.find("at line") > 0:
|
2023-01-07 20:26:17 +01:00
|
|
|
line = msg.split("at line")[-1].split(" ")[-1].to_int()
|
|
|
|
return line
|
|
|
|
|
|
|
|
|
|
|
|
func _get_path_and_inner_class_name_from_test_path(path):
|
2023-01-20 23:34:39 +01:00
|
|
|
var to_return = {path = "", inner_class = ""}
|
2023-01-07 20:26:17 +01:00
|
|
|
|
|
|
|
to_return.path = path
|
2023-01-20 23:34:39 +01:00
|
|
|
if !path.ends_with(".gd"):
|
|
|
|
var loc = path.find(".gd")
|
|
|
|
to_return.inner_class = path.split(".")[-1]
|
2023-01-07 20:26:17 +01:00
|
|
|
to_return.path = path.substr(0, loc + 3)
|
|
|
|
return to_return
|
|
|
|
|
|
|
|
|
|
|
|
func _handle_tree_item_select(item, force_scroll):
|
|
|
|
var item_type = item.get_metadata(0).type
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
var path = ""
|
|
|
|
var line = -1
|
|
|
|
var method_name = ""
|
|
|
|
var inner_class = ""
|
2023-01-07 20:26:17 +01:00
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
if item_type == "test":
|
2023-01-07 20:26:17 +01:00
|
|
|
var s_item = item.get_parent()
|
2023-01-20 23:34:39 +01:00
|
|
|
path = s_item.get_metadata(0)["path"]
|
|
|
|
inner_class = s_item.get_metadata(0)["inner_class"]
|
2023-01-07 20:26:17 +01:00
|
|
|
line = -1
|
|
|
|
method_name = item.get_text(0)
|
2023-01-20 23:34:39 +01:00
|
|
|
elif item_type == "assert":
|
2023-01-07 20:26:17 +01:00
|
|
|
var s_item = item.get_parent().get_parent()
|
2023-01-20 23:34:39 +01:00
|
|
|
path = s_item.get_metadata(0)["path"]
|
|
|
|
inner_class = s_item.get_metadata(0)["inner_class"]
|
2023-01-07 20:26:17 +01:00
|
|
|
|
|
|
|
line = _get_line_number_from_assert_msg(item.get_text(0))
|
|
|
|
method_name = item.get_parent().get_text(0)
|
2023-01-20 23:34:39 +01:00
|
|
|
elif item_type == "script":
|
|
|
|
path = item.get_metadata(0)["path"]
|
|
|
|
if item.get_parent() != _root:
|
2023-01-07 20:26:17 +01:00
|
|
|
inner_class = item.get_text(0)
|
|
|
|
line = -1
|
2023-01-20 23:34:39 +01:00
|
|
|
method_name = ""
|
2023-01-07 20:26:17 +01:00
|
|
|
else:
|
|
|
|
return
|
|
|
|
|
|
|
|
var path_info = _get_path_and_inner_class_name_from_test_path(path)
|
2023-01-20 23:34:39 +01:00
|
|
|
if force_scroll or _ctrls.toolbar.show_script.pressed:
|
2023-01-07 20:26:17 +01:00
|
|
|
_goto_code(path, line, method_name, inner_class)
|
2023-01-20 23:34:39 +01:00
|
|
|
if force_scroll or _ctrls.toolbar.scroll_output.pressed:
|
2023-01-07 20:26:17 +01:00
|
|
|
_goto_output(path, method_name, inner_class)
|
|
|
|
|
|
|
|
|
|
|
|
# starts at beginning of text edit and searches for each search term, moving
|
|
|
|
# through the text as it goes; ensuring that, when done, it found the first
|
|
|
|
# occurance of the last srting that happend after the first occurance of
|
|
|
|
# each string before it. (Generic way of searching for a method name in an
|
|
|
|
# inner class that may have be a duplicate of a method name in a different
|
|
|
|
# inner class)
|
|
|
|
func _get_line_number_for_seq_search(search_strings, te):
|
|
|
|
# var te = _editors.get_current_text_edit()
|
|
|
|
var result = null
|
|
|
|
var line = Vector2i(-1, -1)
|
|
|
|
var s_flags = 0
|
|
|
|
|
|
|
|
var i = 0
|
|
|
|
var string_found = true
|
2023-01-20 23:34:39 +01:00
|
|
|
while i < search_strings.size() and string_found:
|
2023-01-07 20:26:17 +01:00
|
|
|
result = te.search(search_strings[i], s_flags, line.y, line.x)
|
2023-01-20 23:34:39 +01:00
|
|
|
if result.x != -1:
|
2023-01-07 20:26:17 +01:00
|
|
|
line = result
|
|
|
|
else:
|
|
|
|
string_found = false
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
return line.y
|
|
|
|
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
func _goto_code(path, line, method_name = "", inner_class = ""):
|
|
|
|
if _interface == null:
|
|
|
|
print("going to ", [path, line, method_name, inner_class])
|
2023-01-07 20:26:17 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
_open_file(path, line)
|
2023-01-20 23:34:39 +01:00
|
|
|
if line == -1:
|
2023-01-07 20:26:17 +01:00
|
|
|
var search_strings = []
|
2023-01-20 23:34:39 +01:00
|
|
|
if inner_class != "":
|
2023-01-07 20:26:17 +01:00
|
|
|
search_strings.append(inner_class)
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
if method_name != "":
|
2023-01-07 20:26:17 +01:00
|
|
|
search_strings.append(method_name)
|
|
|
|
|
|
|
|
line = _get_line_number_for_seq_search(search_strings, _editors.get_current_text_edit())
|
2023-01-20 23:34:39 +01:00
|
|
|
if line != -1:
|
2023-01-07 20:26:17 +01:00
|
|
|
_interface.get_script_editor().goto_line(line)
|
|
|
|
|
|
|
|
|
|
|
|
func _goto_output(path, method_name, inner_class):
|
2023-01-20 23:34:39 +01:00
|
|
|
if _output_control == null:
|
2023-01-07 20:26:17 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
var search_strings = [path]
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
if inner_class != "":
|
2023-01-07 20:26:17 +01:00
|
|
|
search_strings.append(inner_class)
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
if method_name != "":
|
2023-01-07 20:26:17 +01:00
|
|
|
search_strings.append(method_name)
|
|
|
|
|
|
|
|
var line = _get_line_number_for_seq_search(search_strings, _output_control.get_rich_text_edit())
|
2023-01-20 23:34:39 +01:00
|
|
|
if line != -1:
|
2023-01-07 20:26:17 +01:00
|
|
|
_output_control.scroll_to_line(line)
|
|
|
|
|
|
|
|
|
|
|
|
func _show_all_passed():
|
2023-01-20 23:34:39 +01:00
|
|
|
if _root.get_children() == null:
|
|
|
|
add_centered_text("Everything passed!")
|
2023-01-07 20:26:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _set_collapsed_on_all(item, value):
|
2023-01-20 23:34:39 +01:00
|
|
|
if item == _root:
|
2023-01-07 20:26:17 +01:00
|
|
|
var node = _root.get_children()
|
2023-01-20 23:34:39 +01:00
|
|
|
while node != null:
|
|
|
|
node.call_recursive("set_collapsed", value)
|
2023-01-07 20:26:17 +01:00
|
|
|
node = node.get_next()
|
|
|
|
else:
|
2023-01-20 23:34:39 +01:00
|
|
|
item.call_recursive("set_collapsed", value)
|
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
|
|
|
|
# --------------
|
|
|
|
# Events
|
|
|
|
# --------------
|
|
|
|
func _on_Tree_item_selected():
|
|
|
|
# do not force scroll
|
|
|
|
var item = _ctrls.tree.get_selected()
|
|
|
|
_handle_tree_item_select(item, false)
|
|
|
|
# it just looks better if the left is always selected.
|
2023-01-20 23:34:39 +01:00
|
|
|
if item.is_selected(1):
|
2023-01-07 20:26:17 +01:00
|
|
|
item.deselect(1)
|
|
|
|
item.select(0)
|
|
|
|
|
|
|
|
|
|
|
|
func _on_Tree_item_activated():
|
|
|
|
# force scroll
|
2023-01-20 23:34:39 +01:00
|
|
|
print("double clicked")
|
2023-01-07 20:26:17 +01:00
|
|
|
_handle_tree_item_select(_ctrls.tree.get_selected(), true)
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
func _on_Collapse_pressed():
|
|
|
|
collapse_selected()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_Expand_pressed():
|
|
|
|
expand_selected()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_CollapseAll_pressed():
|
|
|
|
collapse_all()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_ExpandAll_pressed():
|
|
|
|
expand_all()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_Hide_Passing_pressed():
|
|
|
|
_hide_passing = _ctrls.toolbar.hide_passing.button_pressed
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
# --------------
|
|
|
|
# Public
|
|
|
|
# --------------
|
|
|
|
func load_json_file(path):
|
|
|
|
var text = _utils.get_file_as_text(path)
|
2023-01-20 23:34:39 +01:00
|
|
|
if text != "":
|
2023-01-07 20:26:17 +01:00
|
|
|
var test_json_conv = JSON.new()
|
|
|
|
test_json_conv.parse(text)
|
|
|
|
var result = test_json_conv.get_data()
|
2023-01-20 23:34:39 +01:00
|
|
|
if result.error != OK:
|
|
|
|
add_centered_text(
|
|
|
|
str(
|
|
|
|
path,
|
|
|
|
" has invalid json in it \n",
|
|
|
|
"Error ",
|
|
|
|
result.error,
|
|
|
|
"@",
|
|
|
|
result.error_line,
|
|
|
|
"\n",
|
|
|
|
result.error_string
|
|
|
|
)
|
|
|
|
)
|
2023-01-07 20:26:17 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
load_json_results(result.result)
|
|
|
|
else:
|
2023-01-20 23:34:39 +01:00
|
|
|
add_centered_text(str(path, " was empty or does not exist."))
|
2023-01-07 20:26:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
func load_json_results(j):
|
|
|
|
clear()
|
2023-01-20 23:34:39 +01:00
|
|
|
add_centered_text("Nothing Here")
|
2023-01-07 20:26:17 +01:00
|
|
|
_load_result_tree(j)
|
|
|
|
|
|
|
|
|
|
|
|
func add_centered_text(t):
|
|
|
|
_ctrls.lbl_overlay.text = t
|
|
|
|
|
|
|
|
|
|
|
|
func clear_centered_text():
|
2023-01-20 23:34:39 +01:00
|
|
|
_ctrls.lbl_overlay.text = ""
|
2023-01-07 20:26:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
func clear():
|
|
|
|
_ctrls.tree.clear()
|
|
|
|
_root = _ctrls.tree.create_item()
|
|
|
|
clear_centered_text()
|
|
|
|
|
|
|
|
|
|
|
|
func set_interface(which):
|
|
|
|
_interface = which
|
|
|
|
|
|
|
|
|
|
|
|
func set_script_text_editors(value):
|
|
|
|
_editors = value
|
|
|
|
|
|
|
|
|
|
|
|
func collapse_all():
|
|
|
|
_set_collapsed_on_all(_root, true)
|
|
|
|
|
|
|
|
|
|
|
|
func expand_all():
|
|
|
|
_set_collapsed_on_all(_root, false)
|
|
|
|
|
|
|
|
|
|
|
|
func collapse_selected():
|
|
|
|
var item = _ctrls.tree.get_selected()
|
2023-01-20 23:34:39 +01:00
|
|
|
if item != null:
|
2023-01-07 20:26:17 +01:00
|
|
|
_set_collapsed_on_all(item, true)
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
func expand_selected():
|
|
|
|
var item = _ctrls.tree.get_selected()
|
2023-01-20 23:34:39 +01:00
|
|
|
if item != null:
|
2023-01-07 20:26:17 +01:00
|
|
|
_set_collapsed_on_all(item, false)
|
|
|
|
|
|
|
|
|
|
|
|
func set_show_orphans(should):
|
|
|
|
_show_orphans = should
|
|
|
|
|
|
|
|
|
|
|
|
func set_font(font_name, size):
|
|
|
|
pass
|
2023-01-20 23:34:39 +01:00
|
|
|
|
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
# var dyn_font = FontFile.new()
|
|
|
|
# var font_data = FontFile.new()
|
|
|
|
# font_data.font_path = 'res://addons/gut/fonts/' + font_name + '-Regular.ttf'
|
|
|
|
# font_data.antialiased = true
|
|
|
|
# dyn_font.font_data = font_data
|
|
|
|
#
|
|
|
|
# _font = dyn_font
|
|
|
|
# _font.size = size
|
|
|
|
# _font_size = size
|
|
|
|
|
|
|
|
|
|
|
|
func set_output_control(value):
|
|
|
|
_output_control = value
|