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

Method _update_template_menu

editor/script/script_create_dialog.cpp:536–621  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

534}
535
536void ScriptCreateDialog::_update_template_menu() {
537 bool is_language_using_templates = language->is_using_templates();
538 template_menu->set_disabled(false);
539 template_menu->clear();
540 template_list.clear();
541
542 if (is_language_using_templates) {
543 // Get the latest templates used for each type of node from project settings then global settings.
544 Dictionary last_local_templates = EditorSettings::get_singleton()->get_project_metadata("script_setup", "templates_dictionary", Dictionary());
545 Dictionary last_global_templates = EDITOR_GET("_script_setup_templates_dictionary");
546 String inherits_base_type = parent_name->get_text();
547
548 // If it inherits from a script, get its parent class first.
549 if (inherits_base_type[0] == '"') {
550 inherits_base_type = _get_parent_class_of_script(inherits_base_type.unquote());
551 }
552
553 // Get all ancestor node for selected base node.
554 // There templates will also fit the base node.
555 Vector<String> hierarchy = _get_hierarchy(inherits_base_type);
556 int last_used_template = -1;
557 int preselected_template = -1;
558 int previous_ancestor_level = -1;
559
560 // Templates can be stored in tree different locations.
561 Vector<ScriptLanguage::TemplateLocation> template_locations;
562 template_locations.append(ScriptLanguage::TEMPLATE_PROJECT);
563 template_locations.append(ScriptLanguage::TEMPLATE_EDITOR);
564 template_locations.append(ScriptLanguage::TEMPLATE_BUILT_IN);
565
566 for (const ScriptLanguage::TemplateLocation &template_location : template_locations) {
567 String display_name = _get_script_origin_label(template_location);
568 bool separator = false;
569 int ancestor_level = 0;
570 for (const String &current_node : hierarchy) {
571 Vector<ScriptLanguage::ScriptTemplate> templates_found;
572 if (template_location == ScriptLanguage::TEMPLATE_BUILT_IN) {
573 templates_found = language->get_built_in_templates(current_node);
574 } else {
575 String template_directory;
576 if (template_location == ScriptLanguage::TEMPLATE_PROJECT) {
577 template_directory = EditorPaths::get_singleton()->get_project_script_templates_dir();
578 } else {
579 template_directory = EditorPaths::get_singleton()->get_script_templates_dir();
580 }
581 templates_found = _get_user_templates(language, current_node, template_directory, template_location);
582 }
583 if (!templates_found.is_empty()) {
584 if (!separator) {
585 template_menu->add_separator();
586 template_menu->set_item_text(-1, display_name);
587 template_menu->set_item_auto_translate_mode(-1, AUTO_TRANSLATE_MODE_ALWAYS);
588 separator = true;
589 }
590 for (ScriptLanguage::ScriptTemplate &t : templates_found) {
591 template_menu->add_item(t.inherit + ": " + t.name);
592 int id = template_menu->get_item_count() - 1;
593 // Check if this template should be preselected if node isn't in the last used dictionary.

Callers

nothing calls this directly

Calls 15

_get_hierarchyFunction · 0.85
get_project_metadataMethod · 0.80
unquoteMethod · 0.80
DictionaryClass · 0.50
StringClass · 0.50
is_using_templatesMethod · 0.45
set_disabledMethod · 0.45
clearMethod · 0.45
get_textMethod · 0.45

Tested by

no test coverage detected