From e762cfe21e85fa23cb67ddc9c0331ff35b4146e5 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Thu, 21 Jul 2022 21:14:32 +0200 Subject: [PATCH] Implemented the text element filter --- I18N Commander/Processor/TextElementProcessor.cs | 8 ++++++-- .../Components/TextElements.Designer.cs | 1 + .../UI WinForms/Components/TextElements.cs | 14 ++++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/I18N Commander/Processor/TextElementProcessor.cs b/I18N Commander/Processor/TextElementProcessor.cs index 48e7562..8c63e17 100644 --- a/I18N Commander/Processor/TextElementProcessor.cs +++ b/I18N Commander/Processor/TextElementProcessor.cs @@ -8,10 +8,14 @@ namespace Processor; public static class TextElementProcessor { // Load all text elements for one particular section: - public static async Task> GetTextElements(Section section) + public static async Task> GetTextElements(Section section, string filterTerm) { await using var db = ProcessorMeta.ServiceProvider.GetRequiredService(); - return await db.TextElements.Where(n => n.Section == section).OrderBy(n => n.Name).ThenBy(n => n.Id).ToListAsync(); + + if(string.IsNullOrWhiteSpace(filterTerm)) + return await db.TextElements.Where(n => n.Section == section).OrderBy(n => n.Name).ThenBy(n => n.Id).ToListAsync(); + else + return await db.TextElements.Where(n => n.Section == section && n.Name.Contains(filterTerm)).OrderBy(n => n.Name).ThenBy(n => n.Id).ToListAsync(); } // Load one text element by id: diff --git a/I18N Commander/UI WinForms/Components/TextElements.Designer.cs b/I18N Commander/UI WinForms/Components/TextElements.Designer.cs index 8d5c900..a9a5cfd 100644 --- a/I18N Commander/UI WinForms/Components/TextElements.Designer.cs +++ b/I18N Commander/UI WinForms/Components/TextElements.Designer.cs @@ -129,6 +129,7 @@ this.textBoxFilter.Size = new System.Drawing.Size(554, 34); this.textBoxFilter.TabIndex = 2; this.textBoxFilter.WordWrap = false; + this.textBoxFilter.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBoxFilter_KeyUp); // // labelFilter // diff --git a/I18N Commander/UI WinForms/Components/TextElements.cs b/I18N Commander/UI WinForms/Components/TextElements.cs index f1e5e2a..aa6e354 100644 --- a/I18N Commander/UI WinForms/Components/TextElements.cs +++ b/I18N Commander/UI WinForms/Components/TextElements.cs @@ -9,7 +9,7 @@ public partial class TextElements : UserControl { private Section? currentSection; private TextElement? currentTextElement; - + public TextElements() { this.InitializeComponent(); @@ -17,7 +17,7 @@ public partial class TextElements : UserControl // Check if we are in the designer: if(Program.SERVICE_PROVIDER is null) return; - + // Create an image list from a resource: var imgList = new ImageList(); imgList.ImageSize = new Size(45, 45); @@ -40,7 +40,7 @@ public partial class TextElements : UserControl // Update the path: this.labelSectionPath.Text = await SectionProcessor.GetSectionPath(this.currentSection.DataKey); - this.LoadTextElements(); + await this.LoadTextElements(); }; // When the text element is changed, update the button states: @@ -52,13 +52,13 @@ public partial class TextElements : UserControl } // Loads all the text elements for the current section. - private async void LoadTextElements() + private async Task LoadTextElements() { if (this.currentSection is null) return; // Load the text elements: - var textElements = await TextElementProcessor.GetTextElements(this.currentSection); + var textElements = await TextElementProcessor.GetTextElements(this.currentSection, this.textBoxFilter.Text); // Update the list: this.listTextElements.Items.Clear(); @@ -136,7 +136,7 @@ public partial class TextElements : UserControl return; // Reload the text elements: - this.LoadTextElements(); + await this.LoadTextElements(); } private async void listTextElements_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) @@ -148,4 +148,6 @@ public partial class TextElements : UserControl // Fire the event: AppEvents.TextElementChanged(this.currentTextElement); } + + private async void textBoxFilter_KeyUp(object sender, KeyEventArgs e) => await this.LoadTextElements(); } \ No newline at end of file