diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index c8bb5a5fc3de..722946dce538 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -2034,13 +2034,7 @@ void FileSystemDock::_file_option(int p_option, const Vector &p_selected } break; case FILE_REIMPORT: { - // Reimport all selected files. - Vector reimport; - for (int i = 0; i < p_selected.size(); i++) { - reimport.push_back(p_selected[i]); - } - - ERR_FAIL_COND_MSG(reimport.size() == 0, "You need to select files to reimport them."); + ImportDock::get_singleton()->reimport_resources(p_selected); } break; case FILE_NEW_FOLDER: { @@ -2650,6 +2644,37 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vectoradd_icon_item(get_theme_icon(SNAME("NonFavorite"), SNAME("EditorIcons")), TTR("Remove from Favorites"), FILE_REMOVE_FAVORITE); } + + { + List resource_extensions; + ResourceFormatImporter::get_singleton()->get_recognized_extensions_for_type("Resource", &resource_extensions); + HashSet extension_list; + for (const String &extension : resource_extensions) { + extension_list.insert(extension); + } + + bool resource_valid = true; + String main_extension; + + for (int i = 0; i != p_paths.size(); ++i) { + String extension = p_paths[i].get_extension(); + if (extension_list.has(extension)) { + if (main_extension.is_empty()) { + main_extension = extension; + } else if (extension != main_extension) { + resource_valid = false; + break; + } + } else { + resource_valid = false; + break; + } + } + + if (resource_valid) { + p_popup->add_icon_item(get_theme_icon(SNAME("Load"), SNAME("EditorIcons")), TTR("Reimport"), FILE_REIMPORT); + } + } } if (p_paths.size() == 1) { diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp index b5680f2f2c31..824a65c443ee 100644 --- a/editor/import_dock.cpp +++ b/editor/import_dock.cpp @@ -316,6 +316,21 @@ void ImportDock::set_edit_multiple_paths(const Vector &p_paths) { } } +void ImportDock::reimport_resources(const Vector &p_paths) { + switch (p_paths.size()) { + case 0: + ERR_FAIL_MSG("You need to select files to reimport them."); + case 1: + set_edit_path(p_paths[0]); + break; + default: + set_edit_multiple_paths(p_paths); + break; + } + + _reimport_attempt(); +} + void ImportDock::_update_preset_menu() { preset->get_popup()->clear(); diff --git a/editor/import_dock.h b/editor/import_dock.h index f627cd965d15..57f3e820a358 100644 --- a/editor/import_dock.h +++ b/editor/import_dock.h @@ -98,6 +98,7 @@ class ImportDock : public VBoxContainer { public: void set_edit_path(const String &p_path); void set_edit_multiple_paths(const Vector &p_paths); + void reimport_resources(const Vector &p_paths); void initialize_import_options() const; void clear();