mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Modules - Added support for SVG icons in sidebar
Modules - Removed separate DisplayIconPath property Data model debugger - Generics now display their types nicely Data model debugger - Type keywords are used where applicable Data model debugger - Nullables display properly
This commit is contained in:
1 parent
7b7b75be78
commit
09cd0b4dae
15 files changed
+255
-44
No files matched your search
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using Artemis.Core;
|
||||
|
||||
namespace Artemis.UI.Shared
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <see cref="T:System.Type" /> into <see cref="T:System.String" />.
|
||||
/// </summary>
|
||||
public class TypeToStringConverter : IValueConverter
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
bool humanizeProvided = bool.TryParse(parameter?.ToString(), out bool humanize);
|
||||
if (value is Type type)
|
||||
return type.GetDisplayName(humanizeProvided && humanize);
|
||||
|
||||
return value?.ToString();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ namespace Artemis.UI.Shared
|
||||
private string _countDisplay;
|
||||
private IEnumerable _list;
|
||||
private int _listCount;
|
||||
private Type _displayValueType;
|
||||
|
||||
internal DataModelListViewModel(DataModel dataModel, DataModelVisualizationViewModel parent, DataModelPath dataModelPath) : base(dataModel, parent, dataModelPath)
|
||||
{
|
||||
@@ -30,6 +31,12 @@ namespace Artemis.UI.Shared
|
||||
set => SetAndNotify(ref _listCount, value);
|
||||
}
|
||||
|
||||
public Type DisplayValueType
|
||||
{
|
||||
get => _displayValueType;
|
||||
set => SetAndNotify(ref _displayValueType, value);
|
||||
}
|
||||
|
||||
public string CountDisplay
|
||||
{
|
||||
get => _countDisplay;
|
||||
@@ -68,6 +75,7 @@ namespace Artemis.UI.Shared
|
||||
return;
|
||||
|
||||
List = GetCurrentValue() as IEnumerable;
|
||||
DisplayValueType = List?.GetType();
|
||||
if (List == null)
|
||||
return;
|
||||
|
||||
|
||||
+16
-6
@@ -1,4 +1,5 @@
|
||||
using Artemis.Core;
|
||||
using System;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.DataModelExpansions;
|
||||
using Artemis.UI.Shared.Services;
|
||||
|
||||
@@ -6,12 +7,21 @@ namespace Artemis.UI.Shared
|
||||
{
|
||||
public class DataModelPropertiesViewModel : DataModelVisualizationViewModel
|
||||
{
|
||||
private Type _displayValueType;
|
||||
|
||||
internal DataModelPropertiesViewModel(DataModel dataModel, DataModelVisualizationViewModel parent, DataModelPath dataModelPath) : base(dataModel, parent, dataModelPath)
|
||||
{
|
||||
}
|
||||
|
||||
public Type DisplayValueType
|
||||
{
|
||||
get => _displayValueType;
|
||||
set => SetAndNotify(ref _displayValueType, value);
|
||||
}
|
||||
|
||||
public override void Update(IDataModelUIService dataModelUIService)
|
||||
{
|
||||
DisplayValueType = DataModelPath?.GetPropertyType();
|
||||
// Always populate properties
|
||||
PopulateProperties(dataModelUIService);
|
||||
|
||||
@@ -28,15 +38,15 @@ namespace Artemis.UI.Shared
|
||||
return Parent.IsRootViewModel ? DataModel : base.GetCurrentValue();
|
||||
}
|
||||
|
||||
internal override int GetChildDepth()
|
||||
{
|
||||
return PropertyDescription != null && !PropertyDescription.ResetsDepth ? Depth + 1 : 1;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return DisplayPath ?? Path;
|
||||
}
|
||||
|
||||
internal override int GetChildDepth()
|
||||
{
|
||||
return PropertyDescription != null && !PropertyDescription.ResetsDepth ? Depth + 1 : 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-3
@@ -81,7 +81,9 @@ namespace Artemis.UI.Shared
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string DisplayPath => string.Join(" › ", DataModelPath.Segments.Select(s => s.GetPropertyDescription()?.Name ?? s.Identifier));
|
||||
public virtual string DisplayPath => DataModelPath != null
|
||||
? string.Join(" › ", DataModelPath.Segments.Select(s => s.GetPropertyDescription()?.Name ?? s.Identifier))
|
||||
: null;
|
||||
|
||||
/// <summary>
|
||||
/// Updates the datamodel and if in an parent, any children
|
||||
@@ -133,7 +135,7 @@ namespace Artemis.UI.Shared
|
||||
}
|
||||
|
||||
if (looseMatch)
|
||||
IsMatchingFilteredTypes = filteredTypes.Any(t => t.IsCastableFrom(type) ||
|
||||
IsMatchingFilteredTypes = filteredTypes.Any(t => t.IsCastableFrom(type) ||
|
||||
t == typeof(Enum) && type.IsEnum ||
|
||||
t == typeof(IEnumerable<>) && type.IsGenericEnumerable());
|
||||
else
|
||||
@@ -267,7 +269,7 @@ namespace Artemis.UI.Shared
|
||||
// For other value types create a child view model
|
||||
if (propertyType.IsClass || propertyType.IsStruct())
|
||||
return new DataModelPropertiesViewModel(DataModel, this, dataModelPath) {Depth = depth};
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -5,6 +5,11 @@
|
||||
private bool _showNull;
|
||||
private bool _showToString;
|
||||
|
||||
public DefaultDataModelDisplayViewModel()
|
||||
{
|
||||
ShowNull = true;
|
||||
}
|
||||
|
||||
public bool ShowToString
|
||||
{
|
||||
get => _showToString;
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Shared.Controls;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
|
||||
namespace Artemis.UI.Shared
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides utilities for UI-related plugin tasks
|
||||
/// </summary>
|
||||
public static class PluginUtilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Transforms the provided icon so that it is usable by the <see cref="ArtemisIcon" /> control
|
||||
/// </summary>
|
||||
/// <param name="pluginInfo">The info of the plugin the icon belongs to</param>
|
||||
/// <param name="icon">
|
||||
/// The icon, may be a string representation of a <see cref="PackIconKind" /> or a relative path
|
||||
/// pointing to a .svg file
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
public static object GetPluginIcon(PluginInfo pluginInfo, string icon)
|
||||
{
|
||||
if (icon == null)
|
||||
return PackIconKind.QuestionMarkCircle;
|
||||
|
||||
// Icon is provided as a path
|
||||
if (icon.EndsWith(".svg"))
|
||||
{
|
||||
string iconPath = pluginInfo.ResolveRelativePath(icon);
|
||||
if (!File.Exists(iconPath))
|
||||
return PackIconKind.QuestionMarkCircle;
|
||||
return iconPath;
|
||||
}
|
||||
|
||||
// Icon is provided as string to avoid having to reference MaterialDesignThemes
|
||||
bool parsedIcon = Enum.TryParse(icon, true, out PackIconKind iconEnum);
|
||||
if (parsedIcon == false)
|
||||
iconEnum = PackIconKind.QuestionMarkCircle;
|
||||
return iconEnum;
|
||||
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user