|
| 1 | +namespace Mapbox.Editor |
| 2 | +{ |
| 3 | + using System.Collections; |
| 4 | + using System.Collections.Generic; |
| 5 | + using UnityEngine; |
| 6 | + using UnityEditor.IMGUI.Controls; |
| 7 | + using UnityEditor; |
| 8 | + using Mapbox.Unity.Map; |
| 9 | + |
| 10 | + public class VectorSubLayerTreeView : TreeView |
| 11 | + { |
| 12 | + public SerializedProperty Layers; |
| 13 | + |
| 14 | + public VectorSubLayerTreeView(TreeViewState state) |
| 15 | + : base(state) |
| 16 | + { |
| 17 | + showAlternatingRowBackgrounds = true; |
| 18 | + showBorder = true; |
| 19 | + Reload(); |
| 20 | + } |
| 21 | + |
| 22 | + protected override TreeViewItem BuildRoot() |
| 23 | + { |
| 24 | + // The root item is required to have a depth of -1, and the rest of the items increment from that. |
| 25 | + var root = new TreeViewItem { id = -1, depth = -1, displayName = "Root" }; |
| 26 | + |
| 27 | + var items = new List<TreeViewItem>(); |
| 28 | + var index = 0; |
| 29 | + |
| 30 | + if (Layers != null) |
| 31 | + { |
| 32 | + for (int i = 0; i < Layers.arraySize; i++) |
| 33 | + { |
| 34 | + var name = Layers.GetArrayElementAtIndex(i).FindPropertyRelative("coreOptions.sublayerName").stringValue; |
| 35 | + //Debug.Log(name); |
| 36 | + items.Add(new TreeViewItem { id = index, depth = 0, displayName = name }); |
| 37 | + index++; |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + // Utility method that initializes the TreeViewItem.children and .parent for all items. |
| 42 | + SetupParentsAndChildrenFromDepths(root, items); |
| 43 | + |
| 44 | + // Return root of the tree |
| 45 | + return root; |
| 46 | + } |
| 47 | + |
| 48 | + protected override bool CanRename(TreeViewItem item) |
| 49 | + { |
| 50 | + return true; |
| 51 | + } |
| 52 | + |
| 53 | + protected override void RenameEnded(RenameEndedArgs args) |
| 54 | + { |
| 55 | + if (Layers != null) |
| 56 | + { |
| 57 | + //var layer = Layers[args.itemID]; // |
| 58 | + //layer = args.newName; |
| 59 | + var layer = Layers.GetArrayElementAtIndex(args.itemID); |
| 60 | + if (string.IsNullOrEmpty(args.newName.Trim())) |
| 61 | + { |
| 62 | + layer.FindPropertyRelative("coreOptions.sublayerName").stringValue = args.originalName; |
| 63 | + } |
| 64 | + else |
| 65 | + { |
| 66 | + layer.FindPropertyRelative("coreOptions.sublayerName").stringValue = args.newName; |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | +} |
0 commit comments