Display conditions - Loosened up type rules for dynamic comparisons

Display conditions - Improved static value input and added support for int and double
This commit is contained in:
Robert committed 2020-07-07 17:29:20 +02:00
1 parent 68b9a4b933
commit f617a6461a
21 files changed
+197 -172

No files matched your search

+8 -3
View File
@@ -83,9 +83,6 @@
<Resource Include="Resources\Images\Logo\logo-512.ico" />
<Resource Include="Resources\Images\Logo\logo-512.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="FodyWeavers.xml" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Cursors\aero_rotate_tl.cur" />
</ItemGroup>
@@ -309,4 +306,12 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Page Update="DataModelVisualization\Input\DoubleDataModelInputView.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="DataModelVisualization\Input\IntDataModelInputView.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>
</Project>
@@ -0,0 +1,18 @@
<UserControl x:Class="Artemis.UI.DataModelVisualization.Input.DoubleDataModelInputView"
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.DataModelVisualization.Input"
xmlns:System="clr-namespace:System;assembly=System.Runtime"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
xmlns:behaviors="clr-namespace:Artemis.UI.Shared.Behaviors;assembly=Artemis.UI.Shared"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<TextBox VerticalAlignment="Center" Text="{Binding InputValue}" PreviewTextInput="{s:Action NumberValidationTextBox}">
<b:Interaction.Behaviors>
<behaviors:PutCursorAtEndTextBoxBehavior/>
</b:Interaction.Behaviors>
</TextBox>
</UserControl>
@@ -0,0 +1,20 @@
using System.Text.RegularExpressions;
using System.Windows.Input;
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
using Artemis.UI.Shared.DataModelVisualization;
namespace Artemis.UI.DataModelVisualization.Input
{
public class DoubleDataModelInputViewModel : DataModelInputViewModel<double>
{
public DoubleDataModelInputViewModel(DataModelPropertyAttribute description, double initialValue) : base(description, initialValue)
{
}
public void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
{
var regex = new Regex("^[.|,][0-9]+$|^[0-9]*[.|,]{0,1}[0-9]*$");
e.Handled = !regex.IsMatch(e.Text);
}
}
}
@@ -0,0 +1,18 @@
<UserControl x:Class="Artemis.UI.DataModelVisualization.Input.IntDataModelInputView"
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.DataModelVisualization.Input"
xmlns:System="clr-namespace:System;assembly=System.Runtime"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
xmlns:behaviors="clr-namespace:Artemis.UI.Shared.Behaviors;assembly=Artemis.UI.Shared"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<TextBox VerticalAlignment="Center" Text="{Binding InputValue}" PreviewTextInput="{s:Action NumberValidationTextBox}">
<b:Interaction.Behaviors>
<behaviors:PutCursorAtEndTextBoxBehavior/>
</b:Interaction.Behaviors>
</TextBox>
</UserControl>
@@ -0,0 +1,20 @@
using System.Text.RegularExpressions;
using System.Windows.Input;
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
using Artemis.UI.Shared.DataModelVisualization;
namespace Artemis.UI.DataModelVisualization.Input
{
public class IntDataModelInputViewModel : DataModelInputViewModel<int>
{
public IntDataModelInputViewModel(DataModelPropertyAttribute description, int initialValue) : base(description, initialValue)
{
}
public void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
{
var regex = new Regex("[^0-9]+");
e.Handled = regex.IsMatch(e.Text);
}
}
}
@@ -9,7 +9,7 @@
xmlns:behaviors="clr-namespace:Artemis.UI.Shared.Behaviors;assembly=Artemis.UI.Shared"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<TextBox VerticalAlignment="Center" Text="{Binding InputValue, UpdateSourceTrigger=PropertyChanged}">
<TextBox VerticalAlignment="Center" Text="{Binding InputValue}">
<b:Interaction.Behaviors>
<behaviors:PutCursorAtEndTextBoxBehavior/>
</b:Interaction.Behaviors>
-5
View File
@@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<PropertyChanged />
</Weavers>
-64
View File
@@ -1,64 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="PropertyChanged" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="InjectOnPropertyNameChanged" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the On_PropertyName_Changed feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="EventInvokerNames" type="xs:string">
<xs:annotation>
<xs:documentation>Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEquality" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEqualityUsingBaseEquals" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="UseStaticEqualsFromBase" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the static Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="SuppressWarnings" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to turn off build warnings from this weaver.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="SuppressOnPropertyNameChangedWarning" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to turn off build warnings about mismatched On_PropertyName_Changed methods.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
@@ -113,7 +113,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions
if (RightSideInputViewModel == null)
return;
if (!message.KeyDown && message.EventArgs.Key == Key.Escape)
if (!message.KeyDown && message.EventArgs.Key == Key.Escape)
RightSideInputViewModel.Cancel();
if (!message.KeyDown && message.EventArgs.Key == Key.Enter)
RightSideInputViewModel.Submit();
@@ -124,7 +124,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions
if (RightSideInputViewModel == null)
return;
if (message.Sender is FrameworkElement frameworkElement && !frameworkElement.IsDescendantOf(RightSideInputViewModel.View))
if (message.Sender is FrameworkElement frameworkElement && !frameworkElement.IsDescendantOf(RightSideInputViewModel.View))
RightSideInputViewModel.Submit();
}
@@ -156,7 +156,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions
// If static, only allow selecting properties also supported by input
if (DisplayConditionPredicate.PredicateType == PredicateType.Static)
LeftSideDataModel.ApplyTypeFilter(_supportedInputTypes.ToArray());
LeftSideDataModel.ApplyTypeFilter(false, _supportedInputTypes.ToArray());
// Determine the left side property first
SelectedLeftSideProperty = DisplayConditionPredicate.LeftPropertyPath != null
@@ -164,21 +164,29 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions
: null;
var leftSideType = SelectedLeftSideProperty?.PropertyInfo?.PropertyType;
// Right side may only select properties matching the left side
if (SelectedLeftSideProperty != null)
RightSideDataModel.ApplyTypeFilter(leftSideType);
else
RightSideDataModel.ApplyTypeFilter();
// Determine the right side property first
if (DisplayConditionPredicate.RightPropertyPath != null)
if (DisplayConditionPredicate.PredicateType == PredicateType.Dynamic)
{
// 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;
// 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
SelectedRightSideProperty = null;
{
if (DisplayConditionPredicate.RightStaticValue != null && DisplayConditionPredicate.RightStaticValue.GetType() != leftSideType)
DisplayConditionPredicate.RightStaticValue = null;
}
// Get the supported operators
Operators = _dataModelService.GetCompatibleConditionOperators(leftSideType);
@@ -201,13 +209,6 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions
UpdateInputValue
);
_eventAggregator.Subscribe(this);
// After the animation finishes attempt to focus the input field
Task.Run(async () =>
{
await Task.Delay(400);
await Execute.OnUIThreadAsync(() => RightSideInputViewModel.View.MoveFocus(new TraversalRequest(FocusNavigationDirection.First)));
});
}
public void UpdateInputValue(object value, bool isSubmitted)
@@ -38,6 +38,8 @@ namespace Artemis.UI.Services
return;
_dataModelVisualizationService.RegisterDataModelInput<StringDataModelInputViewModel>(Constants.CorePluginInfo);
_dataModelVisualizationService.RegisterDataModelInput<IntDataModelInputViewModel>(Constants.CorePluginInfo);
_dataModelVisualizationService.RegisterDataModelInput<DoubleDataModelInputViewModel>(Constants.CorePluginInfo);
_registeredBuiltInDataModelInputs = true;
}