Merge branch 'master' of bitbucket.org:bluetradesys/spark
This commit is contained in:
commit
4ad3f7e91b
3 files changed
+49
-8
No files matched your search
@@ -2,6 +2,7 @@
|
||||
using mbts.ui.spark;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
@@ -37,7 +38,8 @@ namespace mbts.spark
|
||||
public virtual IReadOnlyCollection<SyntheticEditor2.IParameter> sub_items { get; }
|
||||
public abstract T get_value(LegSpreaderParamsTuple leg_tup);
|
||||
public abstract void set_value(LegSpreaderParamsTuple leg_tup, T value);
|
||||
public object create_cell(LegSpreaderParamsTuple leg_tup) { return new ParameterRowCell<T>(this, leg_tup); }
|
||||
public virtual bool has_errors(IReadOnlyCollection<LegSpreaderParamsTuple> leg_tups) { return false; }
|
||||
public SyntheticEditor2.ICell create_cell(LegSpreaderParamsTuple leg_tup) { return new ParameterRowCell<T>(this, leg_tup); }
|
||||
}
|
||||
|
||||
internal class SizeRowModel : ParameterBase<double> {
|
||||
@@ -67,6 +69,7 @@ namespace mbts.spark
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, bool value) { leg_tup.leg_params.IsActiveQuoting = value; }
|
||||
public override string display_name { get; } = "Is Active Quote";
|
||||
public override string[] section_path { get; } = new[] { SectionNames.Quote };
|
||||
public override bool has_errors(IReadOnlyCollection<LegSpreaderParamsTuple> leg_tups) { return !leg_tups.Any(lt => lt.leg_params.IsActiveQuoting); }
|
||||
}
|
||||
|
||||
#region Quote
|
||||
@@ -180,7 +183,7 @@ namespace mbts.spark
|
||||
}
|
||||
#endregion
|
||||
|
||||
internal class ParameterRowCell<T> {
|
||||
internal class ParameterRowCell<T> : SyntheticEditor2.ICell {
|
||||
public ParameterRowCell(IParameter<T> model, LegSpreaderParamsTuple leg_tup) {
|
||||
_model = model;
|
||||
_leg_tup = leg_tup;
|
||||
@@ -189,7 +192,15 @@ namespace mbts.spark
|
||||
private readonly IParameter<T> _model;
|
||||
private readonly LegSpreaderParamsTuple _leg_tup;
|
||||
|
||||
public T value { get => _model.get_value(_leg_tup); set => _model.set_value(_leg_tup, value); }
|
||||
public T value {
|
||||
get => _model.get_value(_leg_tup);
|
||||
set {
|
||||
_model.set_value(_leg_tup, value);
|
||||
value_changed?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public event Action value_changed;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,8 +112,8 @@
|
||||
SnapsToDevicePixels="True">
|
||||
<SelectiveScrollingGrid Margin="{Binding section_count, Converter={StaticResource ReverseRowHeaderGroupIndentConverter}}">
|
||||
<SelectiveScrollingGrid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</SelectiveScrollingGrid.ColumnDefinitions>
|
||||
<DataGridRowHeader SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical"
|
||||
Background="Transparent"
|
||||
@@ -124,9 +124,18 @@
|
||||
<DataGridCellsPresenter Grid.Column="1" ItemsPanel="{TemplateBinding ItemsPanel}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
|
||||
</SelectiveScrollingGrid>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="usp:SyntheticEditor2.RowHasErrors" Value="True">
|
||||
<Setter Property="BorderBrush" Value="Red"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
<Style x:Key="DataGridRowStyle" TargetType="DataGridRow">
|
||||
<Setter Property="BorderThickness" Value="1,0"/>
|
||||
<Setter Property="BorderBrush" Value="Transparent"/>
|
||||
<Setter Property="Template" Value="{StaticResource DataGridRowTemplate}"/>
|
||||
<Setter Property="usp:SyntheticEditor2.RowHasErrors" Value="{Binding has_errors}"/>
|
||||
</Style>
|
||||
<ControlTemplate x:Key="SyntheticEditor2Template" TargetType="usp:SyntheticEditor2">
|
||||
<Border BorderBrush="{TemplateBinding BorderBrush}"
|
||||
|
||||
@@ -25,7 +25,13 @@ namespace mbts.ui.spark
|
||||
{
|
||||
string display_name { get; }
|
||||
string[] section_path { get; }
|
||||
object create_cell(LegSpreaderParamsTuple leg_tup);
|
||||
bool has_errors(IReadOnlyCollection<LegSpreaderParamsTuple> leg_tups);
|
||||
ICell create_cell(LegSpreaderParamsTuple leg_tup);
|
||||
}
|
||||
|
||||
public interface ICell
|
||||
{
|
||||
event Action value_changed;
|
||||
}
|
||||
|
||||
#region SyntheticName
|
||||
@@ -79,16 +85,25 @@ namespace mbts.ui.spark
|
||||
internal class ParameterRow : DataGridExRow<Security>
|
||||
{
|
||||
public ParameterRow(IParameter model, IReadOnlyCollection<LegSpreaderParamsTuple> legs) {
|
||||
_cells = new ReadOnlyDictionary<Security, object>(legs.ToDictionary(l => l.leg.Security, model.create_cell));
|
||||
_has_errors = backing(nameof(has_errors), false);
|
||||
_cells = new ReadOnlyDictionary<Security, ICell>(legs.ToDictionary(l => l.leg.Security, model.create_cell));
|
||||
foreach(var c in _cells.Values) {
|
||||
_has_errors.set(model.has_errors(legs));
|
||||
c.value_changed += () => _has_errors.set(model.has_errors(legs));
|
||||
}
|
||||
display_name = model.display_name;
|
||||
section_path = model.section_path;
|
||||
}
|
||||
private readonly IReadOnlyDictionary<Security, object> _cells;
|
||||
|
||||
private readonly IReadOnlyDictionary<Security, ICell> _cells;
|
||||
private readonly Property<bool> _has_errors;
|
||||
|
||||
public string display_name { get; }
|
||||
public string[] section_path { get; }
|
||||
public int section_count => section_path.Length;
|
||||
public override object get_cell(Security col_key) { return _cells[col_key]; }
|
||||
public string this[string section_no] => int.TryParse(section_no, out int i) && i < section_path.Length ? section_path[i] : null;
|
||||
public bool has_errors => _has_errors.Value;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -113,6 +128,12 @@ namespace mbts.ui.spark
|
||||
public DataTemplateSelector ParameterCellEditingTemplateSelector { get => GetValue(ParameterCellEditingTemplateSelectorProperty) as DataTemplateSelector; set => SetValue(ParameterCellEditingTemplateSelectorProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region RowHasError
|
||||
public static readonly DependencyProperty RowHasErrorsProperty = DependencyProperty.RegisterAttached("RowHasErrors", typeof(bool), typeof(SyntheticEditor2), new PropertyMetadata(false));
|
||||
public static bool GetRowHasErrors(DependencyObject d) { return (bool)d.GetValue(RowHasErrorsProperty); }
|
||||
public static void SetRowHasErrors(DependencyObject d, bool value) { d.SetValue(RowHasErrorsProperty, value); }
|
||||
#endregion
|
||||
|
||||
private static void GenerateParameterRows(DependencyObject d, DependencyPropertyChangedEventArgs e) {
|
||||
var parameters = d.GetValue(ParametersProperty) as IReadOnlyCollection<IParameter>;
|
||||
var legs = d.GetValue(LegTuplesProperty) as IReadOnlyCollection<LegSpreaderParamsTuple>;
|
||||
|
||||
Reference in new issue
Block a user