From 0adc95b0161c932bd0aaae5e50839c6d383edc85 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Wed, 13 Jul 2022 20:07:06 +0200 Subject: [PATCH] Fixed path construction of sections - Fixed missed loading of parents - Made processing async --- I18N Commander/Processor/SectionProcessor.cs | 14 +++++++++++--- .../UI WinForms/Components/TextElements.cs | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/I18N Commander/Processor/SectionProcessor.cs b/I18N Commander/Processor/SectionProcessor.cs index 31be354..560a712 100644 --- a/I18N Commander/Processor/SectionProcessor.cs +++ b/I18N Commander/Processor/SectionProcessor.cs @@ -138,13 +138,21 @@ public static class SectionProcessor public static Section GetSection(DataContext db, string sectionKey) => db.Sections.First(n => n.DataKey == sectionKey); - public static string GetSectionPath(DataContext db, string sectionKey) + public static async Task GetSectionPath(DataContext db, string sectionKey) { - var section = db.Sections.First(n => n.DataKey == sectionKey); + var section = await db.Sections.FirstAsync(n => n.DataKey == sectionKey); + + // Ensure, that the database loaded the section's parent: + await db.Entry(section).Reference(n => n.Parent).LoadAsync(); + var path = section.Name; while (section.Parent != null) { - section = section.Parent; + section = await db.Sections.FirstAsync(n => n.DataKey == section.Parent.DataKey); + + // Ensure, that the database loaded the section's parent: + await db.Entry(section).Reference(n => n.Parent).LoadAsync(); + path = $"{section.Name}/{path}"; } diff --git a/I18N Commander/UI WinForms/Components/TextElements.cs b/I18N Commander/UI WinForms/Components/TextElements.cs index 1b044e8..3e244dd 100644 --- a/I18N Commander/UI WinForms/Components/TextElements.cs +++ b/I18N Commander/UI WinForms/Components/TextElements.cs @@ -26,14 +26,14 @@ public partial class TextElements : UserControl this.Disposed += (_, _) => this.db.Dispose(); // When the section is changed, update this component: - AppEvents.WhenSectionChanged += (sender, section) => + AppEvents.WhenSectionChanged += async (sender, section) => { this.currentSection = section; this.buttonAdd.Enabled = this.currentSection is not null; // Update the path: if (this.currentSection is not null) - this.labelSectionPath.Text = SectionProcessor.GetSectionPath(this.db, this.currentSection.DataKey); + this.labelSectionPath.Text = await SectionProcessor.GetSectionPath(this.db, this.currentSection.DataKey); }; } } \ No newline at end of file