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(); }
/// <summary> /// Event on format cell /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private static void FastOlvOnFormatCell(object sender, FormatCellEventArgs args) { CodeExplorerItem obj = (CodeExplorerItem)args.Model; var curScope = ParserHandler.GetScopeOfLine(Npp.Line.CurrentLine); // currently selected block if (curScope != null && !obj.IsNotBlock && obj.DisplayText.Equals(curScope.Name)) { RowBorderDecoration rbd = new RowBorderDecoration { FillBrush = new SolidBrush(Color.FromArgb(50, ThemeManager.Current.MenuFocusedBack)), BorderPen = new Pen(Color.FromArgb(128, ThemeManager.Current.MenuFocusedBack.IsColorDark() ? ControlPaint.Light(ThemeManager.Current.MenuFocusedBack, 0.10f) : ControlPaint.Dark(ThemeManager.Current.MenuFocusedBack, 0.10f)), 1), BoundsPadding = new Size(-2, 0), CornerRounding = 6.0f }; args.SubItem.Decoration = rbd; } // display the flags int offset = -5; obj.DoForEachFlag((name, flag) => { Image tryImg = (Image)ImageResources.ResourceManager.GetObject(name); if (tryImg != null) { ImageDecoration decoration = new ImageDecoration(tryImg, 100, ContentAlignment.MiddleRight) { Offset = new Size(offset, 0) }; if (args.SubItem.Decoration == null) { args.SubItem.Decoration = decoration; } else { args.SubItem.Decorations.Add(decoration); } offset -= 20; } }); // display the sub string if (offset < -5) { offset -= 5; } if (!string.IsNullOrEmpty(obj.SubString)) { TextDecoration decoration = new TextDecoration(obj.SubString, 100) { Alignment = ContentAlignment.MiddleRight, Offset = new Size(offset, 0), Font = FontManager.GetFont(FontStyle.Bold, 10), TextColor = ThemeManager.Current.SubTextFore, CornerRounding = 1f, Rotation = 0, BorderWidth = 1, BorderColor = ThemeManager.Current.SubTextFore }; args.SubItem.Decorations.Add(decoration); } }