diff --git a/I18N Commander/UI WinForms/Components/TextElements.cs b/I18N Commander/UI WinForms/Components/TextElements.cs index ea31b88..b7dec0e 100644 --- a/I18N Commander/UI WinForms/Components/TextElements.cs +++ b/I18N Commander/UI WinForms/Components/TextElements.cs @@ -55,6 +55,37 @@ public partial class TextElements : UserControl else this.buttonChangeMultiLine.Image = Icons.icons8_align_text_left_512; }; + + AppEvents.WhenTranslationChanged += async (_, translation) => + { + if (translation is null) + return; + + // Check if the translation is in the current text element. + // When this is the case, update the list view item. We want + // to update the progress part. + if (this.currentTextElement?.Translations.Any(n => n.Id == translation.Id) ?? false) + { + // Determine the translation progress: + var progress = await TranslationProcessor.CalculateTranslationProgress(this.currentTextElement); + + if (this.listTextElements.InvokeRequired) + this.listTextElements.Invoke(UpdateListElement); + else + UpdateListElement(); + + void UpdateListElement() + { + // Get the list view item by searching the TAG property: + var item = this.listTextElements.Items.Cast().FirstOrDefault(n => n.Tag is int id && id == this.currentTextElement.Id); + if (item is null) + return; + + // Update the progress text: + item.Text = $"{this.currentTextElement.Name} [{progress.Result}%]"; + } + } + }; } // Loads all the text elements for the current section. @@ -69,11 +100,15 @@ public partial class TextElements : UserControl // Update the list: this.listTextElements.Items.Clear(); foreach (var textElement in textElements) - this.listTextElements.Items.Add(new ListViewItem(textElement.Name, textElement.IsMultiLine ? 1 : 0) + { + // Determine the translation progress: + var progress = await TranslationProcessor.CalculateTranslationProgress(textElement); + this.listTextElements.Items.Add(new ListViewItem($"{textElement.Name} [{progress.Result}%]", textElement.IsMultiLine ? 1 : 0) { Tag = textElement.Id, }); - + } + this.column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); } @@ -107,6 +142,7 @@ public partial class TextElements : UserControl }); this.column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); + AppEvents.TranslationChanged(null); } private async void buttonRemove_Click(object sender, EventArgs e) @@ -118,11 +154,12 @@ public partial class TextElements : UserControl if(MessageBox.Show(this.currentTextElement.Translations.Count > 0 ? $"Are you sure, you want to remove the text element '{this.currentTextElement.Name}', its {this.currentTextElement.Translations.Count} translations and so on?" : $"Are you sure, you want to remove the text element '{this.currentTextElement.Name}'?", "Remove text element", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No) return; - // Remove the text element1 from the database: + // Remove the text element from the database: await TextElementProcessor.DeleteTextElement(this.currentTextElement.Id); // Reload the data: await this.LoadTextElements(); + AppEvents.TranslationChanged(null); } private async void buttonRename_Click(object sender, EventArgs e)