Example #1
0
        //public int GetTextsToRoot()
        //{
        //    foreach (var child in ChildItems)
        //        if (child.HasData)
        //            return 1;
        //        else
        //            return child.GetTextsToRoot()
        //    return this.ParentItem.GetTextsToRoot().Append(this.Text);
        //}


        public ModelTreeItem VirtualizeChildrenByTextPrefix(string virtualNodeText, string textPrefix)
        {
            var           selectedChildren = ChildItems.Where(c => c.Text.StartsWith(textPrefix)).ToArray();
            ModelTreeItem newNode          = new ModelTreeItem(this.Level + 1, virtualNodeText, imageFunc: this._ImageFunc)
            {
                IsVirtual = true, ParentItem = this
            };

            if (!selectedChildren.Any())
            {
                return(newNode);
            }

            //int oldIndexInChildItems = this.ChildItems.IndexOf(selectedChildren.First());

            foreach (var selectedChild in selectedChildren)
            {
                ChildItems.Remove(selectedChild);
                selectedChild.ParentItem = newNode;
                selectedChild.IncreaseLevelRecursive(1);
                newNode.ChildItems.Add(selectedChild);
            }

            //this.ChildItems.Insert(oldIndexInChildItems, newNode);
            this.ChildItems.Add(newNode);
            return(newNode);
        }
Example #2
0
        public BurgerMenuItem GetChildItemByKey(string key)
        {
            IEnumerable <BurgerMenuItem> matchingChildren = ChildItems.Where(bmi => bmi.Key.EndsWith(key));

            if (matchingChildren.Any())
            {
                return(matchingChildren.First());
            }
            else
            {
                return(null);
            }
        }
Example #3
0
        private async void DeleteButton_Clicked(object sender, EventArgs e)
        {
            var btn            = sender as IconButton;
            var deleteItemArgs = new DeleteItemEventArgs()
            {
                Id   = btn.Tag as String,
                Type = Field.Name.ToPropertyName()
            };

            var obj = ChildItems as Object;

            if (obj is System.Collections.IList)
            {
                if (await SLWIOC.Get <LagoVista.Core.PlatformSupport.IPopupServices>().ConfirmAsync(XPlatResources.Msg_ConfirmDeleteItemTitle, XPlatResources.Msg_ConfirmDeleteItem))
                {
                    var childList       = ChildItems as System.Collections.IList;
                    var itemToBeDeleted = ChildItems.Where(itm => itm.ToEntityHeader().Id == btn.Tag as string).FirstOrDefault();
                    childList.Remove(itemToBeDeleted);
                    Deleted?.Invoke(sender, deleteItemArgs);
                    Refresh();
                }
            }
        }
Example #4
0
        public void GenerateCollectionsRecursive()
        {
            List <ModelTreeItem> newNodes = new List <ModelTreeItem>();

            {
                // Identify collections by separator characters.
                var collectionGroups = ChildItems.GroupBy(c =>
                {
                    int indexOfSeparator = c.Text.IndexOfAny(_CollectionSeparators);
                    if (indexOfSeparator > 0)
                    {
                        return(c.Text.Substring(0, indexOfSeparator));
                    }
                    return(string.Empty);
                });

                foreach (var group in collectionGroups)
                {
                    if (group.Count() > 1 && group.Key != string.Empty)
                    {
                        // Locate the full collection name within the items text.
                        int originalSeparatorIndex = group.Key.Length;
                        int refinedSeparatorIndex  = originalSeparatorIndex;

                        while (true)
                        {
                            if (group.First().Text.Length < refinedSeparatorIndex)
                            {
                                break;
                            }
                            int newSeparatorIndex = group.First().Text.IndexOfAny(_CollectionSeparators, refinedSeparatorIndex + 1);
                            if (newSeparatorIndex > refinedSeparatorIndex)
                            {
                                string newPrefix = group.First().Text.Substring(0, newSeparatorIndex);
                                if (group.Any(t => t.Text.Length < newSeparatorIndex || t.Text.Substring(0, newSeparatorIndex) != newPrefix))
                                {
                                    break;
                                }
                                refinedSeparatorIndex = newSeparatorIndex;
                            }
                            else
                            {
                                break;
                            }
                        }
                        string newCollectionKey = originalSeparatorIndex != refinedSeparatorIndex?group.First().Text.Substring(0, refinedSeparatorIndex) : group.Key;

                        // Virtualize collection, except if the name matches with this node.
                        if (this.Text != newCollectionKey)
                        {
                            newNodes.Add(this.VirtualizeChildrenByTextPrefix(newCollectionKey, newCollectionKey));
                        }
                    }
                }
            }

            foreach (var child in ChildItems.Where(c => !newNodes.Contains(c)))
            {
                child.GenerateCollectionsRecursive();
            }
        }