Exemplo n.º 1
0
        void UpdateRegionCombo(int line, int column)
        {
            if (parsedDocument == null)
            {
                return;
            }
            bool hasRegions = parsedDocument.UserRegions.Any();

            regionCombo.Sensitive = hasRegions;
            FoldingRegion region = hasRegions ? parsedDocument.UserRegions.Where(r => r.Region.Contains(line, column)).LastOrDefault() : null;

            if (regionCombo.CurrentItem == region)
            {
                return;
            }
            if (region == null)
            {
                regionCombo.SetItem("", null, null);
            }
            else
            {
                regionCombo.SetItem(region.Name,                  //GettextCatalog.GetString ("Region {0}", region.Name),
                                    ImageService.GetPixbuf(Gtk.Stock.Add, IconSize.Menu),
                                    region);
            }
            UpdateRegionComboTip(region);
        }
Exemplo n.º 2
0
        async static Task <PathEntry> GetRegionEntry(ParsedDocument unit, DocumentLocation loc)
        {
            PathEntry     entry;
            FoldingRegion reg = null;

            try {
                if (unit != null)
                {
                    var regions = await unit.GetUserRegionsAsync().ConfigureAwait(false);

                    if (!regions.Any())
                    {
                        return(null);
                    }
                    reg = regions.LastOrDefault(r => r.Region.Contains(loc));
                }
            } catch (AggregateException) {
                return(null);
            } catch (OperationCanceledException) {
                return(null);
            }
            if (reg == null)
            {
                entry = new PathEntry(GettextCatalog.GetString("No region"));
            }
            else
            {
                var pixbuf = await Runtime.RunInMainThread(() => CompilationUnitDataProvider.Pixbuf).ConfigureAwait(false);

                entry = new PathEntry(pixbuf, GLib.Markup.EscapeText(reg.Name));
            }
            entry.Position = EntryPosition.Right;
            return(entry);
        }
Exemplo n.º 3
0
        List <FoldingRegion> CreateTestFoldingRegionList()
        {
            FoldingRegion        fold  = CreateTestFoldingRegion();
            List <FoldingRegion> folds = new List <FoldingRegion>();

            folds.Add(fold);
            return(folds);
        }
        public override IEnumerable <FoldingRegion> GenerateFolds()
        {
            if (XDocument == null)
            {
                yield break;
            }

            foreach (XNode node in XDocument.AllDescendentNodes)
            {
                if (node is XCData)
                {
                    if (node.Region.End.Line - node.Region.Start.Line > 2)
                    {
                        yield return(new FoldingRegion("<![CDATA[ ]]>", node.Region));
                    }
                }
                else if (node is XComment)
                {
                    if (node.Region.End.Line - node.Region.Start.Line > 2)
                    {
                        yield return(new FoldingRegion("<!-- -->", node.Region));
                    }
                }
                else if (node is XElement)
                {
                    XElement el = (XElement)node;
                    if (el.IsClosed && el.ClosingTag.Region.End.Line - el.Region.Start.Line > 2)
                    {
                        yield return(new FoldingRegion
                                         (string.Format("<{0}...>", el.Name.FullName),
                                         new DomRegion(el.Region.Start, el.ClosingTag.Region.End)));
                    }
                }
                else if (node is XDocType)
                {
                    XDocType dt = (XDocType)node;
                    string   id = !String.IsNullOrEmpty(dt.PublicFpi) ? dt.PublicFpi
                                                : !String.IsNullOrEmpty(dt.Uri) ? dt.Uri : null;

                    if (id != null && dt.Region.End.Line - dt.Region.Start.Line > 2)
                    {
                        if (id.Length > 50)
                        {
                            id = id.Substring(0, 47) + "...";
                        }

                        FoldingRegion fr = new FoldingRegion(string.Format("<!DOCTYPE {0}>", id), dt.Region);
                        fr.IsFoldedByDefault = true;
                        yield return(fr);
                    }
                }
            }
        }
Exemplo n.º 5
0
        void RegionChanged(object sender, EventArgs e)
        {
            if (loadingMembers || regionCombo.CurrentItem == null)
            {
                return;
            }

            FoldingRegion selectedRegion = (FoldingRegion)this.regionCombo.CurrentItem;

            // If we can, we navigate to the line location of the IMember.
            int line = Math.Max(1, selectedRegion.Region.Start.Line);

            JumpTo(Math.Max(1, line), 1);
        }
        //
        // -----------------------------------------------------
        // Borrowed from ParsedDocument and overridden
        // -----------------------------------------------------
        //

        public override IEnumerable <FoldingRegion> GenerateFolds()
        {
            foreach (FoldingRegion fold in AdditionalFolds)
            {
                yield return(fold);
            }

            foreach (FoldingRegion fold in ConditionalRegions.ToFolds())
            {
                yield return(fold);
            }

            IEnumerable <FoldingRegion> commentFolds = Comments.ToPythonFolds();

            if (CompilationUnit != null && CompilationUnit.Types != null && CompilationUnit.Types.Count > 0)
            {
                commentFolds = commentFolds.FlagIfInsideMembers(CompilationUnit.Types, delegate(FoldingRegion f) {
                    f.Type = FoldType.CommentInsideMember;
                });
            }
            foreach (FoldingRegion fold in commentFolds)
            {
                yield return(fold);
            }

            if (CompilationUnit == null)
            {
                yield break;
            }

            FoldingRegion usingFold = CompilationUnit.Usings.ToFold();

            if (usingFold != null)
            {
                yield return(usingFold);
            }

            foreach (FoldingRegion fold in CompilationUnit.Types.ToFolds())
            {
                yield return(fold);
            }

            PythonCompilationUnit pyUnit = CompilationUnit as PythonCompilationUnit;

            foreach (IMember m in pyUnit.Members)
            {
                var fold = new FoldingRegion(m.Name, m.BodyRegion, FoldType.Member);
                yield return(fold);
            }
        }
Exemplo n.º 7
0
        public void GetFolds_FakeXmlFoldParserUsed_ReturnsFoldsFromFakeXmlFoldParser()
        {
            CreateXmlFoldingManager();
            FoldingRegion fold = CreateFoldingRegion();

            fakeXmlFoldParser.Folds.Add(fold);

            MockDocument expectedSnapshot = new MockDocument();

            fakeTextEditor.MockDocument.SetSnapshot(expectedSnapshot);

            ITextBuffer snapshot = xmlFoldingManager.CreateTextEditorSnapshot();

            IList <FoldingRegion> folds = xmlFoldingManager.GetFolds(snapshot);

            Assert.AreEqual(fakeXmlFoldParser.Folds, folds);
        }
Exemplo n.º 8
0
        public void UpdateFolds_NoParameterPassedToMethod_SnapshotPassedToXmlFoldParser()
        {
            CreateXmlFoldingManager();
            AddDocumentPositionToOffsetReturnValue(5);
            AddDocumentPositionToOffsetReturnValue(10);

            MockDocument expectedSnapshot = new MockDocument();

            fakeTextEditor.MockDocument.SetSnapshot(expectedSnapshot);

            FoldingRegion fold = CreateTestFoldingRegion();

            fakeXmlFoldParser.Folds.Add(fold);

            xmlFoldingManager.UpdateFolds();

            Assert.AreEqual(expectedSnapshot, fakeXmlFoldParser.TextBufferPassedToGetFolds);
        }
Exemplo n.º 9
0
        void AddRegion(string name, ILocation startLocation, ILocation endLocation)
        {
            DomRegion region;

            if (endLocation == null)
            {
                region = new DomRegion(startLocation.BeginLine, startLocation.BeginColumn,
                                       startLocation.EndLine, startLocation.EndColumn);
            }
            else
            {
                region = new DomRegion(startLocation.BeginLine, startLocation.BeginColumn,
                                       endLocation.EndLine, endLocation.EndColumn);
            }

            FoldingRegion f = new FoldingRegion(name, region);

            regions.Add(f);
        }
Exemplo n.º 10
0
        public void UpdateFolds_NoParameterPassedToMethod_FakeXmlFoldParserFoldsUsedToUpdateFakeFoldingManager()
        {
            CreateXmlFoldingManager();
            AddDocumentPositionToOffsetReturnValue(5);
            AddDocumentPositionToOffsetReturnValue(10);

            MockDocument expectedSnapshot = new MockDocument();

            fakeTextEditor.MockDocument.SetSnapshot(expectedSnapshot);

            FoldingRegion fold = CreateTestFoldingRegion();

            fakeXmlFoldParser.Folds.Add(fold);

            xmlFoldingManager.UpdateFolds();

            IList <NewFolding> newFolds = fakeFoldingManager.NewFoldsPassedToUpdateFoldings;

            List <NewFolding> expectedFolds = CreateTestNewFoldingList();

            NewFoldingHelper.AssertAreEqual(expectedFolds, newFolds);
        }
Exemplo n.º 11
0
        static void AddTreeClassContents(TreeStore store, TreeIter parent, ParsedDocument parsedDocument, IType cls)
        {
            List <object> items = new List <object> ();

            foreach (object o in cls.Members)
            {
                items.Add(o);
            }

            items.Sort(delegate(object x, object y) {
                DomRegion r1 = GetRegion(x), r2 = GetRegion(y);
                return(r1.CompareTo(r2));
            });

            List <FoldingRegion> regions = new List <FoldingRegion> ();

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

            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 = 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.Contains(itemRegion))
                    {
                        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 IType)
                {
                    AddTreeClassContents(store, childIter, parsedDocument, (IType)item);
                }
            }
        }
        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);
                }
            }
        }
        public void AddRegion(IList <FoldingRegion> foldingRegions)
        {
            FoldingRegion namedFoldingRegion = CreateFoldingRegion();

            foldingRegions.Add(namedFoldingRegion);
        }
Exemplo n.º 14
0
        // Yoinked from C# binding
        void UpdatePath(object sender, Mono.TextEditor.DocumentLocationEventArgs e)
        {
            var unit           = Document.CompilationUnit;
            var textEditorData = Document.Editor;

            if (unit == null)
            {
                return;
            }

            var              loc    = textEditorData.Caret.Location;
            IType            type   = unit.GetTypeAt(loc.Line, loc.Column);
            List <PathEntry> result = new List <PathEntry> ();
            Ambience         amb    = GetAmbience();
            IMember          member = null;
            INode            node   = (INode)unit;

            if (type != null && type.ClassType != ClassType.Delegate)
            {
                member = type.GetMemberAt(loc.Line, loc.Column);
            }

            if (null != member)
            {
                node = member;
            }
            else if (null != type)
            {
                node = type;
            }

            while (node != null)
            {
                PathEntry entry;
                if (node is ICompilationUnit)
                {
                    if (!Document.ParsedDocument.UserRegions.Any())
                    {
                        break;
                    }
                    FoldingRegion reg = Document.ParsedDocument.UserRegions.LastOrDefault(r => r.Region.Contains(loc.Line, loc.Column));
                    if (reg == null)
                    {
                        entry = new PathEntry(GettextCatalog.GetString("No region"));
                    }
                    else
                    {
                        entry = new PathEntry(CompilationUnitDataProvider.Pixbuf, reg.Name);
                    }
                    entry.Position = EntryPosition.Right;
                }
                else
                {
                    entry = new PathEntry(ImageService.GetPixbuf(((IMember)node).StockIcon, Gtk.IconSize.Menu), amb.GetString((IMember)node, OutputFlags.IncludeGenerics | OutputFlags.IncludeParameters | OutputFlags.ReformatDelegates));
                }
                entry.Tag = node;
                result.Insert(0, entry);
                node = node.Parent;
            }

            PathEntry noSelection = null;

            if (type == null)
            {
                noSelection = new PathEntry(GettextCatalog.GetString("No selection"))
                {
                    Tag = new CustomNode(Document.CompilationUnit)
                };
            }
            else if (member == null && type.ClassType != ClassType.Delegate)
            {
                noSelection = new PathEntry(GettextCatalog.GetString("No selection"))
                {
                    Tag = new CustomNode(type)
                }
            }
            ;
            if (noSelection != null)
            {
                result.Add(noSelection);
            }

            var prev = CurrentPath;

            CurrentPath = result.ToArray();
            OnPathChanged(this, new DocumentPathChangedEventArgs(prev));
        }
Exemplo n.º 15
0
		int CompareFoldingRegion(FoldingRegion lhs, FoldingRegion rhs)
		{
			int compareBeginLine = lhs.Region.BeginLine.CompareTo(rhs.Region.BeginLine);
			if (compareBeginLine == 0) {
				return lhs.Region.BeginColumn.CompareTo(rhs.Region.BeginColumn);
			}
			return compareBeginLine;
		}
Exemplo n.º 16
0
		NewFolding ConvertToNewFold(FoldingRegion foldingRegion)
		{
			NewFolding newFold = new NewFolding();
			
			newFold.Name = foldingRegion.Name;
			newFold.StartOffset = GetStartOffset(foldingRegion.Region);
			newFold.EndOffset = GetEndOffset(foldingRegion.Region);
			
			return newFold;
		}
Exemplo n.º 17
0
 void UpdateRegionComboTip(FoldingRegion region)
 {
     regionCombo.TooltipText = region != null?GettextCatalog.GetString("Region {0}", region.Name) : GettextCatalog.GetString("Region list");
 }