public int IndexOf(GenericMenuElementData p_element)
        {
            if (_cachedItems == null)
            {
                _cachedItems = RootData.GetNonFolderElements();
            }

            return(_cachedItems.IndexOf(p_element));
        }
 public IEnumerator <GenericMenuElementData> GetEnumerator()
 {
     TryFixCachedElements();
     for (int i = 0; i < m_rootElementIds.Count; ++i)
     {
         GenericMenuElementData v_element = null;
         _cachedElementsDict.TryGetValue(m_rootElementIds[i], out v_element);
         yield return(v_element);
     }
 }
        protected internal virtual GenericMenuElementData AddItemAtSubPath_Internal(List <string> p_pathSplitted, bool p_enabled)
        {
            GenericMenuElementData v_element = null;

            if (p_pathSplitted.Count > 0)
            {
                var v_currentName = p_pathSplitted[0];
                //Dont accept empty names
                if (string.IsNullOrEmpty(v_currentName))
                {
                    return(null);
                }
                //Try Find or create element using recursion interating over hierarchy
                else
                {
                    //Remove path to try finalize recursion
                    p_pathSplitted.RemoveAt(0);

                    //Create item if does not exists, or get it
                    if (p_pathSplitted.Count == 0)
                    {
                        //v_element = GetItemAtSubPath(v_currentName);
                        //Create Element if not found in hierarchy
                        if (v_element == null)
                        {
                            v_element            = new GenericMenuElementData();
                            v_element.m_name     = v_currentName;
                            v_element.m_isFolder = false;
                            this.Add(v_element);
                        }
                    }
                    //Check in Sub-folders (create if does not exists)
                    else
                    {
                        var v_folder = GetElementInfoAtSubPath_Internal(new List <string>()
                        {
                            v_currentName
                        }, true, false);
                        if (v_folder == null)
                        {
                            v_folder            = new GenericMenuElementData();
                            v_folder.m_name     = v_currentName;
                            v_folder.m_isFolder = true;
                            this.Add(v_folder);
                        }
                        v_element = v_folder.AddItemAtSubPath_Internal(p_pathSplitted, p_enabled);
                    }
                }
            }
            if (v_element != null)
            {
                v_element.Enabled = p_enabled;
            }
            return(v_element);
        }
        public GenericMenuElementData GetElementById(int p_id)
        {
            TryFixCachedElements();
            GenericMenuElementData v_element = null;

            if (p_id < 0 || !_cachedElementsDict.TryGetValue(p_id, out v_element))
            {
                v_element = null;
            }
            return(v_element);
        }
        public virtual GenericMenuElementData this[int i]
        {
            get
            {
                TryFixCachedElements();
                GenericMenuElementData v_element = null;
                _cachedElementsDict.TryGetValue(m_rootElementIds[i], out v_element);

                return(v_element);
            }
        }
 //Called by childrens
 protected internal bool AddAndCacheElement_Internal(GenericMenuElementData p_element)
 {
     TryFixCachedElements();
     if (p_element != null && !_cachedElementsDict.ContainsKey(p_element.Id))
     {
         p_element.Root = this;
         m_cachedElements.Add(p_element);
         _cachedElementsDict[p_element.Id] = p_element;
         return(true);
     }
     return(false);
 }
        protected virtual GenericMenuElementData AddItem_Internal(List <string> p_splittedPath, bool p_enabled)
        {
            var v_currentName = p_splittedPath.Count > 0 ? p_splittedPath[0] : null;

            if (p_splittedPath.Count > 0)
            {
                p_splittedPath.RemoveAt(0);
            }

            GenericMenuElementData v_includedElement = null;

            //Add in Hierarchy
            if (p_splittedPath.Count > 0)
            {
                GenericMenuElementData v_parentWithName = null;
                foreach (var v_element in this)
                {
                    if (v_element.Name == v_currentName && v_element.IsFolder)
                    {
                        v_parentWithName = v_element;
                        break;
                    }
                }
                if (v_parentWithName == null)
                {
                    v_parentWithName          = new GenericMenuElementData();
                    v_parentWithName.Name     = v_currentName;
                    v_parentWithName.IsFolder = true;
                    v_parentWithName.Enabled  = true;
                    if (AddAndCacheElement_Internal(v_parentWithName))
                    {
                        //Add in Root (is a Folder in Root)
                        m_rootElementIds.Add(v_parentWithName.Id);
                    }
                }
                v_includedElement = v_parentWithName.AddItemAtSubPath_Internal(p_splittedPath, p_enabled);
            }
            //Create in Root Elements
            else if (p_splittedPath.Count == 0)
            {
                v_includedElement          = new GenericMenuElementData();
                v_includedElement.Name     = v_currentName;
                v_includedElement.IsFolder = false;
                v_includedElement.Enabled  = p_enabled;
                if (AddAndCacheElement_Internal(v_includedElement))
                {
                    //Add in Root (is an item in Root)
                    m_rootElementIds.Add(v_includedElement.Id);
                }
            }
            return(v_includedElement);
        }
 public virtual bool Add(GenericMenuElementData p_itemInfo)
 {
     if (p_itemInfo != null && m_root != null)
     {
         if (!m_childIds.Contains(p_itemInfo.Id))
         {
             m_childIds.Add(p_itemInfo.Id);
         }
         p_itemInfo.m_parentId = this.Id;
         return(m_root.AddAndCacheElement_Internal(p_itemInfo));
     }
     return(false);
 }
        protected GenericMenuElementData[] GetCurrentExpandedList()
        {
            if (_cachedItems == null)
            {
                _cachedItems = RootData.GetNonFolderElements();
            }

            GenericMenuElementData[] v_list   = null;
            GenericMenuElementData   v_parent = GetCurrentSelectedFolder();

            if (v_parent != null)
            {
                v_list = v_parent.GetChildren();
            }
            else
            {
                v_list = RootData.GetRootElements();
            }

            return(v_list);
        }
        protected internal virtual GenericMenuElementData GetElementInfoAtSubPath_Internal(List <string> p_pathSplitted, bool p_acceptFolder, bool p_acceptFiles)
        {
            if ((!p_acceptFiles && !p_acceptFolder) ||
                p_pathSplitted == null ||
                p_pathSplitted.Count == 0)
            {
                return(null);
            }

            GenericMenuElementData v_itemFound = null;

            foreach (var v_child in this)
            {
                //We found a possible child
                if (v_child.Name == p_pathSplitted[0])
                {
                    //Last Path to Search
                    if (p_pathSplitted.Count <= 1)
                    {
                        //Must be same type of searching
                        if (v_child.IsFolder == p_acceptFolder || !v_child.IsFolder == p_acceptFiles)
                        {
                            p_pathSplitted.RemoveAt(0);
                            v_itemFound = v_child;
                            break;
                        }
                    }
                    //Enter inside folder if paths need continue interaction
                    else if (v_child.IsFolder)
                    {
                        p_pathSplitted.RemoveAt(0);
                        v_itemFound = v_child.GetElementInfoAtSubPath_Internal(p_pathSplitted, p_acceptFolder, p_acceptFiles);
                        break;
                    }
                }
            }
            return(v_itemFound);
        }
 public virtual bool Contains(GenericMenuElementData p_item)
 {
     return(p_item != null?m_childIds.Contains(p_item.Id) : false);
 }
 public int IndexOf(GenericMenuElementData p_item)
 {
     return(p_item != null?m_childIds.IndexOf(p_item.Id) : -1);
 }
        public bool Remove(GenericMenuElementData p_item)
        {
            var v_index = IndexOf(p_item);

            return(RemoveAt(v_index));
        }