Skip to content

Commit ad4c2c3

Browse files
committed
Merge pull request godotengine#116097 from KoBeWi/but_who_will_validate_validation_panel
Fix auto-translation of EditorValidationPanel
2 parents 30faebb + e022526 commit ad4c2c3

9 files changed

Lines changed: 89 additions & 71 deletions

editor/docks/groups_editor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ void GroupsEditor::_show_add_group_dialog() {
704704
add_group_dialog->register_text_enter(add_group_description);
705705

706706
add_validation_panel = memnew(EditorValidationPanel);
707-
add_validation_panel->add_line(EditorValidationPanel::MSG_ID_DEFAULT, TTR("Group name is valid."));
707+
add_validation_panel->add_line(EditorValidationPanel::MSG_ID_DEFAULT, TTRC("Group name is valid."));
708708
add_validation_panel->set_update_callback(callable_mp(this, &GroupsEditor::_check_add));
709709
add_validation_panel->set_accept_button(add_group_dialog->get_ok_button());
710710

@@ -745,7 +745,7 @@ void GroupsEditor::_show_rename_group_dialog() {
745745
rename_group_dialog->register_text_enter(rename_group);
746746

747747
rename_validation_panel = memnew(EditorValidationPanel);
748-
rename_validation_panel->add_line(EditorValidationPanel::MSG_ID_DEFAULT, TTR("Group name is valid."));
748+
rename_validation_panel->add_line(EditorValidationPanel::MSG_ID_DEFAULT, TTRC("Group name is valid."));
749749
rename_validation_panel->set_update_callback(callable_mp(this, &GroupsEditor::_check_rename));
750750
rename_validation_panel->set_accept_button(rename_group_dialog->get_ok_button());
751751

@@ -832,9 +832,9 @@ void GroupsEditor::_check_rename() {
832832

833833
void GroupsEditor::_validate_name(const String &p_name, EditorValidationPanel *p_validation_panel) {
834834
if (p_name.is_empty()) {
835-
p_validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTR("Group can't be empty."), EditorValidationPanel::MSG_ERROR);
835+
p_validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTRC("Group can't be empty."), EditorValidationPanel::MSG_ERROR);
836836
} else if (_has_group(p_name)) {
837-
p_validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTR("Group already exists."), EditorValidationPanel::MSG_ERROR);
837+
p_validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTRC("Group already exists."), EditorValidationPanel::MSG_ERROR);
838838
}
839839
}
840840

editor/gui/directory_create_dialog.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ void DirectoryCreateDialog::_on_dir_path_changed() {
102102
if (error.is_empty()) {
103103
if (path.contains_char('/')) {
104104
if (mode == MODE_DIRECTORY) {
105-
validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTR("Using slashes in folder names will create subfolders recursively."), EditorValidationPanel::MSG_OK);
105+
validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTRC("Using slashes in folder names will create subfolders recursively."), EditorValidationPanel::MSG_OK);
106106
} else {
107-
validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTR("Using slashes in path will create the file in subfolder, creating new subfolders if necessary."), EditorValidationPanel::MSG_OK);
107+
validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTRC("Using slashes in path will create the file in subfolder, creating new subfolders if necessary."), EditorValidationPanel::MSG_OK);
108108
}
109109
} else if (mode == MODE_FILE) {
110-
validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTR("File name is valid."), EditorValidationPanel::MSG_OK);
110+
validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTRC("File name is valid."), EditorValidationPanel::MSG_OK);
111111
}
112112
} else {
113113
validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, error, EditorValidationPanel::MSG_ERROR);
@@ -177,7 +177,7 @@ DirectoryCreateDialog::DirectoryCreateDialog() {
177177

178178
validation_panel = memnew(EditorValidationPanel);
179179
vb->add_child(validation_panel);
180-
validation_panel->add_line(EditorValidationPanel::MSG_ID_DEFAULT, TTR("Folder name is valid."));
180+
validation_panel->add_line(EditorValidationPanel::MSG_ID_DEFAULT, TTRC("Folder name is valid."));
181181
validation_panel->set_update_callback(callable_mp(this, &DirectoryCreateDialog::_on_dir_path_changed));
182182
validation_panel->set_accept_button(get_ok_button());
183183

editor/gui/editor_validation_panel.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void EditorValidationPanel::_update() {
4242
}
4343

4444
valid = true;
45-
update_callback.callv(Array());
45+
update_callback.call();
4646

4747
if (accept_button) {
4848
accept_button->set_disabled(!valid);
@@ -52,11 +52,25 @@ void EditorValidationPanel::_update() {
5252

5353
void EditorValidationPanel::_notification(int p_what) {
5454
switch (p_what) {
55+
case NOTIFICATION_TRANSLATION_CHANGED: {
56+
if (is_visible_in_tree()) {
57+
update();
58+
} else {
59+
pending_update = true;
60+
}
61+
} break;
62+
5563
case NOTIFICATION_THEME_CHANGED: {
5664
theme_cache.valid_color = get_theme_color(SNAME("success_color"), EditorStringName(Editor));
5765
theme_cache.warning_color = get_theme_color(SNAME("warning_color"), EditorStringName(Editor));
5866
theme_cache.error_color = get_theme_color(SNAME("error_color"), EditorStringName(Editor));
5967
} break;
68+
69+
case NOTIFICATION_VISIBILITY_CHANGED: {
70+
if (is_visible_in_tree() && pending_update) {
71+
_update();
72+
}
73+
} break;
6074
}
6175
}
6276

@@ -65,10 +79,11 @@ void EditorValidationPanel::add_line(int p_id, const String &p_valid_message) {
6579

6680
Label *label = memnew(Label);
6781
label->set_focus_mode(FOCUS_ACCESSIBILITY);
68-
message_container->add_child(label);
6982
label->set_custom_minimum_size(Size2(200 * EDSCALE, 0));
7083
label->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
7184
label->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
85+
label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
86+
message_container->add_child(label);
7287

7388
valid_messages[p_id] = p_valid_message;
7489
labels[p_id] = label;
@@ -89,7 +104,10 @@ void EditorValidationPanel::update() {
89104
return;
90105
}
91106
pending_update = true;
92-
callable_mp(this, &EditorValidationPanel::_update).call_deferred();
107+
108+
if (is_visible_in_tree()) {
109+
callable_mp(this, &EditorValidationPanel::_update).call_deferred();
110+
}
93111
}
94112

95113
void EditorValidationPanel::set_message(int p_id, const String &p_text, MessageType p_type, bool p_auto_prefix) {
@@ -103,9 +121,9 @@ void EditorValidationPanel::set_message(int p_id, const String &p_text, MessageT
103121
label->show();
104122

105123
if (p_auto_prefix) {
106-
label->set_text(String(U"") + p_text);
124+
label->set_text(String(U"") + TTR(p_text));
107125
} else {
108-
label->set_text(p_text);
126+
label->set_text(TTR(p_text));
109127
}
110128

111129
switch (p_type) {

editor/inspector/add_metadata_dialog.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ AddMetadataDialog::AddMetadataDialog() {
6464

6565
validation_panel = memnew(EditorValidationPanel);
6666
vbc->add_child(validation_panel);
67-
validation_panel->add_line(EditorValidationPanel::MSG_ID_DEFAULT, TTR("Metadata name is valid."));
67+
validation_panel->add_line(EditorValidationPanel::MSG_ID_DEFAULT, TTRC("Metadata name is valid."));
6868
validation_panel->set_update_callback(callable_mp(this, &AddMetadataDialog::_check_meta_name));
6969
validation_panel->set_accept_button(get_ok_button());
7070

@@ -104,12 +104,12 @@ void AddMetadataDialog::_check_meta_name() {
104104
const String meta_name = add_meta_name->get_text();
105105

106106
if (meta_name.is_empty()) {
107-
validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTR("Metadata name can't be empty."), EditorValidationPanel::MSG_ERROR);
107+
validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTRC("Metadata name can't be empty."), EditorValidationPanel::MSG_ERROR);
108108
} else if (!meta_name.is_valid_ascii_identifier()) {
109-
validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTR("Metadata name must be a valid identifier."), EditorValidationPanel::MSG_ERROR);
109+
validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTRC("Metadata name must be a valid identifier."), EditorValidationPanel::MSG_ERROR);
110110
} else if (_existing_metas.find(meta_name)) {
111111
validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, vformat(TTR("Metadata with name \"%s\" already exists."), meta_name), EditorValidationPanel::MSG_ERROR);
112112
} else if (meta_name[0] == '_') {
113-
validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTR("Names starting with _ are reserved for editor-only metadata."), EditorValidationPanel::MSG_ERROR);
113+
validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTRC("Names starting with _ are reserved for editor-only metadata."), EditorValidationPanel::MSG_ERROR);
114114
}
115115
}

editor/plugins/plugin_config_dialog.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ void PluginConfigDialog::_on_canceled() {
107107

108108
void PluginConfigDialog::_on_required_text_changed() {
109109
if (name_edit->get_text().is_empty()) {
110-
validation_panel->set_message(MSG_ID_PLUGIN, TTR("Plugin name cannot be blank."), EditorValidationPanel::MSG_ERROR);
110+
validation_panel->set_message(MSG_ID_PLUGIN, TTRC("Plugin name cannot be blank."), EditorValidationPanel::MSG_ERROR);
111111
}
112112
if (subfolder_edit->is_visible()) {
113113
if (!subfolder_edit->get_text().is_empty() && !subfolder_edit->get_text().is_valid_filename()) {
114-
validation_panel->set_message(MSG_ID_SUBFOLDER, TTR("Subfolder name is not a valid folder name."), EditorValidationPanel::MSG_ERROR);
114+
validation_panel->set_message(MSG_ID_SUBFOLDER, TTRC("Subfolder name is not a valid folder name."), EditorValidationPanel::MSG_ERROR);
115115
} else {
116116
String path = "res://addons/" + _get_subfolder();
117117
if (!_edit_mode && DirAccess::exists(path)) { // Only show this error if in "create" mode.
118-
validation_panel->set_message(MSG_ID_SUBFOLDER, TTR("Subfolder cannot be one which already exists."), EditorValidationPanel::MSG_ERROR);
118+
validation_panel->set_message(MSG_ID_SUBFOLDER, TTRC("Subfolder cannot be one which already exists."), EditorValidationPanel::MSG_ERROR);
119119
}
120120
}
121121
} else {
@@ -132,7 +132,7 @@ void PluginConfigDialog::_on_required_text_changed() {
132132
validation_panel->set_message(MSG_ID_SCRIPT, vformat(TTR("Script extension must match chosen language extension (.%s)."), ext), EditorValidationPanel::MSG_ERROR);
133133
}
134134
if (language->get_name() == "GDScript") {
135-
validation_panel->set_message(MSG_ID_ENABLE_WARNINGS, TTR("Consider enabling GDScript warnings for this plugin by adding an entry for it to the project setting Debug > GDScript > Warnings > Directory Rules."), EditorValidationPanel::MSG_INFO);
135+
validation_panel->set_message(MSG_ID_ENABLE_WARNINGS, TTRC("Consider enabling GDScript warnings for this plugin by adding an entry for it to the project setting Debug > GDScript > Warnings > Directory Rules."), EditorValidationPanel::MSG_INFO);
136136
}
137137
}
138138

@@ -316,11 +316,11 @@ PluginConfigDialog::PluginConfigDialog() {
316316

317317
validation_panel = memnew(EditorValidationPanel);
318318
vbox->add_child(validation_panel);
319-
validation_panel->add_line(MSG_ID_PLUGIN, TTR("Plugin name is valid."));
320-
validation_panel->add_line(MSG_ID_SCRIPT, TTR("Script extension is valid."));
321-
validation_panel->add_line(MSG_ID_SUBFOLDER, TTR("Subfolder name is valid."));
322-
validation_panel->add_line(MSG_ID_ACTIVE, "");
323-
validation_panel->add_line(MSG_ID_ENABLE_WARNINGS, "");
319+
validation_panel->add_line(MSG_ID_PLUGIN, TTRC("Plugin name is valid."));
320+
validation_panel->add_line(MSG_ID_SCRIPT, TTRC("Script extension is valid."));
321+
validation_panel->add_line(MSG_ID_SUBFOLDER, TTRC("Subfolder name is valid."));
322+
validation_panel->add_line(MSG_ID_ACTIVE);
323+
validation_panel->add_line(MSG_ID_ENABLE_WARNINGS);
324324
validation_panel->set_update_callback(callable_mp(this, &PluginConfigDialog::_on_required_text_changed));
325325
validation_panel->set_accept_button(get_ok_button());
326326

editor/scene/group_settings_editor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ void GroupSettingsEditor::_check_rename() {
126126
}
127127

128128
if (new_name.is_empty()) {
129-
rename_validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTR("Group can't be empty."), EditorValidationPanel::MSG_ERROR);
129+
rename_validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTRC("Group can't be empty."), EditorValidationPanel::MSG_ERROR);
130130
} else if (ProjectSettings::get_singleton()->has_global_group(new_name)) {
131-
rename_validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTR("Group already exists."), EditorValidationPanel::MSG_ERROR);
131+
rename_validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTRC("Group already exists."), EditorValidationPanel::MSG_ERROR);
132132
}
133133
}
134134

@@ -449,7 +449,7 @@ void GroupSettingsEditor::_show_rename_dialog() {
449449
rename_group_dialog->register_text_enter(rename_group);
450450

451451
rename_validation_panel = memnew(EditorValidationPanel);
452-
rename_validation_panel->add_line(EditorValidationPanel::MSG_ID_DEFAULT, TTR("Group name is valid."));
452+
rename_validation_panel->add_line(EditorValidationPanel::MSG_ID_DEFAULT, TTRC("Group name is valid."));
453453
rename_validation_panel->set_update_callback(callable_mp(this, &GroupSettingsEditor::_check_rename));
454454
rename_validation_panel->set_accept_button(rename_group_dialog->get_ok_button());
455455

editor/scene/scene_create_dialog.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void SceneCreateDialog::update_dialog() {
103103
scene_name = scene_name_edit->get_text().strip_edges();
104104

105105
if (scene_name.is_empty()) {
106-
validation_panel->set_message(MSG_ID_PATH, TTR("Scene name is empty."), EditorValidationPanel::MSG_ERROR);
106+
validation_panel->set_message(MSG_ID_PATH, TTRC("Scene name is empty."), EditorValidationPanel::MSG_ERROR);
107107
}
108108

109109
if (validation_panel->is_valid()) {
@@ -114,16 +114,16 @@ void SceneCreateDialog::update_dialog() {
114114
}
115115

116116
if (validation_panel->is_valid() && !scene_name.is_valid_filename()) {
117-
validation_panel->set_message(MSG_ID_PATH, TTR("File name invalid."), EditorValidationPanel::MSG_ERROR);
117+
validation_panel->set_message(MSG_ID_PATH, TTRC("File name invalid."), EditorValidationPanel::MSG_ERROR);
118118
} else if (validation_panel->is_valid() && scene_name[0] == '.') {
119-
validation_panel->set_message(MSG_ID_PATH, TTR("File name begins with a dot."), EditorValidationPanel::MSG_ERROR);
119+
validation_panel->set_message(MSG_ID_PATH, TTRC("File name begins with a dot."), EditorValidationPanel::MSG_ERROR);
120120
}
121121

122122
if (validation_panel->is_valid()) {
123123
scene_name = directory.path_join(scene_name);
124124
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
125125
if (da->file_exists(scene_name)) {
126-
validation_panel->set_message(MSG_ID_PATH, TTR("File already exists."), EditorValidationPanel::MSG_ERROR);
126+
validation_panel->set_message(MSG_ID_PATH, TTRC("File already exists."), EditorValidationPanel::MSG_ERROR);
127127
}
128128
}
129129

@@ -148,9 +148,9 @@ void SceneCreateDialog::update_dialog() {
148148
}
149149

150150
if (root_name.is_empty()) {
151-
validation_panel->set_message(MSG_ID_ROOT, TTR("Invalid root node name."), EditorValidationPanel::MSG_ERROR);
151+
validation_panel->set_message(MSG_ID_ROOT, TTRC("Invalid root node name."), EditorValidationPanel::MSG_ERROR);
152152
} else if (root_name != root_name.validate_node_name()) {
153-
validation_panel->set_message(MSG_ID_ROOT, TTR("Invalid root node name characters have been replaced."), EditorValidationPanel::MSG_WARNING);
153+
validation_panel->set_message(MSG_ID_ROOT, TTRC("Invalid root node name characters have been replaced."), EditorValidationPanel::MSG_WARNING);
154154
}
155155
}
156156

@@ -303,8 +303,8 @@ SceneCreateDialog::SceneCreateDialog() {
303303

304304
validation_panel = memnew(EditorValidationPanel);
305305
main_vb->add_child(validation_panel);
306-
validation_panel->add_line(MSG_ID_PATH, TTR("Scene name is valid."));
307-
validation_panel->add_line(MSG_ID_ROOT, TTR("Root node valid."));
306+
validation_panel->add_line(MSG_ID_PATH, TTRC("Scene name is valid."));
307+
validation_panel->add_line(MSG_ID_ROOT, TTRC("Root node valid."));
308308
validation_panel->set_update_callback(callable_mp(this, &SceneCreateDialog::update_dialog));
309309
validation_panel->set_accept_button(get_ok_button());
310310

0 commit comments

Comments
 (0)