Esempio n. 1
0
        ///HELP AREA
        void DoFooter(Rect helpRect, Event e)
        {
            helpRectRequiredHeight = 0;
            var hoveringNode = hoveringIndex >= 0 && currentNode.children.Count > 0 ? currentNode.children.Values.ToList()[hoveringIndex] : null;

            GUI.color = new Color(0, 0, 0, 0.3f);
            Styles.Draw(helpRect, GUI.skin.textField);
            GUI.color = Color.white;
            GUILayout.BeginArea(helpRect);
            GUILayout.BeginVertical();
            var doc = string.Empty;

            if (hoveringNode != null && hoveringNode.isLeaf)
            {
                doc = hoveringNode.item.content.tooltip;
                var memberInfo = hoveringNode.item.userData as MemberInfo;
                if (memberInfo != null && string.IsNullOrEmpty(doc))
                {
                    if (memberInfo is System.Type)
                    {
                        doc = TypePrefs.GetTypeDoc(memberInfo);
                    }
                    else
                    {
                        doc = DocsByReflection.GetMemberSummary(memberInfo);
                    }
                }
            }

            GUILayout.Label(string.Format("<size=9>{0}</size>", doc), helpStyle);
            GUILayout.EndVertical();
            GUILayout.EndArea();
        }
Esempio n. 2
0
        ///HELP AREA
        void DoFooter(Rect helpRect, Event e)
        {
            helpRectRequiredHeight = 0;
            var hoveringNode = hoveringIndex >= 0 && currentNode.children.Count > 0? currentNode.children.Values.ToList()[hoveringIndex] : null;

            GUI.color = new Color(0, 0, 0, 0.3f);
            GUI.Box(helpRect, "", (GUIStyle)"TextField");
            GUI.color = Color.white;
            GUILayout.BeginArea(helpRect);
            GUILayout.BeginVertical();
            var        doc        = string.Empty;
            MemberInfo memberInfo = null;

            if (hoveringNode != null && hoveringNode.item != null)
            {
                memberInfo = hoveringNode.item.userData as MemberInfo;
                doc        = hoveringNode.item.content.tooltip;
                if (memberInfo != null && string.IsNullOrEmpty(doc))
                {
                    doc = DocsByReflection.GetMemberSummary(memberInfo);
                }
            }

            GUILayout.Label(string.Format("<size=9>{0}</size>", doc), helpStyle);
            GUILayout.EndVertical();
            GUILayout.EndArea();
        }
Esempio n. 3
0
        ///Get documentation for type fetched either by the [Description] attribute, or it's xml doc.
        public static string GetTypeDoc(MemberInfo info)
        {
            if (info == null)
            {
                return(null);
            }
            var type = info is Type ? info as Type : info.ReflectedType;

            if (type == null)
            {
                return(null);
            }

            string doc = null;

            if (typeDocs.TryGetValue(type.FullName, out doc))
            {
                return(doc);
            }

            var descAtt = type.RTGetAttribute <DescriptionAttribute>(true);

            if (descAtt != null)
            {
                doc = descAtt.description;
            }

            if (doc == null)
            {
                doc = DocsByReflection.GetMemberSummary(type);
            }

            if (doc == null)
            {
                doc = "No Documentation";
            }

            return(typeDocs[type.FullName] = doc);
        }
        //Show stuff
        public override void OnGUI(Rect rect)
        {
            var e = Event.current;

            EditorGUIUtility.SetIconSize(Vector2.zero);
            hoveringIndex = Mathf.Clamp(hoveringIndex, -1, currentNode.children.Count - 1);

            ///MAIN AREA
            mainRect = new Rect(rect.x, rect.y, rect.width, rect.height - helpRectHeight);
            GUI.Box(mainRect, "", (GUIStyle)"PreBackground");
            GUILayout.BeginArea(mainRect);

            //HEADER
            GUILayout.Space(2);
            GUILayout.Label(string.Format("<color=#dddddd><size=15><b>{0}</b></size></color>", title), headerStyle);

            ///SEARCH
            if (e.keyCode == KeyCode.DownArrow)
            {
                GUIUtility.keyboardControl = 0;
            }
            if (e.keyCode == KeyCode.UpArrow)
            {
                GUIUtility.keyboardControl = 0;
            }
            // GUILayout.Space(2);
            GUILayout.BeginHorizontal();
            GUI.SetNextControlName("SearchToolbar");
            search = EditorGUILayout.TextField(search, (GUIStyle)"ToolbarSeachTextField");
            if (GUILayout.Button("", (GUIStyle)"ToolbarSeachCancelButton"))
            {
                search = string.Empty;
                GUIUtility.keyboardControl = 0;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            searchMode      = (SearchMode)EditorGUILayout.EnumPopup(searchMode);
            filterFavorites = EditorGUILayout.ToggleLeft("Filter Favorites", filterFavorites);
            GUILayout.EndHorizontal();

            EditorUtils.BoldSeparator();

            ///BACK
            if (currentNode.parent != null && string.IsNullOrEmpty(search))
            {
                GUILayout.BeginHorizontal("box");
                if (GUILayout.Button(string.Format("<b><size=14>◄ {0}/{1}</size></b>", currentNode.parent.name, currentNode.name), (GUIStyle)"label"))
                {
                    currentNode = currentNode.parent;
                }
                GUILayout.EndHorizontal();
                var lastRect = GUILayoutUtility.GetLastRect();
                if (lastRect.Contains(e.mousePosition))
                {
                    GUI.color = hoverColor;
                    GUI.DrawTexture(lastRect, EditorGUIUtility.whiteTexture);
                    GUI.color = Color.white;
                    base.editorWindow.Repaint();
                    hoveringIndex = -1;
                }
            }

            //Go back with right click as well...
            if (e.type == EventType.MouseDown && e.button == 1)
            {
                e.Use();
                if (currentNode.parent != null)
                {
                    currentNode = currentNode.parent;
                }
            }


            ///TREE
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos, false, false);
            GUILayout.BeginVertical();

            if (search != lastSearch)
            {
                hoveringIndex = 0;
                if (!string.IsNullOrEmpty(search) && search.Length >= 2)
                {
                    var searchRootNode = new Node()
                    {
                        name = "Search Root"
                    };
                    var a = GetCleanSearchString(search);
                    foreach (var node in leafNodes)
                    {
                        var b     = GetCleanSearchString(node.name);
                        var match = false;
                        if (searchMode == SearchMode.Contains && b.Contains(a))
                        {
                            match = true;
                        }
                        if (searchMode == SearchMode.StartsWith && b.StartsWith(a))
                        {
                            match = true;
                        }
                        if (match)
                        {
                            searchRootNode.children[node.name] = node;
                        }
                    }
                    currentNode = searchRootNode;
                }
                else
                {
                    currentNode = rootNode;
                }
                lastSearch = search;
            }



            var  i          = 0;
            var  itemAdded  = false;
            Node lastParent = null;

            foreach (var childPair in currentNode.children)
            {
                var node = childPair.Value;

                if (search != null && search.Length >= 2)
                {
                    var currentParent = node.parent;
                    if (currentParent != lastParent)
                    {
                        lastParent = currentParent;
                        GUI.color  = EditorGUIUtility.isProSkin? Color.black : Color.white;
                        GUILayout.BeginHorizontal("box");
                        GUI.color = Color.white;
                        if (GUILayout.Button(currentParent.unfolded? "▼" : "▶", (GUIStyle)"label", GUILayout.Width(16)))
                        {
                            currentParent.unfolded = !currentParent.unfolded;
                        }
                        GUILayout.Label(string.Format("<size=12><b>{0}</b></size>", currentParent.fullPath));
                        GUILayout.EndHorizontal();
                    }

                    if (!node.parent.unfolded)
                    {
                        continue;
                    }
                }

                if (filterFavorites && !node.isFavorite && !node.HasAnyFavoriteChild())
                {
                    continue;
                }

                itemAdded = true;
                var leafItem     = node.item;
                var icon         = leafItem != null? leafItem.content.image : EditorUtils.folderIcon;
                var itemDisabled = leafItem != null && leafItem.func == null && leafItem.func2 == null;

                GUI.color = EditorGUIUtility.isProSkin? Color.white : new Color(0.8f, 0.8f, 0.8f, 1);
                GUILayout.BeginHorizontal("box");
                GUI.color = Color.white;

                //Prefix icon
                GUILayout.Label(icon, GUILayout.Width(32), GUILayout.Height(16));

                GUI.enabled = !itemDisabled;

                //Favorite
                GUI.color = node.isFavorite? Color.white : (node.HasAnyFavoriteChild()? new Color(1, 1, 1, 0.2f) : new Color(0f, 0f, 0f, 0.4f));
                if (GUILayout.Button(EditorUtils.favoriteIcon, GUIStyle.none, GUILayout.Width(16), GUILayout.Height(16)))
                {
                    node.ToggleFavorite();
                }
                GUI.color = Color.white;

                //Content
                var label = node.name;
                if (search != null && search.Length >= 2)                  //simple highlight
                {
                    label = Regex.Replace(label, search, "<b>$&</b>", RegexOptions.IgnoreCase);
                }

                if (GUILayout.Button(string.Format("<size=10>{0}</size>",
                                                   (leafItem == null? string.Format("<b>{0}</b>", label) : label)),
                                     (GUIStyle)"label", GUILayout.Width(0), GUILayout.ExpandWidth(true)))
                {
                    if (leafItem != null)
                    {
                        ExecuteItemFunc(leafItem);
                        break;
                    }
                    else
                    {
                        currentNode   = node;
                        hoveringIndex = 0;
                        break;
                    }
                }

                //Suffix icon
                GUILayout.Label(leafItem != null? "<b>+</b>" : "►", GUILayout.Width(20));

                GUILayout.EndHorizontal();
                var lastRect = GUILayoutUtility.GetLastRect();

                if (lastRect.Contains(e.mousePosition) && e.type == EventType.MouseMove)
                {
                    hoveringIndex = i;
                }

                if (hoveringIndex == i)
                {
                    GUI.color = hoverColor;
                    GUI.DrawTexture(lastRect, EditorGUIUtility.whiteTexture);
                    GUI.color = Color.white;
                    base.editorWindow.Repaint();
                }

                i++;

                GUI.enabled = true;
            }


            if (!itemAdded)
            {
                GUILayout.Label("No results to display with current search and filter combination");
            }

            GUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
            GUILayout.EndArea();


            GUILayout.FlexibleSpace();


            ///HELP AREA
            var hoveringNode = hoveringIndex >= 0 && currentNode.children.Count > 0? currentNode.children.Values.ToList()[hoveringIndex] : null;
            var helpRect     = new Rect(rect.x + 2, rect.yMax - helpRectHeight + 2, rect.width - 4, helpRectHeight - 2);

            GUI.color = new Color(0, 0, 0, 0.3f);
            GUI.Box(helpRect, "", (GUIStyle)"TextField");
            GUI.color = Color.white;
            GUILayout.BeginArea(helpRect);
            GUILayout.BeginVertical();
            var doc = string.Empty;

            if (hoveringNode != null && hoveringNode.item != null)
            {
                doc = hoveringNode.item.content.tooltip;
                var memberInfo = hoveringNode.item.userData as MemberInfo;
                if (memberInfo != null && string.IsNullOrEmpty(doc))
                {
                    doc = DocsByReflection.GetMemberSummary(memberInfo);
                }
            }
            GUILayout.Label(doc, EditorStyles.wordWrappedLabel);
            GUILayout.EndVertical();
            GUILayout.EndArea();


            //handle the events
            HandeEvents(e);
            if (!init)
            {
                init = true;
                EditorGUI.FocusTextInControl("SearchToolbar");
            }

            EditorGUIUtility.SetIconSize(Vector2.zero);
        }