Display conditions - Implemented expression tree creation

Display conditions - Use the most appropriate number input
UI general - Use current localisation for decimal seperators and enfore in inputs
This commit is contained in:
Robert committed 2020-07-08 17:26:17 +02:00
1 parent b869078f08
commit 3da2fbcf0a
21 files changed
+282 -131

No files matched your search

+6 -2
View File
@@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Markup;
using System.Windows.Threading;
using Artemis.Core.Models.Profile.Conditions;
using Artemis.Core.Ninject;
@@ -34,8 +37,6 @@ namespace Artemis.UI
protected override void Launch()
{
var test = new DisplayCondition();
StartupArguments = Args.ToList();
var logger = Kernel.Get<ILogger>();
@@ -52,6 +53,9 @@ namespace Artemis.UI
throw;
}
// Ensure WPF uses the right culture in binding converters
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
// Create and bind the root view, this is a tray icon so don't show it with the window manager
Execute.OnUIThread(() => viewManager.CreateAndBindViewForModelIfNecessary(RootViewModel));
@@ -1,8 +1,8 @@
using System.Text.RegularExpressions;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Windows.Input;
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
using Artemis.UI.Shared.DataModelVisualization;
using FluentValidation.TestHelper;
namespace Artemis.UI.DataModelVisualization.Input
{
@@ -14,7 +14,8 @@ namespace Artemis.UI.DataModelVisualization.Input
public void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
{
var regex = new Regex("^[.|,][0-9]+$|^[0-9]*[.|,]{0,1}[0-9]*$");
var seperator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
var regex = new Regex("^["+ seperator + "][0-9]+$|^[0-9]*["+ seperator + "]{0,1}[0-9]*$");
e.Handled = !regex.IsMatch(e.Text);
}
}
@@ -1,5 +1,4 @@
using System;
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;
using System.Windows.Input;
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
using Artemis.UI.Shared.DataModelVisualization;
@@ -17,10 +16,5 @@ namespace Artemis.UI.DataModelVisualization.Input
var regex = new Regex("[^0-9]+");
e.Handled = regex.IsMatch(e.Text);
}
protected override int ConvertToSupportedType(object source)
{
return Convert.ToInt32(source);
}
}
}
@@ -33,12 +33,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions
private List<Type> _supportedInputTypes;
public DisplayConditionPredicateViewModel(DisplayConditionPredicate displayConditionPredicate,
DisplayConditionViewModel parent,
IProfileEditorService profileEditorService,
IDataModelVisualizationService dataModelVisualizationService,
IDataModelService dataModelService,
IEventAggregator eventAggregator)
public DisplayConditionPredicateViewModel(DisplayConditionPredicate displayConditionPredicate, DisplayConditionViewModel parent, IProfileEditorService profileEditorService,
IDataModelVisualizationService dataModelVisualizationService, IDataModelService dataModelService, IEventAggregator eventAggregator)
: base(displayConditionPredicate, parent)
{
_profileEditorService = profileEditorService;
@@ -54,9 +50,6 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions
}
public DisplayConditionPredicate DisplayConditionPredicate => (DisplayConditionPredicate) Model;
public DelegateCommand SelectLeftPropertyCommand { get; }
public DelegateCommand SelectRightPropertyCommand { get; }
public DelegateCommand SelectOperatorCommand { get; }
public bool ShowRightSidePropertySelection => DisplayConditionPredicate.PredicateType == PredicateType.Dynamic;
public bool CanActivateRightSideInputViewModel => SelectedLeftSideProperty?.PropertyInfo != null;
@@ -108,26 +101,6 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions
set => SetAndNotify(ref _operators, value);
}
public void Handle(MainWindowKeyEvent message)
{
if (RightSideInputViewModel == null)
return;
if (!message.KeyDown && message.EventArgs.Key == Key.Escape)
RightSideInputViewModel.Cancel();
if (!message.KeyDown && message.EventArgs.Key == Key.Enter)
RightSideInputViewModel.Submit();
}
public void Handle(MainWindowMouseEvent message)
{
if (RightSideInputViewModel == null)
return;
if (message.Sender is FrameworkElement frameworkElement && !frameworkElement.IsDescendantOf(RightSideInputViewModel.View))
RightSideInputViewModel.Submit();
}
public void Initialize()
{
Task.Run(() =>
@@ -142,7 +115,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions
}
// Determine which types are currently supported
_supportedInputTypes = _dataModelVisualizationService.RegisteredDataModelEditors.Select(e => e.SupportedType).ToList();
var editors = _dataModelVisualizationService.RegisteredDataModelEditors;
_supportedInputTypes = editors.Select(e => e.SupportedType).ToList();
_supportedInputTypes.AddRange(editors.Where(e => e.CompatibleConversionTypes != null).SelectMany(e => e.CompatibleConversionTypes));
IsInitialized = true;
Update();
@@ -164,38 +139,51 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions
: null;
var leftSideType = SelectedLeftSideProperty?.PropertyInfo?.PropertyType;
if (DisplayConditionPredicate.PredicateType == PredicateType.Dynamic)
{
// Right side may only select properties matching the left side
if (SelectedLeftSideProperty != null)
RightSideDataModel.ApplyTypeFilter(true, leftSideType);
else
RightSideDataModel.ApplyTypeFilter(true);
// Determine the right side property
if (DisplayConditionPredicate.RightPropertyPath != null)
{
// Ensure the right side property still matches the left side type, else set it to null
var selectedProperty = RightSideDataModel.GetChildByPath(DisplayConditionPredicate.RightDataModelGuid, DisplayConditionPredicate.RightPropertyPath);
SelectedRightSideProperty = selectedProperty.IsMatchingFilteredTypes ? selectedProperty : null;
}
else
SelectedRightSideProperty = null;
}
else
{
if (DisplayConditionPredicate.RightStaticValue != null && DisplayConditionPredicate.RightStaticValue.GetType() != leftSideType)
DisplayConditionPredicate.RightStaticValue = null;
}
// Get the supported operators
Operators = _dataModelService.GetCompatibleConditionOperators(leftSideType);
if (DisplayConditionPredicate.Operator == null || !DisplayConditionPredicate.Operator.SupportsType(leftSideType))
DisplayConditionPredicate.Operator = Operators.FirstOrDefault(o => o.SupportsType(leftSideType));
if (DisplayConditionPredicate.PredicateType == PredicateType.Dynamic)
UpdateRightSideDynamic(leftSideType);
else
UpdateRightSideStatic(leftSideType);
DisplayConditionPredicate.CreateExpression(_dataModelService);
NotifyOfPropertyChange(nameof(DisplayConditionPredicate));
}
#region Dynamic input
private void UpdateRightSideDynamic(Type leftSideType)
{
// Right side may only select properties matching the left side
if (SelectedLeftSideProperty != null)
RightSideDataModel.ApplyTypeFilter(true, leftSideType);
else
RightSideDataModel.ApplyTypeFilter(true);
// Determine the right side property
if (DisplayConditionPredicate.RightPropertyPath != null)
{
// Ensure the right side property still matches the left side type, else set it to null
var selectedProperty = RightSideDataModel.GetChildByPath(DisplayConditionPredicate.RightDataModelGuid, DisplayConditionPredicate.RightPropertyPath);
SelectedRightSideProperty = selectedProperty.IsMatchingFilteredTypes ? selectedProperty : null;
}
else
SelectedRightSideProperty = null;
}
#endregion
#region Static input
private void UpdateRightSideStatic(Type leftSideType)
{
if (DisplayConditionPredicate.RightStaticValue != null && DisplayConditionPredicate.RightStaticValue.GetType() != leftSideType)
DisplayConditionPredicate.RightStaticValue = null;
}
public void ActivateRightSideInputViewModel()
{
if (SelectedLeftSideProperty?.PropertyInfo == null)
@@ -215,7 +203,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions
{
if (isSubmitted)
{
DisplayConditionPredicate.RightStaticValue = value;
var leftSideType = SelectedLeftSideProperty?.PropertyInfo?.PropertyType;
if (value != null && value.GetType() != leftSideType)
DisplayConditionPredicate.RightStaticValue = Convert.ChangeType(value, leftSideType);
else
DisplayConditionPredicate.RightStaticValue = value;
Update();
}
@@ -224,6 +217,34 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions
_eventAggregator.Unsubscribe(this);
}
public void Handle(MainWindowKeyEvent message)
{
if (RightSideInputViewModel == null)
return;
if (!message.KeyDown && message.EventArgs.Key == Key.Escape)
RightSideInputViewModel.Cancel();
if (!message.KeyDown && message.EventArgs.Key == Key.Enter)
RightSideInputViewModel.Submit();
}
public void Handle(MainWindowMouseEvent message)
{
if (RightSideInputViewModel == null)
return;
if (message.Sender is FrameworkElement frameworkElement && !frameworkElement.IsDescendantOf(RightSideInputViewModel.View))
RightSideInputViewModel.Submit();
}
#endregion
#region Commands
public DelegateCommand SelectLeftPropertyCommand { get; }
public DelegateCommand SelectRightPropertyCommand { get; }
public DelegateCommand SelectOperatorCommand { get; }
private void ExecuteSelectLeftProperty(object context)
{
if (!(context is DataModelVisualizationViewModel vm))
@@ -252,5 +273,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions
DisplayConditionPredicate.Operator = displayConditionOperator;
Update();
}
#endregion
}
}
@@ -37,9 +37,9 @@ namespace Artemis.UI.Services
if (_registeredBuiltInDataModelInputs)
return;
_dataModelVisualizationService.RegisterDataModelInput<StringDataModelInputViewModel>(Constants.CorePluginInfo, Constants.NumberTypes);
_dataModelVisualizationService.RegisterDataModelInput<IntDataModelInputViewModel>(Constants.CorePluginInfo, Constants.NumberTypes);
_dataModelVisualizationService.RegisterDataModelInput<DoubleDataModelInputViewModel>(Constants.CorePluginInfo, Constants.NumberTypes);
_dataModelVisualizationService.RegisterDataModelInput<StringDataModelInputViewModel>(Constants.CorePluginInfo, null);
_dataModelVisualizationService.RegisterDataModelInput<IntDataModelInputViewModel>(Constants.CorePluginInfo, Constants.IntegralNumberTypes);
_dataModelVisualizationService.RegisterDataModelInput<DoubleDataModelInputViewModel>(Constants.CorePluginInfo, Constants.FloatNumberTypes);
_registeredBuiltInDataModelInputs = true;
}