mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Display conditions - Some work on inputs supporting multiple types
This commit is contained in:
1 parent
3639185171
commit
92dfbb354a
16 files changed
+112
-49
No files matched your search
@@ -1,9 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
|
||||
using Artemis.UI.Shared.Exceptions;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Shared.DataModelVisualization
|
||||
@@ -38,11 +41,29 @@ namespace Artemis.UI.Shared.DataModelVisualization
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public sealed override void Cancel()
|
||||
public sealed override void Cancel()
|
||||
{
|
||||
OnCancel();
|
||||
UpdateCallback(InputValue, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// May be called to convert an object to one of the types defined in CompatibleConversionTypes
|
||||
/// </summary>
|
||||
/// <param name="source">The object to convert, will always be of a type contained in CompatibleConversionTypes</param>
|
||||
/// <returns>The converted value</returns>
|
||||
protected virtual T ConvertToSupportedType(object source)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
internal override object InternalConvertToSupportedType(object source)
|
||||
{
|
||||
if (CompatibleConversionTypes != null && CompatibleConversionTypes.Contains(source.GetType()))
|
||||
return ConvertToSupportedType(source);
|
||||
|
||||
throw new ArtemisSharedUIException($"Cannot convert source of type {source.GetType().Name} because the data model input view model does not support it.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -58,6 +79,11 @@ namespace Artemis.UI.Shared.DataModelVisualization
|
||||
|
||||
internal Action<object, bool> UpdateCallback { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the types this input view model can support through type conversion
|
||||
/// </summary>
|
||||
internal IReadOnlyCollection<Type> CompatibleConversionTypes { get; set; }
|
||||
|
||||
public void AttachView(UIElement view)
|
||||
{
|
||||
if (View != null)
|
||||
@@ -98,5 +124,7 @@ namespace Artemis.UI.Shared.DataModelVisualization
|
||||
protected virtual void OnCancel()
|
||||
{
|
||||
}
|
||||
|
||||
internal abstract object InternalConvertToSupportedType(object source);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user