Ejemplo n.º 1
0
        void UpdateOutlineSelection(object sender, Mono.TextEditor.DocumentLocationEventArgs e)
        {
            if (clickedOnOutlineItem || SyntaxTree == null || TreeStore == null)
            {
                return;
            }

            IStatement stmt;

            var caretLocation  = Document.Editor.Caret.Location;
            var caretLocationD = new CodeLocation(caretLocation.Column, caretLocation.Line);

            var currentblock = DResolver.SearchBlockAt(SyntaxTree, caretLocationD, out stmt);

            INode selectedASTNode = null;

            if (currentblock == null)
            {
                return;
            }

            foreach (var n in currentblock)
            {
                if (caretLocationD >= n.Location && caretLocationD <= n.EndLocation)
                {
                    selectedASTNode = n;
                    break;
                }
            }

            // Select parameter node if needed
            if (selectedASTNode == null && currentblock is DMethod)
            {
                foreach (var n in (currentblock as DMethod).Parameters)
                {
                    if (caretLocationD >= n.Location && caretLocationD <= n.EndLocation)
                    {
                        selectedASTNode = n;
                        break;
                    }
                }
            }

            if (selectedASTNode == null)
            {
                selectedASTNode = stmt != null ? stmt.ParentNode : currentblock;
            }

            if (selectedASTNode == null)
            {
                return;
            }

            TreeStore.Foreach((TreeModel model, TreePath path, TreeIter iter) =>
            {
                var n = model.GetValue(iter, 0);
                if (n == selectedASTNode)
                {
                    dontJumpToDeclaration = true;
                    //var parentPath = path.Copy().Up();

                    TreeView.ExpandToPath(path);
                    TreeView.Selection.SelectIter(iter);
                    dontJumpToDeclaration = false;

                    return(true);
                }

                return(false);
            });
        }
Ejemplo n.º 2
0
        void UpdatePath(object sender, Mono.TextEditor.DocumentLocationEventArgs e)
        {
            var parsedDocument = Document.ParsedDocument;

            if (parsedDocument == null || parsedDocument.ParsedFile == null)
            {
                return;
            }
            amb = new AstAmbience(document.GetFormattingOptions());

            var unit = parsedDocument.GetAst <SyntaxTree> ();

            if (unit == null)
            {
                return;
            }

            var loc         = Document.Editor.Caret.Location;
            var compExt     = Document.GetContent <CSharpCompletionTextEditorExtension> ();
            var caretOffset = Document.Editor.Caret.Offset;
            var segType     = compExt.GetTypeAt(caretOffset);

            if (segType != null)
            {
                loc = segType.Region.Begin;
            }

            var curType = (EntityDeclaration)unit.GetNodeAt(loc, n => n is TypeDeclaration || n is DelegateDeclaration);

            var curProject = ownerProjects.Count > 1 ? Document.Project : null;

            var segMember = compExt.GetMemberAt(caretOffset);

            if (segMember != null)
            {
                loc = segMember.Region.Begin;
            }
            else
            {
                loc = Document.Editor.Caret.Location;
            }

            var curMember = unit.GetNodeAt <EntityDeclaration> (loc);

            if (curType == curMember || curType is DelegateDeclaration)
            {
                curMember = null;
            }
            if (isPathSet && curType == lastType && curMember == lastMember && curProject == lastProject)
            {
                return;
            }

            var curTypeMakeup   = GetEntityMarkup(curType);
            var curMemberMarkup = GetEntityMarkup(curMember);

            if (isPathSet && curType != null && lastType != null && curType.StartLocation == lastType.StartLocation && curTypeMakeup == lastTypeMarkup &&
                curMember != null && lastMember != null && curMember.StartLocation == lastMember.StartLocation && curMemberMarkup == lastMemberMarkup && curProject == lastProject)
            {
                return;
            }

            lastType       = curType;
            lastTypeMarkup = curTypeMakeup;

            lastMember       = curMember;
            lastMemberMarkup = curMemberMarkup;

            lastProject = curProject;

            var result = new List <PathEntry> ();

            if (ownerProjects.Count > 1)
            {
                // Current project if there is more than one
                result.Add(new PathEntry(ImageService.GetIcon(Document.Project.StockIcon, Gtk.IconSize.Menu), GLib.Markup.EscapeText(Document.Project.Name))
                {
                    Tag = Document.Project
                });
            }

            if (curType == null)
            {
                if (CurrentPath != null && CurrentPath.Length == 1 && CurrentPath [0].Tag is IUnresolvedFile)
                {
                    return;
                }
                if (CurrentPath != null && CurrentPath.Length == 2 && CurrentPath [1].Tag is IUnresolvedFile)
                {
                    return;
                }
                var prevPath = CurrentPath;
                result.Add(new PathEntry(GettextCatalog.GetString("No selection"))
                {
                    Tag = unit
                });
                CurrentPath = result.ToArray();
                OnPathChanged(new DocumentPathChangedEventArgs(prevPath));
                return;
            }

            if (curType != null)
            {
                var type = curType;
                var pos  = result.Count;
                while (type != null)
                {
                    var declaringType = type.Parent as TypeDeclaration;
                    result.Insert(pos, new PathEntry(ImageService.GetIcon(type.GetStockIcon(), Gtk.IconSize.Menu), GetEntityMarkup(type))
                    {
                        Tag = (AstNode)declaringType ?? unit
                    });
                    type = declaringType;
                }
            }

            if (curMember != null)
            {
                result.Add(new PathEntry(ImageService.GetIcon(curMember.GetStockIcon(), Gtk.IconSize.Menu), curMemberMarkup)
                {
                    Tag = curMember
                });
                if (curMember is Accessor)
                {
                    var parent = curMember.Parent as EntityDeclaration;
                    if (parent != null)
                    {
                        result.Insert(result.Count - 1, new PathEntry(ImageService.GetIcon(parent.GetStockIcon(), Gtk.IconSize.Menu), GetEntityMarkup(parent))
                        {
                            Tag = parent
                        });
                    }
                }
            }

            var entry = GetRegionEntry(parsedDocument, loc);

            if (entry != null)
            {
                result.Add(entry);
            }

            PathEntry noSelection = null;

            if (curType == null)
            {
                noSelection = new PathEntry(GettextCatalog.GetString("No selection"))
                {
                    Tag = unit
                };
            }
            else if (curMember == null && !(curType is DelegateDeclaration))
            {
                noSelection = new PathEntry(GettextCatalog.GetString("No selection"))
                {
                    Tag = curType
                };
            }

            if (noSelection != null)
            {
                result.Add(noSelection);
            }

            var prev = CurrentPath;

            if (prev != null && prev.Length == result.Count)
            {
                bool equals = true;
                for (int i = 0; i < prev.Length; i++)
                {
                    if (prev [i].Markup != result [i].Markup)
                    {
                        equals = false;
                        break;
                    }
                }
                if (equals)
                {
                    return;
                }
            }
            //		Gtk.Application.Invoke (delegate {
            CurrentPath = result.ToArray();
            OnPathChanged(new DocumentPathChangedEventArgs(prev));
            //		});
            //	});
        }
        // Yoinked from C# binding
        void UpdatePath(object sender, Mono.TextEditor.DocumentLocationEventArgs e)
        {
            var unit = Document.CompilationUnit;

            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.Where(r => r.Region.Contains(loc.Line, loc.Column)).LastOrDefault();
                    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, 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(new DocumentPathChangedEventArgs(prev));
        }
Ejemplo n.º 4
0
        private void UpdatePath(object sender, Mono.TextEditor.DocumentLocationEventArgs e)
        {
            var ast = Document.ParsedDocument as ParsedDModule;

            if (ast == null)
            {
                return;
            }

            var SyntaxTree = ast.DDom;

            if (SyntaxTree == null)
            {
                return;
            }

            // Resolve the hovered piece of code
            var        loc          = new CodeLocation(Document.Editor.Caret.Location.Column, Document.Editor.Caret.Location.Line);
            IStatement stmt         = null;
            var        currentblock = DResolver.SearchBlockAt(SyntaxTree, loc, out stmt) as IBlockNode;

            //could be an enum value, which is not IBlockNode
            if (currentblock is DEnum)
            {
                foreach (INode nd in (currentblock as DEnum).Children)
                {
                    if ((nd is DEnumValue) &&
                        ((nd.Location <= loc) && (nd.EndLocation >= loc)))
                    {
                        currentblock = nd as IBlockNode;
                        break;
                    }
                }
            }

            List <PathEntry> result = new List <PathEntry>();
            INode            node   = currentblock;

            while ((node != null) && ((node is IBlockNode) || (node is DEnumValue)))
            {
                PathEntry entry;

                var icon = DCompletionData.GetNodeIcon(node as DNode);

                entry          = new PathEntry(icon.IsNull?null: ImageService.GetPixbuf(icon.Name, IconSize.Menu), node.Name + DParameterDataProvider.GetNodeParamString(node));
                entry.Position = EntryPosition.Left;
                entry.Tag      = node;
                //do not include the module in the path bar
                if ((node.Parent != null) && !((node is DNode) && (node as DNode).IsAnonymous))
                {
                    result.Insert(0, entry);
                }
                node = node.Parent;
            }

            if (!((currentblock is DMethod) || (currentblock is DEnumValue)))
            {
                PathEntry noSelection = new PathEntry(GettextCatalog.GetString("No Selection"))
                {
                    Tag = new NoSelectionCustomNode(currentblock)
                };
                result.Add(noSelection);
            }

            var prev = CurrentPath;

            CurrentPath = result.ToArray();
            OnPathChanged(new DocumentPathChangedEventArgs(prev));
        }
 void HandlePositionChanged(object sender, Mono.TextEditor.DocumentLocationEventArgs e)
 {
     CompletionWindowManager.UpdateCursorPosition();
 }
Ejemplo n.º 6
0
        void UpdatePath(object sender, Mono.TextEditor.DocumentLocationEventArgs e)
        {
            var parsedDocument = Document.ParsedDocument;

            if (parsedDocument == null || parsedDocument.ParsedFile == null)
            {
                return;
            }
            amb = new AstAmbience(document.GetFormattingOptions());

            var unit = parsedDocument.GetAst <CompilationUnit> ();

            if (unit == null)
            {
                return;
            }

            var loc = Document.Editor.Caret.Location;

            var curType   = unit.GetNodeAt <TypeDeclaration> (loc);
            var curMember = unit.GetNodeAt <EntityDeclaration> (loc);

            if (curType == curMember)
            {
                curMember = null;
            }
            if (curType == lastType && lastMember == curMember)
            {
                return;
            }
            if (curType != null && lastType != null && curType.StartLocation == lastType.StartLocation && GetEntityMarkup(curType) == GetEntityMarkup(lastType) &&
                curMember != null && lastMember != null && curMember.StartLocation == lastMember.StartLocation && GetEntityMarkup(curMember) == GetEntityMarkup(lastMember))
            {
                return;
            }

            lastType   = curType;
            lastMember = curMember;

            if (curType == null)
            {
                if (CurrentPath != null && CurrentPath.Length == 1 && CurrentPath [0].Tag is IParsedFile)
                {
                    return;
                }
                var prevPath = CurrentPath;
                CurrentPath = new PathEntry[] { new PathEntry(GettextCatalog.GetString("No selection"))
                                                {
                                                    Tag = unit
                                                } };
                OnPathChanged(new DocumentPathChangedEventArgs(prevPath));
                return;
            }

            //	ThreadPool.QueueUserWorkItem (delegate {
            var result = new List <PathEntry> ();

            if (curType != null)
            {
                var type = curType;
                while (type != null)
                {
                    var declaringType = type.Parent as TypeDeclaration;
                    result.Insert(0, new PathEntry(ImageService.GetPixbuf(type.GetStockIcon(), Gtk.IconSize.Menu), GetEntityMarkup(type))
                    {
                        Tag = (AstNode)declaringType ?? unit
                    });
                    type = declaringType;
                }
            }

            if (curMember != null)
            {
                result.Add(new PathEntry(ImageService.GetPixbuf(curMember.GetStockIcon(), Gtk.IconSize.Menu), GetEntityMarkup(curMember))
                {
                    Tag = curMember
                });
                if (curMember is Accessor)
                {
                    var parent = curMember.Parent as EntityDeclaration;
                    if (parent != null)
                    {
                        result.Insert(result.Count - 1, new PathEntry(ImageService.GetPixbuf(parent.GetStockIcon(), Gtk.IconSize.Menu), GetEntityMarkup(parent))
                        {
                            Tag = parent
                        });
                    }
                }
            }

            var entry = GetRegionEntry(parsedDocument, loc);

            if (entry != null)
            {
                result.Add(entry);
            }

            PathEntry noSelection = null;

            if (curType == null)
            {
                noSelection = new PathEntry(GettextCatalog.GetString("No selection"))
                {
                    Tag = unit
                };
            }
            else if (curMember == null)
            {
                noSelection = new PathEntry(GettextCatalog.GetString("No selection"))
                {
                    Tag = curType
                };
            }

            if (noSelection != null)
            {
                result.Add(noSelection);
            }

            var prev = CurrentPath;

            if (prev != null && prev.Length == result.Count)
            {
                bool equals = true;
                for (int i = 0; i < prev.Length; i++)
                {
                    if (prev [i].Markup != result [i].Markup)
                    {
                        equals = false;
                        break;
                    }
                }
                if (equals)
                {
                    return;
                }
            }
            //		Gtk.Application.Invoke (delegate {
            CurrentPath = result.ToArray();
            OnPathChanged(new DocumentPathChangedEventArgs(prev));
            //		});
            //	});
        }