using DataModel.Database; using DataModel.Database.Common; using Microsoft.Extensions.DependencyInjection; using Processor; namespace UI_WinForms.Components; public partial class TextElements : UserControl { private readonly DataContext db; private Section? currentSection; public TextElements() { this.InitializeComponent(); // Check if we are in the designer: if(Program.SERVICE_PROVIDER is null) return; // Get the DI context from the main form: this.db = Program.SERVICE_PROVIDER.GetService()!; // Dispose of the context when the control is disposed: this.Disposed += (_, _) => this.db.Dispose(); // When the section is changed, update this component: 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 = await SectionProcessor.GetSectionPath(this.db, this.currentSection.DataKey); }; } }