Example #1
0
 private CodeExplorerFlag AddExternalFlag(CodeExplorerFlag flag)
 {
     if (_isBaseFile)
     {
         return(flag);
     }
     return(flag | CodeExplorerFlag.External);
 }
Example #2
0
 /// <summary>
 /// Apply an action for each flag of the item
 /// </summary>
 /// <param name="toApplyOnFlag"></param>
 public void DoForEachFlag(Action <string, CodeExplorerFlag> toApplyOnFlag)
 {
     foreach (var name in Enum.GetNames(typeof(CodeExplorerFlag)))
     {
         CodeExplorerFlag flag = (CodeExplorerFlag)Enum.Parse(typeof(CodeExplorerFlag), name);
         if (flag == 0 || !Flag.HasFlag(flag))
         {
             continue;
         }
         toApplyOnFlag(name, flag);
     }
 }
Example #3
0
        private void UpdateTreeDataAction()
        {
            // get the list of items
            var tempList = ParserHandler.ParserVisitor.ParsedExplorerItemsList.ToList();

            if (tempList.Count == 0)
            {
                return;
            }

            _initialObjectsList = new List <CodeExplorerItem>();

            if (Config.Instance.CodeExplorerSortingType != SortingType.Unsorted)
            {
                // we built the tree "manually"
                tempList.Sort(new ExplorerObjectSortingClass(Config.Instance.CodeExplorerSortingType));

                HashSet <CodeExplorerBranch> foundBranches = new HashSet <CodeExplorerBranch>();

                // for each distinct type of items, create a branch (if the branchType is not a root item like Root or MainBlock)
                CodeExplorerItem currentLvl1Parent = null;
                var iItem = 0;
                while (iItem < tempList.Count)
                {
                    var item = tempList[iItem];

                    // add an extra item that will be a new branch
                    if (!item.IsRoot && !foundBranches.Contains(item.Branch))
                    {
                        var branchDisplayText = item.Branch.GetDescription();

                        currentLvl1Parent = new CodeExplorerItem {
                            DisplayText = branchDisplayText,
                            Branch      = item.Branch,
                            CanExpand   = true,
                            // by default, the lvl 1 branches are expanded
                            IsExpanded = (!_expandedBranches.ContainsKey(branchDisplayText) ? _isExpanded : _expandedBranches[branchDisplayText])
                        };
                        foundBranches.Add(item.Branch);
                        _initialObjectsList.Add(currentLvl1Parent);
                    }

                    // Add a child item to the current branch
                    if (foundBranches.Contains(item.Branch))
                    {
                        // For each duplicated item (same Icon and same displayText), we create a new branch
                        var iIdentical         = iItem + 1;
                        CodeExplorerFlag flags = 0;

                        // while we match identical items
                        while (iIdentical < tempList.Count &&
                               tempList[iItem].IconType == tempList[iIdentical].IconType &&
                               tempList[iItem].DisplayText.EqualsCi(tempList[iIdentical].DisplayText))
                        {
                            flags = flags | tempList[iIdentical].Flag;
                            iIdentical++;
                        }
                        // if we found identical item
                        if (iIdentical > iItem + 1)
                        {
                            // we create a branch for them
                            var currentLvl2Parent = new CodeExplorerItem {
                                DisplayText = tempList[iItem].DisplayText,
                                Branch      = tempList[iItem].Branch,
                                IconType    = tempList[iItem].IconType,
                                CanExpand   = true,
                                // by default, the lvl 2 branches are NOT expanded
                                IsExpanded = _expandedBranches.ContainsKey(tempList[iItem].DisplayText) && _expandedBranches[tempList[iItem].DisplayText],
                                Ancestors  = new List <FilteredItemTree> {
                                    currentLvl1Parent
                                },
                                SubString  = "x" + (iIdentical - iItem),
                                IsNotBlock = tempList[iItem].IsNotBlock,
                                Flag       = flags
                            };
                            _initialObjectsList.Add(currentLvl2Parent);

                            // add child items to the newly created lvl 2 branch
                            for (int i = iItem; i < iIdentical; i++)
                            {
                                tempList[i].Ancestors = new List <FilteredItemTree> {
                                    currentLvl1Parent, currentLvl2Parent
                                };
                                tempList[i].IsNotBlock = true;
                                _initialObjectsList.Add(tempList[i]);
                            }

                            // last child
                            (_initialObjectsList.LastOrDefault() ?? new CodeExplorerItem()).IsLastItem = true;

                            iItem += (iIdentical - iItem);

                            // last child of the branch
                            if (iItem >= tempList.Count - 1 || item.Branch != tempList[iItem].Branch)
                            {
                                currentLvl2Parent.IsLastItem = true;
                            }

                            continue;
                        }

                        // single item, add it normally
                        item.Ancestors = new List <FilteredItemTree> {
                            currentLvl1Parent
                        };
                        _initialObjectsList.Add(item);

                        // last child of the branch
                        if (iItem == tempList.Count - 1 || item.Branch != tempList[iItem + 1].Branch)
                        {
                            item.IsLastItem = true;
                        }
                    }
                    else
                    {
                        // add existing item as a root item
                        _initialObjectsList.Add(item);
                    }

                    iItem++;
                }

                // last branch, last item and first item
                (_initialObjectsList.FirstOrDefault() ?? new CodeExplorerItem()).IsFirstItem = true;
                (currentLvl1Parent ?? new CodeExplorerItem()).IsLastItem = true;
                (_initialObjectsList.LastOrDefault() ?? new CodeExplorerItem()).IsLastItem = true;
            }
            else
            {
                _initialObjectsList = tempList;
            }

            TotalItems = _initialObjectsList.Count;
            ApplyFilter();
        }