예제 #1
0
        public override void LoadContainers(bool refresh)
        {
            if (refresh || ContainerChildren.Count == 0 || ContainerChildren.FirstOrDefault() == ContainerVM.PLACE_HOLDER)
            {
                // due to nature of shell enumeration
                // we can load both file and folders together.

                ContainerChildren.Clear();
                SingleChildren.Clear();

                foreach (ShellObject sub in Folder)
                {
                    var folder = sub as ShellFolder;
                    if (folder != null)
                    {
                        ContainerChildren.Add(new ShellFolderVM(Provider, this, folder));
                    }
                    else
                    {
                        var file = sub as ShellFile;
                        if (file != null)
                        {
                            SingleChildren.Add(new ShellFileVM(Provider, this, file));
                        }
                        else
                        {
                            sub.Dispose();
                        }
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Add an attribute to be applied to the element of the specified id.
        /// </summary>
        public ElementBuilder SetAttribute(string id, string key, Func <string> getValue)
        {
            ElementBuilder builder;

            // get the builder of the child if already assigned
            if (SingleChildren.TryGetValue(id, out builder))
            {
                Teple <string, IFunc <string> > value;
                if (builder.Attributes.TryGetValue(key, out value))
                {
                    value.ArgB = new FuncSet <string>(getValue);
                }
                else
                {
                    builder.Attributes.Add(key, new Teple <string, IFunc <string> >(null, new FuncSet <string>(getValue)));
                }
            }
            else
            {
                builder = new ElementBuilder();
                _singleChildren.Add(id, builder = new ElementBuilder());
                builder.Attributes.Add(id, new Teple <string, IFunc <string> >(null, new FuncSet <string>(getValue)));
            }
            return(builder);
        }
예제 #3
0
        /// <summary>
        /// Add an attribute to be applied to the element of the specified id.
        /// </summary>
        public ElementBuilder SetAttribute(string id, string key, string value, IAction <Element> onElement = null)
        {
            ElementBuilder builder;

            if (!SingleChildren.TryGetValue(id, out builder))
            {
                _singleChildren.Add(id, builder = new ElementBuilder());
            }
            if (builder.Attributes == null)
            {
                builder.Attributes = new Dictionary <string, Teple <string, IFunc <string> > >();
            }
            Teple <string, IFunc <string> > attribute;

            if (builder.Attributes.TryGetValue(key, out attribute))
            {
                attribute.ArgA = value;
            }
            else
            {
                builder.Attributes.Add(key, new Teple <string, IFunc <string> >(value, null));
            }
            if (onElement != null)
            {
                builder._onBuilt = onElement;
            }
            return(builder);
        }
예제 #4
0
        /// <summary>
        /// Get a builder for the element specified by id.
        /// </summary>
        public ElementBuilder Get(string id)
        {
            ElementBuilder builder;

            if (!SingleChildren.TryGetValue(id, out builder))
            {
                _singleChildren.Add(id, builder = new ElementBuilder());
            }
            return(builder);
        }
예제 #5
0
 /// <summary>
 /// Loads the <see cref="SingleChildren"/> collection.
 /// </summary>
 /// <param name="refresh">if set to <c>true</c> then always load, otherwise it'll only load when necessary.</param>
 public virtual void LoadSingles(bool refresh)
 {
     if (refresh || SingleChildren.Count == 0)
     {
         SingleChildren.Clear();
         foreach (var c in Provider.GetSingleChildren(this))
         {
             SingleChildren.Add(c);
         }
     }
 }
예제 #6
0
        /// <summary>
        /// Remove the specified child by id.
        /// </summary>
        public void RemoveChild(string id)
        {
            ElementBuilder builder;

            if (SingleChildren.TryGetValue(id, out builder))
            {
                builder.Action = BuilderAction.Remove;
            }
            else
            {
                builder        = new ElementBuilder();
                builder.Action = BuilderAction.Remove;
                _singleChildren.Add(id, builder);
            }
        }
예제 #7
0
        /// <summary>
        /// Add a child to the element builder to replace an existing id.
        /// </summary>
        public ElementBuilder ReplaceChild(string id, Element element, IAction <Element> onElement = null)
        {
            ElementBuilder builder;

            if (!SingleChildren.TryGetValue(id, out builder))
            {
                _singleChildren.Add(id, builder = new ElementBuilder());
            }
            builder.Action  = BuilderAction.Replace;
            builder.Element = element;
            if (onElement != null)
            {
                builder._onBuilt = onElement;
            }
            return(builder);
        }
예제 #8
0
        /// <summary>
        /// Add an attribute to be applied to the element of the specified id.
        /// </summary>
        public ElementBuilder AddContent(string id, Func <string> content, IAction <Element> onElement = null)
        {
            ElementBuilder builder;

            if (!SingleChildren.TryGetValue(id, out builder))
            {
                _singleChildren.Add(id, builder = new ElementBuilder());
            }
            if (builder.Content == null)
            {
                builder.Content = new ArrayRig <Teple <string, IFunc <string> > >();
            }
            builder.Content.Add(new Teple <string, IFunc <string> >(null, new FuncSet <string>(content)));
            if (onElement != null)
            {
                builder._onBuilt = onElement;
            }
            return(builder);
        }