예제 #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);
        }
예제 #2
0
        /// <summary>
        ///     Adds an element as a child of this one, while updating its parent and oldparent field
        /// </summary>
        /// <param name="elem">The element in question</param>
        internal void AddChild(BrowserInternalElement elem)
        {

            elem.OldParent = elem.Parent;
            if (elem.Parent != null)
                elem.Parent.Items.Remove(elem);

            elem.Parent = this;
            this.Items.Add(elem);
        }
예제 #3
0
        /// <summary>
        ///     Adds an element as a child of this one, while updating its parent and oldparent field
        /// </summary>
        /// <param name="elem">The element in question</param>
        internal void AddChild(BrowserInternalElement elem)
        {
            elem.OldParent = elem.Parent;
            if (elem.Parent != null)
            {
                elem.Parent.Items.Remove(elem);
            }

            elem.Parent = this;
            this.Items.Add(elem);
        }
예제 #4
0
        /// <summary>
        ///     Add a category, given a delimited name
        /// </summary>
        /// <param name="categoryName">The comma delimited name </param>
        /// <returns>The newly created item</returns>
        public BrowserItem AddCategory(string categoryName)
        {
            // if already added, return immediately
            if (_browserCategoryDict.ContainsKey(categoryName))
            {
                return(_browserCategoryDict[categoryName]);
            }

            // otherwise split the categoryname
            var splitCat = new List <string>();

            if (categoryName.Contains(CATEGORY_DELIMITER))
            {
                splitCat = categoryName.Split(CATEGORY_DELIMITER).ToList();
            }
            else
            {
                splitCat.Add(categoryName);
            }

            // attempt to add root element
            if (splitCat.Count == 1)
            {
                return(this.AddRootCategory(categoryName));
            }

            var currentCatName = splitCat[0];

            // attempt to add all other categoires
            var currentCat = (BrowserItem)BrowserRootCategories.FirstOrDefault((x) => x.Name == splitCat[0]);

            if (currentCat == null)
            {
                currentCat = AddRootCategory(splitCat[0]);
            }

            for (var i = 1; i < splitCat.Count; i++)
            {
                currentCatName = currentCatName + CATEGORY_DELIMITER + splitCat[i];

                var tempCat = currentCat.Items.FirstOrDefault((x) => x.Name == splitCat[i]);
                if (tempCat == null)
                {
                    tempCat = new BrowserInternalElement(splitCat[i], currentCat);
                    currentCat.AddChild((BrowserInternalElement)tempCat);
                    _browserCategoryDict.Add(currentCatName, tempCat);
                }

                currentCat = tempCat;
            }

            return(currentCat);
        }
예제 #5
0
        /// <summary>
        ///     Attempt to add a new category to the browser and an item as one of its children
        /// </summary>
        /// <param name="category">The name of the category - a string possibly separated with one period </param>
        /// <param name="item">The item to add as a child of that category</param>
        internal void TryAddCategoryAndItem(string category, BrowserInternalElement item)
        {
            var cat = this.AddCategory(category);

            cat.AddChild(item);

            item.FullCategoryName = category;

            var searchEleItem = item as SearchElementBase;

            if (searchEleItem != null)
            {
                _searchElements.Add(searchEleItem);
            }
        }
예제 #6
0
        /// <summary>
        ///     Attempt to add a new category to the browser and an item as one of its children
        /// </summary>
        /// <param name="category">The name of the category - a string possibly separated with one period </param>
        /// <param name="item">The item to add as a child of that category</param>
        public void TryAddCategoryAndItem(string category, BrowserInternalElement item)
        {
            if (!NodeCategories.ContainsKey(category))
            {
                NodeCategories.Add(category, new CategorySearchElement(category));
            }

            var cat = this.AddCategory(category);

            cat.AddChild(item);

            item.FullCategoryName = category;

            var searchEleItem = item as SearchElementBase;

            if (searchEleItem != null)
            {
                _browserLeaves.Add(searchEleItem);
            }
        }
 public BrowserInternalElementViewModel(BrowserInternalElement model)
     : base(model)
 {}
예제 #8
0
 internal static BrowserInternalElementViewModel WrapExplicit(BrowserInternalElement elem)
 {
     return new BrowserInternalElementViewModel(elem);
 }