Added event when a text element gets selected

This commit is contained in:
tsommer committed 2022-07-20 20:51:12 +02:00
1 parent 0e4a99332b
commit af47eb606c
4 files changed
+41 -3

No files matched your search

@@ -169,6 +169,7 @@
this.listTextElements.TabIndex = 5;
this.listTextElements.UseCompatibleStateImageBehavior = false;
this.listTextElements.View = System.Windows.Forms.View.Details;
this.listTextElements.ItemSelectionChanged += new System.Windows.Forms.ListViewItemSelectionChangedEventHandler(this.listTextElements_ItemSelectionChanged);
//
// column
//
@@ -8,6 +8,7 @@ namespace UI_WinForms.Components;
public partial class TextElements : UserControl
{
private Section? currentSection;
private TextElement? currentTextElement;
public TextElements()
{
@@ -30,15 +31,24 @@ public partial class TextElements : UserControl
AppEvents.WhenSectionChanged += async (sender, section) =>
{
this.currentSection = section;
this.currentTextElement = null;
this.buttonAdd.Enabled = this.currentSection is not null;
this.buttonRename.Enabled = this.buttonRemove.Enabled = false;
// Update the path:
if (this.currentSection is null)
return;
// Update the path:
this.labelSectionPath.Text = await SectionProcessor.GetSectionPath(this.currentSection.DataKey);
this.LoadTextElements();
};
// When the text element is changed, update the button states:
AppEvents.WhenTextElementChanged += (sender, textElement) =>
{
this.currentTextElement = textElement;
this.buttonRename.Enabled = this.buttonRemove.Enabled = this.currentTextElement is not null;
};
}
// Loads all the text elements for the current section.
@@ -55,7 +65,7 @@ public partial class TextElements : UserControl
foreach (var textElement in textElements)
this.listTextElements.Items.Add(new ListViewItem(textElement.Name, 0)
{
Tag = textElement.Code,
Tag = textElement.Id,
});
this.column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
@@ -86,7 +96,7 @@ public partial class TextElements : UserControl
// Add the text element to the list:
this.listTextElements.Items.Add(new ListViewItem(newTextElement.Result!.Name, 0)
{
Tag = newTextElement.Result.Code,
Tag = newTextElement.Result.Id,
});
this.column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
@@ -101,4 +111,14 @@ public partial class TextElements : UserControl
{
}
private async void listTextElements_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
// Load the text element:
var selectedTextElementId = (int)e.Item.Tag;
this.currentTextElement = await TextElementProcessor.LoadTextElement(selectedTextElementId);
// Fire the event:
AppEvents.TextElementChanged(this.currentTextElement);
}
}