diff --git a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
index 2fbe44f1901..29f61fd54ca 100644
--- a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
+++ b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
@@ -2180,6 +2180,18 @@ private void OpenFromJson(object parameters)
this.ShowStartPage = false; // Hide start page if there's one.
}
+ ///
+ /// Resets trust warning state when a preemptively shown popup should be dismissed.
+ ///
+ /// True when this open/insert flow displayed the trust warning before command execution.
+ private void ResetTrustWarningStateIfNeeded(bool trustWarningWasShown)
+ {
+ if (!trustWarningWasShown || FileTrustViewModel == null) return;
+
+ FileTrustViewModel.ShowWarningPopup = false;
+ RunSettings.ForceBlockRun = false;
+ }
+
///
/// Open a definition or workspace.
/// For most cases, parameters variable refers to the file path to open
@@ -2203,6 +2215,7 @@ private void Open(object parameters)
fileContents = string.Empty;
bool forceManualMode = false;
bool isTemplate = false;
+ bool trustWarningWasShown = false;
try
{
if (parameters is Tuple packedParams)
@@ -2229,25 +2242,33 @@ private void Open(object parameters)
&& !DynamoModel.IsTestMode
&& !PreferenceSettings.DisableTrustWarnings
&& FileTrustViewModel != null;
- RunSettings.ForceBlockRun = displayTrustWarning;
- // Execute graph open command
- ExecuteCommand(new DynamoModel.OpenFileCommand(filePath, forceManualMode, isTemplate));
- // Apply annotation updates based on the preference setting
- RefreshAnnotationDescriptions();
-
- // Only show trust warning popop when current opened workspace is homeworkspace and not custom node workspace
- if (displayTrustWarning && (currentWorkspaceViewModel?.IsHomeSpace ?? false))
+ if (displayTrustWarning)
{
- // Skip these when opening dyf
FileTrustViewModel.AllowOneTimeTrust = false;
FileTrustViewModel.DynFileDirectoryName = directoryName;
FileTrustViewModel.ShowWarningPopup = true;
(HomeSpaceViewModel as HomeWorkspaceViewModel)?.UpdateRunStatusMsgBasedOnStates();
+ trustWarningWasShown = true;
+ }
+
+ RunSettings.ForceBlockRun = displayTrustWarning;
+ // Execute graph open command
+ ExecuteCommand(new DynamoModel.OpenFileCommand(filePath, forceManualMode, isTemplate));
+
+ if (trustWarningWasShown)
+ {
+ // Hide the preemptively shown popup if trust is now satisfied (trusted path or warnings disabled).
+ ShowHideFileTrustWarningIfCurrentWorkspaceTrusted();
}
+
+ // Apply annotation updates based on the preference setting
+ RefreshAnnotationDescriptions();
}
catch (Exception e)
{
+ ResetTrustWarningStateIfNeeded(trustWarningWasShown);
+
if (!DynamoModel.IsTestMode)
{
string commandString = String.Format(Resources.MessageErrorOpeningFileGeneral);
@@ -2301,6 +2322,7 @@ private void Insert(object parameters)
filePath = string.Empty;
fileContents = string.Empty;
bool forceManualMode = true;
+ bool trustWarningWasShown = false;
try
{
if (parameters is Tuple packedParams)
@@ -2321,24 +2343,30 @@ private void Insert(object parameters)
&& !DynamoModel.IsTestMode
&& !PreferenceSettings.DisableTrustWarnings
&& FileTrustViewModel != null;
- RunSettings.ForceBlockRun = displayTrustWarning;
- // Execute graph open command
- ExecuteCommand(new DynamoModel.InsertFileCommand(filePath, forceManualMode));
-
- this.FitViewCommand.Execute(null);
- // Only show trust warning popup when current opened workspace is homeworkspace and not custom node workspace
- if (displayTrustWarning && (currentWorkspaceViewModel?.IsHomeSpace ?? false))
+ if (displayTrustWarning)
{
- // Skip these when opening dyf
FileTrustViewModel.AllowOneTimeTrust = false;
FileTrustViewModel.DynFileDirectoryName = directoryName;
FileTrustViewModel.ShowWarningPopup = true;
(HomeSpaceViewModel as HomeWorkspaceViewModel)?.UpdateRunStatusMsgBasedOnStates();
+ trustWarningWasShown = true;
+ }
+
+ RunSettings.ForceBlockRun = displayTrustWarning;
+ // Execute graph open command
+ ExecuteCommand(new DynamoModel.InsertFileCommand(filePath, forceManualMode));
+
+ this.FitViewCommand.Execute(null);
+ if (trustWarningWasShown)
+ {
+ ShowHideFileTrustWarningIfCurrentWorkspaceTrusted();
}
}
catch (Exception e)
{
+ ResetTrustWarningStateIfNeeded(trustWarningWasShown);
+
if (!DynamoModel.IsTestMode)
{
string commandString = String.Format(Resources.MessageErrorOpeningFileGeneral);
diff --git a/test/DynamoCoreWpfTests/DynamoViewTests.cs b/test/DynamoCoreWpfTests/DynamoViewTests.cs
index 030edfefbcd..ba704d70f79 100644
--- a/test/DynamoCoreWpfTests/DynamoViewTests.cs
+++ b/test/DynamoCoreWpfTests/DynamoViewTests.cs
@@ -106,6 +106,66 @@ public void OpeningWorkspaceWithTclsrustWarning()
DynamoModel.IsTestMode = true;
}
+ [Test]
+ public void WhenOpeningWorkspaceThenTrustWarningIsShownBeforeCommand()
+ {
+ DynamoModel.IsTestMode = false;
+ bool? popupStateWhenOpenStarts = null;
+
+ void OnCommandStarting(DynamoModel.RecordableCommand command)
+ {
+ if (command is DynamoModel.OpenFileCommand)
+ {
+ popupStateWhenOpenStarts = ViewModel.FileTrustViewModel.ShowWarningPopup;
+ }
+ }
+
+ Model.CommandStarting += OnCommandStarting;
+ try
+ {
+ Open(@"core\CustomNodes\TestAdd.dyn");
+ }
+ finally
+ {
+ Model.CommandStarting -= OnCommandStarting;
+ DynamoModel.IsTestMode = true;
+ }
+
+ Assert.IsTrue(popupStateWhenOpenStarts.GetValueOrDefault(false));
+ }
+
+ [Test]
+ public void WhenInsertingWorkspaceThenTrustWarningIsShownBeforeCommand()
+ {
+ DynamoModel.IsTestMode = false;
+ bool? popupStateWhenInsertStarts = null;
+
+ void OnCommandStarting(DynamoModel.RecordableCommand command)
+ {
+ if (command is DynamoModel.InsertFileCommand)
+ {
+ popupStateWhenInsertStarts = ViewModel.FileTrustViewModel.ShowWarningPopup;
+ }
+ }
+
+ Model.CommandStarting += OnCommandStarting;
+ try
+ {
+ var insertMethod = typeof(DynamoViewModel).GetMethod("Insert", BindingFlags.NonPublic | BindingFlags.Instance);
+ Assert.NotNull(insertMethod);
+
+ var insertPath = Path.Combine(GetTestDirectory(ExecutingDirectory), @"core\CustomNodes\TestAdd.dyn");
+ insertMethod.Invoke(ViewModel, new object[] { insertPath });
+ }
+ finally
+ {
+ Model.CommandStarting -= OnCommandStarting;
+ DynamoModel.IsTestMode = true;
+ }
+
+ Assert.IsTrue(popupStateWhenInsertStarts.GetValueOrDefault(false));
+ }
+
[Test]
public void TestHomeWorkspaceClosedBeforeCustomNode()
{