Update remaps in "file_removed" signal

This commit is contained in:
PucklaMotzer09 2022-01-04 17:23:35 +01:00
parent e6b0496415
commit 0f9086e131
2 changed files with 36 additions and 2 deletions

View File

@ -382,6 +382,7 @@ void LocalizationEditor::_update_pot_file_extensions() {
void LocalizationEditor::connect_filesystem_dock_signals(FileSystemDock *p_fs_dock) { void LocalizationEditor::connect_filesystem_dock_signals(FileSystemDock *p_fs_dock) {
p_fs_dock->connect("files_moved", callable_mp(this, &LocalizationEditor::_filesystem_files_moved)); p_fs_dock->connect("files_moved", callable_mp(this, &LocalizationEditor::_filesystem_files_moved));
p_fs_dock->connect("file_removed", callable_mp(this, &LocalizationEditor::_filesystem_file_removed));
} }
void LocalizationEditor::_filesystem_files_moved(const String &p_old_file, const String &p_new_file) { void LocalizationEditor::_filesystem_files_moved(const String &p_old_file, const String &p_new_file) {
@ -409,8 +410,7 @@ void LocalizationEditor::_filesystem_files_moved(const String &p_old_file, const
bool remapped_files_updated = false; bool remapped_files_updated = false;
for (int j = 0; j < remapped_files.size(); j++) { for (int j = 0; j < remapped_files.size(); j++) {
// Find the first ':' after 'res://'. int splitter_pos = remapped_files[j].rfind(":");
int splitter_pos = remapped_files[j].find(":", remapped_files[j].find("/"));
String res_path = remapped_files[j].substr(0, splitter_pos); String res_path = remapped_files[j].substr(0, splitter_pos);
if (res_path == p_old_file) { if (res_path == p_old_file) {
@ -436,6 +436,39 @@ void LocalizationEditor::_filesystem_files_moved(const String &p_old_file, const
} }
} }
void LocalizationEditor::_filesystem_file_removed(const String &p_file) {
// Check if the remaps are affected.
Dictionary remaps;
if (ProjectSettings::get_singleton()->has_setting("internationalization/locale/translation_remaps")) {
remaps = ProjectSettings::get_singleton()->get("internationalization/locale/translation_remaps");
}
bool remaps_changed = remaps.has(p_file);
if (!remaps_changed) {
Array remap_keys = remaps.keys();
for (int i = 0; i < remap_keys.size() && !remaps_changed; i++) {
PackedStringArray remapped_files = remaps[remap_keys[i]];
for (int j = 0; j < remapped_files.size() && !remaps_changed; j++) {
int splitter_pos = remapped_files[j].rfind(":");
String res_path = remapped_files[j].substr(0, splitter_pos);
remaps_changed = p_file == res_path;
if (remaps_changed) {
print_verbose(vformat("Remap value \"%s\" of key \"%s\" has been removed from the file system.", remapped_files[j], remap_keys[i]));
}
}
}
} else {
print_verbose(vformat("Remap key \"%s\" has been removed from the file system.", p_file));
}
if (remaps_changed) {
update_translations();
emit_signal("localization_changed");
}
}
void LocalizationEditor::update_translations() { void LocalizationEditor::update_translations() {
if (updating_translations) { if (updating_translations) {
return; return;

View File

@ -83,6 +83,7 @@ class LocalizationEditor : public VBoxContainer {
void _update_pot_file_extensions(); void _update_pot_file_extensions();
void _filesystem_files_moved(const String &p_old_file, const String &p_new_file); void _filesystem_files_moved(const String &p_old_file, const String &p_new_file);
void _filesystem_file_removed(const String &p_file);
protected: protected:
void _notification(int p_what); void _notification(int p_what);