void MonoDevelop.DesignerSupport.IOutlinedDocument.ReleaseOutlineWidget()
        {
            if (outlineTreeView == null)
            {
                return;
            }
            var w = (ScrolledWindow)outlineTreeView.Parent;

            w.Destroy();
            if (outlineTreeModelSort != null)
            {
                outlineTreeModelSort.Dispose();
                outlineTreeModelSort = null;
            }
            if (outlineTreeStore != null)
            {
                outlineTreeStore.Dispose();
                outlineTreeStore = null;
            }
            outlineTreeView = null;
            settings        = null;
            foreach (var tw in toolbarWidgets)
            {
                tw.Destroy();
            }
            toolbarWidgets = null;
            comparer       = null;
        }
        Widget MonoDevelop.DesignerSupport.IOutlinedDocument.GetOutlineWidget()
        {
            if (outlineTreeView != null)
            {
                return(outlineTreeView);
            }

            outlineTreeStore     = new TreeStore(typeof(object));
            outlineTreeModelSort = new TreeModelSort(outlineTreeStore);

            settings = ClassOutlineSettings.Load();
            comparer = new ClassOutlineNodeComparer(GetAmbience(), settings, outlineTreeModelSort);

            outlineTreeModelSort.SetSortFunc(0, comparer.CompareNodes);
            outlineTreeModelSort.SetSortColumnId(0, SortType.Ascending);

            outlineTreeView = new MonoDevelop.Ide.Gui.Components.PadTreeView(outlineTreeStore);

            var pixRenderer = new CellRendererImage();

            pixRenderer.Xpad = 0;
            pixRenderer.Ypad = 0;

            outlineTreeView.TextRenderer.Xpad = 0;
            outlineTreeView.TextRenderer.Ypad = 0;

            TreeViewColumn treeCol = new TreeViewColumn();

            treeCol.PackStart(pixRenderer, false);

            treeCol.SetCellDataFunc(pixRenderer, new TreeCellDataFunc(OutlineTreeIconFunc));
            treeCol.PackStart(outlineTreeView.TextRenderer, true);

            treeCol.SetCellDataFunc(outlineTreeView.TextRenderer, new TreeCellDataFunc(OutlineTreeTextFunc));
            outlineTreeView.AppendColumn(treeCol);

            outlineTreeView.HeadersVisible = false;

            outlineTreeView.Selection.Changed += delegate {
                JumpToDeclaration(false);
            };

            outlineTreeView.RowActivated += delegate {
                JumpToDeclaration(true);
            };

            this.lastCU = Document.ParsedDocument;

            outlineTreeView.Realized += delegate { RefillOutlineStore(); };
            UpdateSorting();

            var sw = new CompactScrolledWindow();

            sw.Add(outlineTreeView);
            sw.ShowAll();
            return(sw);
        }
 public override void Dispose()
 {
     if (disposed)
     {
         return;
     }
     disposed = true;
     if (Document != null)
     {
         Document.DocumentParsed -= UpdateDocumentOutline;
     }
     RemoveRefillOutlineStoreTimeout();
     lastCU   = null;
     settings = null;
     comparer = null;
     base.Dispose();
 }
        static void AddTreeClassContents(TreeStore store, TreeIter parent, ParsedDocument parsedDocument, ITypeDefinition cls, IUnresolvedTypeDefinition part)
        {
            List <object> items = new List <object> ();

            if (cls.Kind != TypeKind.Delegate)
            {
                foreach (var o in cls.GetMembers(m => part.Region.FileName == m.Region.FileName && part.Region.IsInside(m.Region.Begin)))
                {
                    items.Add(o);
                }
                foreach (var o in cls.GetNestedTypes(m => part.Region.FileName == m.Region.FileName && part.Region.IsInside(m.Region.Begin)))
                {
                    if (o.DeclaringType == cls)
                    {
                        items.Add(o);
                    }
                }
                foreach (var o in cls.GetConstructors(m => part.Region.FileName == m.Region.FileName && part.Region.IsInside(m.Region.Begin)))
                {
                    if (o.IsSynthetic)
                    {
                        continue;
                    }
                    items.Add(o);
                }
            }
            items.Sort(ClassOutlineNodeComparer.CompareRegion);
            List <FoldingRegion> regions = new List <FoldingRegion> ();

            foreach (FoldingRegion fr in parsedDocument.UserRegions)
            {
                //check regions inside class
                if (cls.BodyRegion.IsInside(fr.Region.Begin) && cls.BodyRegion.IsInside(fr.Region.End))
                {
                    regions.Add(fr);
                }
            }
            regions.Sort(delegate(FoldingRegion x, FoldingRegion y) { return(x.Region.Begin.CompareTo(y.Region.Begin)); });

            IEnumerator <FoldingRegion> regionEnumerator = regions.GetEnumerator();

            if (!regionEnumerator.MoveNext())
            {
                regionEnumerator = null;
            }

            FoldingRegion currentRegion = null;
            TreeIter      currentParent = parent;

            foreach (object item in items)
            {
                //no regions left; quick exit
                if (regionEnumerator != null)
                {
                    DomRegion itemRegion = ClassOutlineNodeComparer.GetRegion(item);

                    //advance to a region that could potentially contain this member
                    while (regionEnumerator != null && !OuterEndsAfterInner(regionEnumerator.Current.Region, itemRegion))
                    {
                        if (!regionEnumerator.MoveNext())
                        {
                            regionEnumerator = null;
                        }
                    }

                    //if member is within region, make sure it's the current parent.
                    //If not, move target iter back to class parent
                    if (regionEnumerator != null && regionEnumerator.Current.Region.IsInside(itemRegion.Begin))
                    {
                        if (currentRegion != regionEnumerator.Current)
                        {
                            currentParent = store.AppendValues(parent, regionEnumerator.Current);
                            currentRegion = regionEnumerator.Current;
                        }
                    }
                    else
                    {
                        currentParent = parent;
                    }
                }

                TreeIter childIter = store.AppendValues(currentParent, item);
                if (item is ITypeDefinition)
                {
                    AddTreeClassContents(store, childIter, parsedDocument, (ITypeDefinition)item, part);
                }
            }
        }
        IEnumerable <Widget> MonoDevelop.DesignerSupport.IOutlinedDocument.GetToolbarWidgets()
        {
            if (toolbarWidgets != null)
            {
                return(toolbarWidgets);
            }

            var groupToggleButton = new ToggleButton()
            {
                Image       = new Image(Ide.Gui.Stock.GroupByCategory, IconSize.Menu),
                TooltipText = GettextCatalog.GetString("Group entries by type"),
                Active      = settings.IsGrouped,
            };

            groupToggleButton.Toggled += delegate {
                if (groupToggleButton.Active == settings.IsGrouped)
                {
                    return;
                }
                settings.IsGrouped = groupToggleButton.Active;
                UpdateSorting();
            };

            var sortAlphabeticallyToggleButton = new ToggleButton()
            {
                Image       = new Image(Ide.Gui.Stock.SortAlphabetically, IconSize.Menu),
                TooltipText = GettextCatalog.GetString("Sort entries alphabetically"),
                Active      = settings.IsSorted,
            };

            sortAlphabeticallyToggleButton.Toggled += delegate {
                if (sortAlphabeticallyToggleButton.Active == settings.IsSorted)
                {
                    return;
                }
                settings.IsSorted = sortAlphabeticallyToggleButton.Active;
                UpdateSorting();
            };

            var preferencesButton = new DockToolButton(Ide.Gui.Stock.Options)
            {
                TooltipText = GettextCatalog.GetString("Open preferences dialog"),
            };

            preferencesButton.Clicked += delegate {
                using (var dialog = new ClassOutlineSortingPreferencesDialog(settings)) {
                    if (MonoDevelop.Ide.MessageService.ShowCustomDialog(dialog) == (int)Gtk.ResponseType.Ok)
                    {
                        dialog.SaveSettings();
                        comparer = new ClassOutlineNodeComparer(GetAmbience(), settings, outlineTreeModelSort);
                        UpdateSorting();
                    }
                }
            };

            return(toolbarWidgets = new Widget[] {
                groupToggleButton,
                sortAlphabeticallyToggleButton,
                new VSeparator(),
                preferencesButton,
            });
        }