Added loading of section's text entries
This commit is contained in:
		
							parent
							
								
									fb2f573de4
								
							
						
					
					
						commit
						32ebd69194
					
				
							
								
								
									
										14
									
								
								I18N Commander/Processor/TextElementProcessor.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								I18N Commander/Processor/TextElementProcessor.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using DataModel.Database;
 | 
			
		||||
using DataModel.Database.Common;
 | 
			
		||||
using Microsoft.EntityFrameworkCore;
 | 
			
		||||
 | 
			
		||||
namespace Processor;
 | 
			
		||||
 | 
			
		||||
public static class TextElementProcessor
 | 
			
		||||
{
 | 
			
		||||
    public static Task<IAsyncEnumerable<TextElement>> GetTextElements(DataContext db, Section section)
 | 
			
		||||
    {
 | 
			
		||||
        return Task.FromResult(db.TextElements.Where(n => n.Section == section).AsAsyncEnumerable());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -32,8 +32,33 @@ public partial class TextElements : UserControl
 | 
			
		||||
            this.buttonAdd.Enabled = this.currentSection is not null;
 | 
			
		||||
            
 | 
			
		||||
            // Update the path:
 | 
			
		||||
            if (this.currentSection is not null)
 | 
			
		||||
            if (this.currentSection is null)
 | 
			
		||||
                return;
 | 
			
		||||
            
 | 
			
		||||
            this.labelSectionPath.Text = await SectionProcessor.GetSectionPath(this.db, this.currentSection.DataKey);
 | 
			
		||||
            this.LoadTextElements();
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    // Loads all the text elements for the current section.
 | 
			
		||||
    private async void LoadTextElements()
 | 
			
		||||
    {
 | 
			
		||||
        if (this.currentSection is null)
 | 
			
		||||
            return;
 | 
			
		||||
        
 | 
			
		||||
        // Load the text elements:
 | 
			
		||||
        var textElements = await TextElementProcessor.GetTextElements(this.db, this.currentSection);
 | 
			
		||||
        
 | 
			
		||||
        // Update the list:
 | 
			
		||||
        this.listTextElements.Items.Clear();
 | 
			
		||||
        await foreach (var textElement in textElements)
 | 
			
		||||
        {
 | 
			
		||||
            var item = new ListViewItem(textElement.Name)
 | 
			
		||||
            {
 | 
			
		||||
                Tag = textElement
 | 
			
		||||
            };
 | 
			
		||||
            
 | 
			
		||||
            this.listTextElements.Items.Add(item);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user