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

Dynamo 2.16.2 Hotfix #14157

Merged
merged 7 commits into from
Jul 13, 2023
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
50 changes: 48 additions & 2 deletions src/DynamoCore/Configuration/PreferenceSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -900,6 +900,52 @@ public bool IsTrustedLocation(string location)
}

}

/// <summary>
/// Different ways to ask the user about display the Trusted location
/// </summary>
public enum AskForTrustedLocationResult
{
/// <summary>
/// Ask for the Trusted location
/// </summary>
Ask,
/// <summary>
/// Don't ask about the Trusted location
/// </summary>
DontAsk,
/// <summary>
/// Unable to ask about the Trusted location
/// </summary>
UnableToAsk
}

/// <summary>
/// AskForTrustedLocation function
/// </summary>
/// <param name="isOpenedFile"></param>
/// <param name="isHomeSpace"></param>
/// <param name="isShowStartPage"></param>
/// <param name="isDisableTrustWarnings"></param>
/// <param name="isFileInTrustedLocation"></param>
/// <returns></returns>
public static AskForTrustedLocationResult AskForTrustedLocation(bool isOpenedFile, bool isFileInTrustedLocation, bool isHomeSpace, bool isShowStartPage, bool isDisableTrustWarnings)
{
AskForTrustedLocationResult result = AskForTrustedLocationResult.UnableToAsk;
if (isOpenedFile)
{
if (isHomeSpace && !isShowStartPage && !isDisableTrustWarnings && !isFileInTrustedLocation)
{
result = AskForTrustedLocationResult.Ask;
}
else
{
result = AskForTrustedLocationResult.DontAsk;
}
}
return result;
}

#endregion

#region ILogSource
Expand All @@ -915,4 +961,4 @@ internal void OnMessageLogged(ILogMessage msg)
}
#endregion
}
}
}
8 changes: 4 additions & 4 deletions src/DynamoCoreWpf/Controls/ShortcutToolbar.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.ObjectModel;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Media;
Expand Down Expand Up @@ -39,15 +39,15 @@ public ObservableCollection<ShortcutBarItem> ShortcutBarRightSideItems
/// Construct a ShortcutToolbar.
/// </summary>
/// <param name="updateManager"></param>
public ShortcutToolbar(IUpdateManager updateManager)
public ShortcutToolbar(DynamoViewModel dynamoViewModel)
{
shortcutBarItems = new ObservableCollection<ShortcutBarItem>();
shortcutBarRightSideItems = new ObservableCollection<ShortcutBarItem>();

InitializeComponent();
UpdateControl.DataContext = updateManager;
UpdateControl.DataContext = dynamoViewModel.Model.UpdateManager;

var shortcutToolbar = new ShortcutToolbarViewModel();
var shortcutToolbar = new ShortcutToolbarViewModel(dynamoViewModel);
DataContext = shortcutToolbar;
}

Expand Down
1 change: 1 addition & 0 deletions src/DynamoCoreWpf/DynamoCoreWpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@
</Compile>
<Compile Include="UI\SharedResourceDictionary.cs" />
<Compile Include="Utilities\PreferencesPanelUtilities.cs" />
<Compile Include="Utilities\WebView2Utilities.cs" />
<Compile Include="ViewModels\Core\AnnotationExtension.cs" />
<Compile Include="ViewModels\Core\AnnotationViewModel.cs" />
<Compile Include="Utilities\ResourceUtilities.cs" />
Expand Down
18 changes: 18 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.

6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3296,4 +3296,10 @@ You can manage this in Preferences -&gt; Security.</value>
<data name="PrePackagePublishTitle" xml:space="preserve">
<value>Package Upload Scan</value>
</data>
<data name="WebView2RequiredMessage" xml:space="preserve">
<value>Dynamo requires WebView2 Evergreen Runtime, which is not installed on your computer. Please use the link below to download the Evergreen Standalone Installer and install the program. Then relaunch Dynamo. \n\n#WebView2 Runtime Installer=https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-sectionedge/webview2/#download-section</value>
</data>
<data name="WebView2RequiredTitle" xml:space="preserve">
<value>WebView2 Required</value>
</data>
</root>
8 changes: 7 additions & 1 deletion src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3283,4 +3283,10 @@ You can manage this in Preferences -&gt; Security.</value>
<data name="PrePackagePublishTitle" xml:space="preserve">
<value>Package Upload Scan</value>
</data>
</root>
<data name="WebView2RequiredMessage" xml:space="preserve">
<value>Dynamo requires WebView2 Evergreen Runtime, which is not installed on your computer. Please use the link below to download the Evergreen Standalone Installer and install the program. Then relaunch Dynamo. \n\n#WebView2 Runtime Installer=https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-sectionedge/webview2/#download-section</value>
</data>
<data name="WebView2RequiredTitle" xml:space="preserve">
<value>WebView2 Required</value>
</data>
</root>
2 changes: 1 addition & 1 deletion src/DynamoCoreWpf/Rendering/HelixRenderPackage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.DesignScript.Interfaces;
Expand Down
12 changes: 11 additions & 1 deletion src/DynamoCoreWpf/UI/Prompts/DynamoMessageBox.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Window x:Class="Dynamo.UI.Prompts.DynamoMessageBox"
<Window x:Class="Dynamo.UI.Prompts.DynamoMessageBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
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"
Title="{x:Static p:Resources.GenericTaskDialogTitle}"
MinWidth="400"
Expand Down Expand Up @@ -115,6 +116,15 @@
Foreground="#3C3C3C"
Text="{Binding BodyText, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap" />
<localui:CustomRichTextBox x:Name="ContentRichTextBox"
IsDocumentEnabled="True"
Visibility="Collapsed"
DockPanel.Dock="Left"
Grid.Row="1"
Margin="20"
CustomText="{Binding BodyText}"
Style="{StaticResource CustomRichTextBoxStyle}">
</localui:CustomRichTextBox>

<!-- Buttons -->
<DockPanel Name="ButtonsDockPanel"
Expand Down
33 changes: 32 additions & 1 deletion src/DynamoCoreWpf/UI/Prompts/DynamoMessageBox.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
Expand Down Expand Up @@ -122,6 +122,37 @@ public static MessageBoxResult Show(string messageBoxText, string caption, Messa
dynamoMessageBox.ShowDialog();
return dynamoMessageBox.CustomDialogResult;
}


/// <summary>
/// Displays a dialog to the user and returns their choice as a MessageBoxResult.
/// </summary>
/// <param name="messageBoxText">Content of the message</param>
/// <param name="caption">MessageBox title</param>
/// <param name="showRichTextBox">True if we will be using the RichTextBox instead of the usual one</param>
/// <param name="button">OK button shown in the MessageBox</param>
/// <param name="icon">Type of message: Warning, Error</param>
/// <returns></returns>
public static MessageBoxResult Show(string messageBoxText, string caption, bool showRichTextBox, MessageBoxButton button,
MessageBoxImage icon)
{
var dynamoMessageBox = new DynamoMessageBox
{
BodyText = messageBoxText,
TitleText = caption,
MessageBoxButton = button,
MessageBoxImage = icon
};

if (showRichTextBox)
{
dynamoMessageBox.BodyTextBlock.Visibility = Visibility.Collapsed;
dynamoMessageBox.ContentRichTextBox.Visibility = Visibility.Visible;
}
dynamoMessageBox.ConfigureButtons(button);
dynamoMessageBox.ShowDialog();
return dynamoMessageBox.CustomDialogResult;
}
/// <summary>
/// Displays a dialog to the user and returns their choice as a MessageBoxResult.
/// </summary>
Expand Down
12 changes: 11 additions & 1 deletion src/DynamoCoreWpf/Utilities/MessageBoxUtilities.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Windows;
using Dynamo.UI.Prompts;

Expand All @@ -10,6 +10,7 @@ public class MessageBoxService {
internal interface IMessageBox
{
MessageBoxResult Show(string msg, string title, MessageBoxButton button, MessageBoxImage img);
MessageBoxResult Show(string msg, string title, bool showRichTextBox, MessageBoxButton button, MessageBoxImage img);
MessageBoxResult Show(Window owner,string msg, string title, MessageBoxButton button, MessageBoxImage img);
MessageBoxResult Show(string msg, string title, MessageBoxButton button, IEnumerable<string> buttonNames, MessageBoxImage img);
}
Expand All @@ -23,6 +24,11 @@ MessageBoxResult IMessageBox.Show(string msg, string title, MessageBoxButton but
return DynamoMessageBox.Show(msg, title, button, img);
}

MessageBoxResult IMessageBox.Show(string msg, string title, bool showRichTextBox, MessageBoxButton button, MessageBoxImage img)
{
return DynamoMessageBox.Show(msg, title, showRichTextBox, button, img);
}

public MessageBoxResult Show(Window owner, string msg, string title, MessageBoxButton button, MessageBoxImage img)
{
return DynamoMessageBox.Show(owner,msg, title, button, img);
Expand All @@ -43,6 +49,10 @@ public static MessageBoxResult Show(string msg, string title, MessageBoxButton b
{
return (msg_box ?? (msg_box = new DefaultMessageBox())).Show(msg, title, button, img);
}
public static MessageBoxResult Show(string msg, string title, bool showRichTextBox, MessageBoxButton button, MessageBoxImage img)
{
return (msg_box ?? (msg_box = new DefaultMessageBox())).Show(msg, title, showRichTextBox, button, img);
}
public static MessageBoxResult Show(Window owner,string msg, string title, MessageBoxButton button, MessageBoxImage img)
{
return (msg_box ?? (msg_box = new DefaultMessageBox())).Show(owner,msg, title, button, img);
Expand Down
40 changes: 40 additions & 0 deletions src/DynamoCoreWpf/Utilities/WebView2Utilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Windows;
using Dynamo.Wpf.Properties;
using Dynamo.Wpf.Utilities;
using Microsoft.Web.WebView2.Core;

namespace Dynamo.Utilities
{
/// <summary>
/// This class will contain several utility functions that will be used for the WebView2 component
/// </summary>
public static class WebView2Utilities
{
/// <summary>
/// Validate if the WebView2 Evergreen Runtime is installed in the computer, otherwise it will show a MessageBox about installing the Runtime and then exit Dynamo
/// </summary>
/// <returns></returns>
public static bool ValidateWebView2RuntimeInstalled()
{
try
{
string availableVersion = CoreWebView2Environment.GetAvailableBrowserVersionString();
return true;
}
//We reach the catch section only when the Webview2 Runtime is not installed
catch (WebView2RuntimeNotFoundException)
{
var messageStr = Resources.ResourceManager.GetString("WebView2RequiredMessage");
if(messageStr.IndexOf("\\n") >= 0)
messageStr = messageStr.Replace("\\n", "\n");

MessageBoxService.Show(messageStr,
Resources.WebView2RequiredTitle,
true,
MessageBoxButton.OK,
MessageBoxImage.Error);
return false;
}
}
}
}
18 changes: 18 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3097,6 +3097,24 @@ private bool AskUserToSaveWorkspacesOrCancel(bool allowCancel = true)
return true;
}

/// <summary>
/// Check if the current file is located in a Trusted Location in order to display to the User the proper message
/// </summary>
public void CheckCurrentFileInTrustedLocation()
{
PreferenceSettings.AskForTrustedLocationResult askToTheUser =
PreferenceSettings.AskForTrustedLocation(CurrentSpaceViewModel.FileName.Length > 0,
CurrentSpaceViewModel.FileName.Length > 0 ? PreferenceSettings.IsTrustedLocation(Path.GetDirectoryName(CurrentSpaceViewModel.FileName)) : false,
(currentWorkspaceViewModel?.IsHomeSpace ?? false),
ShowStartPage,
model.PreferenceSettings.DisableTrustWarnings);

if (askToTheUser == PreferenceSettings.AskForTrustedLocationResult.Ask) {

FileTrustViewModel.AllowOneTimeTrust = false;
}
}

#endregion
}
}
13 changes: 11 additions & 2 deletions src/DynamoCoreWpf/ViewModels/Core/ShortcutToolbarViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using Dynamo.ViewModels;
using Dynamo.UI.Commands;
using Dynamo.ViewModels;
using System;
using System.Windows;

namespace Dynamo.Wpf.ViewModels.Core
{
internal class ShortcutToolbarViewModel : ViewModelBase
{
public ShortcutToolbarViewModel()
public ShortcutToolbarViewModel(DynamoViewModel dynamoViewModel)
{
NotificationsNumber = 0;
ShowSaveImageDialogAndSaveResultCommand = new DelegateCommand(dynamoViewModel.ShowSaveImageDialogAndSaveResult);
}

private int notificationsNumber;
Expand Down Expand Up @@ -36,5 +39,11 @@ public bool IsNotificationsCounterVisible
return true;
}
}


/// <summary>
/// Exports an image from the user's 3D background or workpace
/// </summary>
public DelegateCommand ShowSaveImageDialogAndSaveResultCommand { get; set; }
}
}
8 changes: 8 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,14 @@ internal void Save(string filePath, bool isBackup = false, EngineController engi
Model.FileName = filePath;
Model.OnSaved();
}

// If a new CustomNodeWorkspaceModel is created, store that info in CustomNodeManager without creating an instance of the custom node.
if (this.Model is CustomNodeWorkspaceModel customNodeWorkspaceModel)
{
//If the custom node Name is already set and the FileName is already set then we don't need to change the Name with "backup"
if(string.IsNullOrEmpty(customNodeWorkspaceModel.Name) && string.IsNullOrEmpty(customNodeWorkspaceModel.FileName))
customNodeWorkspaceModel.SetInfo(Path.GetFileNameWithoutExtension(filePath));
}
}
catch (Exception ex)
{
Expand Down
Loading