Set auto translate mode for drag previews

- Controls
  - `LineEdit`, `TextEdit`: Always disabled since it's dragging user input.
  - `TabBar`: Use the same auto translate mode as the node.
  - `RichTextLabel`: Always disable since auto translation is done
    differently from other controls (selection text you get
    programmatically is always after auto translation).
- Editor
  - Disable drag preview auto translation if the text is user input,
    filename, or class name.
  - Also disabled unexpected auto translation for audio bus effect names.
This commit is contained in:
Haoyu Qiu 2024-09-19 08:14:00 +08:00
parent 694d3c2930
commit 14321b8ed5
18 changed files with 22 additions and 1 deletions

View File

@ -254,6 +254,7 @@ Variant ActionMapEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from
Label *label = memnew(Label(name));
label->set_theme_type_variation("HeaderSmall");
label->set_modulate(Color(1, 1, 1, 1.0f));
label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
action_tree->set_drag_preview(label);
Dictionary drag_data;

View File

@ -3241,6 +3241,7 @@ Variant AnimationTrackEdit::get_drag_data(const Point2 &p_point) {
tb->set_flat(true);
tb->set_text(path_cache);
tb->set_icon(icon_cache);
tb->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
tb->add_theme_constant_override("icon_max_width", get_theme_constant("class_icon_size", EditorStringName(Editor)));
set_drag_preview(tb);

View File

@ -615,6 +615,7 @@ Variant CreateDialog::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
tb->set_flat(true);
tb->set_icon(ti->get_icon(0));
tb->set_text(ti->get_text(0));
tb->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
favorites->set_drag_preview(tb);
return d;

View File

@ -657,6 +657,7 @@ Variant EditorAudioBus::get_drag_data_fw(const Point2 &p_point, Control *p_from)
Label *l = memnew(Label);
l->set_text(item->get_text(0));
l->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
effects->set_drag_preview(l);
return fxd;
@ -929,6 +930,7 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
hb->add_child(scale);
effects = memnew(Tree);
effects->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
effects->set_hide_root(true);
effects->set_custom_minimum_size(Size2(0, 80) * EDSCALE);
effects->set_hide_folding(true);
@ -954,6 +956,7 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
set_focus_mode(FOCUS_CLICK);
effect_options = memnew(PopupMenu);
effect_options->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // Don't translate class names.
effect_options->connect("index_pressed", callable_mp(this, &EditorAudioBus::_effect_add));
add_child(effect_options);
List<StringName> effect_list;

View File

@ -644,6 +644,7 @@ Variant EditorAutoloadSettings::get_drag_data_fw(const Point2 &p_point, Control
for (int i = 0; i < max_size; i++) {
Label *label = memnew(Label(autoloads[i]));
label->set_self_modulate(Color(1, 1, 1, Math::lerp(1, 0, float(i) / PREVIEW_LIST_MAX_SIZE)));
label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
preview->add_child(label);
}

View File

@ -893,6 +893,7 @@ Variant EditorProperty::get_drag_data(const Point2 &p_point) {
Label *drag_label = memnew(Label);
drag_label->set_text(property);
drag_label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // Don't translate raw property name.
set_drag_preview(drag_label);
return dp;
}

View File

@ -5663,6 +5663,7 @@ Dictionary EditorNode::drag_resource(const Ref<Resource> &p_res, Control *p_from
Control *drag_control = memnew(Control);
TextureRect *drag_preview = memnew(TextureRect);
Label *label = memnew(Label);
label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
Ref<Texture2D> preview;
@ -5715,6 +5716,7 @@ Dictionary EditorNode::drag_files_and_dirs(const Vector<String> &p_paths, Contro
HBoxContainer *hbox = memnew(HBoxContainer);
TextureRect *icon = memnew(TextureRect);
Label *label = memnew(Label);
label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
if (p_paths[i].ends_with("/")) {
label->set_text(p_paths[i].substr(0, p_paths[i].length() - 1).get_file());

View File

@ -697,7 +697,7 @@ Variant EditorSettingsDialog::get_drag_data_fw(const Point2 &p_point, Control *p
return Variant();
}
String label_text = "Event " + itos(selected->get_meta("event_index"));
String label_text = vformat(TTRC("Event %d"), selected->get_meta("event_index"));
Label *label = memnew(Label(label_text));
label->set_modulate(Color(1, 1, 1, 1.0f));
shortcuts->set_drag_preview(label);

View File

@ -713,6 +713,7 @@ Variant ProjectExportDialog::get_drag_data_fw(const Point2 &p_point, Control *p_
drag->add_child(tr);
Label *label = memnew(Label);
label->set_text(presets->get_item_text(pos));
label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // Don't translate user input.
drag->add_child(label);
presets->set_drag_preview(drag);

View File

@ -1361,6 +1361,7 @@ Variant SceneTreeEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from
tf->set_texture(icons[i]);
hb->add_child(tf);
Label *label = memnew(Label(selected_nodes[i]->get_name()));
label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
hb->add_child(label);
vb->add_child(hb);
hb->set_modulate(Color(1, 1, 1, opacity_item));

View File

@ -3101,6 +3101,7 @@ Variant ScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
drag_preview->add_child(tf);
}
Label *label = memnew(Label(preview_name));
label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // Don't translate script names and class names.
drag_preview->add_child(label);
set_drag_preview(drag_preview);

View File

@ -614,6 +614,7 @@ Variant ShaderEditorPlugin::get_drag_data_fw(const Point2 &p_point, Control *p_f
drag_preview->add_child(tf);
}
Label *label = memnew(Label(preview_name));
label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // Don't translate script names.
drag_preview->add_child(label);
main_split->set_drag_preview(drag_preview);

View File

@ -689,6 +689,7 @@ Variant Skeleton3DEditor::get_drag_data_fw(const Point2 &p_point, Control *p_fro
tf->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
hb->add_child(tf);
Label *label = memnew(Label(selected->get_text(0)));
label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
hb->add_child(label);
vb->add_child(hb);
hb->set_modulate(Color(1, 1, 1, 1));

View File

@ -5994,6 +5994,7 @@ Variant VisualShaderEditor::get_drag_data_fw(const Point2 &p_point, Control *p_f
Label *label = memnew(Label);
label->set_text(it->get_text(0));
label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
set_drag_preview(label);
return d;
}
@ -6560,6 +6561,7 @@ VisualShaderEditor::VisualShaderEditor() {
parameters->set_hide_folding(false);
parameters->set_h_size_flags(SIZE_EXPAND_FILL);
parameters->set_v_size_flags(SIZE_EXPAND_FILL);
parameters->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
parameters->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_param_selected));
parameters->connect("nothing_selected", callable_mp(this, &VisualShaderEditor::_param_unselected));
sc->add_child(parameters);

View File

@ -921,6 +921,7 @@ Variant LineEdit::get_drag_data(const Point2 &p_point) {
String t = get_selected_text();
Label *l = memnew(Label);
l->set_text(t);
l->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // Don't translate user input.
set_drag_preview(l);
return t;
}

View File

@ -5431,6 +5431,7 @@ Variant RichTextLabel::get_drag_data(const Point2 &p_point) {
String t = get_selected_text();
Label *l = memnew(Label);
l->set_text(t);
l->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // Text is already translated.
set_drag_preview(l);
return t;
}

View File

@ -1250,6 +1250,7 @@ Variant TabBar::_handle_get_drag_data(const String &p_type, const Point2 &p_poin
}
Label *label = memnew(Label(get_tab_title(tab_over)));
label->set_auto_translate_mode(get_auto_translate_mode()); // Reflect how the title is displayed.
drag_preview->add_child(label);
set_drag_preview(drag_preview);

View File

@ -3034,6 +3034,7 @@ Variant TextEdit::get_drag_data(const Point2 &p_point) {
if (has_selection() && selection_drag_attempt) {
String t = get_selected_text();
Label *l = memnew(Label);
l->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // Don't translate user input.
l->set_text(t);
set_drag_preview(l);
return t;