From cfd302b8169c4b4a598b60a7331f34fac3684afe Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Tue, 10 Sep 2024 02:38:59 -0400 Subject: [PATCH 01/13] init --- .../AssemblySharedInfo.cs | 4 +- .../Commands/WorkspaceCommands.cs | 11 +++ src/DynamoCoreWpf/PublicAPI.Unshipped.txt | 3 + .../ViewModels/Core/DynamoViewModel.cs | 90 +++++++++++++++++++ .../Core/DynamoViewModelDelegateCommands.cs | 4 +- .../ViewModels/Core/WorkspaceViewModel.cs | 3 +- src/DynamoCoreWpf/Views/Core/DynamoView.xaml | 2 + .../Views/Core/DynamoView.xaml.cs | 24 ++++- .../Views/Core/WorkspaceView.xaml | 8 +- .../Views/Core/WorkspaceView.xaml.cs | 31 +++++++ .../PythonNodeModelsWpf/PythonNode.cs | 35 +------- .../PythonNodeModelsWpf/PythonStringNode.cs | 9 +- 12 files changed, 182 insertions(+), 42 deletions(-) diff --git a/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs b/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs index 2b14532f635..129c9560b87 100644 --- a/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs +++ b/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs @@ -45,7 +45,7 @@ // to distinguish one build from another. AssemblyFileVersion is specified // in AssemblyVersionInfo.cs so that it can be easily incremented by the // automated build process. -[assembly: AssemblyVersion("3.4.0.6124")] +[assembly: AssemblyVersion("3.4.0.6177")] // By default, the "Product version" shown in the file properties window is @@ -64,4 +64,4 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyFileVersion("3.4.0.6124")] +[assembly: AssemblyFileVersion("3.4.0.6177")] diff --git a/src/DynamoCoreWpf/Commands/WorkspaceCommands.cs b/src/DynamoCoreWpf/Commands/WorkspaceCommands.cs index cb402539e11..b15c1194291 100644 --- a/src/DynamoCoreWpf/Commands/WorkspaceCommands.cs +++ b/src/DynamoCoreWpf/Commands/WorkspaceCommands.cs @@ -328,6 +328,17 @@ public bool HasSelection get { return DynamoSelection.Instance.Selection.Count > 0; } } + [JsonIgnore] + public bool CanUpdatePythonEngine + { + get { return DynamoViewModel.CanUpdatePythonNodeEngine(null); } + } + [JsonIgnore] + public bool CanUpdateAllPythonEngine + { + get { return DynamoViewModel.CanUpdateAllPythonEngine(null); } + } + [JsonIgnore] public bool IsGeometryOperationEnabled { diff --git a/src/DynamoCoreWpf/PublicAPI.Unshipped.txt b/src/DynamoCoreWpf/PublicAPI.Unshipped.txt index ef105d2fb6a..76281ee4061 100644 --- a/src/DynamoCoreWpf/PublicAPI.Unshipped.txt +++ b/src/DynamoCoreWpf/PublicAPI.Unshipped.txt @@ -2144,6 +2144,8 @@ Dynamo.ViewModels.DynamoViewModel.UngroupAnnotationCommand.get -> Dynamo.UI.Comm Dynamo.ViewModels.DynamoViewModel.UngroupAnnotationCommand.set -> void Dynamo.ViewModels.DynamoViewModel.UngroupModelCommand.get -> Dynamo.UI.Commands.DelegateCommand Dynamo.ViewModels.DynamoViewModel.UngroupModelCommand.set -> void +Dynamo.ViewModels.DynamoViewModel.UpdateAllPythonEngineCommand.get -> Dynamo.UI.Commands.DelegateCommand +Dynamo.ViewModels.DynamoViewModel.UpdateAllPythonEngineCommand.set -> void Dynamo.ViewModels.DynamoViewModel.UpdateGraphicHelpersScale(object parameter) -> void Dynamo.ViewModels.DynamoViewModel.UpdateGraphicHelpersScaleCommand.get -> Dynamo.UI.Commands.DelegateCommand Dynamo.ViewModels.DynamoViewModel.UpdateGraphicHelpersScaleCommand.set -> void @@ -2992,6 +2994,7 @@ Dynamo.ViewModels.WorkspaceViewModel.CanFindNodesFromElements.set -> void Dynamo.ViewModels.WorkspaceViewModel.CanPaste.get -> bool Dynamo.ViewModels.WorkspaceViewModel.CanRunNodeToCode.get -> bool Dynamo.ViewModels.WorkspaceViewModel.CanShowInfoBubble.get -> bool +Dynamo.ViewModels.WorkspaceViewModel.CanUpdatePythonEngine.get -> bool Dynamo.ViewModels.WorkspaceViewModel.CanZoomIn.get -> bool Dynamo.ViewModels.WorkspaceViewModel.CanZoomOut.get -> bool Dynamo.ViewModels.WorkspaceViewModel.Checksum.get -> string diff --git a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs index fc339f9b0f9..cd622dd82f4 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs @@ -15,6 +15,7 @@ using System.Windows.Media; using System.Windows.Threading; using Dynamo.Configuration; +using Dynamo.Controls; using Dynamo.Core; using Dynamo.Engine; using Dynamo.Exceptions; @@ -22,6 +23,7 @@ using Dynamo.Graph.Annotations; using Dynamo.Graph.Connectors; using Dynamo.Graph.Nodes; +using Dynamo.Graph.Notes; using Dynamo.Graph.Workspaces; using Dynamo.Interfaces; using Dynamo.Logging; @@ -1394,6 +1396,94 @@ private void Paste(object parameter) RaiseCanExecuteUndoRedo(); } + internal bool CanUpdatePythonNodeEngine(object parameter) + { + if (DynamoSelection.Instance.Selection.Count > 0 && SelectionHasPythonNodes()) + { + return true; + } + return false; + } + private bool SelectionHasPythonNodes() + { + if (DynamoSelection.Instance.Selection.OfType().Any() || DynamoSelection.Instance.Selection.OfType().Any()) + { + return true; + } + return false; + } + internal void UpdatePythonNodeEngine(PythonNodeBase pythonNode, string engine) + { + this.ExecuteCommand( + new DynamoModel.UpdateModelValueCommand( + Guid.Empty, pythonNode.GUID, nameof(pythonNode.EngineName), engine)); + pythonNode.OnNodeModified(); + } + internal void UpdateAllPythonEngine(object param) + { + var pNodes = Model.CurrentWorkspace.Nodes.OfType().ToList(); + if (pNodes.Count == 0) return; + var result = MessageBoxService.Show( + Owner, + string.Format(Properties.Resources.UpdateAllPythonEngineWarning, pNodes.Count, param.ToString()), + Properties.Resources.UpdateAllPythonEngineWarningTitle, + MessageBoxButton.YesNo, + MessageBoxImage.Exclamation); + if (result == MessageBoxResult.Yes) + { + Model.CurrentWorkspace.Nodes.OfType().ToList().ForEach(x => UpdatePythonNodeEngine(x, param.ToString())); + } + } + internal bool CanUpdateAllPythonEngine(object param) + { + return true; + } + + /// + /// Adds the python engine to the menu items and subscribes to their click event for updating the engine. + /// + /// List of python nodes + /// context menu item to which the engines will be added to + /// Update event handler, to trigger engine update for the node + /// Python engine to be added + internal void AddPythonEngineToMenuItems(List pythonNodeModel, + MenuItem pythonEngineVersionMenu, + RoutedEventHandler updateEngineDelegate, + string engineName) + { + //if all nodes in the selection are set to a specific engine, then that engine will be checked in the list. + bool hasCommonEngine = pythonNodeModel.All(x => x.EngineName == engineName); + var currentItem = pythonEngineVersionMenu.Items.Cast().FirstOrDefault(x => x.Header as string == engineName); + if (currentItem != null) + { + if (pythonNodeModel.Count == 1) return; + currentItem.IsChecked = hasCommonEngine; + return; + } + MenuItem pythonEngineItem = null; + //if single node, then checked property is bound to the engine value, as python node context menu is not recreated + if (pythonNodeModel.Count == 1) + { + var pythonNode = pythonNodeModel.FirstOrDefault(); ; + pythonEngineItem = new MenuItem { Header = engineName, IsCheckable = false }; + pythonEngineItem.SetBinding(MenuItem.IsCheckedProperty, new System.Windows.Data.Binding(nameof(pythonNode.EngineName)) + { + Source = pythonNode, + Converter = new CompareToParameterConverter(), + ConverterParameter = engineName + }); + } + else + { + //when updating multiple nodes checked value is not bound to any specific node, + //rather takes into account all the selected nodes + pythonEngineItem = new MenuItem { Header = engineName, IsCheckable = true }; + pythonEngineItem.IsChecked = hasCommonEngine; + } + pythonEngineItem.Click += updateEngineDelegate; + pythonEngineVersionMenu.Items.Add(pythonEngineItem); + } + /// /// After command framework is implemented, this method should now be only /// called from a menu item (i.e. Ctrl + W). It should not be used as a way diff --git a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModelDelegateCommands.cs b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModelDelegateCommands.cs index f1c79c4ba57..9469d13eb63 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModelDelegateCommands.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModelDelegateCommands.cs @@ -51,7 +51,8 @@ private void InitializeDelegateCommands() ToggleFullscreenWatchShowingCommand = new DelegateCommand(ToggleFullscreenWatchShowing, CanToggleFullscreenWatchShowing); ToggleBackgroundGridVisibilityCommand = new DelegateCommand(ToggleBackgroundGridVisibility, CanToggleBackgroundGridVisibility); UpdateGraphicHelpersScaleCommand = new DelegateCommand(UpdateGraphicHelpersScale, CanUpdateGraphicHelpersScale); - AlignSelectedCommand = new DelegateCommand(AlignSelected, CanAlignSelected); ; + AlignSelectedCommand = new DelegateCommand(AlignSelected, CanAlignSelected); + UpdateAllPythonEngineCommand = new DelegateCommand(UpdateAllPythonEngine, CanUpdateAllPythonEngine); UndoCommand = new DelegateCommand(Undo, CanUndo); RedoCommand = new DelegateCommand(Redo, CanRedo); CopyCommand = new DelegateCommand(_ => model.Copy(), CanCopy); @@ -138,6 +139,7 @@ private void InitializeDelegateCommands() public DelegateCommand GoToWorkspaceCommand { get; set; } public DelegateCommand DeleteCommand { get; set; } public DelegateCommand AlignSelectedCommand { get; set; } + public DelegateCommand UpdateAllPythonEngineCommand { get; set; } public DelegateCommand PostUIActivationCommand { get; set; } public DelegateCommand ToggleFullscreenWatchShowingCommand { get; set; } public DelegateCommand ToggleBackgroundGridVisibilityCommand { get; set; } diff --git a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs index 213f58e9c3d..a3175672525 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs @@ -1780,7 +1780,8 @@ private void RefreshViewOnSelectionChange(object sender, NotifyCollectionChanged RaisePropertyChanged("HasSelection"); RaisePropertyChanged("IsGeometryOperationEnabled"); RaisePropertyChanged("AnyNodeVisible"); - RaisePropertyChanged("SelectionArgumentLacing"); + RaisePropertyChanged("SelectionArgumentLacing"); + RaisePropertyChanged("CanUpdatePythonEngine"); } /// diff --git a/src/DynamoCoreWpf/Views/Core/DynamoView.xaml b/src/DynamoCoreWpf/Views/Core/DynamoView.xaml index 7ecc0b9f40d..0aa89dc4369 100644 --- a/src/DynamoCoreWpf/Views/Core/DynamoView.xaml +++ b/src/DynamoCoreWpf/Views/Core/DynamoView.xaml @@ -534,6 +534,8 @@ + x.Name).ToList(); + availablePythonEngines.Select(pythonEngine => new MenuItem + { + Header = pythonEngine, + Command = dynamoViewModel.UpdateAllPythonEngineCommand, + CommandParameter = pythonEngine + }).ToList().ForEach(x => PythonEngineMenu.Items.Add(x)); + } + private void OnWorkspaceHidden(WorkspaceModel workspace) { CalculateWindowMinWidth(); diff --git a/src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml b/src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml index 8d8eee1d1f8..ed15168f8d2 100644 --- a/src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml +++ b/src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml @@ -381,6 +381,7 @@ @@ -710,7 +711,7 @@ Visibility="{Binding Path=CanFindNodesFromElements, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}" /> - + + + + + + ()) + { + item.Click -= UpdateSelectedPythonNodeEngines; + } + PythonEngineMenu.Items.Clear(); + } + + private void AddPythonEngineOptions(MenuItem contextMenuItem) + { + var pythonEngineVersionMenu = contextMenuItem; + var selectedNodes = DynamoSelection.Instance.Selection.OfType().ToList(); + PythonEngineManager.Instance.AvailableEngines.ToList().ForEach(engineName => ViewModel.DynamoViewModel.AddPythonEngineToMenuItems(selectedNodes, pythonEngineVersionMenu, UpdateSelectedPythonNodeEngines, engineName.Name)); + } + + private void UpdateSelectedPythonNodeEngines(object sender, EventArgs e) + { + if (sender is MenuItem menuItem) + { + var selectedNodes = DynamoSelection.Instance.Selection.OfType().ToList(); + selectedNodes.ForEach(pythonNodeModel => + { + ViewModel.DynamoViewModel.UpdatePythonNodeEngine(pythonNodeModel, (string)menuItem.Header); + }); + } } private void OnGeometryScaling_Click(object sender, RoutedEventArgs e) diff --git a/src/Libraries/PythonNodeModelsWpf/PythonNode.cs b/src/Libraries/PythonNodeModelsWpf/PythonNode.cs index fbbbf5b9822..dcbd1e7bcef 100644 --- a/src/Libraries/PythonNodeModelsWpf/PythonNode.cs +++ b/src/Libraries/PythonNodeModelsWpf/PythonNode.cs @@ -94,8 +94,8 @@ public void CustomizeView(PythonNode nodeModel, NodeView nodeView) learnMoreItem.Click += OpenPythonLearningMaterial; - PythonNodeUtils.GetEngineNames(nodeModel).ForEach(engineName => AddPythonEngineToMenuItems( - pythonNodeModel,pythonEngineVersionMenu,UpdateEngine,engineName)); + PythonNodeUtils.GetEngineNames(nodeModel).ForEach(engineName => dynamoViewModel.AddPythonEngineToMenuItems( + new List() { pythonNodeModel }, pythonEngineVersionMenu, UpdateEngine, engineName)); PythonEngineManager.Instance.AvailableEngines.CollectionChanged += PythonEnginesChanged; @@ -302,10 +302,7 @@ private void UpdateEngine(object sender, EventArgs e) { if (sender is MenuItem menuItem) { - dynamoViewModel.ExecuteCommand( - new DynamoModel.UpdateModelValueCommand( - Guid.Empty, pythonNodeModel.GUID, nameof(pythonNodeModel.EngineName), (string)menuItem.Header)); - pythonNodeModel.OnNodeModified(); + dynamoViewModel.UpdatePythonNodeEngine(pythonNodeModel, (string)menuItem.Header); } } @@ -317,34 +314,10 @@ private void PythonEnginesChanged(object sender, NotifyCollectionChangedEventArg { if(item is PythonEngine newEngine) { - AddPythonEngineToMenuItems(pythonNodeModel,pythonEngineVersionMenu,UpdateEngine,newEngine.Name); + dynamoViewModel.AddPythonEngineToMenuItems(new List() { pythonNodeModel }, pythonEngineVersionMenu, UpdateEngine, newEngine.Name); } } } } - - /// - /// Adds python engine to MenuItems, if that engine name is not already present. - /// - internal static void AddPythonEngineToMenuItems(PythonNodeBase pythonNodeModel, - MenuItem pythonEngineVersionMenu, - RoutedEventHandler updateEngineDelegate, - string engineName) - { - - if (pythonEngineVersionMenu.Items.Cast().Any(x => x.Header as string == engineName)) - { - return; - } - var pythonEngineItem = new MenuItem { Header = engineName, IsCheckable = false }; - pythonEngineItem.Click += updateEngineDelegate; - pythonEngineItem.SetBinding(MenuItem.IsCheckedProperty, new Binding(nameof(pythonNodeModel.EngineName)) - { - Source = pythonNodeModel, - Converter = new CompareToParameterConverter(), - ConverterParameter = engineName - }); - pythonEngineVersionMenu.Items.Add(pythonEngineItem); - } } } diff --git a/src/Libraries/PythonNodeModelsWpf/PythonStringNode.cs b/src/Libraries/PythonNodeModelsWpf/PythonStringNode.cs index 45ff31609ff..113cf090a4b 100644 --- a/src/Libraries/PythonNodeModelsWpf/PythonStringNode.cs +++ b/src/Libraries/PythonNodeModelsWpf/PythonStringNode.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Windows; @@ -33,8 +34,8 @@ public void CustomizeView(PythonStringNode nodeModel, NodeView nodeView) pythonEngineVersionMenu = new MenuItem { Header = PythonNodeModels.Properties.Resources.PythonNodeContextMenuEngineSwitcher, IsCheckable = false }; nodeView.MainContextMenu.Items.Add(pythonEngineVersionMenu); - PythonNodeUtils.GetEngineNames(nodeModel).ForEach(engineName => PythonNodeViewCustomization.AddPythonEngineToMenuItems( - pythonStringNodeModel, pythonEngineVersionMenu, UpdateEngine, engineName)); + PythonNodeUtils.GetEngineNames(nodeModel).ForEach(engineName => dynamoViewModel.AddPythonEngineToMenuItems( + new List() { pythonStringNodeModel }, pythonEngineVersionMenu, UpdateEngine, engineName)); PythonEngineManager.Instance.AvailableEngines.CollectionChanged += PythonEnginesChanged; @@ -106,8 +107,8 @@ private void PythonEnginesChanged(object sender, NotifyCollectionChangedEventArg { if (item is PythonEngine newEngine) { - PythonNodeViewCustomization.AddPythonEngineToMenuItems( - pythonStringNodeModel,pythonEngineVersionMenu,UpdateEngine,newEngine.Name); + dynamoViewModel.AddPythonEngineToMenuItems( + new List() { pythonStringNodeModel }, pythonEngineVersionMenu,UpdateEngine,newEngine.Name); } } } From a9607b4bdfab4b1345385fca284b60bd21ee65b1 Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Tue, 10 Sep 2024 02:40:21 -0400 Subject: [PATCH 02/13] Update AssemblySharedInfo.cs --- src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs b/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs index 129c9560b87..669fc83f9b1 100644 --- a/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs +++ b/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs @@ -8,7 +8,7 @@ // associated with an assembly. [assembly: AssemblyCompany("Autodesk, Inc")] [assembly: AssemblyProduct("Dynamo")] -[assembly: AssemblyCopyright("Copyright © Autodesk, Inc 2024")] +[assembly: AssemblyCopyright("Copyright © Autodesk, Inc 2024")] [assembly: AssemblyTrademark("")] //In order to begin building localizable applications, set @@ -45,7 +45,7 @@ // to distinguish one build from another. AssemblyFileVersion is specified // in AssemblyVersionInfo.cs so that it can be easily incremented by the // automated build process. -[assembly: AssemblyVersion("3.4.0.6177")] +[assembly: AssemblyVersion("3.4.0.6124")] // By default, the "Product version" shown in the file properties window is @@ -64,4 +64,4 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyFileVersion("3.4.0.6177")] +[assembly: AssemblyVersion("3.4.0.6124")] From 0eb43c159619441a7043bd472acea5098d9dc383 Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Tue, 10 Sep 2024 02:42:44 -0400 Subject: [PATCH 03/13] Revert "Update AssemblySharedInfo.cs" This reverts commit a9607b4bdfab4b1345385fca284b60bd21ee65b1. --- src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs b/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs index 669fc83f9b1..129c9560b87 100644 --- a/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs +++ b/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs @@ -8,7 +8,7 @@ // associated with an assembly. [assembly: AssemblyCompany("Autodesk, Inc")] [assembly: AssemblyProduct("Dynamo")] -[assembly: AssemblyCopyright("Copyright © Autodesk, Inc 2024")] +[assembly: AssemblyCopyright("Copyright © Autodesk, Inc 2024")] [assembly: AssemblyTrademark("")] //In order to begin building localizable applications, set @@ -45,7 +45,7 @@ // to distinguish one build from another. AssemblyFileVersion is specified // in AssemblyVersionInfo.cs so that it can be easily incremented by the // automated build process. -[assembly: AssemblyVersion("3.4.0.6124")] +[assembly: AssemblyVersion("3.4.0.6177")] // By default, the "Product version" shown in the file properties window is @@ -64,4 +64,4 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.4.0.6124")] +[assembly: AssemblyFileVersion("3.4.0.6177")] From 898c5d13a6f7b55cfb28d04a2aef857a791cdd22 Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Tue, 10 Sep 2024 02:43:36 -0400 Subject: [PATCH 04/13] Update AssemblySharedInfo.cs --- src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs b/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs index 129c9560b87..5d97a80637f 100644 --- a/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs +++ b/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs @@ -8,7 +8,7 @@ // associated with an assembly. [assembly: AssemblyCompany("Autodesk, Inc")] [assembly: AssemblyProduct("Dynamo")] -[assembly: AssemblyCopyright("Copyright © Autodesk, Inc 2024")] +[assembly: AssemblyCopyright("Copyright � Autodesk, Inc 2024")] [assembly: AssemblyTrademark("")] //In order to begin building localizable applications, set @@ -45,7 +45,7 @@ // to distinguish one build from another. AssemblyFileVersion is specified // in AssemblyVersionInfo.cs so that it can be easily incremented by the // automated build process. -[assembly: AssemblyVersion("3.4.0.6177")] +[assembly: AssemblyVersion("3.4.0.6124")] // By default, the "Product version" shown in the file properties window is @@ -64,4 +64,4 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyFileVersion("3.4.0.6177")] +[assembly: AssemblyFileVersion("3.4.0.6124")] From b7c05f0457f10b1a590721b17c36a5f0ac7cd11c Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Tue, 10 Sep 2024 03:09:46 -0400 Subject: [PATCH 05/13] add --- .../Properties/Resources.Designer.cs | 35 ++++++++++++++++++- .../Properties/Resources.en-US.resx | 9 +++++ src/DynamoCoreWpf/Properties/Resources.resx | 9 +++++ .../ViewModels/Core/DynamoViewModel.cs | 4 +-- .../Views/Core/DynamoView.xaml.cs | 1 + 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/DynamoCoreWpf/Properties/Resources.Designer.cs b/src/DynamoCoreWpf/Properties/Resources.Designer.cs index 37a97fb1fb5..141cc6e0fd4 100644 --- a/src/DynamoCoreWpf/Properties/Resources.Designer.cs +++ b/src/DynamoCoreWpf/Properties/Resources.Designer.cs @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.42000 @@ -10557,5 +10557,38 @@ public static string ZoomLevel { return ResourceManager.GetString("ZoomLevel", resourceCulture); } } + + /// + /// Looks up a localized string similar to Update all {0} python nodes in the current workspace to use {1} engine?. + /// + public static string UpdateAllPythonEngineWarning + { + get + { + return ResourceManager.GetString("UpdateAllPythonEngineWarning", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Update All Python Nodes. + /// + public static string UpdateAllPythonEngineWarningTitle + { + get + { + return ResourceManager.GetString("UpdateAllPythonEngineWarningTitle", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Set Python Engine. + /// + public static string UpdateAllPythonEngineMainMenuHeader + { + get + { + return ResourceManager.GetString("UpdateAllPythonEngineMainMenuHeader", resourceCulture); + } + } } } diff --git a/src/DynamoCoreWpf/Properties/Resources.en-US.resx b/src/DynamoCoreWpf/Properties/Resources.en-US.resx index 962c0041ca9..0afa100be71 100644 --- a/src/DynamoCoreWpf/Properties/Resources.en-US.resx +++ b/src/DynamoCoreWpf/Properties/Resources.en-US.resx @@ -4025,4 +4025,13 @@ To make this file into a new template, save it to a different folder, then move Node Help Data is dumped to \"{0}\". + + Update all {0} python nodes in the current workspace to use {1} engine? + + + Update All Python Nodes + + + Set Python Engine + diff --git a/src/DynamoCoreWpf/Properties/Resources.resx b/src/DynamoCoreWpf/Properties/Resources.resx index b6262ac5efd..ff5426a0527 100644 --- a/src/DynamoCoreWpf/Properties/Resources.resx +++ b/src/DynamoCoreWpf/Properties/Resources.resx @@ -4012,4 +4012,13 @@ To make this file into a new template, save it to a different folder, then move Node Help Data is dumped to \"{0}\". + + Update all {0} python nodes in the current workspace to use {1} engine? + + + Update All Python Nodes + + + Set Python Engine + diff --git a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs index cd622dd82f4..bb4983dd081 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs @@ -1425,8 +1425,8 @@ internal void UpdateAllPythonEngine(object param) if (pNodes.Count == 0) return; var result = MessageBoxService.Show( Owner, - string.Format(Properties.Resources.UpdateAllPythonEngineWarning, pNodes.Count, param.ToString()), - Properties.Resources.UpdateAllPythonEngineWarningTitle, + string.Format(Resources.UpdateAllPythonEngineWarning, pNodes.Count, param.ToString()), + Resources.UpdateAllPythonEngineWarningTitle, MessageBoxButton.YesNo, MessageBoxImage.Exclamation); if (result == MessageBoxResult.Yes) diff --git a/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs b/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs index 77e37aaba3e..9c292f82d2f 100644 --- a/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs +++ b/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs @@ -254,6 +254,7 @@ public DynamoView(DynamoViewModel dynamoViewModel) AddPythonEngineToMainMenu(); PythonEngineManager.Instance.AvailableEngines.CollectionChanged += OnPythonEngineListUpdated; + dynamoViewModel.Owner = this; FocusableGrid.InputBindings.Clear(); From 47ab00c1c8ecd11f85cade096cde2e3ed74fa954 Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Tue, 10 Sep 2024 03:11:00 -0400 Subject: [PATCH 06/13] Update AssemblySharedInfo.cs --- src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs b/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs index 5d97a80637f..4df99fe7241 100644 --- a/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs +++ b/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs @@ -8,7 +8,7 @@ // associated with an assembly. [assembly: AssemblyCompany("Autodesk, Inc")] [assembly: AssemblyProduct("Dynamo")] -[assembly: AssemblyCopyright("Copyright � Autodesk, Inc 2024")] +[assembly: AssemblyCopyright("Copyright © Autodesk, Inc 2024")] [assembly: AssemblyTrademark("")] //In order to begin building localizable applications, set From 9192d785f57cf90fbe78a7b71d9b8cab67e1b045 Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Tue, 10 Sep 2024 03:17:22 -0400 Subject: [PATCH 07/13] clean --- src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs | 1 - src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml | 2 +- src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml.cs | 6 ++---- src/Libraries/PythonNodeModelsWpf/PythonStringNode.cs | 2 -- 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs index bb4983dd081..a02988622b0 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs @@ -23,7 +23,6 @@ using Dynamo.Graph.Annotations; using Dynamo.Graph.Connectors; using Dynamo.Graph.Nodes; -using Dynamo.Graph.Notes; using Dynamo.Graph.Workspaces; using Dynamo.Interfaces; using Dynamo.Logging; diff --git a/src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml b/src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml index ed15168f8d2..7d3f61daa72 100644 --- a/src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml +++ b/src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml @@ -711,7 +711,7 @@ Visibility="{Binding Path=CanFindNodesFromElements, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}" /> - + ().ToList(); + var selectedNodes = DynamoSelection.Instance.Selection.OfType().ToList(); PythonEngineManager.Instance.AvailableEngines.ToList().ForEach(engineName => ViewModel.DynamoViewModel.AddPythonEngineToMenuItems(selectedNodes, pythonEngineVersionMenu, UpdateSelectedPythonNodeEngines, engineName.Name)); } @@ -1171,7 +1169,7 @@ private void UpdateSelectedPythonNodeEngines(object sender, EventArgs e) { if (sender is MenuItem menuItem) { - var selectedNodes = DynamoSelection.Instance.Selection.OfType().ToList(); + var selectedNodes = DynamoSelection.Instance.Selection.OfType().ToList(); selectedNodes.ForEach(pythonNodeModel => { ViewModel.DynamoViewModel.UpdatePythonNodeEngine(pythonNodeModel, (string)menuItem.Header); diff --git a/src/Libraries/PythonNodeModelsWpf/PythonStringNode.cs b/src/Libraries/PythonNodeModelsWpf/PythonStringNode.cs index 113cf090a4b..b7022db6c91 100644 --- a/src/Libraries/PythonNodeModelsWpf/PythonStringNode.cs +++ b/src/Libraries/PythonNodeModelsWpf/PythonStringNode.cs @@ -1,10 +1,8 @@ using System; using System.Collections.Generic; using System.Collections.Specialized; -using System.Linq; using System.Windows; using System.Windows.Controls; -using System.Windows.Data; using Dynamo.Controls; using Dynamo.Models; using Dynamo.PythonServices; From 432736eeaafb30a88774ae501bf886a882ff2f51 Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Tue, 10 Sep 2024 16:34:58 -0400 Subject: [PATCH 08/13] dyf support 1 --- .../ViewModels/Core/DynamoViewModel.cs | 41 ++++++++++++++++--- .../Views/Core/WorkspaceView.xaml.cs | 4 +- .../PythonNodeModelsWpf/PythonNode.cs | 4 +- .../PythonNodeModelsWpf/PythonStringNode.cs | 2 +- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs index a02988622b0..ebfdb84f902 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs @@ -23,6 +23,7 @@ using Dynamo.Graph.Annotations; using Dynamo.Graph.Connectors; using Dynamo.Graph.Nodes; +using Dynamo.Graph.Nodes.CustomNodes; using Dynamo.Graph.Workspaces; using Dynamo.Interfaces; using Dynamo.Logging; @@ -1405,7 +1406,7 @@ internal bool CanUpdatePythonNodeEngine(object parameter) } private bool SelectionHasPythonNodes() { - if (DynamoSelection.Instance.Selection.OfType().Any() || DynamoSelection.Instance.Selection.OfType().Any()) + if (GetSelectedPythonNodes().Any()) { return true; } @@ -1420,7 +1421,7 @@ internal void UpdatePythonNodeEngine(PythonNodeBase pythonNode, string engine) } internal void UpdateAllPythonEngine(object param) { - var pNodes = Model.CurrentWorkspace.Nodes.OfType().ToList(); + var pNodes = GetSelectedPythonNodes(Model.CurrentWorkspace.Nodes); if (pNodes.Count == 0) return; var result = MessageBoxService.Show( Owner, @@ -1430,7 +1431,7 @@ internal void UpdateAllPythonEngine(object param) MessageBoxImage.Exclamation); if (result == MessageBoxResult.Yes) { - Model.CurrentWorkspace.Nodes.OfType().ToList().ForEach(x => UpdatePythonNodeEngine(x, param.ToString())); + pNodes.ForEach(x => UpdatePythonNodeEngine(x, param.ToString())); } } internal bool CanUpdateAllPythonEngine(object param) @@ -1445,10 +1446,12 @@ internal bool CanUpdateAllPythonEngine(object param) /// context menu item to which the engines will be added to /// Update event handler, to trigger engine update for the node /// Python engine to be added + /// Should be set to true, if you require to bind the passed + /// NodeModel engine value with the menu item, works only when a single node is passed in the list. internal void AddPythonEngineToMenuItems(List pythonNodeModel, MenuItem pythonEngineVersionMenu, RoutedEventHandler updateEngineDelegate, - string engineName) + string engineName, bool isBinding = false) { //if all nodes in the selection are set to a specific engine, then that engine will be checked in the list. bool hasCommonEngine = pythonNodeModel.All(x => x.EngineName == engineName); @@ -1461,7 +1464,7 @@ internal void AddPythonEngineToMenuItems(List pythonNodeModel, } MenuItem pythonEngineItem = null; //if single node, then checked property is bound to the engine value, as python node context menu is not recreated - if (pythonNodeModel.Count == 1) + if (pythonNodeModel.Count == 1 && isBinding) { var pythonNode = pythonNodeModel.FirstOrDefault(); ; pythonEngineItem = new MenuItem { Header = engineName, IsCheckable = false }; @@ -1482,7 +1485,33 @@ internal void AddPythonEngineToMenuItems(List pythonNodeModel, pythonEngineItem.Click += updateEngineDelegate; pythonEngineVersionMenu.Items.Add(pythonEngineItem); } - + /// + /// Gets the Python nodes from the provided list, including python nodes inside custom nodes as well. + /// If no list is provided then the current selection will be considered. + /// + /// + internal List GetSelectedPythonNodes(IEnumerable nodes = null) + { + if (nodes == null) + { + nodes = DynamoSelection.Instance.Selection.OfType(); + } + var selectedPythonNodes = nodes.OfType().ToList(); + var customNodes = nodes.Where(x => x.IsCustomFunction).ToList(); + if (customNodes.Count > 0) + { + foreach (var cNode in customNodes) + { + var customNodeFunction = cNode as Function; + var pythonNodesInCN = customNodeFunction?.Definition.FunctionBody.OfType().ToList(); + if (pythonNodesInCN.Count > 0) + { + selectedPythonNodes.AddRange(pythonNodesInCN); + } + } + } + return selectedPythonNodes; + } /// /// After command framework is implemented, this method should now be only /// called from a menu item (i.e. Ctrl + W). It should not be used as a way diff --git a/src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml.cs b/src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml.cs index eefff00ded7..a64660908c0 100644 --- a/src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml.cs +++ b/src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml.cs @@ -1161,7 +1161,7 @@ private void OnContextMenuClosed(object sender, EventArgs e) private void AddPythonEngineOptions(MenuItem contextMenuItem) { var pythonEngineVersionMenu = contextMenuItem; - var selectedNodes = DynamoSelection.Instance.Selection.OfType().ToList(); + var selectedNodes = ViewModel.DynamoViewModel.GetSelectedPythonNodes(); PythonEngineManager.Instance.AvailableEngines.ToList().ForEach(engineName => ViewModel.DynamoViewModel.AddPythonEngineToMenuItems(selectedNodes, pythonEngineVersionMenu, UpdateSelectedPythonNodeEngines, engineName.Name)); } @@ -1169,7 +1169,7 @@ private void UpdateSelectedPythonNodeEngines(object sender, EventArgs e) { if (sender is MenuItem menuItem) { - var selectedNodes = DynamoSelection.Instance.Selection.OfType().ToList(); + var selectedNodes = ViewModel.DynamoViewModel.GetSelectedPythonNodes(); selectedNodes.ForEach(pythonNodeModel => { ViewModel.DynamoViewModel.UpdatePythonNodeEngine(pythonNodeModel, (string)menuItem.Header); diff --git a/src/Libraries/PythonNodeModelsWpf/PythonNode.cs b/src/Libraries/PythonNodeModelsWpf/PythonNode.cs index dcbd1e7bcef..459ffa2fa87 100644 --- a/src/Libraries/PythonNodeModelsWpf/PythonNode.cs +++ b/src/Libraries/PythonNodeModelsWpf/PythonNode.cs @@ -95,7 +95,7 @@ public void CustomizeView(PythonNode nodeModel, NodeView nodeView) learnMoreItem.Click += OpenPythonLearningMaterial; PythonNodeUtils.GetEngineNames(nodeModel).ForEach(engineName => dynamoViewModel.AddPythonEngineToMenuItems( - new List() { pythonNodeModel }, pythonEngineVersionMenu, UpdateEngine, engineName)); + new List() { pythonNodeModel }, pythonEngineVersionMenu, UpdateEngine, engineName, true)); PythonEngineManager.Instance.AvailableEngines.CollectionChanged += PythonEnginesChanged; @@ -314,7 +314,7 @@ private void PythonEnginesChanged(object sender, NotifyCollectionChangedEventArg { if(item is PythonEngine newEngine) { - dynamoViewModel.AddPythonEngineToMenuItems(new List() { pythonNodeModel }, pythonEngineVersionMenu, UpdateEngine, newEngine.Name); + dynamoViewModel.AddPythonEngineToMenuItems(new List() { pythonNodeModel }, pythonEngineVersionMenu, UpdateEngine, newEngine.Name, true); } } } diff --git a/src/Libraries/PythonNodeModelsWpf/PythonStringNode.cs b/src/Libraries/PythonNodeModelsWpf/PythonStringNode.cs index b7022db6c91..69f970a2129 100644 --- a/src/Libraries/PythonNodeModelsWpf/PythonStringNode.cs +++ b/src/Libraries/PythonNodeModelsWpf/PythonStringNode.cs @@ -33,7 +33,7 @@ public void CustomizeView(PythonStringNode nodeModel, NodeView nodeView) nodeView.MainContextMenu.Items.Add(pythonEngineVersionMenu); PythonNodeUtils.GetEngineNames(nodeModel).ForEach(engineName => dynamoViewModel.AddPythonEngineToMenuItems( - new List() { pythonStringNodeModel }, pythonEngineVersionMenu, UpdateEngine, engineName)); + new List() { pythonStringNodeModel }, pythonEngineVersionMenu, UpdateEngine, engineName, true)); PythonEngineManager.Instance.AvailableEngines.CollectionChanged += PythonEnginesChanged; From e1d7062dadc4378ce4e7eb2a722dccc0cac221f8 Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Tue, 10 Sep 2024 16:36:27 -0400 Subject: [PATCH 09/13] Update PublicAPI.Unshipped.txt --- src/DynamoCoreWpf/PublicAPI.Unshipped.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/DynamoCoreWpf/PublicAPI.Unshipped.txt b/src/DynamoCoreWpf/PublicAPI.Unshipped.txt index 76281ee4061..22f10109f6f 100644 --- a/src/DynamoCoreWpf/PublicAPI.Unshipped.txt +++ b/src/DynamoCoreWpf/PublicAPI.Unshipped.txt @@ -2994,6 +2994,7 @@ Dynamo.ViewModels.WorkspaceViewModel.CanFindNodesFromElements.set -> void Dynamo.ViewModels.WorkspaceViewModel.CanPaste.get -> bool Dynamo.ViewModels.WorkspaceViewModel.CanRunNodeToCode.get -> bool Dynamo.ViewModels.WorkspaceViewModel.CanShowInfoBubble.get -> bool +Dynamo.ViewModels.WorkspaceViewModel.CanUpdateAllPythonEngine.get -> bool Dynamo.ViewModels.WorkspaceViewModel.CanUpdatePythonEngine.get -> bool Dynamo.ViewModels.WorkspaceViewModel.CanZoomIn.get -> bool Dynamo.ViewModels.WorkspaceViewModel.CanZoomOut.get -> bool @@ -5495,6 +5496,9 @@ static Dynamo.Wpf.Properties.Resources.UnknowDateFormat.get -> string static Dynamo.Wpf.Properties.Resources.UnloadFailureMessageBoxTitle.get -> string static Dynamo.Wpf.Properties.Resources.UnpinNodeTooltip.get -> string static Dynamo.Wpf.Properties.Resources.UnsavedChangesMessageBoxTitle.get -> string +static Dynamo.Wpf.Properties.Resources.UpdateAllPythonEngineMainMenuHeader.get -> string +static Dynamo.Wpf.Properties.Resources.UpdateAllPythonEngineWarning.get -> string +static Dynamo.Wpf.Properties.Resources.UpdateAllPythonEngineWarningTitle.get -> string static Dynamo.Wpf.Properties.Resources.UpdateMessage.get -> string static Dynamo.Wpf.Properties.Resources.UpdateNodeIconsDebugMenu.get -> string static Dynamo.Wpf.Properties.Resources.UsageReportPromptDialogTitle.get -> string From eaeff3da089847a205dafab75b251178dc567f80 Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Tue, 10 Sep 2024 16:58:23 -0400 Subject: [PATCH 10/13] Update AssemblySharedInfo.cs --- src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs b/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs index 4df99fe7241..5d97a80637f 100644 --- a/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs +++ b/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs @@ -8,7 +8,7 @@ // associated with an assembly. [assembly: AssemblyCompany("Autodesk, Inc")] [assembly: AssemblyProduct("Dynamo")] -[assembly: AssemblyCopyright("Copyright © Autodesk, Inc 2024")] +[assembly: AssemblyCopyright("Copyright � Autodesk, Inc 2024")] [assembly: AssemblyTrademark("")] //In order to begin building localizable applications, set From b5b4be1df58c78f56fc2f2101e860ea47c152830 Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Tue, 10 Sep 2024 17:00:44 -0400 Subject: [PATCH 11/13] Update AssemblySharedInfo.cs --- src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs b/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs index 5d97a80637f..2b14532f635 100644 --- a/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs +++ b/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs @@ -8,7 +8,7 @@ // associated with an assembly. [assembly: AssemblyCompany("Autodesk, Inc")] [assembly: AssemblyProduct("Dynamo")] -[assembly: AssemblyCopyright("Copyright � Autodesk, Inc 2024")] +[assembly: AssemblyCopyright("Copyright © Autodesk, Inc 2024")] [assembly: AssemblyTrademark("")] //In order to begin building localizable applications, set From 49d91358a388fe3926479118d35fbdedda3c6652 Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Tue, 10 Sep 2024 17:15:22 -0400 Subject: [PATCH 12/13] Update DynamoView.xaml.cs --- src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs b/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs index 9c292f82d2f..6f4c6e6e48d 100644 --- a/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs +++ b/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs @@ -252,6 +252,7 @@ public DynamoView(DynamoViewModel dynamoViewModel) this.dynamoViewModel.RequestEnableShortcutBarItems += DynamoViewModel_RequestEnableShortcutBarItems; this.dynamoViewModel.RequestExportWorkSpaceAsImage += OnRequestExportWorkSpaceAsImage; + //add option to update python engine for all python nodes in the workspace. AddPythonEngineToMainMenu(); PythonEngineManager.Instance.AvailableEngines.CollectionChanged += OnPythonEngineListUpdated; dynamoViewModel.Owner = this; @@ -279,6 +280,10 @@ private void OnPythonEngineListUpdated(object sender, NotifyCollectionChangedEve //Update the main menu Python Engine list whenever a python engine is added or removed. AddPythonEngineToMainMenu(); } + + /// + /// Populates the PythonEngineMenu in the main menu bar with currently available python engines. + /// private void AddPythonEngineToMainMenu() { PythonEngineMenu.Items.Clear(); From d0857d19033aacb095a80572ba503ee6ebae8de1 Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Tue, 10 Sep 2024 19:36:56 -0400 Subject: [PATCH 13/13] DYF support --- src/DynamoCore/Models/DynamoModel.cs | 20 +++++++++ .../ViewModels/Core/DynamoViewModel.cs | 43 +++++++++++++++---- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/DynamoCore/Models/DynamoModel.cs b/src/DynamoCore/Models/DynamoModel.cs index e233387a79f..dd1310f5669 100644 --- a/src/DynamoCore/Models/DynamoModel.cs +++ b/src/DynamoCore/Models/DynamoModel.cs @@ -2946,6 +2946,26 @@ public bool OpenCustomNodeWorkspace(Guid guid) return false; } + /// + /// Opens an existing custom node workspace. + /// + /// Identifier of the workspace to open + /// True if workspace was found and open + internal bool OpenCustomNodeWorkspaceSilent(Guid guid) + { + CustomNodeWorkspaceModel customNodeWorkspace; + if (CustomNodeManager.TryGetFunctionWorkspace(guid, IsTestMode, out customNodeWorkspace)) + { + if (!Workspaces.OfType().Contains(customNodeWorkspace)) + { + AddWorkspace(customNodeWorkspace); + } + + return true; + } + + return false; + } /// /// Adds a node to the current workspace. diff --git a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs index ebfdb84f902..4a401ee6e3a 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs @@ -1412,12 +1412,33 @@ private bool SelectionHasPythonNodes() } return false; } + /// + /// Updates the engine for the Python nodes, + /// if the nodes belong to another workspace (like custom nodes), they will be opened silently. + /// + /// + /// internal void UpdatePythonNodeEngine(PythonNodeBase pythonNode, string engine) { - this.ExecuteCommand( - new DynamoModel.UpdateModelValueCommand( - Guid.Empty, pythonNode.GUID, nameof(pythonNode.EngineName), engine)); - pythonNode.OnNodeModified(); + try + { + var workspaceGUID = Guid.Empty; + var cnWorkspace = GetCustomNodeWorkspace(pythonNode); + if (cnWorkspace != null) + { + workspaceGUID = cnWorkspace.Guid; + FocusCustomNodeWorkspace(cnWorkspace.CustomNodeId, true); + } + this.ExecuteCommand( + new DynamoModel.UpdateModelValueCommand( + workspaceGUID, pythonNode.GUID, nameof(pythonNode.EngineName), engine)); + pythonNode.OnNodeModified(); + } + catch(Exception ex) + { + Model.Logger.Log("Failed to update Python node engine: " + ex.Message, LogLevel.Console); + } + } internal void UpdateAllPythonEngine(object param) { @@ -1512,6 +1533,11 @@ internal List GetSelectedPythonNodes(IEnumerable node } return selectedPythonNodes; } + private CustomNodeWorkspaceModel GetCustomNodeWorkspace(NodeModel node) + { + var wg = model.CustomNodeManager.LoadedWorkspaces.Where(x => x.Nodes.Contains(node)).FirstOrDefault(); + return wg ?? null; + } /// /// After command framework is implemented, this method should now be only /// called from a menu item (i.e. Ctrl + W). It should not be used as a way @@ -2685,17 +2711,18 @@ internal bool CanShowPackageManager(object parameters) } /// - /// Change the currently visible workspace to a custom node's workspace + /// Change the currently visible workspace to a custom node's workspace, unless the silent flag is set to true. /// /// The function definition for the custom node workspace to be viewed - internal void FocusCustomNodeWorkspace(Guid symbol) + /// When true, the focus will not switch to the workspace, but it will be opened silently. + internal void FocusCustomNodeWorkspace(Guid symbol, bool silent = false) { if (symbol == null) { throw new Exception(Resources.MessageNodeWithNullFunction); } - - if (model.OpenCustomNodeWorkspace(symbol)) + var res = silent ? model.OpenCustomNodeWorkspaceSilent(symbol) : model.OpenCustomNodeWorkspace(symbol); + if (res) { //set the zoom and offsets events CurrentSpace.OnCurrentOffsetChanged(this, new PointEventArgs(new Point2D(CurrentSpace.X, CurrentSpace.Y)));