Multiprocotol Terminalprogram (BAT)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
2.0 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows;
using MultiTerm.Core.Types;
namespace MultiTerm.Wpf.CustomControl;
internal class Format
{
private readonly string? backgroundColorResourceName;
public string Name { get; set; }
public Brush BackgroundBrush { get; set; }
public FormatType AssociatedFormatType { get; set; }
public Predicate<Key> IsKeyValid { get; set; }
public Format(string name, Brush backgroundBrush, FormatType associatedFormatType, Predicate<Key> keyValidator)
{
this.Name = name;
this.BackgroundBrush = backgroundBrush;
this.AssociatedFormatType = associatedFormatType;
this.IsKeyValid = keyValidator;
}
public Format(string name, string backgroundColorResourceName, FormatType associatedFormatType, Predicate<Key> keyValidator)
{
this.Name = name;
this.backgroundColorResourceName = backgroundColorResourceName;
this.BackgroundBrush = Brushes.White; // set background brush to white
this.AssociatedFormatType = associatedFormatType;
this.IsKeyValid = keyValidator;
}
public static List<string> GetListOfNames(IEnumerable<Format> formats)
{
return formats.Select(item => item.Name).ToList();
}
public static void UpdateBackgroundBrushesFromResources(FrameworkElement fwElement, IEnumerable<Format> formats)
{
if (fwElement == null) throw new ArgumentNullException(nameof(fwElement));
foreach (var format in formats)
{
// if resource name not set => skip
if (format.backgroundColorResourceName == null) continue;
// get background brush color from resources
try
{
format.BackgroundBrush = (SolidColorBrush)fwElement.FindResource(format.backgroundColorResourceName);
}
catch (Exception) { continue; } // ignore
}
}
}