예제 #1
0
        public bool InsertMenuItemAt(AdminNode menuItemToInsert, AdminNode destinationMenuItem, int position)
        {
            if (menuItemToInsert == null)
            {
                throw new ArgumentNullException("menuItemToInsert");
            }

            // insert the node at the destination node
            if (destinationMenuItem == null)
            {
                MenuItems.Insert(position, menuItemToInsert);
                return(true); // success
            }
            else
            {
                foreach (var firstLevelMenuItem in MenuItems)
                {
                    if (firstLevelMenuItem.InsertMenuItem(menuItemToInsert, destinationMenuItem, position))
                    {
                        return(true); // success
                    }
                }
            }
            return(false); // failure
        }
예제 #2
0
        public bool RemoveMenuItem(AdminNode itemToRemove)
        {
            if (MenuItems.Contains(itemToRemove)) // todo: avoid this check by having a single TreeNode as a property of the content tree preset.
            {
                MenuItems.Remove(itemToRemove);
                return(true); // success
            }
            else
            {
                foreach (var firstLevelMenuItem in MenuItems)
                {
                    if (firstLevelMenuItem.RemoveMenuItem(itemToRemove))
                    {
                        return(true); // success
                    }
                }
            }

            return(false); // failure
        }
예제 #3
0
        public AdminNode GetMenuItemById(string id)
        {
            var tempStack = new Stack <AdminNode>(new AdminNode[] { this });

            while (tempStack.Any())
            {
                // evaluate first node
                AdminNode item = tempStack.Pop();
                if (item.UniqueId.Equals(id, StringComparison.OrdinalIgnoreCase))
                {
                    return(item);
                }

                // not that one; continue with the rest.
                foreach (var i in item.Items)
                {
                    tempStack.Push((AdminNode)i);
                }
            }

            //not found
            return(null);
        }
예제 #4
0
        public bool InsertMenuItem(AdminNode nodeToInsert, MenuItem destinationNode, int position)
        {
            var tempStack = new Stack <AdminNode>(new AdminNode[] { this });

            while (tempStack.Any())
            {
                // evaluate first
                MenuItem node = tempStack.Pop();
                if (node.Equals(destinationNode))
                {
                    node.Items.Insert(position, nodeToInsert);
                    return(true); // success
                }

                // not that one. continue
                foreach (var n in node.Items)
                {
                    tempStack.Push((AdminNode)n);
                }
            }

            // failure
            return(false);
        }
예제 #5
0
        // return boolean so that caller can check for success
        public bool RemoveMenuItem(AdminNode nodeToRemove)
        {
            var tempStack = new Stack <AdminNode>(new AdminNode[] { this });

            while (tempStack.Any())
            {
                // evaluate first
                MenuItem item = tempStack.Pop();
                if (item.Items.Contains(nodeToRemove))
                {
                    item.Items.Remove(nodeToRemove);
                    return(true); //success
                }

                // not that one. continue
                foreach (var i in item.Items)
                {
                    tempStack.Push((AdminNode)i);
                }
            }

            // failure
            return(false);
        }