so that john can take a look

This commit is contained in:
Jake Norbut committed 2019-04-22 14:59:22 -05:00
1 parent ea4b330062
commit 64164db22e
6 files changed
+180 -4

No files matched your search

@@ -249,10 +249,11 @@ namespace mbts.spark {
// The end result after this group of lines will be
// ----------------------------------------------
// | Cancel | Qty | Price | Attach | Detach | ...
// | Cancel | Qty | Price | Attach | Update | Detach | ...
// ----------------------------------------------
//
obvm.columns.Insert(0, new OrderBookVM.DetachColumn(typeof(MiniOrderBookView)));
obvm.columns.Insert(0, new OrderBookVM.UpdateColumn(typeof(MiniOrderBookView)));
obvm.columns.Insert(0, new OrderBookVM.AttachColumn(typeof(MiniOrderBookView)));
var price_col = obvm.columns.FirstOrDefault(x => x.id == OrderBookGridView.ColumnKeys.Price.ToString());
var price_index = obvm.columns.indexOf(price_col);
@@ -140,7 +140,7 @@ namespace mbts.spark {
// properly Dispose of it later when the popup is closed.
DataContext = obvm,
Child = view,
StaysOpen = false,
StaysOpen = true,
PlacementTarget = popup_placement_target,
Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom,
VerticalOffset = 5
@@ -914,6 +914,173 @@ namespace mbts.spark {
}
}
public class UpdateColumn : FrameworkElementColumnBase<Columns> {
readonly Type _mini_or_full_ob_type;
readonly string _orderbook_vm_datacontext_binding_path;
readonly string _orderbook_vm_order_mod_vm_binding_path;
//readonly string _begin_attach_command_binding_path;
readonly string _orderbook_vm_modify_selected_orders_cmd_path;
public UpdateColumn(Type mini_or_full_ob_type,
string orderbook_vm_datacontext_path = "DataContext",
string orderbook_vm_order_mod_vm_path = "DataContext.order_mod_vm",
//string begin_attach_command_path = "begin_attach_command",
string orderbook_vm_modify_selected_orders_cmd_path = "DataContext.modify_selected_orders_cmd"
) : base(Columns.Update) {
if (!(mini_or_full_ob_type == typeof(MiniOrderBookView) || mini_or_full_ob_type == typeof(OrderBookView))) {
throw new ArgumentException();
}
id = key.ToString();
Header = DefaultColumnHeaders.Update;
Width = 40;
_mini_or_full_ob_type = mini_or_full_ob_type;
_orderbook_vm_datacontext_binding_path = orderbook_vm_datacontext_path;
_orderbook_vm_order_mod_vm_binding_path = orderbook_vm_order_mod_vm_path;
//_begin_attach_command_binding_path = begin_attach_command_path;
_orderbook_vm_modify_selected_orders_cmd_path = orderbook_vm_modify_selected_orders_cmd_path;
}
// General DataBinding trouble shooting tip:
// This is how one can get extra debug statements during databinding
//PresentationTraceSources.SetTraceLevel(_datacontext_binding, PresentationTraceLevel.High);
public override FrameworkElement view_factory() {
var popup = new System.Windows.Controls.Primitives.Popup();
#region Attach Button
// create the attach button and assign the menu to it
var update_button = new Button() {
Name = "update_button",
Content = new Image() { Source = Icons.AttachAlgos }
};
var update_border = new Border() {
Child = update_button,
BorderThickness = new Thickness(1),
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
update_border.BorderBrush = (new SolidColorBrush(BTSColors.yellow).frozen());
update_button.Click += (s, e) => { popup.IsOpen = !popup.IsOpen; };
var orderbook_vm_datacontext_binding = new Binding(_orderbook_vm_datacontext_binding_path);
orderbook_vm_datacontext_binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, _mini_or_full_ob_type, 1);
// setting the button binding, easy, same visual tree as the MiniOrderBookView
// this has button has to be bound to the orderbook_vm b/c of the popup
// that will be assigned to the PlacementTarget and the DataContext will be
// kept in sync between those controls via a PlacementTarget.DataContext binding
update_button.SetBinding(Button.DataContextProperty, orderbook_vm_datacontext_binding);
//var row_vm_attach_to_visibility = new Binding("DataContext.is_attachable") { Converter = new mbts.ui.converters.BooleanToVisibilityConverter() };
//row_vm_attach_to_visibility.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(MiniOrderBookRowView), 1);
//update_border.SetBinding(Button.VisibilityProperty, row_vm_attach_to_visibility);
var row_vm_update_command_binding = new Binding("DataContext." + nameof(OrderBookRowVM.update_command));
row_vm_update_command_binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(MiniOrderBookRowView), 1);
update_button.SetBinding(Button.CommandProperty, row_vm_update_command_binding);
#endregion
#region OrderParamsPanel
// finally, set the order_params DataContext to that of the ContextMenu
var order_params = new AlgoEditorGridView {
Margin = new Thickness(6),
CanUserChangeAlgoRoot = false,
};
;
var order_params_binding = new Binding(_orderbook_vm_order_mod_vm_binding_path);
order_params_binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Popup), 1);
order_params.SetBinding(FrameworkElement.DataContextProperty, order_params_binding);
order_params.SetBinding(AlgoEditorGridView.AlgoRootsProperty, new Binding(string.Join(".", nameof(OrderParamsVM.algo_vm), nameof(AlgoDefinitionVM.algo_roots))));
order_params.SetBinding(AlgoEditorGridView.SelectedAlgoRootProperty, new Binding(string.Join(".", nameof(OrderParamsVM.algo_vm), nameof(AlgoDefinitionVM.algo_root))));
order_params.SetBinding(AlgoEditorGridView.AlgoParamRowsProperty, new Binding(nameof(OrderParamsVM.param_rows)));
#endregion
#region Dialog Skirt
var dialog_skirt_button_style =
Application.Current.TryFindResource(DialogSkirt.DialogSkirtButtonStyleKey) as Style ??
Application.Current.TryFindResource("CommonButton") as Style ??
Application.Current.TryFindResource(typeof(Button)) as Style;
// go find the OBVM on the ContextMenu to get the command
// The button for which this will server as a Binding to needs to both perform the send_attached_orders
// command *AND* close the algo param popup. Previously this was accomplished by setting both the Command
// and Click event on a Button appropriately, but since the Button that will perform this
// ultimately lives inside of the DialogSkirt, we don't have direct access to it. Ergo,
// we make use of this addition trick from John that allows for both of these things to happen.
// We take our original ICommand (send_attached) and wrap it in another Command by way of a Converter on the binding,
// pure genious!
var modify_selected_button_binding = new Binding(_orderbook_vm_modify_selected_orders_cmd_path) {
Converter = CommandWithActionWrapper.mk_wrap_converter(() => popup.IsOpen = false)
};
modify_selected_button_binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Popup), 1);
// Our ultimate goal is to have the Ok button (DialogSkirtItem) run the send attached orders command.
// Since we're only dealing with binding paths in here and not actual objects, we don't have access
// to an actual Command, which is what the DialogSkirtItem expects. John came up with a sneaky
// way of setting the Button.CommandProperty via a Style backdoor, but it's also necessary to
// create a KeyedStyleSelector here I guess.
// Also, the DialogSkirt Ok button seems to magically close the popup, cool!
var send_attached_button_style = new Style(typeof(Button), dialog_skirt_button_style);
send_attached_button_style.Setters.Add(new Setter(Button.CommandProperty, modify_selected_button_binding));
var awesome_command_style_key = "SendAttachButtonStyleKey";
var cancel_style_key = "CancelButtonStyleKey";
var dialog_skirt = new DialogSkirt {
RightItems = new[] {
new DialogSkirtItem("OK", null, awesome_command_style_key) { is_default = true },
new DialogSkirtItem("Cancel", new DelegateCommand(() => popup.IsOpen = false), cancel_style_key) { is_cancel = true }
}
};
var kss = new KeyedStyleSelector();
kss.Map.Add(new StyleSelectorKeyValue {
Key = awesome_command_style_key,
Value = send_attached_button_style
});
kss.Map.Add(
new StyleSelectorKeyValue {
Key = cancel_style_key,
Value = new Style(typeof(Button), dialog_skirt_button_style)
});
dialog_skirt.RightItemContainerStyleSelector = kss;
Grid.SetRow(dialog_skirt, 1);
var grid = new Grid();
grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
grid.Children.Add(order_params);
grid.Children.Add(dialog_skirt);
var border = new Border() {
Background = BTSColors.common_background_brush,
BorderThickness = new Thickness(1),
Name = "update_border",
Child = grid,
};
#endregion
popup.Child = border;
popup.StaysOpen = true;
popup.PlacementTarget = update_button;
popup.Placement = PlacementMode.Bottom;
// assign the Popup the DataContext of PlacementTarget, which will always be kept in sync with our parent button
popup.SetBinding(Popup.DataContextProperty, new Binding("PlacementTarget.DataContext") {
RelativeSource = new RelativeSource(RelativeSourceMode.Self)
});
var the_whole_thing = new Grid();
the_whole_thing.Children.Add(update_border);
the_whole_thing.Children.Add(popup);
return the_whole_thing;
}
}
public class DetachColumn : FrameworkElementColumnBase<Columns> {
public DetachColumn(Type mini_or_full_ob_type) : base(Columns.Detach) {
@@ -17,7 +17,7 @@ namespace mbts.spark {
const int _unknown_security_price_num_fractional_digits = 9;
readonly OrderBookVM _owner;
Brush _badge_fill;
IRaiseCanExecuteChangedCommand _show_order_modify_cmd, _toggle_expanded_cmd, _cancel_cmd, _modify_order_quantity, _modify_order_price, _detach_command, _attach_command;
IRaiseCanExecuteChangedCommand _show_order_modify_cmd, _toggle_expanded_cmd, _cancel_cmd, _modify_order_quantity, _modify_order_price, _detach_command, _attach_command, _update_command;
bool _is_parent, _is_expanded, _is_selected;
int _depth_level;
SecurityImmutable? _security => order_tuple.security;
@@ -225,6 +225,12 @@ namespace mbts.spark {
})
);
public ICommand update_command => _update_command ?? (
_update_command = new DelegateCommand(() => {
_select_me();
})
);
private void _unselect_me() {
this.is_selected = false;
_owner.current_row = null;
@@ -39,7 +39,8 @@ namespace mbts.spark {
EditableQty = 1 << 23,
EditablePrice = 1 << 24,
Attach = 1 << 25,
Detach = 1 << 26
Detach = 1 << 26,
Update = 1 << 27
}
public OrderBookGridView() =>
@@ -110,6 +110,7 @@ namespace mbts.ui.controls {
Cancel = "Cancel",
Attach = "Attach",
Detach = "Detach",
Update = "Update",
MarketDescription = "Market Description",
ClearedAlias = "Cleared Alias",
ProductDescription = "Product Description",