Godot-TextEditor/addons/text_editor/TE_SymbolsList.gd

108 lines
3.1 KiB
GDScript3
Raw Normal View History

2021-10-11 18:41:26 +02:00
tool
2021-10-18 21:20:19 +02:00
extends "res://addons/text_editor/TE_RichTextLabel.gd"
2021-10-11 05:10:22 +02:00
2021-10-19 01:50:21 +02:00
var hscrolls:Dictionary = {}
2021-10-11 05:10:22 +02:00
func _ready():
var _e
_e = editor.connect("symbols_updated", self, "_redraw")
_e = editor.connect("tags_updated", self, "_redraw")
2021-10-19 01:50:21 +02:00
_e = editor.connect("file_selected", self, "_file_selected")
2021-10-23 05:51:34 +02:00
_e = editor.connect("selected_symbol_line", self, "_selected_symbol_line")
2021-10-19 01:50:21 +02:00
_e = get_v_scroll().connect("value_changed", self, "_scrolling")
2021-10-11 05:10:22 +02:00
add_font_override("normal_font", editor.FONT_R)
add_font_override("bold_font", editor.FONT_B)
add_font_override("italics_font", editor.FONT_I)
add_font_override("bold_italics_font", editor.FONT_BI)
2021-10-11 18:41:26 +02:00
call_deferred("_redraw")
2021-10-11 05:10:22 +02:00
2021-10-23 05:51:34 +02:00
func _selected_symbol_line(line:int):
# scroll_to_line(get_line_count()-1)
scroll_to_line(line)
2021-10-19 01:50:21 +02:00
func _file_selected(file_path:String):
yield(get_tree(), "idle_frame")
get_v_scroll().value = hscrolls.get(file_path, 0)
func _scrolling(v):
hscrolls[editor.get_selected_file()] = get_v_scroll().value
2021-10-18 21:20:19 +02:00
func _clicked(args:Array):
var te:TextEdit = editor.get_selected_tab()
2021-10-23 05:51:34 +02:00
# select entire symbol block?
if Input.is_key_pressed(KEY_CONTROL):
var tab = editor.get_selected_tab()
var symbols = {} if not tab else tab.symbols
var line_index:int = args[1]
var symbol_index:int = symbols.keys().find(line_index)
var next_line:int
# select sub symbol blocks?
if not Input.is_key_pressed(KEY_SHIFT):
var deep = symbols[line_index].deep
while symbol_index < len(symbols)-1 and symbols.values()[symbol_index+1].deep > deep:
symbol_index += 1
if symbol_index == len(symbols)-1:
next_line = tab.get_line_count()-1
else:
next_line = symbols.keys()[symbol_index+1]-1
tab.select(line_index, 0, next_line, len(tab.get_line(next_line)))
te.goto_line(line_index)
else:
te.goto_line(args[1])
2021-10-11 05:10:22 +02:00
func _redraw():
var tab = editor.get_selected_tab()
var symbols = {} if not tab else tab.symbols
2021-10-18 21:20:19 +02:00
var spaces = PoolStringArray([
"- ",
" - ",
" - "
])
var colors = PoolColorArray([
Color.white,
Color.white.darkened(.25),
Color.white.darkened(.5)
])
2021-10-11 05:10:22 +02:00
# no symbols
if not symbols or len(symbols) == 1:
set_bbcode("[color=#%s][i][center]*No symbols*" % [Color.webgray.to_html()])
else:
var t = PoolStringArray()
for line_index in symbols:
if line_index == -1:
continue # special file chapter
var symbol_info = symbols[line_index]
2021-10-18 21:20:19 +02:00
var deep = symbol_info.deep
var space = "" if not deep else clr("-".repeat(deep), Color.white.darkened(.75))
2021-10-19 01:50:21 +02:00
var cl = Color.white
if deep == 0:
cl = editor.color_symbol
if symbol_info.name.begins_with("*") and symbol_info.name.ends_with("*"):
cl = TE_Util.hue_shift(cl, -.33)
elif symbol_info.name.begins_with('"') and symbol_info.name.ends_with('"'):
cl = TE_Util.hue_shift(cl, .33)
2021-10-18 21:20:19 +02:00
if not editor.is_tagged_or_visible(symbol_info.tags):
cl = cl.darkened(.7)
elif deep >= 1:
cl = cl.darkened(.33 * (deep-1))
var tags = "" if not symbol_info.tags else PoolStringArray(symbol_info.tags).join(", ")
t.append(clr(meta(space + symbol_info.name, [symbol_info, line_index], tags), cl))
2021-10-11 05:10:22 +02:00
set_bbcode(t.join("\n"))