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

Method _create_new

editor/script/script_create_dialog.cpp:373–406  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

371}
372
373void ScriptCreateDialog::_create_new() {
374 Ref<Script> scr;
375
376 const ScriptLanguage::ScriptTemplate sinfo = _get_current_template();
377
378 String parent_class = parent_name->get_text();
379 if (!parent_name->get_text().is_quoted() && !ClassDB::class_exists(parent_class) && !ScriptServer::is_global_class(parent_class)) {
380 // If base is a custom type, replace with script path instead.
381 const EditorData::CustomType *type = EditorNode::get_editor_data().get_custom_type_by_name(parent_class);
382 ERR_FAIL_NULL(type);
383 parent_class = "\"" + type->script->get_path() + "\"";
384 }
385
386 String class_name = file_path->get_text().get_file().get_basename();
387 scr = ScriptServer::get_language(language_menu->get_selected())->make_template(sinfo.content, class_name, parent_class);
388
389 if (is_built_in) {
390 scr->set_name(built_in_name->get_text());
391 // Make sure the script is compiled to make its type recognizable.
392 scr->reload();
393 } else {
394 String lpath = ProjectSettings::get_singleton()->localize_path(file_path->get_text());
395 scr->set_path(lpath);
396 Error err = ResourceSaver::save(scr, lpath, ResourceSaver::FLAG_CHANGE_PATH);
397 if (err != OK) {
398 alert->set_text(TTR("Error - Could not create script in filesystem."));
399 alert->popup_centered();
400 return;
401 }
402 }
403
404 emit_signal(SNAME("script_created"), scr);
405 hide();
406}
407
408void ScriptCreateDialog::_load_exist() {
409 String path = file_path->get_text();

Callers

nothing calls this directly

Calls 15

get_languageFunction · 0.85
TTRFunction · 0.85
is_quotedMethod · 0.80
get_basenameMethod · 0.80
localize_pathMethod · 0.80
popup_centeredMethod · 0.80
get_textMethod · 0.45
get_pathMethod · 0.45
get_fileMethod · 0.45
make_templateMethod · 0.45
get_selectedMethod · 0.45

Tested by

no test coverage detected