Beispiel #1
0
        /// <summary>
        /// Searches active tool from top level, depth first, given predicate.
        /// </summary>
        /// <typeparam name="T">Type of the tool.</typeparam>
        /// <param name="tool">Parent tool to start from.</param>
        /// <param name="pred">Tool predicate.</param>
        /// <returns>Tool given type and predicate if active - otherwise null.</returns>
        public static T FindActive <T>(Tool tool, Predicate <T> pred) where T : Tool
        {
            if (tool == null)
            {
                return(null);
            }

            T typedTool = tool as T;

            if (typedTool != null && pred(typedTool))
            {
                return(typedTool);
            }

            foreach (Tool child in tool.GetChildren())
            {
                T result = FindActive(child, pred);
                if (result != null)
                {
                    return(result);
                }
            }

            return(null);
        }
Beispiel #2
0
        private static void TraverseActive(Tool parent, Action <Tool> visitor)
        {
            if (parent == null || visitor == null)
            {
                return;
            }

            visitor(parent);

            foreach (var child in parent.GetChildren())
            {
                TraverseActive(child, visitor);
            }
        }