Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose 'Reimport' on right-click context menu in the FileSystem panel #75137

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2034,13 +2034,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 @@ -2650,6 +2644,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 @@ -316,6 +316,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 @@ -98,6 +98,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