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

Method save_resource_as

editor/editor_node.cpp:1648–1717  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1646}
1647
1648void EditorNode::save_resource_as(const Ref<Resource> &p_resource, const String &p_at_path) {
1649 {
1650 String path = p_resource->get_path();
1651 if (!path.is_resource_file()) {
1652 int srpos = path.find("::");
1653 if (srpos != -1) {
1654 String base = path.substr(0, srpos);
1655 if (!get_edited_scene() || get_edited_scene()->get_scene_file_path() != base) {
1656 show_warning(TTR("This resource can't be saved because it does not belong to the edited scene. Make it unique first."));
1657 return;
1658 }
1659 }
1660 } else if (FileAccess::exists(path + ".import")) {
1661 show_warning(TTR("This resource can't be saved because it was imported from another file. Make it unique first."));
1662 return;
1663 }
1664 }
1665
1666 file->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
1667 saving_resource = p_resource;
1668
1669 current_menu_option = RESOURCE_SAVE_AS;
1670 List<String> extensions;
1671 Ref<PackedScene> sd = memnew(PackedScene);
1672 ResourceSaver::get_recognized_extensions(p_resource, &extensions);
1673 file->clear_filters();
1674
1675 List<String> preferred;
1676 for (const String &E : extensions) {
1677 if (p_resource->is_class("Script") && (E == "tres" || E == "res")) {
1678 // This serves no purpose and confused people.
1679 continue;
1680 }
1681 file->add_filter("*." + E, E.to_upper());
1682 preferred.push_back(E);
1683 }
1684 // Lowest provided extension priority.
1685 List<String>::Element *res_element = preferred.find("res");
1686 if (res_element) {
1687 preferred.move_to_back(res_element);
1688 }
1689
1690 if (!p_at_path.is_empty()) {
1691 file->set_current_dir(p_at_path);
1692 if (p_resource->get_path().is_resource_file()) {
1693 file->set_current_file(p_resource->get_path().get_file());
1694 } else {
1695 if (!preferred.is_empty()) {
1696 String resource_name_snake_case = p_resource->get_class().to_snake_case();
1697 file->set_current_file("new_" + resource_name_snake_case + "." + preferred.front()->get().to_lower());
1698 } else {
1699 file->set_current_file(String());
1700 }
1701 }
1702 } else if (!p_resource->get_path().get_base_dir().is_empty()) {
1703 file->set_current_path(p_resource->get_path());
1704 if (!extensions.is_empty()) {
1705 const String ext = p_resource->get_path().get_extension().to_lower();

Callers 7

_menu_optionMethod · 0.80
_menu_item_pressedMethod · 0.80
_edit_menu_cbkMethod · 0.80
_save_resourceMethod · 0.80
_resource_createdMethod · 0.80
drop_data_fwMethod · 0.80

Calls 15

TTRFunction · 0.85
is_resource_fileMethod · 0.80
substrMethod · 0.80
get_scene_file_pathMethod · 0.80
to_upperMethod · 0.80
move_to_backMethod · 0.80
to_snake_caseMethod · 0.80
to_lowerMethod · 0.80
get_base_dirMethod · 0.80
replacenMethod · 0.80
StringClass · 0.50
get_pathMethod · 0.45

Tested by 1

_save_resourceMethod · 0.64