Beispiel #1
0
        /// <summary>
        /// Add a single category as a child of a category.  If the category already exists, just return that one.
        /// </summary>
        /// <param name="parent">The parent category </param>
        /// <param name="childCategoryName">The name of the child category (can't be nested)</param>
        /// <returns>The newly created category</returns>
        internal BrowserItem TryAddChildCategory(BrowserItem parent, string childCategoryName)
        {
            var newCategoryName = parent.Name + CATEGORY_DELIMITER + childCategoryName;

            // support long nested categories like Math.Math.StaticMembers.Abs
            var parentItem = parent as BrowserInternalElement;

            while (parentItem != null)
            {
                var grandParent = parentItem.Parent;
                if (null == grandParent)
                {
                    break;
                }

                newCategoryName = grandParent.Name + CATEGORY_DELIMITER + newCategoryName;
                parentItem      = grandParent as BrowserInternalElement;
            }

            if (ContainsCategory(newCategoryName))
            {
                return(GetCategoryByName(newCategoryName));
            }

            var tempCat = new BrowserInternalElement(childCategoryName, parent);

            parent.AddChild(tempCat);

            return(tempCat);
        }
        internal override void Execute()
        {
            var endState = !this.IsExpanded;

            foreach (var ele in this.Siblings)
            {
                ele.IsExpanded = false;
            }

            //Walk down the tree expanding anything nested one layer deep
            //this can be removed when we have the hierachy implemented properly
            if (this.Items.Count == 1)
            {
                BrowserItem subElement = this.Items[0];

                while (subElement.Items.Count == 1)
                {
                    subElement.IsExpanded = true;
                    subElement            = subElement.Items[0];
                }

                subElement.IsExpanded = true;
            }

            this.IsExpanded = endState;
        }
        protected BrowserItemViewModel(BrowserItem model)
        {
            Model = model;
            ToggleIsExpandedCommand = new DelegateCommand(Model.Execute);
            Items = new ObservableCollection<BrowserItemViewModel>();

            foreach (var item in Model.Items)
            {
                Items.Add(Wrap(item));
            }

            Model.Items.CollectionChanged += ItemsOnCollectionChanged;
        }
Beispiel #4
0
        /// <summary>
        /// Remove an empty category from browser and search.  Useful when a single item is removed.
        /// </summary>
        /// <param name="ele"></param>
        internal void RemoveEmptyCategory(BrowserItem ele)
        {
            if (ele is BrowserRootElement && ele.Items.Count == 0)
            {
                RemoveEmptyRootCategory(ele as BrowserRootElement);
                return;
            }

            if (ele is BrowserInternalElement && ele.Items.Count == 0)
            {
                var internalEle = ele as BrowserInternalElement;

                internalEle.Parent.Items.Remove(internalEle);
                RemoveEmptyCategory(internalEle.Parent);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Remove a category and all its children from the browser and search.  The category does
        /// not have to be empty.
        /// </summary>
        /// <param name="ele"></param>
        internal void RemoveCategory(BrowserItem ele)
        {
            var nodes = ele.Items.Where(x => x is NodeSearchElement)
                        .Cast <NodeSearchElement>().ToList();

            var cats = ele.Items.Where(x => x is BrowserInternalElement)
                       .Cast <BrowserInternalElement>().ToList();

            nodes.Select(x => x.Name).ToList().ForEach(RemoveNode);
            cats.ToList().ForEach(RemoveCategory);

            ele.Items.Clear();

            if (ele is BrowserRootElement)
            {
                BrowserRootCategories.Remove(ele as BrowserRootElement);
            }
            else if (ele is BrowserInternalElement)
            {
                (ele as BrowserInternalElement).Parent.Items.Remove(ele);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BrowserInternalElement"/> class.
 /// </summary>
 /// <param name="name">Name of element.</param>
 /// <param name="parent">Parent element.</param>
 internal BrowserInternalElement(string name, BrowserItem parent)
 {
     this._name = name;
     this.Parent = parent;
     this.OldParent = null;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BrowserInternalElement"/> class.
 /// </summary>
 /// <param name="name">Name of element.</param>
 /// <param name="parent">Parent element.</param>
 internal BrowserInternalElement(string name, BrowserItem parent)
 {
     this._name     = name;
     this.Parent    = parent;
     this.OldParent = null;
 }
 internal static BrowserItemViewModel Wrap(BrowserItem item)
 {
     dynamic itemDyn = item;
     return WrapExplicit(itemDyn);
 }
Beispiel #9
0
 internal BrowserItem TryGetSubCategory(BrowserItem category, string catName)
 {
     return(category.Items.FirstOrDefault(x => x.Name == catName));
 }