Skip to content

Commit

Permalink
Merge pull request #75137 from nongvantinh/implement-6320
Browse files Browse the repository at this point in the history
Expose 'Reimport' on right-click context menu in the FileSystem panel
  • Loading branch information
akien-mga committed Aug 7, 2023
2 parents 40f116f + f40a5fc commit bbfa74a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
39 changes: 32 additions & 7 deletions editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions editor/import_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions editor/import_dock.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class ImportDock : public VBoxContainer {
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();

Expand Down

0 comments on commit bbfa74a

Please sign in to comment.