Properly warn about the effects of changing an import type, as well as force editor restart. Fixes #23874

This commit is contained in:
Juan Linietsky 2019-01-25 17:23:56 -03:00
parent 6d4d55cd42
commit 5bd3f72878
6 changed files with 90 additions and 8 deletions

View file

@ -1108,12 +1108,15 @@ void EditorNode::_save_scene(String p_file, int idx) {
}
}
void EditorNode::save_all_scenes_and_restart() {
void EditorNode::save_all_scenes() {
_menu_option_confirm(RUN_STOP, true);
exiting = true;
_save_all_scenes();
}
void EditorNode::restart_editor() {
exiting = true;
String to_reopen;
if (get_tree()->get_edited_scene_root()) {
@ -2305,7 +2308,8 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
ProjectSettings::get_singleton()->set("rendering/quality/driver/driver_name", video_driver_request);
ProjectSettings::get_singleton()->save();
save_all_scenes_and_restart();
save_all_scenes();
restart_editor();
} break;
default: {
if (p_option >= IMPORT_PLUGIN_BASE) {

View file

@ -782,7 +782,8 @@ public:
void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu);
void remove_tool_menu_item(const String &p_name);
void save_all_scenes_and_restart();
void save_all_scenes();
void restart_editor();
void dim_editor(bool p_dimming);

View file

@ -372,6 +372,62 @@ void ImportDock::clear() {
preset->get_popup()->clear();
}
static bool _find_owners(EditorFileSystemDirectory *efsd, const String &p_path) {
if (!efsd)
return false;
for (int i = 0; i < efsd->get_subdir_count(); i++) {
if (_find_owners(efsd->get_subdir(i), p_path)) {
return true;
}
}
for (int i = 0; i < efsd->get_file_count(); i++) {
Vector<String> deps = efsd->get_file_deps(i);
if (deps.find(p_path) != -1)
return true;
}
return false;
}
void ImportDock::_reimport_attempt() {
bool need_restart = false;
bool used_in_resources = false;
for (int i = 0; i < params->paths.size(); i++) {
Ref<ConfigFile> config;
config.instance();
Error err = config->load(params->paths[i] + ".import");
ERR_CONTINUE(err != OK);
String imported_with = config->get_value("remap", "importer");
if (imported_with != params->importer->get_importer_name()) {
need_restart = true;
if (_find_owners(EditorFileSystem::get_singleton()->get_filesystem(), params->paths[i])) {
used_in_resources = true;
}
}
}
if (need_restart) {
label_warning->set_visible(used_in_resources);
reimport_confirm->popup_centered_minsize();
return;
}
_reimport();
}
void ImportDock::_reimport_and_restart() {
EditorNode::get_singleton()->save_all_scenes();
_reimport();
EditorNode::get_singleton()->restart_editor();
}
void ImportDock::_reimport() {
for (int i = 0; i < params->paths.size(); i++) {
@ -416,6 +472,7 @@ void ImportDock::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
import_opts->edit(params);
label_warning->add_color_override("font_color", get_color("warning_color", "Editor"));
} break;
}
}
@ -433,6 +490,8 @@ void ImportDock::_bind_methods() {
ClassDB::bind_method(D_METHOD("_preset_selected"), &ImportDock::_preset_selected);
ClassDB::bind_method(D_METHOD("_importer_selected"), &ImportDock::_importer_selected);
ClassDB::bind_method(D_METHOD("_property_toggled"), &ImportDock::_property_toggled);
ClassDB::bind_method(D_METHOD("_reimport_and_restart"), &ImportDock::_reimport_and_restart);
ClassDB::bind_method(D_METHOD("_reimport_attempt"), &ImportDock::_reimport_attempt);
}
void ImportDock::initialize_import_options() const {
@ -469,11 +528,22 @@ ImportDock::ImportDock() {
add_child(hb);
import = memnew(Button);
import->set_text(TTR("Reimport"));
import->connect("pressed", this, "_reimport");
import->connect("pressed", this, "_reimport_attempt");
hb->add_spacer();
hb->add_child(import);
hb->add_spacer();
reimport_confirm = memnew(ConfirmationDialog);
reimport_confirm->get_ok()->set_text(TTR("Save scenes, re-import and restart"));
add_child(reimport_confirm);
reimport_confirm->connect("confirmed", this, "_reimport_and_restart");
VBoxContainer *vbc_confirm = memnew(VBoxContainer());
vbc_confirm->add_child(memnew(Label(TTR("Changing the type of an imported file requires editor restart."))));
label_warning = memnew(Label(TTR("WARNING: Assets exist that use this resource, they may stop loading properly.")));
vbc_confirm->add_child(label_warning);
reimport_confirm->add_child(vbc_confirm);
params = memnew(ImportDockParameters);
}

View file

@ -36,6 +36,7 @@
#include "editor/editor_file_system.h"
#include "editor/editor_inspector.h"
#include "scene/gui/box_container.h"
#include "scene/gui/dialogs.h"
#include "scene/gui/menu_button.h"
#include "scene/gui/option_button.h"
#include "scene/gui/popup_menu.h"
@ -52,6 +53,8 @@ class ImportDock : public VBoxContainer {
List<PropertyInfo> properties;
Map<StringName, Variant> property_values;
ConfirmationDialog *reimport_confirm;
Label *label_warning;
Button *import;
ImportDockParameters *params;
@ -61,6 +64,8 @@ class ImportDock : public VBoxContainer {
void _update_options(const Ref<ConfigFile> &p_config = Ref<ConfigFile>());
void _property_toggled(const StringName &p_prop, bool p_checked);
void _reimport_attempt();
void _reimport_and_restart();
void _reimport();
enum {

View file

@ -1606,7 +1606,8 @@ TabContainer *ProjectSettingsEditor::get_tabs() {
}
void ProjectSettingsEditor::_editor_restart() {
EditorNode::get_singleton()->save_all_scenes_and_restart();
EditorNode::get_singleton()->save_all_scenes();
EditorNode::get_singleton()->restart_editor();
}
void ProjectSettingsEditor::_editor_restart_request() {

View file

@ -375,7 +375,8 @@ void EditorSettingsDialog::_focus_current_search_box() {
}
void EditorSettingsDialog::_editor_restart() {
EditorNode::get_singleton()->save_all_scenes_and_restart();
EditorNode::get_singleton()->save_all_scenes();
EditorNode::get_singleton()->restart_editor();
}
void EditorSettingsDialog::_editor_restart_request() {