From 7da69f18d4b838061c21eab70a275087650d725d Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 2 Jun 2025 22:01:06 +0200 Subject: [PATCH] Add button to quickly jump into Localized String Table that contains it #3301 --- .../Editors/LocalizedStringEditor.cs | 62 ++++++++++++++++--- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/Source/Editor/CustomEditors/Editors/LocalizedStringEditor.cs b/Source/Editor/CustomEditors/Editors/LocalizedStringEditor.cs index 76ceb7488..221bfd7a9 100644 --- a/Source/Editor/CustomEditors/Editors/LocalizedStringEditor.cs +++ b/Source/Editor/CustomEditors/Editors/LocalizedStringEditor.cs @@ -21,6 +21,7 @@ namespace FlaxEditor.CustomEditors.Editors public sealed class LocalizedStringEditor : GenericEditor { private TextBoxElement _idElement, _valueElement; + private Button _viewStringButton; /// public override DisplayStyle Style => DisplayStyle.Inline; @@ -70,6 +71,21 @@ namespace FlaxEditor.CustomEditors.Editors }; addString.SetAnchorPreset(AnchorPresets.MiddleRight, false, true); addString.ButtonClicked += OnAddStringClicked; + + var viewString = new Button + { + Visible = false, + Width = 16.0f, + BackgroundColor = Color.White, + BackgroundColorHighlighted = Color.Gray, + BackgroundBrush = new SpriteBrush(Editor.Instance.Icons.Search12), + TooltipText = "Find localized text in Localized String Table asset for the current locale...", + Parent = valueElement.TextBox, + }; + viewString.SetAnchorPreset(AnchorPresets.MiddleRight, false, true); + viewString.LocalX -= 16.0f; + viewString.ButtonClicked += OnViewStringClicked; + _viewStringButton = viewString; } /// @@ -80,6 +96,7 @@ namespace FlaxEditor.CustomEditors.Editors if (_valueElement != null) { _valueElement.TextBox.WatermarkText = Localization.GetString(_idElement.Text); + _viewStringButton.Visible = !string.IsNullOrEmpty(_valueElement.TextBox.WatermarkText); } } @@ -92,14 +109,21 @@ namespace FlaxEditor.CustomEditors.Editors _valueElement = null; } - private void OnSelectStringClicked(Button button) + private bool GetSettings(out LocalizationSettings settings) { - var settings = GameSettings.Load(); + settings = GameSettings.Load(); if (settings?.LocalizedStringTables == null || settings.LocalizedStringTables.Length == 0) { MessageBox.Show("No valid localization settings setup."); - return; + return true; } + return false; + } + + private void OnSelectStringClicked(Button button) + { + if (GetSettings(out var settings)) + return; Profiler.BeginEvent("LocalizedStringEditor.OnSelectStringClicked"); var allKeys = new HashSet(); for (int i = 0; i < settings.LocalizedStringTables.Length; i++) @@ -136,6 +160,7 @@ namespace FlaxEditor.CustomEditors.Editors { menu.Hide(); _idElement.TextBox.SetTextAsUser(after[0].Text); + _valueElement.TextBox.SetTextAsUser(string.Empty); } }; searchBox.TextChanged += delegate @@ -158,12 +183,8 @@ namespace FlaxEditor.CustomEditors.Editors private void OnAddStringClicked(Button button) { - var settings = GameSettings.Load(); - if (settings?.LocalizedStringTables == null || settings.LocalizedStringTables.Length == 0) - { - MessageBox.Show("No valid localization settings setup."); + if (GetSettings(out var settings)) return; - } Profiler.BeginEvent("LocalizedStringEditor.OnAddStringClicked"); var allKeys = new HashSet(); for (int i = 0; i < settings.LocalizedStringTables.Length; i++) @@ -231,5 +252,30 @@ namespace FlaxEditor.CustomEditors.Editors _idElement.TextBox.SetTextAsUser(newKey); Profiler.EndEvent(); } + + private void OnViewStringClicked(Button button) + { + if (GetSettings(out var settings)) + return; + var id = _idElement.TextBox.Text; + var value = _valueElement.TextBox.WatermarkText; + for (int i = 0; i < settings.LocalizedStringTables.Length; i++) + { + var table = settings.LocalizedStringTables[i]; + if (table && !table.WaitForLoaded()) + { + var entries = table.Entries; + if (entries.TryGetValue(id, out var messages)) + { + if (messages.Length != 0 && messages[0] == value) + { + Editor.Instance.ContentEditing.Open(table); + return; + } + } + } + } + MessageBox.Show("Unable to find localized string table."); + } } }