Added translation progress to text elements

This commit is contained in:
Thorsten Sommer 2022-09-26 22:08:30 +02:00
parent 6c7b5dbade
commit 0f732e0766
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -55,6 +55,37 @@ public partial class TextElements : UserControl
else else
this.buttonChangeMultiLine.Image = Icons.icons8_align_text_left_512; 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<ListViewItem>().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. // Loads all the text elements for the current section.
@ -69,10 +100,14 @@ public partial class TextElements : UserControl
// Update the list: // Update the list:
this.listTextElements.Items.Clear(); this.listTextElements.Items.Clear();
foreach (var textElement in textElements) 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, Tag = textElement.Id,
}); });
}
this.column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); this.column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
} }
@ -107,6 +142,7 @@ public partial class TextElements : UserControl
}); });
this.column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); this.column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
AppEvents.TranslationChanged(null);
} }
private async void buttonRemove_Click(object sender, EventArgs e) 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) 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; return;
// Remove the text element1 from the database: // Remove the text element from the database:
await TextElementProcessor.DeleteTextElement(this.currentTextElement.Id); await TextElementProcessor.DeleteTextElement(this.currentTextElement.Id);
// Reload the data: // Reload the data:
await this.LoadTextElements(); await this.LoadTextElements();
AppEvents.TranslationChanged(null);
} }
private async void buttonRename_Click(object sender, EventArgs e) private async void buttonRename_Click(object sender, EventArgs e)