diff options
Diffstat (limited to 'editor/editor_data.cpp')
-rw-r--r-- | editor/editor_data.cpp | 89 |
1 files changed, 62 insertions, 27 deletions
diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index 4c4dacbeb5..fa4703d425 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -273,16 +273,6 @@ EditorPlugin *EditorData::get_editor(Object *p_object) { return nullptr; } -EditorPlugin *EditorData::get_subeditor(Object *p_object) { - for (int i = editor_plugins.size() - 1; i > -1; i--) { - if (!editor_plugins[i]->has_main_screen() && editor_plugins[i]->handles(p_object)) { - return editor_plugins[i]; - } - } - - return nullptr; -} - Vector<EditorPlugin *> EditorData::get_subeditors(Object *p_object) { Vector<EditorPlugin *> sub_plugins; for (int i = editor_plugins.size() - 1; i > -1; i--) { @@ -468,24 +458,25 @@ void EditorData::add_custom_type(const String &p_type, const String &p_inherits, custom_types[p_inherits].push_back(ct); } -Object *EditorData::instance_custom_type(const String &p_type, const String &p_inherits) { +Variant EditorData::instance_custom_type(const String &p_type, const String &p_inherits) { if (get_custom_types().has(p_inherits)) { for (int i = 0; i < get_custom_types()[p_inherits].size(); i++) { if (get_custom_types()[p_inherits][i].name == p_type) { Ref<Script> script = get_custom_types()[p_inherits][i].script; - Object *ob = ClassDB::instance(p_inherits); - ERR_FAIL_COND_V(!ob, nullptr); - if (ob->is_class("Node")) { - ob->call("set_name", p_type); + Variant ob = ClassDB::instance(p_inherits); + ERR_FAIL_COND_V(!ob, Variant()); + Node *n = Object::cast_to<Node>(ob); + if (n) { + n->set_name(p_type); } - ob->set_script(script); + ((Object *)ob)->set_script(script); return ob; } } } - return nullptr; + return Variant(); } void EditorData::remove_custom_type(const String &p_type) { @@ -509,6 +500,7 @@ int EditorData::add_edited_scene(int p_at_pos) { EditedScene es; es.root = nullptr; es.path = String(); + es.file_modified_time = 0; es.history_current = -1; es.version = 0; es.live_edit_root = NodePath(String("/root")); @@ -665,6 +657,10 @@ void EditorData::set_edited_scene_root(Node *p_root) { p_root->set_filename(edited_scene[current_edited_scene].path); } } + + if (edited_scene[current_edited_scene].path != "") { + edited_scene.write[current_edited_scene].file_modified_time = FileAccess::get_modified_time(edited_scene[current_edited_scene].path); + } } int EditorData::get_edited_scene_count() const { @@ -696,6 +692,21 @@ uint64_t EditorData::get_scene_version(int p_idx) const { return edited_scene[p_idx].version; } +void EditorData::set_scene_modified_time(int p_idx, uint64_t p_time) { + if (p_idx == -1) { + p_idx = current_edited_scene; + } + + ERR_FAIL_INDEX(p_idx, edited_scene.size()); + + edited_scene.write[p_idx].file_modified_time = p_time; +} + +uint64_t EditorData::get_scene_modified_time(int p_idx) const { + ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), 0); + return edited_scene[p_idx].file_modified_time; +} + String EditorData::get_scene_type(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String()); if (!edited_scene[p_idx].root) { @@ -730,7 +741,7 @@ Ref<Script> EditorData::get_scene_root_script(int p_idx) const { return s; } -String EditorData::get_scene_title(int p_idx) const { +String EditorData::get_scene_title(int p_idx, bool p_always_strip_extension) const { ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String()); if (!edited_scene[p_idx].root) { return TTR("[empty]"); @@ -738,12 +749,28 @@ String EditorData::get_scene_title(int p_idx) const { if (edited_scene[p_idx].root->get_filename() == "") { return TTR("[unsaved]"); } - bool show_ext = EDITOR_DEF("interface/scene_tabs/show_extension", false); - String name = edited_scene[p_idx].root->get_filename().get_file(); - if (!show_ext) { - name = name.get_basename(); + + const String filename = edited_scene[p_idx].root->get_filename().get_file(); + const String basename = filename.get_basename(); + + if (p_always_strip_extension) { + return basename; + } + + // Return the filename including the extension if there's ambiguity (e.g. both `foo.tscn` and `foo.scn` are being edited). + for (int i = 0; i < edited_scene.size(); i++) { + if (i == p_idx) { + // Don't compare the edited scene against itself. + continue; + } + + if (edited_scene[i].root && basename == edited_scene[i].root->get_filename().get_file().get_basename()) { + return filename; + } } - return name; + + // Else, return just the basename as there's no ambiguity. + return basename; } void EditorData::set_scene_path(int p_idx, const String &p_path) { @@ -867,18 +894,18 @@ StringName EditorData::script_class_get_base(const String &p_class) const { return script->get_language()->get_global_class_name(base_script->get_path()); } -Object *EditorData::script_class_instance(const String &p_class) { +Variant EditorData::script_class_instance(const String &p_class) { if (ScriptServer::is_global_class(p_class)) { - Object *obj = ClassDB::instance(ScriptServer::get_global_class_native_base(p_class)); + Variant obj = ClassDB::instance(ScriptServer::get_global_class_native_base(p_class)); if (obj) { Ref<Script> script = script_class_load_script(p_class); if (script.is_valid()) { - obj->set_script(script); + ((Object *)obj)->set_script(script); } return obj; } } - return nullptr; + return Variant(); } Ref<Script> EditorData::script_class_load_script(const String &p_class) const { @@ -931,6 +958,14 @@ void EditorData::script_class_save_icon_paths() { } } + Dictionary old; + if (ProjectSettings::get_singleton()->has_setting("_global_script_class_icons")) { + old = ProjectSettings::get_singleton()->get("_global_script_class_icons"); + } + if ((!old.is_empty() || d.is_empty()) && d.hash() == old.hash()) { + return; + } + if (d.is_empty()) { if (ProjectSettings::get_singleton()->has_setting("_global_script_class_icons")) { ProjectSettings::get_singleton()->clear("_global_script_class_icons"); |