You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
Make the loading scene open in the current scene tab if the current scene is empty
This commit is contained in:
@@ -3926,15 +3926,19 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b
|
|||||||
}
|
}
|
||||||
|
|
||||||
int prev = editor_data.get_edited_scene();
|
int prev = editor_data.get_edited_scene();
|
||||||
int idx = editor_data.add_edited_scene(-1);
|
int idx = prev;
|
||||||
|
|
||||||
if (!editor_data.get_edited_scene_root() && editor_data.get_edited_scene_count() == 2) {
|
if (prev == -1 || editor_data.get_edited_scene_root() || !editor_data.get_scene_path(prev).is_empty()) {
|
||||||
_remove_edited_scene();
|
idx = editor_data.add_edited_scene(-1);
|
||||||
} else if (p_silent_change_tab) {
|
|
||||||
|
if (p_silent_change_tab) {
|
||||||
_set_current_scene_nocheck(idx);
|
_set_current_scene_nocheck(idx);
|
||||||
} else {
|
} else {
|
||||||
_set_current_scene(idx);
|
_set_current_scene(idx);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
EditorUndoRedoManager::get_singleton()->clear_history(false, editor_data.get_current_edited_scene_history_id());
|
||||||
|
}
|
||||||
|
|
||||||
dependency_errors.clear();
|
dependency_errors.clear();
|
||||||
|
|
||||||
@@ -3950,7 +3954,7 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b
|
|||||||
dependency_error->show(DependencyErrorDialog::MODE_SCENE, lpath, errors);
|
dependency_error->show(DependencyErrorDialog::MODE_SCENE, lpath, errors);
|
||||||
opening_prev = false;
|
opening_prev = false;
|
||||||
|
|
||||||
if (prev != -1) {
|
if (prev != -1 && prev != idx) {
|
||||||
_set_current_scene(prev);
|
_set_current_scene(prev);
|
||||||
editor_data.remove_scene(idx);
|
editor_data.remove_scene(idx);
|
||||||
}
|
}
|
||||||
@@ -3961,7 +3965,7 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b
|
|||||||
_dialog_display_load_error(lpath, err);
|
_dialog_display_load_error(lpath, err);
|
||||||
opening_prev = false;
|
opening_prev = false;
|
||||||
|
|
||||||
if (prev != -1) {
|
if (prev != -1 && prev != idx) {
|
||||||
_set_current_scene(prev);
|
_set_current_scene(prev);
|
||||||
editor_data.remove_scene(idx);
|
editor_data.remove_scene(idx);
|
||||||
}
|
}
|
||||||
@@ -3997,7 +4001,7 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b
|
|||||||
sdata.unref();
|
sdata.unref();
|
||||||
_dialog_display_load_error(lpath, ERR_FILE_CORRUPT);
|
_dialog_display_load_error(lpath, ERR_FILE_CORRUPT);
|
||||||
opening_prev = false;
|
opening_prev = false;
|
||||||
if (prev != -1) {
|
if (prev != -1 && prev != idx) {
|
||||||
_set_current_scene(prev);
|
_set_current_scene(prev);
|
||||||
editor_data.remove_scene(idx);
|
editor_data.remove_scene(idx);
|
||||||
}
|
}
|
||||||
@@ -4023,10 +4027,6 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b
|
|||||||
_load_editor_plugin_states_from_config(editor_state_cf);
|
_load_editor_plugin_states_from_config(editor_state_cf);
|
||||||
}
|
}
|
||||||
|
|
||||||
_update_title();
|
|
||||||
scene_tabs->update_scene_tabs();
|
|
||||||
_add_to_recent_scenes(lpath);
|
|
||||||
|
|
||||||
if (editor_folding.has_folding_data(lpath)) {
|
if (editor_folding.has_folding_data(lpath)) {
|
||||||
editor_folding.load_scene_folding(new_scene, lpath);
|
editor_folding.load_scene_folding(new_scene, lpath);
|
||||||
} else if (EDITOR_GET("interface/inspector/auto_unfold_foreign_scenes")) {
|
} else if (EDITOR_GET("interface/inspector/auto_unfold_foreign_scenes")) {
|
||||||
@@ -4066,6 +4066,14 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b
|
|||||||
save_editor_layout_delayed();
|
save_editor_layout_delayed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (p_set_inherited) {
|
||||||
|
EditorUndoRedoManager::get_singleton()->set_history_as_unsaved(editor_data.get_current_edited_scene_history_id());
|
||||||
|
}
|
||||||
|
|
||||||
|
_update_title();
|
||||||
|
scene_tabs->update_scene_tabs();
|
||||||
|
_add_to_recent_scenes(lpath);
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5860,15 +5860,36 @@ bool CanvasItemEditorViewport::_create_instance(Node *parent, String &path, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CanvasItemEditorViewport::_perform_drop_data() {
|
void CanvasItemEditorViewport::_perform_drop_data() {
|
||||||
|
ERR_FAIL_COND(selected_files.size() <= 0);
|
||||||
|
|
||||||
_remove_preview();
|
_remove_preview();
|
||||||
|
|
||||||
|
if (!target_node) {
|
||||||
// Without root dropping multiple files is not allowed
|
// Without root dropping multiple files is not allowed
|
||||||
if (!target_node && selected_files.size() > 1) {
|
if (selected_files.size() > 1) {
|
||||||
accept->set_text(TTR("Cannot instantiate multiple nodes without root."));
|
accept->set_text(TTR("Cannot instantiate multiple nodes without root."));
|
||||||
accept->popup_centered();
|
accept->popup_centered();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const String &path = selected_files[0];
|
||||||
|
Ref<Resource> res = ResourceLoader::load(path);
|
||||||
|
if (res.is_null()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref<PackedScene> scene = res;
|
||||||
|
if (scene.is_valid()) {
|
||||||
|
// Without root node act the same as "Load Inherited Scene".
|
||||||
|
Error err = EditorNode::get_singleton()->load_scene(path, false, true);
|
||||||
|
if (err != OK) {
|
||||||
|
accept->set_text(vformat(TTR("Error instantiating scene from %s."), path.get_file()));
|
||||||
|
accept->popup_centered();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PackedStringArray error_files;
|
PackedStringArray error_files;
|
||||||
|
|
||||||
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
||||||
@@ -5882,29 +5903,23 @@ void CanvasItemEditorViewport::_perform_drop_data() {
|
|||||||
if (res.is_null()) {
|
if (res.is_null()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Ref<PackedScene> scene = Ref<PackedScene>(Object::cast_to<PackedScene>(*res));
|
|
||||||
if (scene != nullptr && scene.is_valid()) {
|
Ref<PackedScene> scene = res;
|
||||||
if (!target_node) {
|
if (scene.is_valid()) {
|
||||||
// Without root node act the same as "Load Inherited Scene"
|
|
||||||
Error err = EditorNode::get_singleton()->load_scene(path, false, true);
|
|
||||||
if (err != OK) {
|
|
||||||
error_files.push_back(path.get_file());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
bool success = _create_instance(target_node, path, drop_pos);
|
bool success = _create_instance(target_node, path, drop_pos);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
error_files.push_back(path.get_file());
|
error_files.push_back(path.get_file());
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Ref<Texture2D> texture = Ref<Texture2D>(Object::cast_to<Texture2D>(*res));
|
Ref<Texture2D> texture = res;
|
||||||
if (texture != nullptr && texture.is_valid()) {
|
if (texture.is_valid()) {
|
||||||
Node *child = Object::cast_to<Node>(ClassDB::instantiate(default_texture_node_type));
|
Node *child = Object::cast_to<Node>(ClassDB::instantiate(default_texture_node_type));
|
||||||
_create_nodes(target_node, child, path, drop_pos);
|
_create_nodes(target_node, child, path, drop_pos);
|
||||||
undo_redo->add_do_method(editor_selection, "add_node", child);
|
undo_redo->add_do_method(editor_selection, "add_node", child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
undo_redo->commit_action();
|
undo_redo->commit_action();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user