Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/DynamoCoreWpf/Interfaces/IWatchHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ private WatchViewModel ProcessThing(object value, ProtoCore.RuntimeCore runtimeC

foreach (var e in keys.Zip(values, (key, val) => new { key, val }))
{
node.Children.Add(ProcessThing(e.val, runtimeCore, tag + ":" + e.key, showRawData, callback));
var child = ProcessThing(e.val, runtimeCore, tag + ":" + e.key, showRawData, callback);
child.DictionaryKey = e.key;
node.Children.Add(child);
}

return node;
Expand All @@ -93,7 +95,9 @@ private WatchViewModel ProcessThing(object value, ProtoCore.RuntimeCore runtimeC

foreach (var e in dict.Keys.Zip(dict.Values, (key, val) => new { key, val }))
{
node.Children.Add(ProcessThing(e.val, runtimeCore, tag + ":" + e.key, showRawData, callback));
var child = ProcessThing(e.val, runtimeCore, tag + ":" + e.key, showRawData, callback);
child.DictionaryKey = e.key;
node.Children.Add(child);
}

return node;
Expand Down Expand Up @@ -204,7 +208,9 @@ private WatchViewModel ProcessThing(MirrorData data, ProtoCore.RuntimeCore runti

foreach (var e in keys.Zip(values, (key, value) => new { key, value }))
{
node.Children.Add(ProcessThing(e.value, runtimeCore, tag + ":" + e.key, showRawData, callback));
var child = ProcessThing(e.value, runtimeCore, tag + ":" + e.key, showRawData, callback);
child.DictionaryKey = e.key;
node.Children.Add(child);
}

return node;
Expand Down
28 changes: 26 additions & 2 deletions src/DynamoCoreWpf/ViewModels/Preview/WatchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ internal void Click()
private readonly Action<string> tagGeometry;
private bool isCollection;
private string valueType;
private string dictionaryKey;

// Instance variable for the number of items in the list
private int numberOfItems;
Expand Down Expand Up @@ -100,20 +101,43 @@ public string Link
}

/// <summary>
/// Returns the last index of the Path,
/// surrounded with square brackets.
/// Returns the last segment of <see cref="Path"/> for display.
/// For list items, the segment is returned as-is; for non-list items, the segment
/// is returned with surrounding spaces.
/// When this item is a dictionary child, returns the dictionary key directly
/// (without splitting on ':') so that keys containing ':' are displayed correctly.
/// </summary>
public string ViewPath
{
get
{
if (dictionaryKey != null)
return string.Format(NodeLabel == LIST ? "{0}" : " {0} ", dictionaryKey);
var splits = Path.Split(':');
if (splits.Count() == 1)
return string.Empty;
return splits.Any() ? string.Format(NodeLabel == LIST ? "{0}" : " {0} ", splits.Last()) : string.Empty;
}
}

/// <summary>
/// When this item is a direct child of a dictionary, stores the dictionary key
/// so that <see cref="ViewPath"/> can return it without splitting on ':'.
/// Setting this property raises a change notification for <see cref="ViewPath"/>.
/// </summary>
internal string DictionaryKey
{
get => dictionaryKey;
set
{
if (dictionaryKey != value)
{
dictionaryKey = value;
RaisePropertyChanged(nameof(ViewPath));
}
}
}

/// <summary>
/// A path describing the location of the data.
/// Path takes the form var_xxxx...:0:1:2, where
Expand Down
28 changes: 27 additions & 1 deletion test/DynamoCoreWpf3Tests/WatchNodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Threading;
using CoreNodeModels;
using DesignScript.Builtin;
using Dynamo.Controls;
using Dynamo.Graph.Nodes;
using Dynamo.Graph.Nodes.ZeroTouch;
Expand Down Expand Up @@ -483,7 +484,32 @@ public void WatchNodeWithBadSize()
Assert.AreEqual(100, watchNode.Height);
}

[Test]
[Test]
public void WatchDictionaryWithColonInKey_ViewPathDisplaysFullKey()
{
// Arrange - dictionary keys containing ':' were previously displayed incorrectly because
// ViewPath split the Path string on ':' and returned only the last segment.
var keys = new[] { "Hope:", ":This Isn't Right:", "help" };
var values = new object[] { 2, 5, 1 };
var dict = Dictionary.ByKeysValues(keys, values);

var watchVM = ViewModel.WatchHandler.GenerateWatchViewModelForData(
dict,
null,
null,
"test_tag",
false);

// Assert that ViewPath of each child returns the full key, including any ':' characters.
// Use a set-based check to be independent of the dictionary iteration order.
Assert.AreEqual(3, watchVM.Children.Count);
var viewPaths = watchVM.Children.Select(c => c.ViewPath.Trim()).ToList();
CollectionAssert.Contains(viewPaths, "Hope:");
CollectionAssert.Contains(viewPaths, ":This Isn't Right:");
CollectionAssert.Contains(viewPaths, "help");
}

[Test]
public void GetNodeLabelTree()
{
// Arrange
Expand Down
Loading