From 023da4ac09130af3be18f24f8d4493f3dcf5a498 Mon Sep 17 00:00:00 2001 From: Deyan Nenov Date: Fri, 8 Dec 2023 03:21:58 +0000 Subject: [PATCH 1/6] remove duplicate dyf file warning from preview generation process (#14711) - dynamo would issue a warning and fail to publish a package if an 'unqualified' file is being used, such as a dyf file already under package control - this check is done when publishing package locally, but I have incorrectly added it to the process of creating a build preview, which stops the process for both local and online submit workflow (cherry picked from commit 3ea1c5c48e90b919c57e257e71565ed51b66c4b3) --- .../PackageManager/PublishPackageViewModel.cs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs b/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs index 192e73c9006..b3fb7fc5e92 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs @@ -2411,22 +2411,6 @@ private void PreviewPackageBuild() .ToList(); try { - var unqualifiedFiles = GetAllUnqualifiedFiles(); - - if (files == null || files.Count() < 1 || unqualifiedFiles.Count() > 0) - { - string filesCannotBePublished = null; - foreach (var file in unqualifiedFiles) - { - filesCannotBePublished = filesCannotBePublished + file + "\n"; - } - string FileNotPublishMessage = string.Format(Resources.FileNotPublishMessage, filesCannotBePublished); - UploadState = PackageUploadHandle.State.Error; - MessageBoxResult response = DynamoModel.IsTestMode ? MessageBoxResult.OK : MessageBoxService.Show(Owner, FileNotPublishMessage, Resources.FileNotPublishCaption, MessageBoxButton.OK, MessageBoxImage.Error); - - return; - } - // Generate the Package Name, either based on the user 'Description', or the root path name, if no 'Description' yet var packageName = !string.IsNullOrEmpty(Name) ? Name : Path.GetFileName(publishPath); var rootItemPreview = RetainFolderStructureOverride ? From 407dfd80ee91ff0bb39ccdae9701beaa375ba9a8 Mon Sep 17 00:00:00 2001 From: pinzart90 <46732933+pinzart90@users.noreply.github.com> Date: Thu, 7 Dec 2023 23:41:24 -0500 Subject: [PATCH 2/6] update (#14710) Co-authored-by: pinzart (cherry picked from commit d5e6c9b4efbf30d8b547017bd3193bf71585b4b4) --- .../DocumentationBrowserView.xaml.cs | 10 +++++++++- src/Notifications/NotificationCenterController.cs | 15 ++++++++++++++- test/DynamoCoreWpfTests/Utility/DispatcherUtil.cs | 6 ++---- .../DocumentationBrowserViewExtensionTests.cs | 3 +++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/DocumentationBrowserViewExtension/DocumentationBrowserView.xaml.cs b/src/DocumentationBrowserViewExtension/DocumentationBrowserView.xaml.cs index b3990d9d288..d3cc6fb3304 100644 --- a/src/DocumentationBrowserViewExtension/DocumentationBrowserView.xaml.cs +++ b/src/DocumentationBrowserViewExtension/DocumentationBrowserView.xaml.cs @@ -6,6 +6,7 @@ using System.Windows; using System.Windows.Controls; using Dynamo.Logging; +using Dynamo.Models; using Dynamo.Utilities; using DynamoUtilities; using Microsoft.Web.WebView2.Core; @@ -216,7 +217,14 @@ public void Dispose() #region ILogSource Implementation private void Log(string message) { - viewModel.MessageLogged?.Invoke(LogMessage.Info(message)); + if (DynamoModel.IsTestMode) + { + System.Console.WriteLine(message); + } + else + { + viewModel?.MessageLogged?.Invoke(LogMessage.Info(message)); + } } #endregion } diff --git a/src/Notifications/NotificationCenterController.cs b/src/Notifications/NotificationCenterController.cs index c66e7cd415e..b8febcc30a2 100644 --- a/src/Notifications/NotificationCenterController.cs +++ b/src/Notifications/NotificationCenterController.cs @@ -19,6 +19,7 @@ using Microsoft.Web.WebView2.Wpf; using Dynamo.Utilities; using Dynamo.Configuration; +using Dynamo.Models; namespace Dynamo.Notifications { @@ -345,10 +346,22 @@ public void Dispose() { if (initState == AsyncMethodState.Started) { - logger?.Log("NotificationCenterController is being disposed but async initialization is still not done"); + Log("NotificationCenterController is being disposed but async initialization is still not done"); } Dispose(true); GC.SuppressFinalize(this); } + + private void Log(string msg) + { + if (DynamoModel.IsTestMode) + { + System.Console.WriteLine(msg); + } + else + { + logger?.Log(msg); + } + } } } diff --git a/test/DynamoCoreWpfTests/Utility/DispatcherUtil.cs b/test/DynamoCoreWpfTests/Utility/DispatcherUtil.cs index b7e21cddb75..18812562d00 100644 --- a/test/DynamoCoreWpfTests/Utility/DispatcherUtil.cs +++ b/test/DynamoCoreWpfTests/Utility/DispatcherUtil.cs @@ -14,7 +14,6 @@ public static class DispatcherUtil /// /// Force the Dispatcher to empty it's queue /// - [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)] public static void DoEvents() { var frame = new DispatcherFrame(); @@ -24,14 +23,13 @@ public static void DoEvents() } /// - /// Force the Dispatcher to empty it's queue every 100 ms for a maximum 4 seconds or until + /// Force the Dispatcher to empty it's queue every 100 ms for a maximum 20 seconds or until /// the check function returns true. /// /// When check returns true, the even loop is stopped. - [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)] public static void DoEventsLoop(Func check = null) { - const int max_count = 40; + const int max_count = 200; int count = 0; while (true) diff --git a/test/DynamoCoreWpfTests/ViewExtensions/DocumentationBrowserViewExtensionTests.cs b/test/DynamoCoreWpfTests/ViewExtensions/DocumentationBrowserViewExtensionTests.cs index e3abc8f4ee7..7f83886ce9a 100644 --- a/test/DynamoCoreWpfTests/ViewExtensions/DocumentationBrowserViewExtensionTests.cs +++ b/test/DynamoCoreWpfTests/ViewExtensions/DocumentationBrowserViewExtensionTests.cs @@ -206,6 +206,9 @@ public void CanHandleDocsEventTriggeredFromDynamoViewModel() // Act var tabsBeforeExternalEventTrigger = this.ViewModel.SideBarTabItems.Count; this.ViewModel.OpenDocumentationLinkCommand.Execute(docsEvent); + + WaitForWebView2Initialization(); + var tabsAfterExternalEventTrigger = this.ViewModel.SideBarTabItems.Count; var htmlContent = GetSidebarDocsBrowserContents(); From f8d4e8005382981dce183aae0b1bda9d1a12eda0 Mon Sep 17 00:00:00 2001 From: Deyan Nenov Date: Fri, 8 Dec 2023 05:19:25 +0000 Subject: [PATCH 3/6] remove package version limitation (#14716) - now allows package version to start with 0 - cannot have 0.0.0 package version (cherry picked from commit 992e54c7c65f2f48070b92932b643582df08b6a1) --- src/DynamoCoreWpf/UI/Converters.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/DynamoCoreWpf/UI/Converters.cs b/src/DynamoCoreWpf/UI/Converters.cs index 6028ffb653e..5e90ac14558 100644 --- a/src/DynamoCoreWpf/UI/Converters.cs +++ b/src/DynamoCoreWpf/UI/Converters.cs @@ -18,7 +18,6 @@ using Dynamo.Search.SearchElements; using Dynamo.UI; using Dynamo.UI.Controls; -using Dynamo.Updates; using Dynamo.Utilities; using Dynamo.ViewModels; using Dynamo.Wpf.Properties; @@ -3898,10 +3897,7 @@ public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is string nullOrEmptyString && String.IsNullOrEmpty(nullOrEmptyString)) return Visibility.Visible; - if (value is string zeroString && zeroString.Equals("0")) - { - return Visibility.Visible; - } + return Visibility.Collapsed; } From 4adf04dadf8f561b70b2bd94b262226777ea75b8 Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Fri, 8 Dec 2023 00:21:17 -0500 Subject: [PATCH 4/6] Localize menu items is Graphic Element Scale dropdown (#14714) * Fix PostDiff job * fix (cherry picked from commit 006113e3983344604833829acdd88baeb5b4c694) --- .../Properties/Resources.Designer.cs | 63 +++++++++++++++++++ .../Properties/Resources.en-US.resx | 23 ++++++- src/DynamoCoreWpf/Properties/Resources.resx | 25 +++++++- .../ViewModels/Menu/PreferencesViewModel.cs | 31 ++++++++- 4 files changed, 138 insertions(+), 4 deletions(-) diff --git a/src/DynamoCoreWpf/Properties/Resources.Designer.cs b/src/DynamoCoreWpf/Properties/Resources.Designer.cs index 2ce5d62be52..91296ed0f99 100644 --- a/src/DynamoCoreWpf/Properties/Resources.Designer.cs +++ b/src/DynamoCoreWpf/Properties/Resources.Designer.cs @@ -3164,6 +3164,69 @@ public static string GenericTaskDialogTitle { } } + /// + /// Looks up a localized string similar to Centimeters. + /// + public static string GESUnitCentimeters { + get { + return ResourceManager.GetString("GESUnitCentimeters", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Feet. + /// + public static string GESUnitFeet { + get { + return ResourceManager.GetString("GESUnitFeet", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Inches. + /// + public static string GESUnitInches { + get { + return ResourceManager.GetString("GESUnitInches", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Kilometers. + /// + public static string GESUnitKilometers { + get { + return ResourceManager.GetString("GESUnitKilometers", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Meters. + /// + public static string GESUnitMeters { + get { + return ResourceManager.GetString("GESUnitMeters", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Miles. + /// + public static string GESUnitMiles { + get { + return ResourceManager.GetString("GESUnitMiles", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Millimeters. + /// + public static string GESUnitMillimeters { + get { + return ResourceManager.GetString("GESUnitMillimeters", resourceCulture); + } + } + /// /// Looks up a localized string similar to _User Interface Tour. /// diff --git a/src/DynamoCoreWpf/Properties/Resources.en-US.resx b/src/DynamoCoreWpf/Properties/Resources.en-US.resx index 9936d518cb8..48de8bdc057 100644 --- a/src/DynamoCoreWpf/Properties/Resources.en-US.resx +++ b/src/DynamoCoreWpf/Properties/Resources.en-US.resx @@ -3861,4 +3861,25 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in To access the Recommended Nodes feature, please read and accept Dynamo > Agreement and Terms of Use. - + + Centimeters + + + Feet + + + Inches + + + Kilometers + + + Meters + + + Miles + + + Millimeters + + \ No newline at end of file diff --git a/src/DynamoCoreWpf/Properties/Resources.resx b/src/DynamoCoreWpf/Properties/Resources.resx index 19a284d4064..9ed38b6d675 100644 --- a/src/DynamoCoreWpf/Properties/Resources.resx +++ b/src/DynamoCoreWpf/Properties/Resources.resx @@ -3602,7 +3602,7 @@ You can manage this in Preferences -> Security. This package is outdated and cannot be installed. - + Publish Version @@ -3848,4 +3848,25 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in To access the Recommended Nodes feature, please read and accept Dynamo > Agreement and Terms of Use. - + + Centimeters + + + Feet + + + Inches + + + Kilometers + + + Meters + + + Miles + + + Millimeters + + \ No newline at end of file diff --git a/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs b/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs index ebba4be9200..df4a7b8c0f8 100644 --- a/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs @@ -1308,6 +1308,35 @@ public bool importSettingsContent(string content) return setSettings(newPreferences); } + /// + /// Returns localized resource strings for Units + /// + private string GetLocalizedUnits(Enum value) + { + if (value != null) + { + switch (value) + { + case Configurations.Units.Millimeters: + return Res.GESUnitMillimeters; + case Configurations.Units.Centimeters: + return Res.GESUnitCentimeters; + case Configurations.Units.Kilometers: + return Res.GESUnitKilometers; + case Configurations.Units.Meters: + return Res.GESUnitMeters; + case Configurations.Units.Inches: + return Res.GESUnitInches; + case Configurations.Units.Feet: + return Res.GESUnitFeet; + case Configurations.Units.Miles: + return Res.GESUnitMiles; + } + } + return null; + } + + private bool setSettings(PreferenceSettings newPreferences) { // Explicit copy @@ -1381,7 +1410,7 @@ public PreferencesViewModel(DynamoViewModel dynamoViewModel) SelectedLanguage = Configurations.SupportedLocaleDic.FirstOrDefault(x => x.Value == preferenceSettings.Locale).Key; // Chose the scaling unit, if option is allowed by user - UnitList = Configurations.SupportedUnits.Keys.Select(x => x.ToString()).ToObservableCollection(); + UnitList = Configurations.SupportedUnits.Keys.Select(x => GetLocalizedUnits(x)).ToObservableCollection(); SelectedUnits = Configurations.SupportedUnits.FirstOrDefault(x => x.Key.ToString() == preferenceSettings.GraphicScaleUnit).Key.ToString(); GroupStyleFontSizeList = preferenceSettings.PredefinedGroupStyleFontSizes; From c044ceb9e6528bb3623038c8c001dae6f0d2181b Mon Sep 17 00:00:00 2001 From: Michael Kirschner Date: Fri, 8 Dec 2023 09:39:22 -0500 Subject: [PATCH 5/6] remove dynamo sandbox app.config (#14713) * remove config * remove autogen stuff (cherry picked from commit 0947455860e3ce6ec1c9f7464927f2e0a2c1af9e) --- src/DynamoSandbox/DynamoSandbox.csproj | 4 +--- src/DynamoSandbox/app.config | 31 -------------------------- 2 files changed, 1 insertion(+), 34 deletions(-) delete mode 100644 src/DynamoSandbox/app.config diff --git a/src/DynamoSandbox/DynamoSandbox.csproj b/src/DynamoSandbox/DynamoSandbox.csproj index 65227319021..d5a3893b678 100644 --- a/src/DynamoSandbox/DynamoSandbox.csproj +++ b/src/DynamoSandbox/DynamoSandbox.csproj @@ -21,6 +21,7 @@ logo_square_32x32.ico + {aa782772-fe61-4226-baa4-eb529fa1646b} @@ -54,9 +55,6 @@ DynamoShapeManager - - - diff --git a/src/DynamoSandbox/app.config b/src/DynamoSandbox/app.config deleted file mode 100644 index c1764196b9e..00000000000 --- a/src/DynamoSandbox/app.config +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From efc2ffc4e30b0b8532b0886066cc4e9f79547f3e Mon Sep 17 00:00:00 2001 From: aparajit-pratap Date: Fri, 8 Dec 2023 12:37:01 -0500 Subject: [PATCH 6/6] 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 picked from commit 89878693fff90c205847b2eca7a1b1a70c2d274f) --- src/Engine/ProtoAssociative/CodeGen_SSA.cs | 58 +++---------------- src/Engine/ProtoCore/DSASM/InstructionSet.cs | 3 +- src/Libraries/CoreNodeModels/Enum.cs | 2 +- .../DynamoCoreWpfTests/NodeExecutionUITest.cs | 53 +++++++++++++++++ test/TestUINodes/TestUINodes.cs | 52 ++++++++++++++++- 5 files changed, 115 insertions(+), 53 deletions(-) diff --git a/src/Engine/ProtoAssociative/CodeGen_SSA.cs b/src/Engine/ProtoAssociative/CodeGen_SSA.cs index 745092a71ad..2958837dfc1 100644 --- a/src/Engine/ProtoAssociative/CodeGen_SSA.cs +++ b/src/Engine/ProtoAssociative/CodeGen_SSA.cs @@ -1,4 +1,4 @@ -using ProtoCore.AST.AssociativeAST; +using ProtoCore.AST.AssociativeAST; using ProtoCore.DSASM; using ProtoCore.Utils; using System.Collections.Generic; @@ -275,7 +275,11 @@ private List BuildSSA(List astList, ProtoCore. BinaryExpressionNode bnode = (node as BinaryExpressionNode); int generatedUID = ProtoCore.DSASM.Constants.kInvalidIndex; - if (context.applySSATransform && core.Options.GenerateSSA) + // Skip SSA for input ASTs that are first assigned null such as this: + // a = null; (update "a") => a = ; + // SSA would break up the null AST into two assignments, which then breaks update: + // a = null; (SSA) => temp = null; a = temp; + if (context.applySSATransform && core.Options.GenerateSSA && !bnode.IsInputExpression) { int ssaID = ProtoCore.DSASM.Constants.kInvalidIndex; string name = ProtoCore.Utils.CoreUtils.GenerateIdentListNameString(bnode.LeftNode); @@ -382,53 +386,6 @@ private List BuildSSA(List astList, ProtoCore. return astList; } - private void DfsSSAIeentList(AssociativeNode node, ref Stack ssaStack, ref List astlist) - { - if (node is IdentifierListNode) - { - IdentifierListNode listNode = node as IdentifierListNode; - - bool isSingleDot = !(listNode.LeftNode is IdentifierListNode) && !(listNode.RightNode is IdentifierListNode); - if (isSingleDot) - { - BinaryExpressionNode bnode = BuildSSAIdentListAssignmentNode(listNode); - astlist.Add(bnode); - ssaStack.Push(bnode); - } - else - { - DfsSSAIeentList(listNode.LeftNode, ref ssaStack, ref astlist); - - IdentifierListNode newListNode = node as IdentifierListNode; - newListNode.Optr = Operator.dot; - - AssociativeNode leftnode = ssaStack.Pop(); - Validity.Assert(leftnode is BinaryExpressionNode); - - newListNode.LeftNode = (leftnode as BinaryExpressionNode).LeftNode; - newListNode.RightNode = listNode.RightNode; - - BinaryExpressionNode bnode = BuildSSAIdentListAssignmentNode(newListNode); - astlist.Add(bnode); - ssaStack.Push(bnode); - - } - } - else if (node is FunctionCallNode) - { - FunctionCallNode fcNode = node as FunctionCallNode; - for (int idx = 0; idx < fcNode.FormalArguments.Count; idx++) - { - AssociativeNode arg = fcNode.FormalArguments[idx]; - - Stack ssaStack1 = new Stack(); - DFSEmitSSA_AST(arg, ssaStack1, ref astlist); - AssociativeNode argNode = ssaStack.Pop(); - fcNode.FormalArguments[idx] = argNode is BinaryExpressionNode ? (argNode as BinaryExpressionNode).LeftNode : argNode; - } - } - } - private void DFSEmitSSA_AST(AssociativeNode node, Stack ssaStack, ref List astlist) { Validity.Assert(null != astlist && null != ssaStack); @@ -488,7 +445,8 @@ private void DFSEmitSSA_AST(AssociativeNode node, Stack ssaStac var bnode = AstFactory.BuildAssignment(leftNode, rightNode); bnode.isSSAAssignment = isSSAAssignment; - bnode.IsInputExpression = astBNode.IsInputExpression; + // TODO: SSA is not called for ASTs that are input expressions. Revisit this if there are any issues. + // bnode.IsInputExpression = astBNode.IsInputExpression; astlist.Add(bnode); ssaStack.Push(bnode); diff --git a/src/Engine/ProtoCore/DSASM/InstructionSet.cs b/src/Engine/ProtoCore/DSASM/InstructionSet.cs index 259f07197a2..801c4d50351 100644 --- a/src/Engine/ProtoCore/DSASM/InstructionSet.cs +++ b/src/Engine/ProtoCore/DSASM/InstructionSet.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using ProtoCore.Exceptions; @@ -10,6 +10,7 @@ namespace ProtoCore.DSASM public enum Registers { RX, + // Register used to temporarily store primitive values for graph update cycles. LX, } diff --git a/src/Libraries/CoreNodeModels/Enum.cs b/src/Libraries/CoreNodeModels/Enum.cs index a6c1639c352..a2c9860da3c 100644 --- a/src/Libraries/CoreNodeModels/Enum.cs +++ b/src/Libraries/CoreNodeModels/Enum.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; diff --git a/test/DynamoCoreWpfTests/NodeExecutionUITest.cs b/test/DynamoCoreWpfTests/NodeExecutionUITest.cs index 73bb94e40ca..8662c69d72e 100644 --- a/test/DynamoCoreWpfTests/NodeExecutionUITest.cs +++ b/test/DynamoCoreWpfTests/NodeExecutionUITest.cs @@ -328,5 +328,58 @@ public void TestSelectionNodeUpdate2() AssertPreviewValue(tsn.GUID.ToString(), 0); } + + [Test] + public void TestDropdownNodeUpdate() + { + var model = GetModel(); + var tdd = new TestDropdown + { + SelectedIndex = 0 + }; + + var command = new DynamoModel.CreateNodeCommand(tdd, 0, 0, true, false); + model.ExecuteCommand(command); + + AssertPreviewValue(tdd.GUID.ToString(), "one"); + + tdd.SelectedIndex = 1; + tdd.OnNodeModified(); + + AssertPreviewValue(tdd.GUID.ToString(), "two"); + + tdd.SelectedIndex = 2; + tdd.OnNodeModified(); + + AssertPreviewValue(tdd.GUID.ToString(), "three"); + + } + + [Test] + public void TestDropdownNodeUpdate1() + { + var model = GetModel(); + var tdd = new TestDropdown(); + + var command = new DynamoModel.CreateNodeCommand(tdd, 0, 0, true, false); + model.ExecuteCommand(command); + + AssertPreviewValue(tdd.GUID.ToString(), null); + + tdd.SelectedIndex = 0; + tdd.OnNodeModified(); + + AssertPreviewValue(tdd.GUID.ToString(), "one"); + + tdd.SelectedIndex = 1; + tdd.OnNodeModified(); + + AssertPreviewValue(tdd.GUID.ToString(), "two"); + + tdd.SelectedIndex = 2; + tdd.OnNodeModified(); + + AssertPreviewValue(tdd.GUID.ToString(), "three"); + } } } diff --git a/test/TestUINodes/TestUINodes.cs b/test/TestUINodes/TestUINodes.cs index cd3e3581545..004c2ff971a 100644 --- a/test/TestUINodes/TestUINodes.cs +++ b/test/TestUINodes/TestUINodes.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.IO; @@ -140,4 +140,54 @@ protected override int GetModelObjectFromIdentifer(string id) return id.Length; } } + + [NodeName("Test Dropdown Node")] + [NodeCategory("TestUINodes")] + [NodeDescription("test dropdown node")] + [OutPortTypes("string")] + [IsDesignScriptCompatible] + [IsVisibleInDynamoLibrary(false)] + public class TestDropdown : DSDropDownBase + { + public TestDropdown() : base("TestDropdown") { } + + + public override IEnumerable BuildOutputAst(List inputAstNodes) + { + AssociativeNode node; + if (SelectedIndex < 0 || SelectedIndex >= Items.Count) + { + node = AstFactory.BuildNullNode(); + return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), node) }; + } + else + { + // get the selected items name + var stringNode = AstFactory.BuildStringNode((string)Items[SelectedIndex].Name); + + // assign the selected name to an actual enumeration value + var assign = AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), stringNode); + + // return the enumeration value + return new List { assign }; + } + } + + protected override SelectionState PopulateItemsCore(string currentSelection) + { + Items.Clear(); + + var symbols = new[] { "one", "two", "three" }; + + + foreach (var symbol in symbols) + { + + Items.Add(new DynamoDropDownItem(symbol, symbol)); + } + + return SelectionState.Restore; + } + + } }