summaryrefslogtreecommitdiff
path: root/tools/editor
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-07-06 20:35:49 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-07-06 20:36:37 -0300
commita78226c32ceb0614e079f5cdd5653af7be729dac (patch)
tree998cfe40fe7f4239c3200f654148e0282c826796 /tools/editor
parente4b7a45a381f028752163d0f57662baa0def0301 (diff)
Only allow built-in scripts to be edited when the scene they belong to is loaded, closes #5403
Diffstat (limited to 'tools/editor')
-rw-r--r--tools/editor/editor_node.cpp5
-rw-r--r--tools/editor/editor_resource_preview.cpp2
-rw-r--r--tools/editor/plugins/script_editor_plugin.cpp77
-rw-r--r--tools/editor/plugins/script_editor_plugin.h4
4 files changed, 84 insertions, 4 deletions
diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp
index ae632ab381..56d745dee6 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 1a0e996110..18ce2bd7f4 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 ee83b6b032..aa0f52d574 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;i<EditorNode::get_singleton()->get_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;i<tab_container->get_child_count();i++) {
+
+ ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
+
+ if (ste) {
+
+ Ref<Script> script = ste->get_edited_script();
+ if (!script.is_valid())
+ continue;
+
+ if (script->get_path().find("::")!=-1 && script->get_path().begins_with(p_scene)) { //is an internal script and belongs to scene being closed
+ _close_tab(i);
+ i--;
+
+ }
+ }
+
+ }
+
+
+}
+
void ScriptEditor::edited_scene_changed() {
_update_modified_scripts_for_external_editor();
@@ -2059,11 +2113,18 @@ void ScriptEditor::_update_script_names() {
}
+
+
void ScriptEditor::edit(const Ref<Script>& p_script) {
if (p_script.is_null())
return;
+ // refuse to open built-in if scene is not loaded
+
+
+
+
// see if already has it
bool open_dominant = EditorSettings::get_singleton()->get("text_editor/open_dominant_script_on_scene_change");
@@ -2527,7 +2588,7 @@ void ScriptEditor::set_scene_root_script( Ref<Script> p_script ) {
if (bool(EditorSettings::get_singleton()->get("external_editor/use_external_editor")))
return;
- if (open_dominant && p_script.is_valid()) {
+ if (open_dominant && p_script.is_valid() && _can_open_in_editor(p_script.ptr())) {
edit(p_script);
}
}
@@ -2915,6 +2976,16 @@ void ScriptEditorPlugin::edit(Object *p_object) {
bool ScriptEditorPlugin::handles(Object *p_object) const {
+ if (p_object->cast_to<Script>()) {
+
+ bool valid = _can_open_in_editor(p_object->cast_to<Script>());
+
+ if (!valid) { //user tried to open it by clicking
+ EditorNode::get_singleton()->show_warning(TTR("Built-in scripts can only be edited when the scene they belong to is loaded"));
+ }
+ return valid;
+ }
+
return p_object->is_type("Script");
}
diff --git a/tools/editor/plugins/script_editor_plugin.h b/tools/editor/plugins/script_editor_plugin.h
index 85412087b4..2e6e2c035c 100644
--- a/tools/editor/plugins/script_editor_plugin.h
+++ b/tools/editor/plugins/script_editor_plugin.h
@@ -234,6 +234,8 @@ class ScriptEditor : public VBoxContainer {
bool _test_script_times_on_disk(Ref<Script> p_for_script=Ref<Script>());
+ void _close_tab(int p_idx);
+
void _close_current_tab();
bool grab_focus_block;
@@ -331,6 +333,8 @@ public:
virtual void edited_scene_changed();
+ void close_builtin_scripts_from_scene(const String& p_scene);
+
ScriptEditorDebugger *get_debugger() { return debugger; }
void set_live_auto_reload_running_scripts(bool p_enabled);