Skip to content

Commit

Permalink
REVIT-215698: Restrict where OnNodeModified is called. (DynamoDS#14656)
Browse files Browse the repository at this point in the history
* Restrict where OnNodeModified is called.

* Clean up.

* Dispose

* No SuppressFinalize

(cherry picked from commit f1f9b74)
  • Loading branch information
twastvedt authored and saintentropy committed Mar 14, 2024
1 parent 8f43cf7 commit 0018fd5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
9 changes: 5 additions & 4 deletions src/Libraries/CoreNodeModels/DropDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ObservableCollection<DynamoDropDownItem> Items
set
{
items = value;
RaisePropertyChanged("Items");
RaisePropertyChanged(nameof(Items));
}
}

Expand Down Expand Up @@ -106,7 +106,6 @@ public int SelectedIndex
selectedString = GetSelectedStringFromItem(Items.ElementAt(value));
}

OnNodeModified();
RaisePropertyChanged("SelectedIndex");
RaisePropertyChanged("SelectedString");
}
Expand Down Expand Up @@ -137,12 +136,12 @@ public string SelectedString
if (item != null)
{
selectedIndex = Items.IndexOf(item);
RaisePropertyChanged("SelectedIndex");
RaisePropertyChanged(nameof(SelectedIndex));
}
}

selectedString = value;
RaisePropertyChanged("SelectedString");
RaisePropertyChanged(nameof(SelectedString));
}
}

Expand Down Expand Up @@ -203,6 +202,8 @@ protected override bool UpdateValueCore(UpdateValueParams updateValueParams)
Warning(Dynamo.Properties.Resources.NothingIsSelectedWarning);
}

OnNodeModified();

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,61 +15,69 @@ namespace CoreNodeModelsWpf.Nodes
public class DropDownNodeViewCustomization : INodeViewCustomization<DSDropDownBase>
{
private DSDropDownBase model;
private ComboBox comboBox;

public void CustomizeView(DSDropDownBase model, NodeView nodeView)
{
this.model = model;

//add a drop down list to the window
var combo = new ComboBox
// Add a drop down list to the window
comboBox = new ComboBox
{
Width = System.Double.NaN,
MinWidth= 150,
Width = double.NaN,
MinWidth = 150,
Height = Configurations.PortHeightInPixels,
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Center
VerticalAlignment = VerticalAlignment.Center,
Style = (Style)SharedDictionaryManager.DynamoModernDictionary["RefreshComboBox"]
};

nodeView.inputGrid.Children.Add(comboBox);
Grid.SetColumn(comboBox, 0);
Grid.SetRow(comboBox, 0);

combo.Style = (Style)SharedDictionaryManager.DynamoModernDictionary["RefreshComboBox"];
comboBox.DropDownOpened += DropDownOpened;
comboBox.SelectionChanged += SelectionChanged;

nodeView.inputGrid.Children.Add(combo);
System.Windows.Controls.Grid.SetColumn(combo, 0);
System.Windows.Controls.Grid.SetRow(combo, 0);
comboBox.DataContext = model;

combo.DropDownOpened += combo_DropDownOpened;

combo.DataContext = model;

// bind this combo box to the selected item hash
var bindingVal = new System.Windows.Data.Binding("Items")
// Bind this combo box to the selected item hash.
var bindingVal = new Binding(nameof(DSDropDownBase.Items))
{
Mode = BindingMode.TwoWay,
Source = model
};
combo.SetBinding(ItemsControl.ItemsSourceProperty, bindingVal);
comboBox.SetBinding(ItemsControl.ItemsSourceProperty, bindingVal);

// bind the selected index to the model property SelectedIndex
var indexBinding = new Binding("SelectedIndex")
// Bind the selected index to the model property SelectedIndex.
var indexBinding = new Binding(nameof(DSDropDownBase.SelectedIndex))
{
Mode = BindingMode.TwoWay,
Source = model
};
combo.SetBinding(Selector.SelectedIndexProperty, indexBinding);
comboBox.SetBinding(Selector.SelectedIndexProperty, indexBinding);
}

private void SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (comboBox.SelectedIndex != -1)
{
model.OnNodeModified();
}
}

public void Dispose()
{
comboBox.DropDownOpened -= DropDownOpened;
comboBox.SelectionChanged -= SelectionChanged;
}

/// <summary>
/// When the dropdown is opened, the node's implementation of PopulateItems is called
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void combo_DropDownOpened(object sender, EventArgs e)
void DropDownOpened(object sender, EventArgs e)
{
this.model.PopulateItems();
model.PopulateItems();
}

}
Expand Down

0 comments on commit 0018fd5

Please sign in to comment.