Ejemplo n.º 1
0
    public void BuildView(IEnumerable <Layer> layers)
    {
        Layers = new List <Layer>(layers);
        Layers.Reverse();
        List <TreeItem> itemList = new List <TreeItem> ();


        Root.Clear();
        foreach (var layer in Layers)
        {
            var objectNames = layer.ObjectPath.Split('/');
            var depth       = objectNames.Length - 1;
            var item        = new TreeItem(layer);
            if (depth <= 0)
            {
                Root.AddChild(item);
            }
            else
            {
                var parent = itemList.FirstOrDefault(x => PSDEditorWindow.IsParent(x.Layer, layer));
                if (parent != null)
                {
                    parent.AddChild(item);
                }
            }
            itemList.Add(item);
        }
    }
Ejemplo n.º 2
0
        private static void PopulateFolders(string dirName, TreeItem <string> parentFolder)
        {
            string[] folderItems = Directory.GetFileSystemEntries(dirName);

            foreach (var folderItem in folderItems)
            {
                TreeItem <string> folderSubItem = new TreeItem <string>(folderItem);
                parentFolder.AddChild(folderSubItem);

                // If the current node is a filename, don't call recursion and continue
                try
                {
                    Directory.GetDirectories(folderItem);
                }
                catch (IOException ex)
                {
                    continue;
                }
                catch (UnauthorizedAccessException)
                {
                    Console.WriteLine("LOG: No access to folder {0}", dirName);
                    continue;
                }

                PopulateFolders(folderItem, folderSubItem);
            }
        }
Ejemplo n.º 3
0
        private static void PopulateFolders(string dirName, TreeItem<string> parentFolder)
        {
            string[] folderItems = Directory.GetFileSystemEntries(dirName);

            foreach (var folderItem in folderItems)
            {
                TreeItem<string> folderSubItem = new TreeItem<string>(folderItem);
                parentFolder.AddChild(folderSubItem);

                // If the current node is a filename, don't call recursion and continue
                try
                {
                    Directory.GetDirectories(folderItem);
                }
                catch (IOException ex)
                {
                    continue;
                }
                catch (UnauthorizedAccessException)
                {
                    Console.WriteLine("LOG: No access to folder {0}", dirName);
                    continue;
                }

                PopulateFolders(folderItem, folderSubItem);
            }
        }
Ejemplo n.º 4
0
        public static void ShowAsPopup(Rect buttonPosition, GUIContent[] labels, int selectedIndex, SelectedIndexEventHandler onSelection, string search = "", SearchChangedEventHandler onSearchChanged = null)
        {
            List <TreeItem> roots                 = new List <TreeItem>();
            TreeItem        selectedItem          = null;
            Dictionary <string, TreeItem> itemMap = new Dictionary <string, TreeItem>();
            List <TreeItem> items                 = new List <TreeItem>();

            //Create all the actual leaf items
            for (int i = 0; i < labels.Length; i++)
            {
                GUIContent label = labels[i];
                string     text  = label.text;

                if (!string.IsNullOrEmpty(text))
                {
                    string[] bits = text.Split(new char[] { '/' });

                    GUIContent leafContent = new GUIContent(bits[bits.Length - 1], label.image, label.tooltip);

                    // We store the index into the labels array in userData
                    TreeItem item = new TreeItem(leafContent, text, (int)i, userSelectedItem => {
                        if (onSelection != null)
                        {
                            onSelection((int)userSelectedItem.UserData);
                        }
                    });

                    if (!itemMap.ContainsKey(text))
                    {
                        items.Add(item);
                        if (!itemMap.ContainsKey(text))
                        {
                            itemMap.Add(text, item);
                        }
                        if (i == selectedIndex)
                        {
                            selectedItem = item;
                        }
                    }
                    else
                    {
                        Debug.LogErrorFormat("Duplicate Key \"{0}\" in label \"{1}\"", text, label);
                    }
                }
            }

            // Create any intermediate parent items
            foreach (TreeItem item in items)
            {
                int index = (int)item.UserData;

                string originalText = labels[index].text;
                if (!string.IsNullOrEmpty(originalText))
                {
                    string[] bits   = originalText.Split(new char[] { '/' });
                    TreeItem prev   = null;
                    TreeItem parent = null;
                    for (int i = 1; i < bits.Length; i++)
                    {
                        prev = parent;
                        string key = string.Join("/", bits.Take(i).ToArray());
                        if (!itemMap.TryGetValue(key, out parent))
                        {
                            parent = new TreeItem(new GUIContent(bits[i - 1]), null);
                            if (prev != null)
                            {
                                prev.AddChild(parent);
                            }
                            else
                            {
                                roots.Add(parent);
                            }
                            itemMap.Add(key, parent);
                        }
                    }
                    // Add the actual item to the parent (if we even found a parent)
                    if (parent != null)
                    {
                        parent.AddChild(item);
                    }
                    else
                    {
                        roots.Add(item);
                    }
                }
            }

            ShowAsPopup(buttonPosition, roots.ToArray(), selectedItem, search, onSearchChanged);
        }