@@ -1291,6 +1291,16 @@ void _save_text_editor_theme_as(const String &p_file) {
12911291 }
12921292}
12931293
1294+ bool ScriptEditor::_script_exists (const String &p_path) const {
1295+ if (p_path.is_empty ()) {
1296+ return false ;
1297+ } else if (p_path.is_resource_file ()) {
1298+ return FileAccess::exists (p_path);
1299+ } else {
1300+ return FileAccess::exists (p_path.get_slice (" ::" , 0 ));
1301+ }
1302+ }
1303+
12941304void ScriptEditor::_file_dialog_action (const String &p_file) {
12951305 switch (file_dialog_option) {
12961306 case FILE_MENU_NEW_TEXTFILE: {
@@ -3038,7 +3048,7 @@ void ScriptEditor::_save_editor_state(ScriptEditorBase *p_editor) {
30383048 }
30393049
30403050 const String &path = p_editor->get_edited_resource ()->get_path ();
3041- if (! path.is_resource_file ()) {
3051+ if (path.is_empty ()) {
30423052 return ;
30433053 }
30443054
@@ -3574,23 +3584,37 @@ void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) {
35743584 ResourceLoader::get_recognized_extensions_for_type (" Script" , &extensions);
35753585 ResourceLoader::get_recognized_extensions_for_type (" JSON" , &extensions);
35763586
3577- for (int i = 0 ; i < scripts. size (); i++ ) {
3578- String path = scripts[i] ;
3587+ for (const Variant &v : scripts) {
3588+ String path = v ;
35793589
3580- Dictionary script_info = scripts[i] ;
3590+ Dictionary script_info = v ;
35813591 if (!script_info.is_empty ()) {
35823592 path = script_info[" path" ];
35833593 }
35843594
3585- if (!FileAccess::exists (path)) {
3595+ if (!_script_exists (path)) {
35863596 if (script_editor_cache->has_section (path)) {
35873597 script_editor_cache->erase_section (path);
35883598 }
35893599 continue ;
3600+ } else if (!path.is_resource_file () && !EditorNode::get_singleton ()->is_scene_open (path.get_slice (" ::" , 0 ))) {
3601+ continue ;
35903602 }
35913603 loaded_scripts.insert (path);
35923604
3593- if (extensions.find (path.get_extension ())) {
3605+ bool is_script = false ;
3606+ if (path.is_resource_file ()) {
3607+ is_script = extensions.find (path.get_extension ());
3608+ } else {
3609+ Ref<Script> scr = ResourceCache::get_ref (path);
3610+ if (scr.is_valid ()) {
3611+ is_script = true ;
3612+ } else {
3613+ continue ;
3614+ }
3615+ }
3616+
3617+ if (is_script) {
35943618 Ref<Resource> scr = ResourceLoader::load (path);
35953619 if (scr.is_null ()) {
35963620 continue ;
@@ -3645,7 +3669,7 @@ void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) {
36453669 continue ;
36463670 }
36473671
3648- if (!FileAccess::exists (E)) {
3672+ if (!_script_exists (E)) {
36493673 script_editor_cache->erase_section (E);
36503674 continue ;
36513675 }
@@ -3682,8 +3706,8 @@ void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) {
36823706 for (int i = 0 ; i < tab_container->get_tab_count (); i++) {
36833707 ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_tab_control (i));
36843708 if (se) {
3685- String path = se->get_edited_resource ()->get_path ();
3686- if (! path.is_resource_file ()) {
3709+ const String path = se->get_edited_resource ()->get_path ();
3710+ if (path.is_empty ()) {
36873711 continue ;
36883712 }
36893713
0 commit comments