瀏覽代碼

Don't edit foreign resources when restoring scene

kobewi 4 年之前
父節點
當前提交
363a9c674a
共有 2 個文件被更改,包括 12 次插入4 次删除
  1. 11 3
      editor/editor_node.cpp
  2. 1 1
      editor/editor_node.h

+ 11 - 3
editor/editor_node.cpp

@@ -2072,11 +2072,19 @@ static bool overrides_external_editor(Object *p_object) {
 	return script->get_language()->overrides_external_editor();
 	return script->get_language()->overrides_external_editor();
 }
 }
 
 
-void EditorNode::_edit_current() {
+void EditorNode::_edit_current(bool p_skip_foreign) {
 	ObjectID current = editor_history.get_current();
 	ObjectID current = editor_history.get_current();
 	Object *current_obj = current.is_valid() ? ObjectDB::get_instance(current) : nullptr;
 	Object *current_obj = current.is_valid() ? ObjectDB::get_instance(current) : nullptr;
-	bool inspector_only = editor_history.is_current_inspector_only();
 
 
+	RES res = Object::cast_to<Resource>(current_obj);
+	if (p_skip_foreign && res.is_valid()) {
+		if (res->get_path().find("::") > -1 && res->get_path().get_slice("::", 0) != editor_data.get_scene_path(get_current_tab())) {
+			// Trying to edit resource that belongs to another scene; abort.
+			current_obj = nullptr;
+		}
+	}
+
+	bool inspector_only = editor_history.is_current_inspector_only();
 	this->current = current_obj;
 	this->current = current_obj;
 
 
 	if (!current_obj) {
 	if (!current_obj) {
@@ -3441,7 +3449,7 @@ void EditorNode::set_current_scene(int p_idx) {
 	}
 	}
 
 
 	Dictionary state = editor_data.restore_edited_scene_state(editor_selection, &editor_history);
 	Dictionary state = editor_data.restore_edited_scene_state(editor_selection, &editor_history);
-	_edit_current();
+	_edit_current(true);
 
 
 	_update_title();
 	_update_title();
 
 

+ 1 - 1
editor/editor_node.h

@@ -455,7 +455,7 @@ private:
 
 
 	void _dialog_action(String p_file);
 	void _dialog_action(String p_file);
 
 
-	void _edit_current();
+	void _edit_current(bool p_skip_foreign = false);
 	void _dialog_display_save_error(String p_file, Error p_error);
 	void _dialog_display_save_error(String p_file, Error p_error);
 	void _dialog_display_load_error(String p_file, Error p_error);
 	void _dialog_display_load_error(String p_file, Error p_error);