Skip to content

Commit 7685bfb

Browse files
Cherry-pick PRs 14394, 14424, 14500, 14740 (#15032)
* DYN-6527: Fix graph update for primitive input nodes that are first initialized to null (#14703) * remove coreclr-ncalc references * add failing test for dropdown node * cleanup * update tests * attempt initial fix * cleanup * update test * review comments * add code comments * cherry-pick PR 14637 * cherry-pick PR 14394 * cherry-pick PR 14740 * Fix for element binding messagebox display on saveas (#14424) * remove coreclr-ncalc references * fix for element binding messagebox on saveas * cherry pick PRs 14424, 14500 * build fix --------- Co-authored-by: Michael Kirschner <[email protected]>
1 parent ca7c111 commit 7685bfb

File tree

9 files changed

+358
-11
lines changed

9 files changed

+358
-11
lines changed

src/DynamoCoreWpf/Properties/Resources.Designer.cs

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/DynamoCoreWpf/Properties/Resources.en-US.resx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3651,4 +3651,13 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
36513651
<data name="PreferencesViewIncludeTimestampExportPathTooltip" xml:space="preserve">
36523652
<value>When toggled on, file names of exported images include date and time of export.</value>
36533653
</data>
3654-
</root>
3654+
<data name="ElementBindingWarningMessage" xml:space="preserve">
3655+
<value>A Save As command will create a workspace which is treated as a completely new file by Dynamo and existing element binding data will be lost. New element binding data will be created as normal as you run this file. Use the Save command instead if you wish to preserve element binding with the host document.</value>
3656+
</data>
3657+
<data name="ElementBindingWarningTitle" xml:space="preserve">
3658+
<value>Element Binding Warning</value>
3659+
</data>
3660+
<data name="ElementBindingDesc" xml:space="preserve">
3661+
<value>Element Binding allows a two-way interaction between Dynamo and the host application like Revit or Civil3D where a user can select an element in the host document and have Dynamo "bind" that element to a node in the workspace.</value>
3662+
</data>
3663+
</root>

src/DynamoCoreWpf/Properties/Resources.resx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3638,4 +3638,13 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
36383638
<data name="PreferencesViewIncludeTimestampExportPathTooltip" xml:space="preserve">
36393639
<value>When toggled on, file names of exported images include date and time of export.</value>
36403640
</data>
3641-
</root>
3641+
<data name="ElementBindingWarningMessage" xml:space="preserve">
3642+
<value>A Save As command will create a workspace which is treated as a completely new file by Dynamo and existing element binding data will be lost. New element binding data will be created as normal as you run this file. Use the Save command instead if you wish to preserve element binding with the host document.</value>
3643+
</data>
3644+
<data name="ElementBindingWarningTitle" xml:space="preserve">
3645+
<value>Element Binding Warning</value>
3646+
</data>
3647+
<data name="ElementBindingDesc" xml:space="preserve">
3648+
<value>Element Binding allows a two-way interaction between Dynamo and the host application like Revit or Civil3D where a user can select an element in the host document and have Dynamo "bind" that element to a node in the workspace.</value>
3649+
</data>
3650+
</root>

src/DynamoCoreWpf/UI/Prompts/DynamoMessageBox.xaml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xmlns:p="clr-namespace:Dynamo.Wpf.Properties;assembly=DynamoCoreWpf"
55
xmlns:ui="clr-namespace:Dynamo.UI"
66
xmlns:localui="clr-namespace:Dynamo.Wpf.UI.GuidedTour"
7-
xmlns:w="clr-namespace:System.Windows;assembly=PresentationCore"
7+
xmlns:fa="http://schemas.fontawesome.io/icons/"
88
Title="{x:Static p:Resources.GenericTaskDialogTitle}"
99
MinWidth="400"
1010
MaxWidth="500"
@@ -98,6 +98,35 @@
9898
Foreground="#3C3C3C"
9999
Text="{Binding TitleText, UpdateSourceTrigger=PropertyChanged}"
100100
TextWrapping="Wrap" />
101+
<Label HorizontalAlignment="Right"
102+
Name="TooltipInfo"
103+
VerticalAlignment="Center"
104+
Height="26"
105+
Width="53"
106+
Margin="20 -3 0 0">
107+
<Label.Style>
108+
<Style TargetType="{x:Type Label}">
109+
<Setter Property="Visibility" Value="Collapsed" />
110+
<Style.Triggers>
111+
<DataTrigger Binding="{Binding ShowTooltip}" Value="True">
112+
<Setter Property="Visibility" Value="Visible" />
113+
</DataTrigger>
114+
</Style.Triggers>
115+
</Style>
116+
</Label.Style>
117+
<Label.ToolTip>
118+
<ToolTip Content="{Binding Path=Tooltip}"
119+
Style="{StaticResource GenericToolTipLight}"/>
120+
</Label.ToolTip>
121+
<Label.Content>
122+
<fa:ImageAwesome Width="15"
123+
Height="15"
124+
VerticalAlignment="Bottom"
125+
HorizontalAlignment="Left"
126+
Icon="QuestionCircle"
127+
Foreground="#808080"/>
128+
</Label.Content>
129+
</Label>
101130
</DockPanel>
102131
<Rectangle Name="Separator"
103132
Grid.Row="0"

src/DynamoCoreWpf/UI/Prompts/DynamoMessageBox.xaml.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ public MessageBoxImage MessageBoxImage
8888
}
8989
}
9090

91+
/// <summary>
92+
/// A tooltip is shown on the message box when this is set to true and if
93+
/// Tooltip is non-null and non-empty.
94+
/// </summary>
95+
public bool ShowTooltip { get; private set; }
96+
97+
/// <summary>
98+
/// A tooltip is shown on the message box when this is set to a non-empty string
99+
/// and ShowTooltip is true.
100+
/// </summary>
101+
public string Tooltip { get; private set; }
102+
91103
#endregion
92104

93105
/// <summary>
@@ -97,6 +109,8 @@ public DynamoMessageBox()
97109
{
98110
InitializeComponent();
99111
DataContext = this;
112+
ShowTooltip = false;
113+
ToolTip = "";
100114
}
101115

102116
/// <summary>
@@ -106,16 +120,19 @@ public DynamoMessageBox()
106120
/// <param name="caption"></param>
107121
/// <param name="button"></param>
108122
/// <param name="icon"></param>
123+
/// <param name="tooltip"></param>
109124
/// <returns></returns>
110125
public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button,
111-
MessageBoxImage icon)
126+
MessageBoxImage icon, string tooltip = "")
112127
{
113128
var dynamoMessageBox = new DynamoMessageBox
114129
{
115130
BodyText = messageBoxText,
116131
TitleText = caption,
117132
MessageBoxButton = button,
118-
MessageBoxImage = icon
133+
MessageBoxImage = icon,
134+
ShowTooltip = !string.IsNullOrEmpty(tooltip),
135+
Tooltip = tooltip
119136
};
120137

121138
dynamoMessageBox.ConfigureButtons(button);

src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,10 +2087,13 @@ private void InternalSaveAs(string path, SaveContext saveContext, bool isBackup
20872087
{
20882088
try
20892089
{
2090-
Model.Logger.Log(String.Format(Properties.Resources.SavingInProgress, path));
2091-
CurrentSpaceViewModel.Save(path, isBackup, Model.EngineController, saveContext);
2090+
Model.Logger.Log(string.Format(Properties.Resources.SavingInProgress, path));
2091+
var hasSaved = CurrentSpaceViewModel.Save(path, isBackup, Model.EngineController, saveContext);
20922092

2093-
if (!isBackup) AddToRecentFiles(path);
2093+
if (!isBackup && hasSaved)
2094+
{
2095+
AddToRecentFiles(path);
2096+
}
20942097
}
20952098
catch (Exception ex)
20962099
{
@@ -2151,8 +2154,10 @@ internal void SaveAs(Guid id, string path, bool isBackup = false, SaveContext sa
21512154
try
21522155
{
21532156
Model.Logger.Log(String.Format(Properties.Resources.SavingInProgress, path));
2154-
Workspaces.Where(w => w.Model.Guid == id).FirstOrDefault().Save(path, isBackup, Model.EngineController, saveContext);
2155-
if (!isBackup) AddToRecentFiles(path);
2157+
var hasSaved = Workspaces.FirstOrDefault(w => w.Model.Guid == id).Save(
2158+
path, isBackup, Model.EngineController, saveContext);
2159+
2160+
if (!isBackup && hasSaved) AddToRecentFiles(path);
21562161
}
21572162
catch (Exception ex)
21582163
{

src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Dynamo.Graph.Workspaces;
2121
using Dynamo.Models;
2222
using Dynamo.Selection;
23+
using Dynamo.UI.Prompts;
2324
using Dynamo.Utilities;
2425
using Dynamo.Wpf.ViewModels;
2526
using Dynamo.Wpf.ViewModels.Core;
@@ -598,7 +599,7 @@ internal void ZoomOutInternal()
598599
/// <param name="engine"></param>
599600
/// <param name="saveContext"></param>
600601
/// <exception cref="ArgumentNullException">Thrown when the file path is null.</exception>
601-
internal void Save(string filePath, bool isBackup = false, EngineController engine = null, SaveContext saveContext = SaveContext.None)
602+
internal bool Save(string filePath, bool isBackup = false, EngineController engine = null, SaveContext saveContext = SaveContext.None)
602603
{
603604
if (String.IsNullOrEmpty(filePath))
604605
{
@@ -627,6 +628,23 @@ internal void Save(string filePath, bool isBackup = false, EngineController engi
627628
{
628629
// For intentional SaveAs either through UI or API calls, replace workspace elements' Guids and workspace Id
629630
jo["Uuid"] = Guid.NewGuid().ToString();
631+
if (jo["Bindings"] != null && jo["Bindings"].Any())
632+
{
633+
jo["Bindings"] = JToken.Parse("[]");
634+
635+
if (!DynamoModel.IsTestMode)
636+
{
637+
var result = DynamoMessageBox.Show(Wpf.Properties.Resources.ElementBindingWarningMessage,
638+
Wpf.Properties.Resources.ElementBindingWarningTitle, MessageBoxButton.OKCancel,
639+
MessageBoxImage.Warning, Wpf.Properties.Resources.ElementBindingDesc);
640+
641+
if (result == MessageBoxResult.Cancel)
642+
{
643+
return false;
644+
}
645+
}
646+
}
647+
630648
saveContent = GuidUtility.UpdateWorkspaceGUIDs(jo.ToString());
631649
}
632650
else
@@ -656,6 +674,8 @@ internal void Save(string filePath, bool isBackup = false, EngineController engi
656674
Debug.WriteLine(ex.Message + " : " + ex.StackTrace);
657675
throw (ex);
658676
}
677+
678+
return true;
659679
}
660680
/// <summary>
661681
/// This function appends view block to the model json

test/DynamoCoreWpfTests/DynamoViewTests.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
34
using System.Diagnostics;
45
using System.Globalization;
@@ -21,6 +22,7 @@
2122
using Dynamo.Wpf.ViewModels.Core;
2223
using Dynamo.Wpf.Views;
2324
using DynamoCoreWpfTests.Utility;
25+
using Newtonsoft.Json.Linq;
2426
using NUnit.Framework;
2527
using SharpDX.DXGI;
2628

@@ -126,6 +128,49 @@ public void OpeningWorkspaceWithTclsrustWarning()
126128
DynamoModel.IsTestMode = true;
127129
}
128130

131+
[Test]
132+
public void ElementBinding_SaveAs()
133+
{
134+
var prebindingPathInTestDir = @"core\callsite\trace_test-prebinding.dyn";
135+
var prebindingPath = Path.Combine(GetTestDirectory(ExecutingDirectory), prebindingPathInTestDir);
136+
137+
var pathInTestsDir = @"core\callsite\trace_test.dyn";
138+
var filePath = Path.Combine(GetTestDirectory(ExecutingDirectory), pathInTestsDir);
139+
140+
// Always start with a fresh workspace with no binding data for this test.
141+
File.Copy(prebindingPath, filePath);
142+
OpenAndRun(pathInTestsDir);
143+
144+
// Assert that the node doesn't have trace data the first time it's run.
145+
var hasTraceData = Model.CurrentWorkspace.Nodes.FirstOrDefault(x =>
146+
x.Name == "IncrementerTracedClass.WasCreatedWithTrace");
147+
Assert.AreEqual(false, hasTraceData.CachedValue.Data);
148+
149+
// Saving the workspace after a run serializes trace data to the DYN.
150+
ViewModel.SaveCommand.Execute(null);
151+
152+
DynamoUtilities.PathHelper.isValidJson(filePath, out string fileContents, out Exception ex);
153+
var obj = DSCore.Data.ParseJSON(fileContents) as Dictionary<string, object>;
154+
Assert.AreEqual(1, (obj["Bindings"] as IEnumerable<object>).Count());
155+
156+
var saveAsPathInTestDir = @"core\callsite\trace_test2.dyn";
157+
var saveAsPath = Path.Combine(GetTestDirectory(ExecutingDirectory), saveAsPathInTestDir);
158+
159+
// SaveAs current workspace, close workspace.
160+
ViewModel.SaveAsCommand.Execute(saveAsPath);
161+
ViewModel.CloseHomeWorkspaceCommand.Execute(null);
162+
163+
Open(saveAsPathInTestDir);
164+
165+
// Assert saved as file doesn't have binding data after open.
166+
DynamoUtilities.PathHelper.isValidJson(saveAsPath, out fileContents, out ex);
167+
obj = DSCore.Data.ParseJSON(fileContents) as Dictionary<string, object>;
168+
Assert.AreEqual(0, (obj["Bindings"] as IEnumerable<object>).Count());
169+
170+
File.Delete(filePath);
171+
File.Delete(saveAsPath);
172+
}
173+
129174
[Test]
130175
public void TestToastNotificationClosingBehavior()
131176
{

0 commit comments

Comments
 (0)