| 814 | } |
| 815 | |
| 816 | void ScriptEditor::_open_recent_script(int p_idx) { |
| 817 | // clear button |
| 818 | if (p_idx == recent_scripts->get_item_count() - 1) { |
| 819 | EditorSettings::get_singleton()->set_project_metadata("recent_files", "scripts", Array()); |
| 820 | callable_mp(this, &ScriptEditor::_update_recent_scripts).call_deferred(); |
| 821 | return; |
| 822 | } |
| 823 | |
| 824 | Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scripts", Array()); |
| 825 | ERR_FAIL_INDEX(p_idx, rc.size()); |
| 826 | |
| 827 | String path = rc[p_idx]; |
| 828 | // if its not on disk its a help file or deleted |
| 829 | if (FileAccess::exists(path)) { |
| 830 | List<String> extensions; |
| 831 | ResourceLoader::get_recognized_extensions_for_type("Script", &extensions); |
| 832 | ResourceLoader::get_recognized_extensions_for_type("JSON", &extensions); |
| 833 | |
| 834 | if (extensions.find(path.get_extension())) { |
| 835 | Ref<Resource> scr = ResourceLoader::load(path); |
| 836 | if (scr.is_valid()) { |
| 837 | edit(scr, true); |
| 838 | return; |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | Error err; |
| 843 | Ref<TextFile> text_file = _load_text_file(path, &err); |
| 844 | if (text_file.is_valid()) { |
| 845 | edit(text_file, true); |
| 846 | return; |
| 847 | } |
| 848 | // if it's a path then it's most likely a deleted file not help |
| 849 | } else if (path.contains("::")) { |
| 850 | // built-in script |
| 851 | String res_path = path.get_slice("::", 0); |
| 852 | EditorNode::get_singleton()->load_scene_or_resource(res_path, false, false); |
| 853 | |
| 854 | Ref<Script> scr = ResourceLoader::load(path); |
| 855 | if (scr.is_valid()) { |
| 856 | edit(scr, true); |
| 857 | return; |
| 858 | } |
| 859 | } else if (!path.is_resource_file()) { |
| 860 | _help_class_open(path); |
| 861 | return; |
| 862 | } |
| 863 | |
| 864 | rc.remove_at(p_idx); |
| 865 | EditorSettings::get_singleton()->set_project_metadata("recent_files", "scripts", rc); |
| 866 | _update_recent_scripts(); |
| 867 | _show_error_dialog(path); |
| 868 | } |
| 869 | |
| 870 | void ScriptEditor::_show_error_dialog(const String &p_path) { |
| 871 | error_dialog->set_text(vformat(TTR("Can't open '%s'. The file could have been moved or deleted."), p_path)); |
nothing calls this directly
no test coverage detected