Merge branch '31-bug-after-creating-a-section-the-selected-section-gets-not-changed' into 'main'

Resolve "Bug: After creating a section, the selected section gets not changed"

Closes #31

See merge request open-source/dotnet/i18n-commander!10
This commit is contained in:
Thorsten 2022-07-23 20:04:14 +00:00
commit 780b012aef
2 changed files with 20 additions and 3 deletions

View File

@ -4,15 +4,23 @@ namespace UI_WinForms;
internal static class AppEvents
{
#region Event: Section was changed
// Section changed event which can be subscribed:
internal static event EventHandler<Section> WhenSectionChanged;
// Method to raise the section changed event:
internal static void SectionChanged(Section section) => AppEvents.WhenSectionChanged?.Invoke(null, section);
internal static void SectionChanged(Section section) => WhenSectionChanged?.Invoke(null, section);
#endregion
#region Event: Text element was changed
// Text element changed event which can be subscribed:
internal static event EventHandler<TextElement> WhenTextElementChanged;
// Method to raise the text element changed event:
internal static void TextElementChanged(TextElement textElement) => AppEvents.WhenTextElementChanged?.Invoke(null, textElement);
internal static void TextElementChanged(TextElement textElement) => WhenTextElementChanged?.Invoke(null, textElement);
#endregion
}

View File

@ -151,6 +151,9 @@ public partial class SectionTree : UserControl
// Ensure, that the added node is visible and gets the focus:
node.EnsureVisible();
this.treeView.SelectedNode = node;
// Fire the click event:
this.treeView_NodeMouseClick(this, new TreeNodeMouseClickEventArgs(node, MouseButtons.Left, 1, 0, 0));
}
private async void buttonRemove_Click(object sender, EventArgs e)
@ -178,6 +181,12 @@ public partial class SectionTree : UserControl
// Reload the tree:
this.LoadNodes(this, EventArgs.Empty);
// Select the first root node:
this.treeView.SelectedNode = this.treeView.Nodes.Count > 0 ? this.treeView.Nodes[0] : null;
// Fire the click event:
this.treeView_NodeMouseClick(this, new TreeNodeMouseClickEventArgs(this.treeView.SelectedNode!, MouseButtons.Left, 1, 0, 0));
}
private async void treeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)