# Holds weakrefs to a ScriptTextEditor and related children nodes # that might be useful. Though the CodeEdit is really the only one, but # since the tree may change, the first TextEdit under a CodeTextEditor is # the one we use...so we hold a ref to the CodeTextEditor too. class ScriptEditorControlRef: var _text_edit = null var _script_editor = null var _code_editor = null func _init(script_edit): _script_editor = weakref(script_edit) _populate_controls() # print("_script_editor = ", script_edit, ' vis = ', is_visible()) func _populate_controls(): # who knows if the tree will change so get the first instance of each # type of control we care about. Chances are there won't be more than # one of these in the future, but their position in the tree may change. _code_editor = weakref(_get_first_child_named('CodeTextEditor', _script_editor.get_ref())) _text_edit = weakref(_get_first_child_named("CodeEdit", _code_editor.get_ref())) func _get_first_child_named(obj_name, parent_obj): if(parent_obj == null): return null var kids = parent_obj.get_children() var index = 0 var to_return = null while(index < kids.size() and to_return == null): if(str(kids[index]).find(str("<", obj_name)) != -1): to_return = kids[index] else: to_return = _get_first_child_named(obj_name, kids[index]) if(to_return == null): index += 1 return to_return func get_script_text_edit(): return _script_editor.get_ref() func get_text_edit(): # ScriptTextEditors that are loaded when the project is opened # do not have their children populated yet. So if we may have to # _populate_controls again if we don't have one. if(_text_edit == null): _populate_controls() return _text_edit.get_ref() func get_script_editor(): return _script_editor func is_visible(): var to_return = false if(_script_editor.get_ref()): to_return = _script_editor.get_ref().visible return to_return # ############################################################################## # # ############################################################################## # Used to make searching for the controls easier and faster. var _script_editors_parent = null # reference the ScriptEditor instance var _script_editor = null # Array of ScriptEditorControlRef containing all the opened ScriptTextEditors # and related controls at the time of the last refresh. var _script_editor_controls = [] var _method_prefix = 'test_' var _inner_class_prefix = 'Test' func _init(script_edit): _script_editor = script_edit refresh() func _is_script_editor(obj): return str(obj).find('