I18NCommander/I18N Commander/UI WinForms/Components/TextElements.cs

39 lines
1.2 KiB
C#
Raw Normal View History

2022-07-12 18:50:42 +00:00
using DataModel.Database;
using DataModel.Database.Common;
using Microsoft.Extensions.DependencyInjection;
using Processor;
2022-07-12 18:50:42 +00:00
namespace UI_WinForms.Components;
2022-07-11 17:52:15 +00:00
public partial class TextElements : UserControl
{
private readonly DataContext db;
2022-07-12 18:50:42 +00:00
private Section? currentSection;
2022-07-11 17:52:15 +00:00
public TextElements()
{
this.InitializeComponent();
2022-07-12 18:50:42 +00:00
// 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<DataContext>()!;
// Dispose of the context when the control is disposed:
this.Disposed += (_, _) => this.db.Dispose();
2022-07-12 18:50:42 +00:00
// When the section is changed, update this component:
AppEvents.WhenSectionChanged += (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);
2022-07-12 18:50:42 +00:00
};
2022-07-11 17:52:15 +00:00
}
}