Plugins - Added timed updates

Modules - Added option to disable updates while activation is overridden
Display conditions - Added SKColor support
Data bindings - Added SKColor support
This commit is contained in:
Robert committed 2020-09-16 20:17:54 +02:00
1 parent d9017c67b4
commit 2eb4d615ae
48 files changed
+269 -100

No files matched your search

@@ -92,7 +92,7 @@
Placement="Bottom"
CustomPopupPlacementCallback="{x:Static materialDesign:CustomPopupPlacementCallbackHelper.LargePopupCallback}"
PlacementTarget="{Binding ElementName=ColorCodeTextBox}"
StaysOpen="False"
StaysOpen="{Binding StaysOpen, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
PopupAnimation="Fade"
IsOpen="{Binding PopupOpen, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}">
<materialDesign:Card Width="200" Height="200" Margin="30" materialDesign:ShadowAssist.ShadowDepth="Depth4">
@@ -101,7 +101,7 @@
<RowDefinition Height="160" />
<RowDefinition />
</Grid.RowDefinitions>
<materialDesign:ColorPicker Grid.Row="0" Color="{Binding Color, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
<materialDesign:ColorPicker Grid.Row="0" Color="{Binding Color, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" MouseUp="ColorGradient_OnMouseUp" />
<Slider Grid.Row="1" Margin="8"
IsMoveToPointEnabled="True"
Orientation="Horizontal"
@@ -18,6 +18,9 @@ namespace Artemis.UI.Shared
public static readonly DependencyProperty PopupOpenProperty = DependencyProperty.Register(nameof(PopupOpen), typeof(bool), typeof(ColorPicker),
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, PopupOpenPropertyChangedCallback));
public static readonly DependencyProperty StaysOpenProperty = DependencyProperty.Register(nameof(StaysOpen), typeof(bool), typeof(ColorPicker),
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, StaysOpenPropertyChangedCallback));
internal static readonly DependencyProperty ColorOpacityProperty = DependencyProperty.Register(nameof(ColorOpacity), typeof(byte), typeof(ColorPicker),
new FrameworkPropertyMetadata((byte) 255, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, ColorOpacityPropertyChangedCallback));
@@ -54,6 +57,12 @@ namespace Artemis.UI.Shared
set => SetValue(PopupOpenProperty, value);
}
public bool StaysOpen
{
get => (bool) GetValue(StaysOpenProperty);
set => SetValue(StaysOpenProperty, value);
}
internal byte ColorOpacity
{
get => (byte) GetValue(ColorOpacityProperty);
@@ -92,6 +101,17 @@ namespace Artemis.UI.Shared
colorPicker._inCallback = false;
}
private static void StaysOpenPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var colorPicker = (ColorPicker) d;
if (colorPicker._inCallback)
return;
colorPicker._inCallback = true;
colorPicker.OnPropertyChanged(nameof(PopupOpen));
colorPicker._inCallback = false;
}
private static void ColorOpacityPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var colorPicker = (ColorPicker) d;
@@ -112,6 +132,12 @@ namespace Artemis.UI.Shared
private void UIElement_OnMouseUp(object sender, MouseButtonEventArgs e)
{
PopupOpen = !PopupOpen;
e.Handled = true;
}
private void ColorGradient_OnMouseUp(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
}
}
}
@@ -15,7 +15,7 @@ namespace Artemis.UI.Shared
/// <inheritdoc />
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value?.ToString();
return value?.ToString()?.ToUpper();
}
/// <inheritdoc />
@@ -20,10 +20,12 @@ namespace Artemis.UI.Shared
{
}
internal override void UpdateValue(object model)
public override void UpdateValue(object model)
{
DisplayValue = model is T value ? value : default;
}
internal override object InternalGuard => null;
}
/// <summary>
@@ -31,9 +33,11 @@ namespace Artemis.UI.Shared
/// </summary>
public abstract class DataModelDisplayViewModel : PropertyChangedBase
{
public abstract void UpdateValue(object model);
/// <summary>
/// Prevents this type being implemented directly, implement <see cref="DataModelDisplayViewModel{T}" /> instead.
/// </summary>
internal abstract void UpdateValue(object model);
internal abstract object InternalGuard { get; }
}
}
@@ -33,7 +33,7 @@
<TextBlock FontWeight="Light"
Text="{Binding TargetPropertyViewModel.PropertyDescription.Prefix}"
Visibility="{Binding TargetPropertyViewModel.PropertyDescription.Prefix, Converter={StaticResource NullToVisibilityConverter}}" />
<TextBlock Text="{Binding Value}" />
<ContentControl s:View.Model="{Binding DisplayViewModel}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
<TextBlock FontWeight="Light"
Text="{Binding TargetPropertyViewModel.PropertyDescription.Affix}"
Visibility="{Binding TargetPropertyViewModel.PropertyDescription.Affix, Converter={StaticResource NullToVisibilityConverter}}" />
@@ -1,19 +1,21 @@
using System;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using Artemis.Core;
using Artemis.Core.DataModelExpansions;
using Artemis.UI.Shared.Services;
using Stylet;
// Remove, annoying while working on it
#pragma warning disable 1591
namespace Artemis.UI.Shared.Input
{
public class DataModelStaticViewModel : PropertyChangedBase
public class DataModelStaticViewModel : PropertyChangedBase, IDisposable
{
private readonly IDataModelUIService _dataModelUIService;
private readonly Window _rootView;
private Brush _buttonBrush = new SolidColorBrush(Color.FromRgb(171, 71, 188));
private DataModelDisplayViewModel _displayViewModel;
private DataModelInputViewModel _inputViewModel;
private string _placeholder = "Enter a value";
private DataModelPropertyAttribute _targetDescription;
@@ -25,6 +27,15 @@ namespace Artemis.UI.Shared.Input
{
TargetType = targetType;
_dataModelUIService = dataModelUIService;
DisplayViewModel = _dataModelUIService.GetDataModelDisplayViewModel(TargetType, true);
_rootView = Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
if (_rootView != null)
{
_rootView.MouseUp += RootViewOnMouseUp;
_rootView.KeyUp += RootViewOnKeyUp;
}
}
public Brush ButtonBrush
@@ -39,6 +50,12 @@ namespace Artemis.UI.Shared.Input
set => SetAndNotify(ref _transitionIndex, value);
}
public DataModelDisplayViewModel DisplayViewModel
{
get => _displayViewModel;
set => SetAndNotify(ref _displayViewModel, value);
}
public DataModelInputViewModel InputViewModel
{
get => _inputViewModel;
@@ -60,7 +77,11 @@ namespace Artemis.UI.Shared.Input
public object Value
{
get => _value;
set => SetAndNotify(ref _value, value);
set
{
if (!SetAndNotify(ref _value, value)) return;
DisplayViewModel?.UpdateValue(_value);
}
}
public string Placeholder
@@ -69,6 +90,19 @@ namespace Artemis.UI.Shared.Input
set => SetAndNotify(ref _placeholder, value);
}
#region IDisposable
public void Dispose()
{
if (_rootView != null)
{
_rootView.MouseUp -= RootViewOnMouseUp;
_rootView.KeyUp -= RootViewOnKeyUp;
}
}
#endregion
public void ActivateInputViewModel()
{
TransitionIndex = 1;
@@ -102,6 +136,30 @@ namespace Artemis.UI.Shared.Input
Value = value;
}
#region Event handlers
private void RootViewOnKeyUp(object sender, KeyEventArgs e)
{
if (InputViewModel == null)
return;
if (e.Key == Key.Escape)
InputViewModel.Cancel();
else if (e.Key == Key.Enter)
InputViewModel.Submit();
}
private void RootViewOnMouseUp(object sender, MouseButtonEventArgs e)
{
if (InputViewModel == null)
return;
if (sender is FrameworkElement frameworkElement && !frameworkElement.IsDescendantOf(InputViewModel.View))
InputViewModel.Submit();
}
#endregion
#region Events
public event EventHandler<DataModelInputStaticEventArgs> ValueUpdated;
@@ -38,8 +38,8 @@ namespace Artemis.UI.Shared
if (DisplayValue == null)
return;
if (DisplayViewModel == null && dataModelUIService.RegisteredDataModelDisplays.Any(d => d.SupportedType == DisplayValue.GetType()))
dataModelUIService.GetDataModelDisplayViewModel(DisplayValue.GetType());
if (DisplayViewModel == null)
DisplayViewModel = dataModelUIService.GetDataModelDisplayViewModel(DisplayValue.GetType(), true);
ListType = DisplayValue.GetType();
UpdateDisplayParameters();
@@ -9,9 +9,6 @@ namespace Artemis.UI.Shared
{
private object _displayValue;
private DataModelDisplayViewModel _displayViewModel;
private bool _showNull;
private bool _showToString;
private bool _showViewModel;
internal DataModelPropertyViewModel(DataModel dataModel, DataModelVisualizationViewModel parent, PropertyInfo propertyInfo) : base(dataModel, parent, propertyInfo)
{
@@ -29,31 +26,13 @@ namespace Artemis.UI.Shared
set => SetAndNotify(ref _displayViewModel, value);
}
public bool ShowToString
{
get => _showToString;
set => SetAndNotify(ref _showToString, value);
}
public bool ShowNull
{
get => _showNull;
set => SetAndNotify(ref _showNull, value);
}
public bool ShowViewModel
{
get => _showViewModel;
set => SetAndNotify(ref _showViewModel, value);
}
public override void Update(IDataModelUIService dataModelUIService)
{
if (Parent != null && !Parent.IsVisualizationExpanded && !Parent.IsRootViewModel)
return;
if (DisplayViewModel == null && dataModelUIService.RegisteredDataModelDisplays.Any(d => d.SupportedType == PropertyInfo.PropertyType))
dataModelUIService.GetDataModelDisplayViewModel(PropertyInfo.PropertyType);
if (DisplayViewModel == null)
DisplayViewModel = dataModelUIService.GetDataModelDisplayViewModel(PropertyInfo.PropertyType, true);
DisplayValue = GetCurrentValue();
UpdateDisplayParameters();
@@ -61,10 +40,6 @@ namespace Artemis.UI.Shared
protected void UpdateDisplayParameters()
{
ShowToString = DisplayValue != null && DisplayViewModel == null;
ShowNull = DisplayValue == null;
ShowViewModel = DisplayValue != null && DisplayViewModel != null;
DisplayViewModel?.UpdateValue(DisplayValue);
}
}
@@ -0,0 +1,23 @@
<UserControl x:Class="Artemis.UI.Shared.DefaultTypes.DataModel.Display.DefaultDataModelDisplayView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Shared.DefaultTypes.DataModel.Display"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:DefaultDataModelDisplayViewModel}">
<Grid>
<!-- Value display -->
<TextBlock Text="{Binding DisplayValue, Mode=OneWay}"
FontFamily="Consolas"
HorizontalAlignment="Right"
Visibility="{Binding ShowToString, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
<TextBlock Text="null"
FontFamily="Consolas"
HorizontalAlignment="Right"
Foreground="{DynamicResource MaterialDesignCheckBoxDisabled}"
Visibility="{Binding ShowNull, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
</Grid>
</UserControl>
@@ -0,0 +1,26 @@
namespace Artemis.UI.Shared.DefaultTypes.DataModel.Display
{
public class DefaultDataModelDisplayViewModel : DataModelDisplayViewModel<object>
{
private bool _showNull;
private bool _showToString;
public bool ShowToString
{
get => _showToString;
set => SetAndNotify(ref _showToString, value);
}
public bool ShowNull
{
get => _showNull;
set => SetAndNotify(ref _showNull, value);
}
protected override void OnDisplayValueUpdated()
{
ShowToString = DisplayValue != null;
ShowNull = DisplayValue == null;
}
}
}
@@ -5,6 +5,7 @@ using Artemis.Core;
using Artemis.Core.DataModelExpansions;
using Artemis.Core.Modules;
using Artemis.Core.Services;
using Artemis.UI.Shared.DefaultTypes.DataModel.Display;
using Artemis.UI.Shared.Input;
using Ninject;
using Ninject.Parameters;
@@ -158,14 +159,14 @@ namespace Artemis.UI.Shared.Services
}
}
public DataModelDisplayViewModel GetDataModelDisplayViewModel(Type propertyType)
public DataModelDisplayViewModel GetDataModelDisplayViewModel(Type propertyType, bool fallBackToDefault)
{
lock (_registeredDataModelDisplays)
{
var match = _registeredDataModelDisplays.FirstOrDefault(d => d.SupportedType == propertyType);
if (match != null)
return (DataModelDisplayViewModel) _kernel.Get(match.ViewModelType);
return null;
return !fallBackToDefault ? null : _kernel.Get<DefaultDataModelDisplayViewModel>();
}
}
@@ -19,7 +19,7 @@ namespace Artemis.UI.Shared.Services
void RemoveDataModelInput(DataModelVisualizationRegistration registration);
void RemoveDataModelDisplay(DataModelVisualizationRegistration registration);
DataModelDisplayViewModel GetDataModelDisplayViewModel(Type propertyType);
DataModelDisplayViewModel GetDataModelDisplayViewModel(Type propertyType, bool fallBackToDefault = false);
DataModelInputViewModel GetDataModelInputViewModel(Type propertyType, DataModelPropertyAttribute description, object initialValue, Action<object, bool> updateCallback);
DataModelDynamicViewModel GetDynamicSelectionViewModel(Module module);