mirror of
https://github.com/godotengine/godot
synced 2024-09-05 05:38:35 +00:00
Merge pull request #75137 from nongvantinh/implement-6320
Expose 'Reimport' on right-click context menu in the FileSystem panel
This commit is contained in:
commit
bbfa74a991
|
@ -2200,13 +2200,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
|
|||
} break;
|
||||
|
||||
case FILE_REIMPORT: {
|
||||
// Reimport all selected files.
|
||||
Vector<String> 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: {
|
||||
|
@ -2830,6 +2824,37 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str
|
|||
if (!all_not_favorites) {
|
||||
p_popup->add_icon_item(get_theme_icon(SNAME("NonFavorite"), SNAME("EditorIcons")), TTR("Remove from Favorites"), FILE_REMOVE_FAVORITE);
|
||||
}
|
||||
|
||||
{
|
||||
List<String> resource_extensions;
|
||||
ResourceFormatImporter::get_singleton()->get_recognized_extensions_for_type("Resource", &resource_extensions);
|
||||
HashSet<String> 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) {
|
||||
|
|
|
@ -324,6 +324,21 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) {
|
|||
}
|
||||
}
|
||||
|
||||
void ImportDock::reimport_resources(const Vector<String> &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();
|
||||
|
||||
|
|
|
@ -102,6 +102,7 @@ protected:
|
|||
public:
|
||||
void set_edit_path(const String &p_path);
|
||||
void set_edit_multiple_paths(const Vector<String> &p_paths);
|
||||
void reimport_resources(const Vector<String> &p_paths);
|
||||
void initialize_import_options() const;
|
||||
void clear();
|
||||
|
||||
|
|
Loading…
Reference in a new issue