From 32ebd691943c22d071985e16b03894f6215abb52 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sat, 16 Jul 2022 22:40:06 +0200 Subject: [PATCH] Added loading of section's text entries --- .../Processor/TextElementProcessor.cs | 14 +++++++++ .../UI WinForms/Components/TextElements.cs | 29 +++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 I18N Commander/Processor/TextElementProcessor.cs diff --git a/I18N Commander/Processor/TextElementProcessor.cs b/I18N Commander/Processor/TextElementProcessor.cs new file mode 100644 index 0000000..e1578dc --- /dev/null +++ b/I18N Commander/Processor/TextElementProcessor.cs @@ -0,0 +1,14 @@ +using System.Collections; +using DataModel.Database; +using DataModel.Database.Common; +using Microsoft.EntityFrameworkCore; + +namespace Processor; + +public static class TextElementProcessor +{ + public static Task> GetTextElements(DataContext db, Section section) + { + return Task.FromResult(db.TextElements.Where(n => n.Section == section).AsAsyncEnumerable()); + } +} \ No newline at end of file diff --git a/I18N Commander/UI WinForms/Components/TextElements.cs b/I18N Commander/UI WinForms/Components/TextElements.cs index 3e244dd..a371e2c 100644 --- a/I18N Commander/UI WinForms/Components/TextElements.cs +++ b/I18N Commander/UI WinForms/Components/TextElements.cs @@ -32,8 +32,33 @@ public partial class TextElements : UserControl this.buttonAdd.Enabled = this.currentSection is not null; // Update the path: - if (this.currentSection is not null) - this.labelSectionPath.Text = await SectionProcessor.GetSectionPath(this.db, this.currentSection.DataKey); + if (this.currentSection is null) + return; + + this.labelSectionPath.Text = await SectionProcessor.GetSectionPath(this.db, this.currentSection.DataKey); + this.LoadTextElements(); }; } + + // Loads all the text elements for the current section. + private async void LoadTextElements() + { + if (this.currentSection is null) + return; + + // Load the text elements: + var textElements = await TextElementProcessor.GetTextElements(this.db, this.currentSection); + + // Update the list: + this.listTextElements.Items.Clear(); + await foreach (var textElement in textElements) + { + var item = new ListViewItem(textElement.Name) + { + Tag = textElement + }; + + this.listTextElements.Items.Add(item); + } + } } \ No newline at end of file