Skip to content

Commit

Permalink
node lock on interaction
Browse files Browse the repository at this point in the history
- in case the node is in 'auto' mode, when user interacts with it, lock it - this is to prevent misunderstanding of what 'auto' mode does
  • Loading branch information
dnenov committed Apr 17, 2024
1 parent e47fec3 commit 9797db1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3969,6 +3969,7 @@ To make this file into a new template, save it to a different folder, then move
<data name="DataInputNodeInformationTooltip" xml:space="preserve">
<value>Toggle on if the input data contains a list.</value>
<comment>Tool-tip for info questionmark icon.</comment>
</data>
<data name="MessagePackageOlderDynamo" xml:space="preserve">
<value>The package or one of its dependencies use an older version of {0} than you are currently using. Do you want to continue?</value>
</data>
Expand All @@ -3977,5 +3978,5 @@ To make this file into a new template, save it to a different folder, then move
</data>
<data name="MessagePackOlderDynamoLink" xml:space="preserve">
<value>#Learn more=https://primer2.dynamobim.org/1_developer_primer_intro/3_developing_for_dynamo/updating-your-packages-and-dynamo-libraries-for-dynamo-3x-net8</value>
</data>
</data>
</root>
1 change: 0 additions & 1 deletion src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3957,7 +3957,6 @@ To make this file into a new template, save it to a different folder, then move
<value>Toggle on if the input data contains a list.</value>
<comment>Tool-tip for info questionmark icon.</comment>
</data>
</root>
<data name="MessagePackageOlderDynamo" xml:space="preserve">
<value>This package or one of its dependencies were created for a previous version of Dynamo. It may not work in this version. Do you want to continue?</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions src/Libraries/CoreNodeModels/DefineData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public bool IsList
set
{
isList = value;

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

OnNodeModified();
RaisePropertyChanged(nameof(IsList));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ namespace CoreNodeModelsWpf.Nodes
/// </summary>
public class DefineDataNodeViewCustomization : DropDownNodeViewCustomization, INodeViewCustomization<DefineData>
{
private ComboBox dropdown;
private ToggleButton toggleButton;

/// <summary>
/// Customize the visual appearance of the DefineData node.
/// </summary>
/// <param name="model"></param>
/// <param name="model">The DefineData model to customize</param>
/// <param name="nodeView"></param>
public void CustomizeView(DefineData model, NodeView nodeView)
{
Expand All @@ -47,7 +50,7 @@ public void CustomizeView(DefineData model, NodeView nodeView)
base.CustomizeView(model, nodeView);

var style = (Style)Dynamo.UI.SharedDictionaryManager.DynamoModernDictionary["NodeViewComboBox"];
var dropdown = (ComboBox)nodeView.inputGrid.Children[1];
dropdown = (ComboBox)nodeView.inputGrid.Children[1];
dropdown.Style = style;

formControl.BaseComboBox = dropdown;
Expand All @@ -58,6 +61,9 @@ public void CustomizeView(DefineData model, NodeView nodeView)
dropdown.MinWidth = 220;
dropdown.FontSize = 12;

// subscribe to the event inside the NodeModel to detect user interacting with the dropdown
dropdown.DropDownOpened += dropDown_DropDownOpened;

// Create the Grid as the root visual for the item template
var gridFactory = new FrameworkElementFactory(typeof(Grid));
var col = new FrameworkElementFactory(typeof(ColumnDefinition));
Expand Down Expand Up @@ -131,7 +137,7 @@ 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"];
var toggleButton = new ToggleButton();
toggleButton = new ToggleButton();
toggleButton.Style = toggleButtonStyle;

Binding isToggleCheckedBinding = new Binding("IsAutoMode");
Expand All @@ -156,6 +162,19 @@ public void CustomizeView(DefineData model, NodeView nodeView)
nodeView.inputGrid.Children.Add(toggleButton);
}

public new void Dispose()
{
if (dropdown != null) dropdown.DropDownOpened -= dropDown_DropDownOpened;
}

private void dropDown_DropDownOpened(object sender, EventArgs e)
{
if (toggleButton != null && toggleButton.IsChecked == true)
{
toggleButton.IsChecked = false;
}
}

public class LevelToIndentConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down

0 comments on commit 9797db1

Please sign in to comment.