mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Implemented layer element saving
Added a working setting to the brush element
This commit is contained in:
1 parent
275d2b32a6
commit
1a44e34d16
24 files changed
+440
-85
No files matched your search
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace Artemis.UI.Converters
|
||||
{
|
||||
[ValueConversion(typeof(Enum), typeof(IEnumerable<Tuple<object, object>>))]
|
||||
public class EnumToCollectionConverter : MarkupExtension, IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return GetAllValuesAndDescriptions(value.GetType());
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
private static string Description(Enum value)
|
||||
{
|
||||
var attributes = value.GetType().GetField(value.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false);
|
||||
if (attributes.Any())
|
||||
return (attributes.First() as DescriptionAttribute)?.Description;
|
||||
|
||||
// If no description is found, the least we can do is replace underscores with spaces
|
||||
var ti = CultureInfo.CurrentCulture.TextInfo;
|
||||
return ti.ToTitleCase(ti.ToLower(value.ToString().Replace("_", " ")));
|
||||
}
|
||||
|
||||
private static IEnumerable<Tuple<object, object>> GetAllValuesAndDescriptions(Type t)
|
||||
{
|
||||
if (!t.IsEnum)
|
||||
throw new ArgumentException($"{nameof(t)} must be an enum type");
|
||||
|
||||
return Enum.GetValues(t).Cast<Enum>().Select(e => new Tuple<object, object>(e, Description(e))).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user