diff options
Diffstat (limited to 'editor/filesystem_dock.cpp')
-rw-r--r-- | editor/filesystem_dock.cpp | 60 |
1 files changed, 12 insertions, 48 deletions
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 3dd0044ab9..2d6ec0c63a 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -43,6 +43,7 @@ #include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/import_dock.h" +#include "editor/scene_create_dialog.h" #include "editor/scene_tree_dock.h" #include "editor/shader_create_dialog.h" #include "scene/gui/label.h" @@ -1469,44 +1470,12 @@ void FileSystemDock::_make_dir_confirm() { } void FileSystemDock::_make_scene_confirm() { - String scene_name = make_scene_dialog_text->get_text().strip_edges(); - - if (scene_name.length() == 0) { - EditorNode::get_singleton()->show_warning(TTR("No name provided.")); - return; - } - - String directory = path; - if (!directory.ends_with("/")) { - directory = directory.get_base_dir(); - } - - String extension = scene_name.get_extension(); - List<String> extensions; - Ref<PackedScene> sd = memnew(PackedScene); - ResourceSaver::get_recognized_extensions(sd, &extensions); - - bool extension_correct = false; - for (const String &E : extensions) { - if (E == extension) { - extension_correct = true; - break; - } - } - if (!extension_correct) { - scene_name = scene_name.get_basename() + ".tscn"; - } - - scene_name = directory.plus_file(scene_name); - - Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES); - if (da->file_exists(scene_name)) { - EditorNode::get_singleton()->show_warning(TTR("A file or folder with this name already exists.")); - return; - } + const String scene_path = make_scene_dialog->get_scene_path(); int idx = EditorNode::get_singleton()->new_scene(); - EditorNode::get_singleton()->get_editor_data().set_scene_path(idx, scene_name); + EditorNode::get_singleton()->get_editor_data().set_scene_path(idx, scene_path); + EditorNode::get_singleton()->set_edited_scene(make_scene_dialog->create_scene_root()); + EditorNode::get_singleton()->save_scene_list({ scene_path }); } void FileSystemDock::_file_removed(String p_file) { @@ -2003,10 +1972,12 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_NEW_SCENE: { - make_scene_dialog_text->set_text("new scene"); - make_scene_dialog_text->select_all(); - make_scene_dialog->popup_centered(Size2(250, 80) * EDSCALE); - make_scene_dialog_text->grab_focus(); + String directory = path; + if (!directory.ends_with("/")) { + directory = directory.get_base_dir(); + } + make_scene_dialog->config(directory); + make_scene_dialog->popup_centered(); } break; case FILE_NEW_SCRIPT: { @@ -3216,15 +3187,8 @@ FileSystemDock::FileSystemDock() { make_dir_dialog->register_text_enter(make_dir_dialog_text); make_dir_dialog->connect("confirmed", callable_mp(this, &FileSystemDock::_make_dir_confirm)); - make_scene_dialog = memnew(ConfirmationDialog); - make_scene_dialog->set_title(TTR("Create Scene")); - VBoxContainer *make_scene_dialog_vb = memnew(VBoxContainer); - make_scene_dialog->add_child(make_scene_dialog_vb); - - make_scene_dialog_text = memnew(LineEdit); - make_scene_dialog_vb->add_margin_child(TTR("Name:"), make_scene_dialog_text); + make_scene_dialog = memnew(SceneCreateDialog); add_child(make_scene_dialog); - make_scene_dialog->register_text_enter(make_scene_dialog_text); make_scene_dialog->connect("confirmed", callable_mp(this, &FileSystemDock::_make_scene_confirm)); make_script_dialog = memnew(ScriptCreateDialog); |