From a78226c32ceb0614e079f5cdd5653af7be729dac Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Wed, 6 Jul 2016 20:35:49 -0300 Subject: [PATCH] Only allow built-in scripts to be edited when the scene they belong to is loaded, closes #5403 --- scene/main/viewport.h | 1 + tools/editor/editor_node.cpp | 5 ++ tools/editor/editor_resource_preview.cpp | 2 +- tools/editor/plugins/script_editor_plugin.cpp | 77 ++++++++++++++++++- tools/editor/plugins/script_editor_plugin.h | 4 + 5 files changed, 85 insertions(+), 4 deletions(-) diff --git a/scene/main/viewport.h b/scene/main/viewport.h index aaa640e0e66..22a97a9888b 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -39,6 +39,7 @@ */ class Camera; +class Camera2D; class Listener; class Control; class CanvasItem; diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index ae632ab3816..56d745dee62 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -3133,6 +3133,11 @@ void EditorNode::_remove_edited_scene() { new_index=1; } + + + if (editor_data.get_scene_path(old_index)!=String()) { + ScriptEditor::get_singleton()->close_builtin_scripts_from_scene(editor_data.get_scene_path(old_index)); + } _scene_tab_changed(new_index); editor_data.remove_scene(old_index); editor_data.get_undo_redo().clear_history(); diff --git a/tools/editor/editor_resource_preview.cpp b/tools/editor/editor_resource_preview.cpp index 1a0e9961100..18ce2bd7f4d 100644 --- a/tools/editor/editor_resource_preview.cpp +++ b/tools/editor/editor_resource_preview.cpp @@ -356,7 +356,7 @@ bool EditorResourcePreview::check_for_invalidation(const String& p_path) { call_deferred("emit_signal","preview_invalidated",p_path); } - return call_invalidated; + } diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp index ee83b6b0321..aa0f52d5748 100644 --- a/tools/editor/plugins/script_editor_plugin.cpp +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -43,6 +43,28 @@ /*** SCRIPT EDITOR ****/ +static bool _can_open_in_editor(Script* p_script) { + + String path = p_script->get_path(); + + if (path.find("::")!=-1) { + //refuse handling this if it can't be edited + + bool valid=false; + for(int i=0;iget_editor_data().get_edited_scene_count();i++) { + if (path.begins_with(EditorNode::get_singleton()->get_editor_data().get_scene_path(i))) { + valid=true; + break; + } + } + + return valid; + } + + return true; +} + + class EditorScriptCodeCompletionCache : public ScriptCodeCompletionCache { @@ -747,9 +769,9 @@ void ScriptEditor::_go_to_tab(int p_idx) { _update_script_colors(); } -void ScriptEditor::_close_current_tab() { +void ScriptEditor::_close_tab(int p_idx) { - int selected = tab_container->get_current_tab(); + int selected = p_idx; if (selected<0 || selected>=tab_container->get_child_count()) return; @@ -795,6 +817,11 @@ void ScriptEditor::_close_current_tab() { _update_script_names(); EditorNode::get_singleton()->save_layout(); +} + +void ScriptEditor::_close_current_tab() { + + _close_tab(tab_container->get_current_tab()); } @@ -1681,6 +1708,33 @@ void ScriptEditor::_notification(int p_what) { } + +void ScriptEditor::close_builtin_scripts_from_scene(const String& p_scene) { + + + + for(int i=0;iget_child_count();i++) { + + ScriptTextEditor *ste = tab_container->get_child(i)->cast_to(); + + if (ste) { + + Ref