AlgoStudio - set template as default impl uses DoubleClick CommandBinding

This commit is contained in:
John Colvin committed 2019-01-21 14:35:15 -06:00
1 parent bc0eb78092
commit 5dd2608210
4 files changed
+21 -37

No files matched your search

@@ -193,12 +193,6 @@
</DataTemplate.Triggers>
</DataTemplate>
</TreeView.Resources>
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem" BasedOn="{StaticResource AlgoTemplateTreeViewItemContainerStyle}">
<Setter Property="IsExpanded" Value="{Binding is_expanded}"/>
<Setter Property="IsSelected" Value="{Binding is_selected}"/>
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
<Grid x:Name="edit_pane" Grid.Column="1" Margin="8,4">
<Grid.RowDefinitions>
@@ -37,27 +37,6 @@ namespace mbts.ui.spark {
public static void SetIsMouseOverNodeContent(DependencyObject d, bool value) => d.SetValue(IsMouseOverNodeContentProperty, value);
#endregion
#region EnableToggleDefaultOnDoubleClick
public static readonly DependencyProperty EnableToggleDefaultOnDoubleClickProperty =
DependencyProperty.RegisterAttached("EnableToggleDefaultOnDoubleClick", typeof(bool), typeof(AlgoStudioView),
new PropertyMetadata((d, e) => {
var tvi = (TreeViewItem)d;
if ((bool)e.NewValue) {
tvi.MouseDoubleClick += _TreeViewItem_MouseDoubleClick;
} else {
tvi.MouseDoubleClick -= _TreeViewItem_MouseDoubleClick;
}
}));
static void _TreeViewItem_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
if (sender is TreeViewItem tvi && tvi.DataContext is AlgoDefinitionTemplateVM tmp)
tmp.is_default = true;
}
public static bool GetEnableToggleDefaultOnDoubleClick(DependencyObject d) => (bool)d.GetValue(EnableToggleDefaultOnDoubleClickProperty);
public static void SetEnableToggleDefaultOnDoubleClick(DependencyObject d, bool value) => d.SetValue(EnableToggleDefaultOnDoubleClickProperty, value);
#endregion
public new AlgoStudioVM DataContext {
get => base.DataContext as AlgoStudioVM;
set => base.DataContext = value;
@@ -1,9 +1,11 @@
using bts.api.orderman;
using bts.utils;
using mbts.spark.utilities;
using mbts.ui;
using mbts.ui.shell;
using mbts.utils;
using System;
using System.Windows.Input;
namespace mbts.spark {
class AlgoDefinitionTemplateVM : DisposableViewModelBase, IAlgoStudioContentVM, IEquatable<AlgoDefinitionTemplateVM> {
@@ -47,6 +49,11 @@ namespace mbts.spark {
_edit_stack.push(_committed);
_can_redo = backing(nameof(can_redo), () => _edit_stack.get_can_redo(_version.value));
_can_undo = backing(nameof(can_undo), () => _edit_stack.get_can_undo(_version.value));
set_as_default_cmd = new DelegateCommand(() => {
// don't call the model if it is already the default - as of 1/21/2019, it's an async call, is not idemptotent, and pumps an observable notification to every ladder/algostudio window.
if (!is_default && vm_key.mode == AlgoVMKey.Mode.Persisted)
_model.algo_model.set_as_default(owner.vm_key.persisted_id, vm_key.persisted_id).ignore();
});
algo_root.definition_changed += _change_logger.execute;
_can_redo.Changed += on_can_redo_changed;
_can_undo.Changed += on_can_undo_changed;
@@ -100,13 +107,7 @@ namespace mbts.spark {
public bool is_dirty => _is_dirty.Value;
public bool can_redo => _can_redo.Value;
public bool can_undo => _can_undo.Value;
public bool is_default {
get => _is_default.Value;
set {
if (_is_default.set_new(value) && value && vm_key.mode == AlgoVMKey.Mode.Persisted)
_model.algo_model.set_as_default(owner.vm_key.persisted_id, vm_key.persisted_id).ignore();
}
}
public bool is_default => _is_default.Value;
public bool is_favorite {
get => _is_favorite.Value;
set {
@@ -121,6 +122,7 @@ namespace mbts.spark {
public bool is_selected { get => _is_selected.Value; set => _is_selected.set(value); }
public bool is_expanded => false;
public bool is_persisted => vm_key.mode == AlgoVMKey.Mode.Persisted;
public ICommand set_as_default_cmd { get; }
public AlgoTemplateData create() =>
create(owner.create_algo_def());
@@ -123,8 +123,7 @@
</Setter>
</Style>
<Style x:Key="AlgoTemplateTreeViewItemContainerStyle" TargetType="TreeViewItem">
<Setter Property="usp:AlgoStudioView.EnableToggleDefaultOnDoubleClick" Value="True"/>
<Style x:Key="AlgoTreeViewItemContainerStyleBase" TargetType="TreeViewItem">
<Setter Property="uag:AlgoTemplateTreeView.NodeLevel" Value="{Binding Path='(uag:AlgoTemplateTreeView.NodeLevel)', RelativeSource={RelativeSource AncestorType=TreeViewItem}, Converter={x:Static uag:AlgoTemplateTreeView.NodeLevelConverter}, FallbackValue={u:Int 0}}"/>
<Setter Property="uag:AlgoTemplateTreeView.ItemsMargin">
<Setter.Value>
@@ -144,6 +143,7 @@
<Setter Property="Background" Value="Transparent" />
<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType=ItemsControl}}"/>
<Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType=ItemsControl}}"/>
<Setter Property="IsSelected" Value="{Binding is_selected}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TreeViewItem}">
@@ -232,6 +232,15 @@
</Setter>
</Style>
<Style x:Key="AlgoTemplateTreeViewItemContainerStyle" TargetType="TreeViewItem" BasedOn="{StaticResource AlgoTreeViewItemContainerStyleBase}">
<Setter Property="u:AttachedCommands.DoubleClick" Value="{Binding set_as_default_cmd}"/>
</Style>
<Style x:Key="AlgoDefinitionTreeViewItemContainerStyle" TargetType="TreeViewItem" BasedOn="{StaticResource AlgoTreeViewItemContainerStyleBase}">
<Setter Property="IsExpanded" Value="{Binding is_expanded}"/>
<Setter Property="ItemContainerStyle" Value="{StaticResource AlgoTemplateTreeViewItemContainerStyle}"/>
</Style>
<Style x:Key="AlgoTemplateTreeViewStyle" TargetType="TreeView">
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
@@ -240,7 +249,7 @@
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="ItemContainerStyle" Value="{StaticResource AlgoTemplateTreeViewItemContainerStyle}"/>
<Setter Property="ItemContainerStyle" Value="{StaticResource AlgoDefinitionTreeViewItemContainerStyle}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TreeView">