コード例 #1
0
        /// <summary>
        /// Gets the node that corresponds to the given category name, if it exists. Otherwise, returns <c>null</c>.
        /// </summary>
        /// <param name="node">The node that contains the category.</param>
        /// <param name="categoryName">The name of the category.</param>
        /// <returns>The node that corresponds to the given category name, or <c>null</c>.</returns>
        public static AssetVirtualNodePresenter GetCategory([NotNull] this INodePresenter node, string categoryName)
        {
            var categoryPropertyName = CategoryData.ComputeCategoryNodeName(categoryName);
            var category             = node.Children.FirstOrDefault(x => x.Name == categoryPropertyName);

            return((AssetVirtualNodePresenter)category);
        }
コード例 #2
0
        protected override void FinalizeTree(IAssetNodePresenter root)
        {
            var asset = root.Asset?.Asset as VideoAsset;

            if (asset != null)
            {
                var size = CategoryData.ComputeCategoryNodeName("Size");
                root[size][nameof(VideoAsset.Width)].AddDependency(root[size][nameof(VideoAsset.IsSizeInPercentage)], false);
                root[size][nameof(VideoAsset.Height)].AddDependency(root[size][nameof(VideoAsset.IsSizeInPercentage)], false);
            }
        }
コード例 #3
0
        public override void UpdateNode(INodePresenter node)
        {
            var member = node as MemberNodePresenter;

            if (member != null)
            {
                // First update: if a member has a CategoryAttribute, we forward this information as an attached property so we can switch its template to represent a header.
                var memberDescriptor = member.MemberDescriptor;
                if (member.MemberAttributes.OfType <CategoryAttribute>().Any())
                {
                    node.AttachedProperties.Add(CategoryData.Key, true);
                    node.AttachedProperties.Set(DisplayData.AutoExpandRuleKey, ExpandRule.Always);
                }

                // Second updater: if a member has a DisplayAttribute with a non-null Category property, we create this category if it doesn't exist and move it into it.
                var displayAttribute = TypeDescriptorFactory.Default.AttributeRegistry.GetAttribute <DisplayAttribute>(memberDescriptor.MemberInfo);
                if (displayAttribute == null)
                {
                    return;
                }

                var categoryPropertyName = CategoryData.ComputeCategoryNodeName(displayAttribute.Category);
                if (node.Parent != null && !string.IsNullOrEmpty(displayAttribute.Category) && node.Parent.Name != categoryPropertyName)
                {
                    var categoryNode = node.Parent.Children.FirstOrDefault(x => x.Name == categoryPropertyName);
                    if (categoryNode == null)
                    {
                        var parent        = node.Parent;
                        var orders        = TypeDescriptorFactory.Default.AttributeRegistry.GetAttributes <CategoryOrderAttribute>(memberDescriptor.DeclaringType);
                        var matchingOrder = orders.FirstOrDefault(x => x.Name == displayAttribute.Category);
                        categoryNode = parent.CreateCategory(displayAttribute.Category, matchingOrder?.Order, matchingOrder?.Expand);
                    }

                    if (!(categoryNode is VirtualNodePresenter))
                    {
                        throw new InvalidOperationException("The category of the node {0} cannot be created because another node with this name already exists.");
                    }

                    node.ChangeParent(categoryNode);
                }
            }
        }
コード例 #4
0
        public static AssetVirtualNodePresenter CreateCategory([NotNull] this INodePresenter node, string categoryName, int?order, ExpandRule?expand, [CanBeNull] params string[] propertiesToMove)
        {
            var categoryPropertyName = CategoryData.ComputeCategoryNodeName(categoryName);

            if (node.Children.Any(x => x.Name == categoryPropertyName))
            {
                throw new InvalidOperationException("The category has already been created or a node with a conflicting name exists.");
            }

            var factory = (AssetNodePresenterFactory)node.Factory;
            var newNode = factory.CreateVirtualNodePresenter(node, categoryPropertyName, typeof(string), order, () => categoryName);

            newNode.AttachedProperties.Add(CategoryData.Key, true);
            newNode.AttachedProperties.Add(DisplayData.AutoExpandRuleKey, expand ?? ExpandRule.Always);
            newNode.DisplayName = categoryName;
            if (propertiesToMove != null)
            {
                foreach (var propertyToMove in propertiesToMove)
                {
                    node[propertyToMove].ChangeParent(newNode);
                }
            }
            return(newNode);
        }