-
Notifications
You must be signed in to change notification settings - Fork 56
/
DropDown.cs
55 lines (44 loc) · 1.79 KB
/
DropDown.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.Collections.Generic;
using DSCoreNodesUI;
using Dynamo.Nodes;
using Dynamo.Utilities;
using ProtoCore.AST.AssociativeAST;
namespace SampleLibraryUI.Examples
{
[NodeName("Drop Down Example")]
[NodeDescription("An example drop down node.")]
[IsDesignScriptCompatible]
public class DropDownExample : DSDropDownBase
{
public DropDownExample() : base("item"){}
public override void PopulateItems()
{
// The Items collection contains the elements
// that appear in the list. For this example, we
// clear the list before adding new items, but you
// can also use the PopulateItems method to add items
// to the list.
Items.Clear();
// Create a number of DynamoDropDownItem objects
// to store the items that we want to appear in our list.
var newItems = new List<DynamoDropDownItem>()
{
new DynamoDropDownItem("Tywin", 0),
new DynamoDropDownItem("Cersei", 1),
new DynamoDropDownItem("Hodor",2)
};
Items.AddRange(newItems);
// Set the selected index to something other
// than -1, the default, so that your list
// has a pre-selection.
SelectedIndex = 0;
}
public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes)
{
// Build an AST node for the type of object contained in your Items collection.
var intNode = AstFactory.BuildIntNode((int)Items[SelectedIndex].Item);
var assign = AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), intNode);
return new List<AssociativeNode> {assign};
}
}
}