diff options
Diffstat (limited to 'editor/editor_node.cpp')
-rw-r--r-- | editor/editor_node.cpp | 104 |
1 files changed, 53 insertions, 51 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index dbbf5d08b8..3129ef3508 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; @@ -1263,15 +1262,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 +2000,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 +2260,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 +2564,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 +2613,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(); } @@ -4651,11 +4651,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"))); } @@ -5341,8 +5342,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 +5777,7 @@ EditorNode::EditorNode() { _edit_current(); current = NULL; + saving_resource = Ref<Resource>(); reference_resource_mem = true; save_external_resources_mem = true; @@ -5819,6 +5820,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(); |