Skip to content

Commit

Permalink
interaction adjustment, dynamoPlayer fix
Browse files Browse the repository at this point in the history
- fix to DynamoPlayer behavior (from Craig)
- adjustment to interaction with the node under AutoMode - now locks the node
  • Loading branch information
dnenov committed Apr 18, 2024
1 parent 9797db1 commit 1b619f7
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 37 deletions.
44 changes: 23 additions & 21 deletions src/Libraries/CoreNodeModels/DefineData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ public bool IsList
set
{
isList = value;

if (IsAutoMode) { IsAutoMode = false; } // Lock the node on user interaction

OnNodeModified();
RaisePropertyChanged(nameof(IsList));
}
Expand All @@ -83,7 +80,7 @@ public bool IsList
///
[JsonProperty]
public string DisplayValue
{
{
get { return displayValue; }
set
{
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -230,28 +227,33 @@ private void DataBridgeCallback(object data)
return;
}

// If data is not null
(bool IsValid, bool UpdateList, DataNodeDynamoType InputType) resultData = (ValueTuple<bool, bool, DataNodeDynamoType>)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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
</ResourceDictionary>
</UserControl.Resources>
<DockPanel VerticalAlignment="Bottom" LastChildFill="False" Margin="0 0 0 -5">
<ToggleButton VerticalAlignment="Center"
<ToggleButton x:Name="listToggleBtn"
VerticalAlignment="Center"
Width="30"
Height="15"
Margin="2,0,0,0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ namespace CoreNodeModelsWpf.Nodes
public class DefineDataNodeViewCustomization : DropDownNodeViewCustomization, INodeViewCustomization<DefineData>
{
private ComboBox dropdown;
private ToggleButton toggleButton;
private ToggleButton modeToggleButton;
private ToggleButton listToggleButton;
private DefineData _model;

/// <summary>
/// Customize the visual appearance of the DefineData node.
Expand All @@ -29,7 +31,11 @@ public class DefineDataNodeViewCustomization : DropDownNodeViewCustomization, IN
/// <param name="nodeView"></param>
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());
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -137,41 +144,74 @@ 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
{
Content = Res.ResourceManager.GetString(nameof(Res.DataInputNodeModeLockTooltip), CultureInfo.InvariantCulture),
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;
}
}

Expand Down

0 comments on commit 1b619f7

Please sign in to comment.