MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / add_callback

Method add_callback

editor/script/script_text_editor.cpp:376–401  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

374}
375
376void ScriptTextEditor::add_callback(const String &p_function, const PackedStringArray &p_args) {
377 ScriptLanguage *language = script->get_language();
378 if (!language->can_make_function()) {
379 return;
380 }
381 code_editor->get_text_editor()->begin_complex_operation();
382 code_editor->get_text_editor()->remove_secondary_carets();
383 code_editor->get_text_editor()->deselect();
384 String code = code_editor->get_text_editor()->get_text();
385 int pos = language->find_function(p_function, code);
386 if (pos == -1) {
387 // Function does not exist, create it at the end of the file.
388 int last_line = code_editor->get_text_editor()->get_line_count() - 1;
389 String func = language->make_function("", p_function, p_args);
390 code_editor->get_text_editor()->insert_text("\n\n" + func, last_line, code_editor->get_text_editor()->get_line(last_line).length());
391 pos = last_line + 3;
392 }
393 // Put caret on the line after the function, after the indent.
394 int indent_column = 1;
395 if (EDITOR_GET("text_editor/behavior/indent/type")) {
396 indent_column = EDITOR_GET("text_editor/behavior/indent/size");
397 }
398 code_editor->get_text_editor()->set_caret_line(pos, true, true, -1);
399 code_editor->get_text_editor()->set_caret_column(indent_column);
400 code_editor->get_text_editor()->end_complex_operation();
401}
402
403bool ScriptTextEditor::show_members_overview() {
404 return true;

Callers

nothing calls this directly

Calls 15

get_text_editorMethod · 0.80
insert_textMethod · 0.80
set_caret_lineMethod · 0.80
end_complex_operationMethod · 0.80
get_languageMethod · 0.45
can_make_functionMethod · 0.45
deselectMethod · 0.45
get_textMethod · 0.45
find_functionMethod · 0.45
get_line_countMethod · 0.45

Tested by

no test coverage detected