| 371 | } |
| 372 | |
| 373 | void 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 | |
| 408 | void ScriptCreateDialog::_load_exist() { |
| 409 | String path = file_path->get_text(); |
nothing calls this directly
no test coverage detected