summaryrefslogtreecommitdiff
path: root/editor/editor_node.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_node.cpp')
-rw-r--r--editor/editor_node.cpp158
1 files changed, 100 insertions, 58 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index dbbf5d08b8..d009ed61b5 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -384,7 +384,6 @@ void EditorNode::_notification(int p_what) {
update_menu->set_icon(gui_base->get_icon("Progress1", "EditorIcons"));
PopupMenu *p = help_menu->get_popup();
- p->set_item_icon(p->get_item_index(HELP_CLASSES), gui_base->get_icon("ClassList", "EditorIcons"));
p->set_item_icon(p->get_item_index(HELP_SEARCH), gui_base->get_icon("HelpSearch", "EditorIcons"));
p->set_item_icon(p->get_item_index(HELP_DOCS), gui_base->get_icon("Instance", "EditorIcons"));
p->set_item_icon(p->get_item_index(HELP_QA), gui_base->get_icon("Instance", "EditorIcons"));
@@ -410,51 +409,50 @@ void EditorNode::_on_plugin_ready(Object *p_script, const String &p_activate_nam
push_item(script.operator->());
}
-void EditorNode::_fs_changed() {
+void EditorNode::_resources_changed(const PoolVector<String> &p_resources) {
- for (Set<FileDialog *>::Element *E = file_dialogs.front(); E; E = E->next()) {
+ List<Ref<Resource> > changed;
- E->get()->invalidate();
- }
+ int rc = p_resources.size();
+ for (int i = 0; i < rc; i++) {
- for (Set<EditorFileDialog *>::Element *E = editor_file_dialogs.front(); E; E = E->next()) {
+ Ref<Resource> res(ResourceCache::get(p_resources.get(i)));
+ if (res.is_null()) {
+ continue;
+ }
- E->get()->invalidate();
- }
+ if (!res->editor_can_reload_from_file())
+ continue;
+ if (!res->get_path().is_resource_file() && !res->get_path().is_abs_path())
+ continue;
+ if (!FileAccess::exists(res->get_path()))
+ continue;
- {
- //reload changed resources
- List<Ref<Resource> > changed;
+ if (res->get_import_path() != String()) {
+ //this is an imported resource, will be reloaded if reimported via the _resources_reimported() callback
+ continue;
+ }
- List<Ref<Resource> > cached;
- ResourceCache::get_cached_resources(&cached);
- // FIXME: This should be done in a thread.
- for (List<Ref<Resource> >::Element *E = cached.front(); E; E = E->next()) {
+ changed.push_back(res);
+ }
- if (!E->get()->editor_can_reload_from_file())
- continue;
- if (!E->get()->get_path().is_resource_file() && !E->get()->get_path().is_abs_path())
- continue;
- if (!FileAccess::exists(E->get()->get_path()))
- continue;
+ if (changed.size()) {
+ for (List<Ref<Resource> >::Element *E = changed.front(); E; E = E->next()) {
+ E->get()->reload_from_file();
+ }
+ }
+}
- if (E->get()->get_import_path() != String()) {
- //this is an imported resource, will be reloaded if reimported via the _resources_reimported() callback
- continue;
- }
+void EditorNode::_fs_changed() {
- uint64_t mt = FileAccess::get_modified_time(E->get()->get_path());
+ for (Set<FileDialog *>::Element *E = file_dialogs.front(); E; E = E->next()) {
- if (mt != E->get()->get_last_modified_time()) {
- changed.push_back(E->get());
- }
- }
+ E->get()->invalidate();
+ }
- if (changed.size()) {
- for (List<Ref<Resource> >::Element *E = changed.front(); E; E = E->next()) {
- E->get()->reload_from_file();
- }
- }
+ for (Set<EditorFileDialog *>::Element *E = editor_file_dialogs.front(); E; E = E->next()) {
+
+ E->get()->invalidate();
}
_mark_unsaved_scenes();
@@ -637,6 +635,7 @@ void EditorNode::save_resource(const Ref<Resource> &p_resource) {
void EditorNode::save_resource_as(const Ref<Resource> &p_resource, const String &p_at_path) {
file->set_mode(EditorFileDialog::MODE_SAVE_FILE);
+ saving_resource = p_resource;
current_option = RESOURCE_SAVE_AS;
List<String> extensions;
@@ -1000,6 +999,22 @@ void EditorNode::_save_scene_with_preview(String p_file, int p_idx) {
EditorResourcePreview::get_singleton()->check_for_invalidation(p_file);
}
+bool EditorNode::_validate_scene_recursive(const String &p_filename, Node *p_node) {
+
+ for (int i = 0; i < p_node->get_child_count(); i++) {
+ Node *child = p_node->get_child(i);
+ if (child->get_filename() == p_filename) {
+ return true;
+ }
+
+ if (_validate_scene_recursive(p_filename, child)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
void EditorNode::_save_scene(String p_file, int idx) {
Node *scene = editor_data.get_edited_scene_root(idx);
@@ -1010,6 +1025,11 @@ void EditorNode::_save_scene(String p_file, int idx) {
return;
}
+ if (scene->get_filename() != String() && _validate_scene_recursive(scene->get_filename(), scene)) {
+ show_accept(TTR("This scene can't be saved because there is a cyclic instancing inclusion.\nPlease resolve it and then attempt to save again."), TTR("OK"));
+ return;
+ }
+
editor_data.apply_changes_in_editors();
_save_default_environment();
@@ -1263,15 +1283,13 @@ void EditorNode::_dialog_action(String p_file) {
case RESOURCE_SAVE:
case RESOURCE_SAVE_AS: {
- uint32_t current = editor_history.get_current();
+ ERR_FAIL_COND(saving_resource.is_null())
+ save_resource_in_path(saving_resource, p_file);
+ saving_resource = Ref<Resource>();
+ ObjectID current = editor_history.get_current();
Object *current_obj = current > 0 ? ObjectDB::get_instance(current) : NULL;
-
- ERR_FAIL_COND(!Object::cast_to<Resource>(current_obj))
-
- RES current_res = RES(Object::cast_to<Resource>(current_obj));
-
- save_resource_in_path(current_res, p_file);
-
+ ERR_FAIL_COND(!current_obj);
+ current_obj->_change_notify();
} break;
case SETTINGS_LAYOUT_SAVE: {
@@ -2003,7 +2021,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
if (err != OK)
ERR_PRINT("Failed to load scene");
editor_data.move_edited_scene_to_index(cur_idx);
- get_undo_redo()->clear_history();
+ get_undo_redo()->clear_history(false);
scene_tabs->set_current_tab(cur_idx);
} break;
@@ -2263,9 +2281,6 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
file->popup_centered_ratio();
} break;
- case HELP_CLASSES: {
- emit_signal("request_help_index", "");
- } break;
case HELP_SEARCH: {
emit_signal("request_help_search", "");
} break;
@@ -2570,6 +2585,12 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled)
return;
}
+ //errors in the script cause the base_type to be ""
+ if (String(script->get_instance_base_type()) == "") {
+ show_warning(vformat(TTR("Unable to load addon script from path: '%s' There seems to be an error in the code, please check the syntax."), path));
+ return;
+ }
+
//could check inheritance..
if (String(script->get_instance_base_type()) != "EditorPlugin") {
show_warning(vformat(TTR("Unable to load addon script from path: '%s' Base type is not EditorPlugin."), path));
@@ -2613,7 +2634,7 @@ void EditorNode::_remove_edited_scene() {
}
_scene_tab_changed(new_index);
editor_data.remove_scene(old_index);
- editor_data.get_undo_redo().clear_history();
+ editor_data.get_undo_redo().clear_history(false);
_update_title();
_update_scene_tabs();
}
@@ -2926,7 +2947,12 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b
_update_scene_tabs();
_add_to_recent_scenes(lpath);
- editor_folding.load_scene_folding(new_scene, lpath);
+ if (editor_folding.has_folding_data(lpath)) {
+ editor_folding.load_scene_folding(new_scene, lpath);
+ } else if (EDITOR_GET("interface/inspector/auto_unfold_foreign_scenes")) {
+ editor_folding.unfold_scene(new_scene);
+ editor_folding.save_scene_folding(new_scene, lpath);
+ }
prev_scene->set_disabled(previous_scenes.size() == 0);
opening_prev = false;
@@ -3223,17 +3249,31 @@ Ref<Texture> EditorNode::get_class_icon(const String &p_class, const String &p_f
void EditorNode::progress_add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel) {
- singleton->progress_dialog->add_task(p_task, p_label, p_steps, p_can_cancel);
+ if (singleton->disable_progress_dialog) {
+ print_line(p_task + ": begin: " + p_label + " steps: " + itos(p_steps));
+ } else {
+ singleton->progress_dialog->add_task(p_task, p_label, p_steps, p_can_cancel);
+ }
}
bool EditorNode::progress_task_step(const String &p_task, const String &p_state, int p_step, bool p_force_refresh) {
- return singleton->progress_dialog->task_step(p_task, p_state, p_step, p_force_refresh);
+ if (singleton->disable_progress_dialog) {
+ print_line("\t" + p_task + ": step " + itos(p_step) + ": " + p_state);
+ return false;
+ } else {
+
+ return singleton->progress_dialog->task_step(p_task, p_state, p_step, p_force_refresh);
+ }
}
void EditorNode::progress_end_task(const String &p_task) {
- singleton->progress_dialog->end_task(p_task);
+ if (singleton->disable_progress_dialog) {
+ print_line(p_task + ": end");
+ } else {
+ singleton->progress_dialog->end_task(p_task);
+ }
}
void EditorNode::progress_add_task_bg(const String &p_task, const String &p_label, int p_steps) {
@@ -3315,7 +3355,7 @@ Error EditorNode::export_preset(const String &p_preset, const String &p_path, bo
export_defer.path = p_path;
export_defer.debug = p_debug;
export_defer.password = p_password;
-
+ disable_progress_dialog = true;
return OK;
}
@@ -4651,11 +4691,12 @@ void EditorNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("_video_driver_selected"), &EditorNode::_video_driver_selected);
+ ClassDB::bind_method(D_METHOD("_resources_changed"), &EditorNode::_resources_changed);
+
ADD_SIGNAL(MethodInfo("play_pressed"));
ADD_SIGNAL(MethodInfo("pause_pressed"));
ADD_SIGNAL(MethodInfo("stop_pressed"));
ADD_SIGNAL(MethodInfo("request_help_search"));
- ADD_SIGNAL(MethodInfo("request_help_index"));
ADD_SIGNAL(MethodInfo("script_add_function_request", PropertyInfo(Variant::OBJECT, "obj"), PropertyInfo(Variant::STRING, "function"), PropertyInfo(Variant::POOL_STRING_ARRAY, "args")));
ADD_SIGNAL(MethodInfo("resource_saved", PropertyInfo(Variant::OBJECT, "obj")));
}
@@ -4704,7 +4745,7 @@ EditorNode::EditorNode() {
_initializing_addons = false;
docks_visible = true;
restoring_scenes = false;
-
+ disable_progress_dialog = false;
scene_distraction = false;
script_distraction = false;
@@ -4877,7 +4918,7 @@ EditorNode::EditorNode() {
EDITOR_DEF_RST("interface/scene_tabs/show_thumbnail_on_hover", true);
EDITOR_DEF_RST("interface/inspector/capitalize_properties", true);
EDITOR_DEF_RST("interface/inspector/disable_folding", false);
- EDITOR_DEF_RST("interface/inspector/auto_unfold_edited", true);
+ EDITOR_DEF_RST("interface/inspector/auto_unfold_foreign_scenes", true);
EDITOR_DEF("interface/inspector/horizontal_vector2_editing", false);
EDITOR_DEF("interface/inspector/horizontal_vector_types_editing", true);
EDITOR_DEF("interface/inspector/open_resources_in_current_inspector", true);
@@ -5341,8 +5382,7 @@ EditorNode::EditorNode() {
p = help_menu->get_popup();
p->set_hide_on_window_lose_focus(true);
p->connect("id_pressed", this, "_menu_option");
- p->add_icon_item(gui_base->get_icon("ClassList", "EditorIcons"), TTR("Classes"), HELP_CLASSES);
- p->add_icon_item(gui_base->get_icon("HelpSearch", "EditorIcons"), TTR("Search"), HELP_SEARCH);
+ p->add_icon_shortcut(gui_base->get_icon("HelpSearch", "EditorIcons"), ED_SHORTCUT("editor/editor_help", TTR("Search"), KEY_F4), HELP_SEARCH);
p->add_separator();
p->add_icon_item(gui_base->get_icon("Instance", "EditorIcons"), TTR("Online Docs"), HELP_DOCS);
p->add_icon_item(gui_base->get_icon("Instance", "EditorIcons"), TTR("Q&A"), HELP_QA);
@@ -5777,6 +5817,7 @@ EditorNode::EditorNode() {
_edit_current();
current = NULL;
+ saving_resource = Ref<Resource>();
reference_resource_mem = true;
save_external_resources_mem = true;
@@ -5819,6 +5860,7 @@ EditorNode::EditorNode() {
EditorFileSystem::get_singleton()->connect("sources_changed", this, "_sources_changed");
EditorFileSystem::get_singleton()->connect("filesystem_changed", this, "_fs_changed");
EditorFileSystem::get_singleton()->connect("resources_reimported", this, "_resources_reimported");
+ EditorFileSystem::get_singleton()->connect("resources_reload", this, "_resources_changed");
_build_icon_type_cache();