Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick PRs 14394, 14424, 14500, 14740 #15032

Merged
merged 9 commits into from
Mar 20, 2024
27 changes: 27 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3651,4 +3651,13 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
<data name="PreferencesViewIncludeTimestampExportPathTooltip" xml:space="preserve">
<value>When toggled on, file names of exported images include date and time of export.</value>
</data>
</root>
<data name="ElementBindingWarningMessage" xml:space="preserve">
<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>
</data>
<data name="ElementBindingWarningTitle" xml:space="preserve">
<value>Element Binding Warning</value>
</data>
<data name="ElementBindingDesc" xml:space="preserve">
<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>
</data>
</root>
11 changes: 10 additions & 1 deletion src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3638,4 +3638,13 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
<data name="PreferencesViewIncludeTimestampExportPathTooltip" xml:space="preserve">
<value>When toggled on, file names of exported images include date and time of export.</value>
</data>
</root>
<data name="ElementBindingWarningMessage" xml:space="preserve">
<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>
</data>
<data name="ElementBindingWarningTitle" xml:space="preserve">
<value>Element Binding Warning</value>
</data>
<data name="ElementBindingDesc" xml:space="preserve">
<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>
</data>
</root>
31 changes: 30 additions & 1 deletion src/DynamoCoreWpf/UI/Prompts/DynamoMessageBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:p="clr-namespace:Dynamo.Wpf.Properties;assembly=DynamoCoreWpf"
xmlns:ui="clr-namespace:Dynamo.UI"
xmlns:localui="clr-namespace:Dynamo.Wpf.UI.GuidedTour"
xmlns:w="clr-namespace:System.Windows;assembly=PresentationCore"
xmlns:fa="http://schemas.fontawesome.io/icons/"
Title="{x:Static p:Resources.GenericTaskDialogTitle}"
MinWidth="400"
MaxWidth="500"
Expand Down Expand Up @@ -98,6 +98,35 @@
Foreground="#3C3C3C"
Text="{Binding TitleText, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap" />
<Label HorizontalAlignment="Right"
Name="TooltipInfo"
VerticalAlignment="Center"
Height="26"
Width="53"
Margin="20 -3 0 0">
<Label.Style>
<Style TargetType="{x:Type Label}">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding ShowTooltip}" Value="True">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
<Label.ToolTip>
<ToolTip Content="{Binding Path=Tooltip}"
Style="{StaticResource GenericToolTipLight}"/>
</Label.ToolTip>
<Label.Content>
<fa:ImageAwesome Width="15"
Height="15"
VerticalAlignment="Bottom"
HorizontalAlignment="Left"
Icon="QuestionCircle"
Foreground="#808080"/>
</Label.Content>
</Label>
</DockPanel>
<Rectangle Name="Separator"
Grid.Row="0"
Expand Down
21 changes: 19 additions & 2 deletions src/DynamoCoreWpf/UI/Prompts/DynamoMessageBox.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ public MessageBoxImage MessageBoxImage
}
}

/// <summary>
/// A tooltip is shown on the message box when this is set to true and if
/// Tooltip is non-null and non-empty.
/// </summary>
public bool ShowTooltip { get; private set; }

/// <summary>
/// A tooltip is shown on the message box when this is set to a non-empty string
/// and ShowTooltip is true.
/// </summary>
public string Tooltip { get; private set; }

#endregion

/// <summary>
Expand All @@ -97,6 +109,8 @@ public DynamoMessageBox()
{
InitializeComponent();
DataContext = this;
ShowTooltip = false;
ToolTip = "";
}

/// <summary>
Expand All @@ -106,16 +120,19 @@ public DynamoMessageBox()
/// <param name="caption"></param>
/// <param name="button"></param>
/// <param name="icon"></param>
/// <param name="tooltip"></param>
/// <returns></returns>
public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button,
MessageBoxImage icon)
MessageBoxImage icon, string tooltip = "")
{
var dynamoMessageBox = new DynamoMessageBox
{
BodyText = messageBoxText,
TitleText = caption,
MessageBoxButton = button,
MessageBoxImage = icon
MessageBoxImage = icon,
ShowTooltip = !string.IsNullOrEmpty(tooltip),
Tooltip = tooltip
};

dynamoMessageBox.ConfigureButtons(button);
Expand Down
15 changes: 10 additions & 5 deletions src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2087,10 +2087,13 @@ private void InternalSaveAs(string path, SaveContext saveContext, bool isBackup
{
try
{
Model.Logger.Log(String.Format(Properties.Resources.SavingInProgress, path));
CurrentSpaceViewModel.Save(path, isBackup, Model.EngineController, saveContext);
Model.Logger.Log(string.Format(Properties.Resources.SavingInProgress, path));
var hasSaved = CurrentSpaceViewModel.Save(path, isBackup, Model.EngineController, saveContext);

if (!isBackup) AddToRecentFiles(path);
if (!isBackup && hasSaved)
{
AddToRecentFiles(path);
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -2151,8 +2154,10 @@ internal void SaveAs(Guid id, string path, bool isBackup = false, SaveContext sa
try
{
Model.Logger.Log(String.Format(Properties.Resources.SavingInProgress, path));
Workspaces.Where(w => w.Model.Guid == id).FirstOrDefault().Save(path, isBackup, Model.EngineController, saveContext);
if (!isBackup) AddToRecentFiles(path);
var hasSaved = Workspaces.FirstOrDefault(w => w.Model.Guid == id).Save(
path, isBackup, Model.EngineController, saveContext);

if (!isBackup && hasSaved) AddToRecentFiles(path);
}
catch (Exception ex)
{
Expand Down
22 changes: 21 additions & 1 deletion src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Dynamo.Graph.Workspaces;
using Dynamo.Models;
using Dynamo.Selection;
using Dynamo.UI.Prompts;
using Dynamo.Utilities;
using Dynamo.Wpf.ViewModels;
using Dynamo.Wpf.ViewModels.Core;
Expand Down Expand Up @@ -598,7 +599,7 @@ internal void ZoomOutInternal()
/// <param name="engine"></param>
/// <param name="saveContext"></param>
/// <exception cref="ArgumentNullException">Thrown when the file path is null.</exception>
internal void Save(string filePath, bool isBackup = false, EngineController engine = null, SaveContext saveContext = SaveContext.None)
internal bool Save(string filePath, bool isBackup = false, EngineController engine = null, SaveContext saveContext = SaveContext.None)
{
if (String.IsNullOrEmpty(filePath))
{
Expand Down Expand Up @@ -627,6 +628,23 @@ internal void Save(string filePath, bool isBackup = false, EngineController engi
{
// For intentional SaveAs either through UI or API calls, replace workspace elements' Guids and workspace Id
jo["Uuid"] = Guid.NewGuid().ToString();
if (jo["Bindings"] != null && jo["Bindings"].Any())
{
jo["Bindings"] = JToken.Parse("[]");

if (!DynamoModel.IsTestMode)
{
var result = DynamoMessageBox.Show(Wpf.Properties.Resources.ElementBindingWarningMessage,
Wpf.Properties.Resources.ElementBindingWarningTitle, MessageBoxButton.OKCancel,
MessageBoxImage.Warning, Wpf.Properties.Resources.ElementBindingDesc);

if (result == MessageBoxResult.Cancel)
{
return false;
}
}
}

saveContent = GuidUtility.UpdateWorkspaceGUIDs(jo.ToString());
}
else
Expand Down Expand Up @@ -656,6 +674,8 @@ internal void Save(string filePath, bool isBackup = false, EngineController engi
Debug.WriteLine(ex.Message + " : " + ex.StackTrace);
throw (ex);
}

return true;
}
/// <summary>
/// This function appends view block to the model json
Expand Down
45 changes: 45 additions & 0 deletions test/DynamoCoreWpfTests/DynamoViewTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
Expand All @@ -21,6 +22,7 @@
using Dynamo.Wpf.ViewModels.Core;
using Dynamo.Wpf.Views;
using DynamoCoreWpfTests.Utility;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using SharpDX.DXGI;

Expand Down Expand Up @@ -126,6 +128,49 @@ public void OpeningWorkspaceWithTclsrustWarning()
DynamoModel.IsTestMode = true;
}

[Test]
public void ElementBinding_SaveAs()
{
var prebindingPathInTestDir = @"core\callsite\trace_test-prebinding.dyn";
var prebindingPath = Path.Combine(GetTestDirectory(ExecutingDirectory), prebindingPathInTestDir);

var pathInTestsDir = @"core\callsite\trace_test.dyn";
var filePath = Path.Combine(GetTestDirectory(ExecutingDirectory), pathInTestsDir);

// Always start with a fresh workspace with no binding data for this test.
File.Copy(prebindingPath, filePath);
OpenAndRun(pathInTestsDir);

// Assert that the node doesn't have trace data the first time it's run.
var hasTraceData = Model.CurrentWorkspace.Nodes.FirstOrDefault(x =>
x.Name == "IncrementerTracedClass.WasCreatedWithTrace");
Assert.AreEqual(false, hasTraceData.CachedValue.Data);

// Saving the workspace after a run serializes trace data to the DYN.
ViewModel.SaveCommand.Execute(null);

DynamoUtilities.PathHelper.isValidJson(filePath, out string fileContents, out Exception ex);
var obj = DSCore.Data.ParseJSON(fileContents) as Dictionary<string, object>;
Assert.AreEqual(1, (obj["Bindings"] as IEnumerable<object>).Count());

var saveAsPathInTestDir = @"core\callsite\trace_test2.dyn";
var saveAsPath = Path.Combine(GetTestDirectory(ExecutingDirectory), saveAsPathInTestDir);

// SaveAs current workspace, close workspace.
ViewModel.SaveAsCommand.Execute(saveAsPath);
ViewModel.CloseHomeWorkspaceCommand.Execute(null);

Open(saveAsPathInTestDir);

// Assert saved as file doesn't have binding data after open.
DynamoUtilities.PathHelper.isValidJson(saveAsPath, out fileContents, out ex);
obj = DSCore.Data.ParseJSON(fileContents) as Dictionary<string, object>;
Assert.AreEqual(0, (obj["Bindings"] as IEnumerable<object>).Count());

File.Delete(filePath);
File.Delete(saveAsPath);
}

[Test]
public void TestToastNotificationClosingBehavior()
{
Expand Down
Loading
Loading