예제 #1
0
        private void Initialize(Rect activatorPosition, IFuzzyOptionTree optionTree, Action <IFuzzyOption> callback)
        {
            tree = optionTree;

            // Port the activator position to screen space

            activatorPosition.position = GUIUtility.GUIToScreenPoint(activatorPosition.position);
            this.activatorPosition     = activatorPosition;

            // Create the hierarchy

            stack = new Stack <FuzzyOptionNode>();
            root  = new FuzzyOptionNode(new Root(optionTree.header));

            ExecuteTask(delegate
            {
                optionTree.Prewarm();

                Populate(root, optionTree.Root());

                // Fit height to children if there is no depth and no search

                var hasSubChildren = root.children.Any(option => option.hasChildren);

                if (!optionTree.searchable && !hasSubChildren)
                {
                    height = 0;

                    if (!string.IsNullOrEmpty(root.option.headerLabel))
                    {
                        height += Styles.headerHeight;
                    }

                    height += root.children.Count * Styles.optionHeight + 1;
                }
            });

            // Add favorites

            favoritesRoot = new FuzzyOptionNode(new FavoritesRoot());
            UpdateFavorites();

            // Setup the search

            searchRoot = new FuzzyOptionNode(new SearchRoot());
            Search();

            // Assign the callback

            this.callback = callback;

            // Show and focus the window

            wantsMouseMove = true;
            var initialSize = new Vector2(activatorPosition.width, height);

            this.ShowAsDropDownWithKeyboardFocus(activatorPosition, initialSize);

            Focus();
        }
예제 #2
0
        public bool EvaluateHasChildren(IFuzzyOptionTree tree)
        {
            if (!hasChildren.HasValue)
            {
                hasChildren = tree.Children(option).Any();
            }

            return(hasChildren.Value);
        }
예제 #3
0
        private void Initialize(IFuzzyOptionTree optionTree, Action <IFuzzyOption> callback)
        {
            tree = optionTree;

            // Create the hierarchy

            stack = new Stack <FuzzyOptionNode>();
            root  = new FuzzyOptionNode(new Root(optionTree.header));

            ExecuteTask(delegate
            {
                optionTree.Prewarm();

                Populate(root, optionTree.Root());

                // Fit height to children if there is no depth and no search

                var hasSubChildren = root.children.Any(option => option.hasChildren);

                if (!optionTree.searchable && !hasSubChildren)
                {
                    height = 0;

                    if (!string.IsNullOrEmpty(root.option.headerLabel))
                    {
                        height += Styles.headerHeight;
                    }

                    height += root.children.Count * Styles.optionHeight + 1;
                }
            });

            // Add favorites

            favoritesRoot = new FuzzyOptionNode(new FavoritesRoot());
            UpdateFavorites();

            // Setup the search

            searchRoot = new FuzzyOptionNode(new SearchRoot());
            Search();

            // Assign the callback

            this.callback = callback;
            // Show and focus the window
        }
예제 #4
0
        public static void Show(Rect activatorPosition, IFuzzyOptionTree optionTree, Action <IFuzzyOption> callback)
        {
            Ensure.That(nameof(optionTree)).IsNotNull(optionTree);

            // Makes sure control exits DelayedTextFields before opening the window
            GUIUtility.keyboardControl = 0;

            if (instance != null)
            {
                instance.Close();
            }
            else
            {
                instance = CreateInstance <FuzzyWindow>();

                instance.Initialize(activatorPosition, optionTree, callback);
            }
        }
예제 #5
0
        public bool isValid => tree != null;         // Will return false after reloading the window from serialization

        public static void Show(Rect activatorPosition, IFuzzyOptionTree optionTree, Action <IFuzzyOption> callback)
        {
            Ensure.That(nameof(optionTree)).IsNotNull(optionTree);

            // Makes sure control exits DelayedTextFields before opening the window
            GUIUtility.keyboardControl = 0;

            if (instance == null)
            {
                instance = CreateInstance <FuzzyWindow>();
            }
            else
            {
                throw new InvalidOperationException("Cannot open two instances of the fuzzy window at once.");
            }

            instance.Initialize(activatorPosition, optionTree, callback);
        }
예제 #6
0
 public static IEnumerable <IFuzzyOptionTree> Extensions(this IFuzzyOptionTree optionTree)
 {
     return(FuzzyOptionTreeExtensionProvider.instance.GetDecorators(optionTree));
 }
예제 #7
0
        private void Initialize(Rect activatorPosition, IFuzzyOptionTree optionTree, Action <IFuzzyOption> callback)
        {
            tree = optionTree;

            // Activator position is assumed to be in screen space, not GUI space
            // This lets us properly position fuzzy windows from context menus where no GUI context is available

            this.activatorPosition = activatorPosition;

            // Create the hierarchy

            stack         = new List <FuzzyOptionNode>();
            root          = new FuzzyOptionNode(new Root(optionTree.header));
            favoritesRoot = new FuzzyOptionNode(new FavoritesRoot());
            stack.Add(root);

            Styles.Initialize();

            ExecuteTask(() =>
            {
                if (!optionTree.prewarmed)
                {
                    optionTree.Prewarm();
                    optionTree.prewarmed = true;
                }
                else
                {
                    optionTree.Rewarm();
                }

                Populate(root, optionTree.Root());

                UpdateFavorites();

                // Fit height to children if there is no depth and no search

                var hasSubChildren = root.children.Any(option => option.hasChildren != false);

                if (!optionTree.searchable && !hasSubChildren)
                {
                    var height = 0f;

                    if (!string.IsNullOrEmpty(root.option.headerLabel))
                    {
                        height += Styles.headerHeight;
                    }

                    foreach (var child in root.children)
                    {
                        if (child.option is FuzzySeparator)
                        {
                            height += Styles.separatorHeight;
                        }
                        else
                        {
                            height += Styles.optionHeight;
                        }
                    }

                    this.height = height + 1;
                }
            });


            // Setup the search

            Search();

            // Assign the callback

            this.callback = callback;

            // Show and focus the window

            wantsMouseMove = true;
            var initialSize = new Vector2(activatorPosition.width, height);

            this.ShowAsDropDown(activatorPosition, initialSize);
            Focus();
        }