Skip to content

Commit

Permalink
fix watchTree silent crash (#12975)
Browse files Browse the repository at this point in the history
* fix watchTree silent crash

* Update WatchTree.xaml.cs

* add test

* Update DynamoViewTests.cs

* Update DynamoViewTests.cs

* remove test

* Delete BiggestRectangle.dyn

Co-authored-by: pinzart <[email protected]>
Co-authored-by: Michael Kirschner <[email protected]>
  • Loading branch information
3 people authored Jun 13, 2022
1 parent 1e0714f commit 11c560e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
5 changes: 1 addition & 4 deletions src/DynamoCoreWpf/Views/Preview/PreviewControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,7 @@ private void RefreshExpandedDisplay(Action refreshDisplay)

if (largeContentGrid.Children.Count == 0)
{
var tree = new WatchTree
{
DataContext = new WatchViewModel(nodeViewModel.DynamoViewModel.BackgroundPreviewViewModel.AddLabelForPath)
};
var tree = new WatchTree(new WatchViewModel(nodeViewModel.DynamoViewModel.BackgroundPreviewViewModel.AddLabelForPath));
tree.treeView1.ItemContainerGenerator.StatusChanged += WatchContainer_StatusChanged;
largeContentGrid.Children.Add(tree);
}
Expand Down
9 changes: 6 additions & 3 deletions src/DynamoCoreWpf/Views/Preview/WatchTree.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ public partial class WatchTree : UserControl
private readonly int minWidthSize = 100;
private readonly int minHeightSize = 38;

public WatchTree()
public WatchTree(WatchViewModel vm)
{
_vm = vm;

InitializeComponent();

DataContext = vm;
this.Loaded += WatchTree_Loaded;
this.Unloaded += WatchTree_Unloaded;
}
Expand All @@ -42,8 +46,7 @@ private void WatchTree_Unloaded(object sender, RoutedEventArgs e)

void WatchTree_Loaded(object sender, RoutedEventArgs e)
{
_vm = this.DataContext as WatchViewModel;
_vm.PropertyChanged += _vm_PropertyChanged;
_vm.PropertyChanged += _vm_PropertyChanged;
}

private void _vm_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
Expand Down
11 changes: 4 additions & 7 deletions src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/Watch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public void CustomizeView(Watch nodeModel, NodeView nodeView)
this.watch = nodeModel;
this.syncContext = new DispatcherSynchronizationContext(nodeView.Dispatcher);

var watchTree = new WatchTree();
// make empty watchViewModel
rootWatchViewModel = new WatchViewModel(dynamoViewModel.BackgroundPreviewViewModel.AddLabelForPath);

var watchTree = new WatchTree(rootWatchViewModel);
watchTree.BorderThickness = new Thickness(1, 1, 1, 1);
watchTree.BorderBrush = new SolidColorBrush(Color.FromRgb(220,220,220));

watchTree.SetWatchNodeProperties();

// make empty watchViewModel
rootWatchViewModel = new WatchViewModel(dynamoViewModel.BackgroundPreviewViewModel.AddLabelForPath);

nodeView.PresentationGrid.Children.Add(watchTree);
nodeView.PresentationGrid.Visibility = Visibility.Visible;
// disable preview control
Expand All @@ -61,9 +61,6 @@ public void CustomizeView(Watch nodeModel, NodeView nodeView)

private void Bind(WatchTree watchTree, NodeView nodeView)
{
// The WatchTree Control is bound to the WatchViewModel
watchTree.DataContext = rootWatchViewModel;

// Add binding for TreeView
var sourceBinding = new Binding("Children")
{
Expand Down
8 changes: 4 additions & 4 deletions test/DynamoCoreWpfTests/DynamoViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


namespace DynamoCoreWpfTests
{
{
public class DynamoViewTests : DynamoTestUIBase
{
// adapted from: NodeViewTests.cs
Expand Down Expand Up @@ -58,11 +58,11 @@ public void FooterNotificationControlTest()

var workspace = ViewModel.Model.CurrentWorkspace as HomeWorkspaceModel;
Debug.Assert(workspace != null, nameof(workspace) + " != null");
workspace.Run();
workspace.Run();

List<NodeModel> errorNodes = ViewModel.Model.CurrentWorkspace.Nodes.ToList().FindAll(n => n.State == ElementState.Error);
List<NodeModel> warningNodes = ViewModel.Model.CurrentWorkspace.Nodes.ToList().FindAll(n => n.State == ElementState.Warning || n.State == ElementState.PersistentWarning);

// We should have 3 nodes in Error state and 3 nodes in Warning state
Assert.AreEqual(3, warningNodes.Count());
Assert.AreEqual(3, errorNodes.Count());
Expand Down Expand Up @@ -92,7 +92,7 @@ public void FooterNotificationControlTest()

// Check if the run message indicates warning
Assert.AreEqual(notificationsControl.runNotificationTextBlock.Text, "Run completed with warnings.");

// After deleting all Error nodes, the counter should get to 0
Assert.AreEqual((items[0] as FooterNotificationItem).NotificationCount, 0);

Expand Down

0 comments on commit 11c560e

Please sign in to comment.