Skip to content

Commit

Permalink
Ensure changes to IsInput & IsOutput mark the node/graph as modified (#…
Browse files Browse the repository at this point in the history
…9257)

* Ensure changes to `Is Input` & `Is Output` mark the node/graph as modified

* mark workspace as modified when input/output gets set

* remove new handler

* switch to nameof

* add testing coverage verifying modifications to IsSetAsInput or IsSetAsOutput marks graph as modified
  • Loading branch information
alfarok committed Nov 27, 2018
1 parent 570486d commit 1d6cd02
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/DynamoCore/Graph/Nodes/NodeModel.cs
Expand Up @@ -35,6 +35,8 @@ public abstract class NodeModel : ModelBase, IRenderPackageSource<NodeModel>, ID
private LacingStrategy argumentLacing = LacingStrategy.Auto;
private bool displayLabels;
private bool isVisible;
private bool isSetAsInput = false;
private bool isSetAsOutput = false;
private bool canUpdatePeriodically;
private string name;
private ElementState state;
Expand Down Expand Up @@ -210,7 +212,6 @@ public virtual bool IsInputNode
}
}

private bool isSetAsInput = false;
/// <summary>
/// This property is user-controllable via a checkbox and is set to true when a user wishes to include
/// this node in a Customizer as an interactive control.
Expand All @@ -228,7 +229,11 @@ public bool IsSetAsInput

set
{
isSetAsInput = value;
if (isSetAsInput != value)
{
isSetAsInput = value;
RaisePropertyChanged(nameof(IsSetAsInput));
}
}
}

Expand All @@ -246,8 +251,6 @@ public virtual bool IsOutputNode
}
}

private bool isSetAsOutput = false;

/// <summary>
/// This property is user-controllable via a checkbox and is set to true when a user wishes to include
/// this node in the OutputData block of the Dyn file.
Expand All @@ -265,7 +268,11 @@ public bool IsSetAsOutput

set
{
isSetAsOutput = value;
if (isSetAsOutput != value)
{
isSetAsOutput = value;
RaisePropertyChanged(nameof(IsSetAsOutput));
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/DynamoCoreWpf/Views/Core/NodeView.xaml.cs
Expand Up @@ -237,6 +237,14 @@ void NodeLogic_PropertyChanged(object sender, System.ComponentModel.PropertyChan
case "CachedValue":
CachedValueChanged();
break;

case "IsSetAsInput":
(this.DataContext as NodeViewModel).DynamoViewModel.CurrentSpace.HasUnsavedChanges = true;
break;

case "IsSetAsOutput":
(this.DataContext as NodeViewModel).DynamoViewModel.CurrentSpace.HasUnsavedChanges = true;
break;
}
}

Expand Down
61 changes: 60 additions & 1 deletion test/DynamoCoreWpfTests/NodeViewTests.cs
@@ -1,5 +1,9 @@
using System;
using System.IO;
using System.Linq;
using Dynamo.Controls;
using Dynamo.Graph.Workspaces;
using Dynamo.ViewModels;
using Dynamo.Selection;
using DynamoCoreWpfTests.Utility;
using NUnit.Framework;
Expand Down Expand Up @@ -170,5 +174,60 @@ public void NodesHaveCorrectLocationsIndpendentOfCulture()

Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
}

[Test]
public void SettingNodeAsInputOrOutputMarksGraphAsModified()
{
Open(@"core\isInput_isOutput\IsInput.dyn");

// Get the node view for a specific node in the graph
NodeView nodeView = NodeViewWithGuid("c275ece0-2316-4e27-8d51-915257374c1e");

// Get a reference to the current workspace
NodeViewModel nodeViewModel = (nodeView.DataContext as NodeViewModel);
WorkspaceModel ws = nodeViewModel.DynamoViewModel.CurrentSpace;

// Verify IsSetAsInput is set to true
Assert.AreEqual(nodeViewModel.IsSetAsInput, true);
// Verify IsSetAsOutput is set to false
Assert.AreEqual(nodeViewModel.IsSetAsOutput, false);
// Verify the graph is not marked as modified
Assert.AreEqual(ws.HasUnsavedChanges, false);

// Set IsSetAsInput to false
nodeViewModel.IsSetAsInput = false;
// Verify graph is marked as modified
Assert.AreEqual(nodeViewModel.IsSetAsInput, false);
Assert.AreEqual(ws.HasUnsavedChanges, true);

// Save the graph
string tempPath = Path.Combine(Path.GetTempPath(), "IsInput.dyn");
ws.Save(tempPath);

// Verify graph is no longer marked as modified
Assert.AreEqual(nodeViewModel.IsSetAsInput, false);
Assert.AreEqual(ws.HasUnsavedChanges, false);

// Repeat process for IsSetAsOutput //

// Verify IsSetAsOutput is set to false
Assert.AreEqual(nodeViewModel.IsSetAsOutput, false);
// Set IsSetAsOutput to true
nodeViewModel.IsSetAsOutput = true;

// Verify graph is marked as modified
Assert.AreEqual(nodeViewModel.IsSetAsOutput, true);
Assert.AreEqual(ws.HasUnsavedChanges, true);

// Save the graph
ws.Save(tempPath);

// Verify graph is no longer marked as modified
Assert.AreEqual(nodeViewModel.IsSetAsOutput, true);
Assert.AreEqual(ws.HasUnsavedChanges, false);

// Delete temp file
File.Delete(tempPath);
}
}
}
}

0 comments on commit 1d6cd02

Please sign in to comment.