From 1b619f77742fe57d63d1723da6728839d77227cf Mon Sep 17 00:00:00 2001 From: Deyan Nenov Date: Thu, 18 Apr 2024 12:45:25 +0100 Subject: [PATCH] interaction adjustment, dynamoPlayer fix - fix to DynamoPlayer behavior (from Craig) - adjustment to interaction with the node under AutoMode - now locks the node --- src/Libraries/CoreNodeModels/DefineData.cs | 44 ++++++------ .../Controls/DefineDataControl.xaml | 3 +- .../NodeViewCustomizations/DefineData.cs | 70 +++++++++++++++---- 3 files changed, 80 insertions(+), 37 deletions(-) diff --git a/src/Libraries/CoreNodeModels/DefineData.cs b/src/Libraries/CoreNodeModels/DefineData.cs index 93ee79d60b0..fcb8c427efd 100644 --- a/src/Libraries/CoreNodeModels/DefineData.cs +++ b/src/Libraries/CoreNodeModels/DefineData.cs @@ -69,9 +69,6 @@ public bool IsList set { isList = value; - - if (IsAutoMode) { IsAutoMode = false; } // Lock the node on user interaction - OnNodeModified(); RaisePropertyChanged(nameof(IsList)); } @@ -83,7 +80,7 @@ public bool IsList /// [JsonProperty] public string DisplayValue - { + { get { return displayValue; } set { @@ -108,10 +105,9 @@ public string PlayerValue get { return playerValue; } set { - var valueToSet = value ?? ""; - if (valueToSet != value) + if (Equals(this.playerValue, null) || !this.playerValue.Equals(value)) { - playerValue = valueToSet; + playerValue = value ?? ""; MarkNodeAsModified(); } } @@ -217,6 +213,7 @@ private void DataBridgeCallback(object data) //Now we reset this value to empty string so that the next time a value is set from upstream nodes we can know that it is not coming from the player playerValue = ""; + // If data is null if (data == null) { if(IsAutoMode) @@ -230,28 +227,33 @@ private void DataBridgeCallback(object data) return; } + // If data is not null (bool IsValid, bool UpdateList, DataNodeDynamoType InputType) resultData = (ValueTuple)data; - if (IsAutoMode && resultData.UpdateList) + if (IsAutoMode) { - IsList = !IsList; - } + if (resultData.UpdateList) + { + IsList = !IsList; + } - if (IsAutoMode && resultData.InputType != null) - { - if(!resultData.IsValid) + if (resultData.InputType != null) { - // Assign to the correct value, if the object was of supported type - var index = Items.IndexOf(Items.First(i => i.Name.Equals(resultData.InputType.Name))); - SelectedIndex = index; + if (!resultData.IsValid) + { + // Assign to the correct value, if the object was of supported type + var index = Items.IndexOf(Items.First(i => i.Name.Equals(resultData.InputType.Name))); + SelectedIndex = index; + } + if (!DisplayValue.Equals(resultData.InputType.Name)) + { + DisplayValue = resultData.InputType.Name; + } } } - - if (resultData.InputType != null) + else { - // Assign the current type - if (!DisplayValue.Equals(resultData.InputType.Name)) - DisplayValue = resultData.InputType.Name; + DisplayValue = SelectedString; } } diff --git a/src/Libraries/CoreNodeModelsWpf/Controls/DefineDataControl.xaml b/src/Libraries/CoreNodeModelsWpf/Controls/DefineDataControl.xaml index 461f085016e..697e6a1568e 100644 --- a/src/Libraries/CoreNodeModelsWpf/Controls/DefineDataControl.xaml +++ b/src/Libraries/CoreNodeModelsWpf/Controls/DefineDataControl.xaml @@ -20,7 +20,8 @@ - { private ComboBox dropdown; - private ToggleButton toggleButton; + private ToggleButton modeToggleButton; + private ToggleButton listToggleButton; + private DefineData _model; /// /// Customize the visual appearance of the DefineData node. @@ -29,7 +31,11 @@ public class DefineDataNodeViewCustomization : DropDownNodeViewCustomization, IN /// public void CustomizeView(DefineData model, NodeView nodeView) { + this._model = model; + var formControl = new DefineDataControl(model); + listToggleButton = formControl.listToggleBtn; + listToggleButton.Click += listToggle_IsClicked; nodeView.inputGrid.Margin = new Thickness(5, 0, 5, 0); nodeView.inputGrid.RowDefinitions.Add(new RowDefinition()); @@ -63,6 +69,7 @@ public void CustomizeView(DefineData model, NodeView nodeView) // subscribe to the event inside the NodeModel to detect user interacting with the dropdown dropdown.DropDownOpened += dropDown_DropDownOpened; + dropdown.DropDownClosed += dropDown_DropDownClosed; // Create the Grid as the root visual for the item template var gridFactory = new FrameworkElementFactory(typeof(Grid)); @@ -137,17 +144,17 @@ public void CustomizeView(DefineData model, NodeView nodeView) // Add the padlock button var toggleButtonStyle = (Style)Dynamo.UI.SharedDictionaryManager.DynamoModernDictionary["PadlockToggleButton"]; var toggleButtonTooltipStyle = (Style)Dynamo.UI.SharedDictionaryManager.DynamoModernDictionary["GenericToolTipLight"]; - toggleButton = new ToggleButton(); - toggleButton.Style = toggleButtonStyle; + modeToggleButton = new ToggleButton(); + modeToggleButton.Style = toggleButtonStyle; Binding isToggleCheckedBinding = new Binding("IsAutoMode"); isToggleCheckedBinding.Mode = BindingMode.TwoWay; - isToggleCheckedBinding.Source = model; - toggleButton.SetBinding(ToggleButton.IsCheckedProperty, isToggleCheckedBinding); + isToggleCheckedBinding.Source = model; + modeToggleButton.SetBinding(ToggleButton.IsCheckedProperty, isToggleCheckedBinding); - toggleButton.Margin = new Thickness(5, 0, 0, 5); - toggleButton.HorizontalAlignment = HorizontalAlignment.Right; - toggleButton.VerticalAlignment = VerticalAlignment.Center; + modeToggleButton.Margin = new Thickness(5, 0, 0, 5); + modeToggleButton.HorizontalAlignment = HorizontalAlignment.Right; + modeToggleButton.VerticalAlignment = VerticalAlignment.Center; var toggleButtonToolTip = new ToolTip { @@ -155,23 +162,56 @@ public void CustomizeView(DefineData model, NodeView nodeView) Style = toggleButtonTooltipStyle }; - toggleButton.ToolTip = toggleButtonToolTip; + modeToggleButton.ToolTip = toggleButtonToolTip; - Grid.SetRow(toggleButton, 0); - Grid.SetColumn(toggleButton, 1); - nodeView.inputGrid.Children.Add(toggleButton); + Grid.SetRow(modeToggleButton, 0); + Grid.SetColumn(modeToggleButton, 1); + nodeView.inputGrid.Children.Add(modeToggleButton); } public new void Dispose() { - if (dropdown != null) dropdown.DropDownOpened -= dropDown_DropDownOpened; + if (dropdown != null) + { + dropdown.DropDownOpened -= dropDown_DropDownOpened; + dropdown.DropDownClosed -= dropDown_DropDownClosed; + } + + if (listToggleButton != null) + { + listToggleButton.Click -= listToggle_IsClicked; + } } private void dropDown_DropDownOpened(object sender, EventArgs e) { - if (toggleButton != null && toggleButton.IsChecked == true) + prevIndex = (sender as ComboBox).SelectedIndex; + } + + private int prevIndex = 0; + + private async void dropDown_DropDownClosed(object sender, EventArgs e) + { + var dropDown = sender as ComboBox; + var selection = dropDown.SelectedIndex; + var selectedValue = dropDown.SelectedValue as DynamoDropDownItem; + + if (modeToggleButton != null && modeToggleButton.IsChecked == true && selection != prevIndex) + { + // Set the SelectedString directly, then lock the node + if (_model != null) + { + _model.SelectedString = selectedValue.Name; + } + modeToggleButton.IsChecked = false; + } + } + + private void listToggle_IsClicked(object sender, RoutedEventArgs e) + { + if (modeToggleButton != null && modeToggleButton.IsChecked == true) { - toggleButton.IsChecked = false; + modeToggleButton.IsChecked = false; } }