Пример #1
0
        public bool RefillOutlineStore()
        {
            DispatchService.AssertGuiThread();
            Gdk.Threads.Enter();

            //refreshingOutline = false;
            if (TreeStore == null || !TreeView.IsRealized)
            {
                refillOutlineStoreId = 0;
                return(false);
            }

            outlineReady = false;

            // Save last selection
            int[]    lastSelectedItem;
            TreeIter i;

            if (TreeView.Selection.GetSelected(out i))
            {
                lastSelectedItem = TreeStore.GetPath(i).Indices;
            }
            else
            {
                lastSelectedItem = null;
            }

            // Save previously expanded items if wanted
            var lastExpanded = new List <int[]>();

            if (DCompilerService.Instance.Outline.ExpansionBehaviour == DocOutlineCollapseBehaviour.ReopenPreviouslyExpanded &&
                TreeStore.GetIterFirst(out i))
            {
                do
                {
                    var path = TreeStore.GetPath(i);
                    if (TreeView.GetRowExpanded(path))
                    {
                        lastExpanded.Add(path.Indices);
                    }
                }while(TreeStore.IterNext(ref i));
            }

            // Clear the tree
            TreeStore.Clear();

            try
            {
                // Build up new tree
                if (SyntaxTree != null)
                {
                    var caretLocation = Document.Editor.Caret.Location;
                    BuildTreeChildren(TreeIter.Zero, SyntaxTree, new CodeLocation(caretLocation.Column, caretLocation.Line));
                }
            }
            catch (Exception ex)
            {
                LoggingService.LogError("Error while updating document outline panel", ex);
            }
            finally
            {
                // Re-Expand tree items
                switch (DCompilerService.Instance.Outline.ExpansionBehaviour)
                {
                case DocOutlineCollapseBehaviour.ExpandAll:
                    TreeView.ExpandAll();
                    break;

                case DocOutlineCollapseBehaviour.ReopenPreviouslyExpanded:
                    foreach (var path in lastExpanded)
                    {
                        TreeView.ExpandToPath(new TreePath(path));
                    }
                    break;
                }

                // Restore selection
                if (lastSelectedItem != null)
                {
                    try
                    {
                        TreeView.ExpandToPath(new TreePath(lastSelectedItem));
                    }
                    catch { }
                }

                outlineReady = true;
            }
            Gdk.Threads.Leave();

            //stop timeout handler
            refillOutlineStoreId = 0;
            return(false);
        }
Пример #2
0
        void UpdateOutlineSelection(object sender, Mono.TextEditor.DocumentLocationEventArgs e)
        {
            if (clickedOnOutlineItem || SyntaxTree == null || TreeStore == null)
            {
                return;
            }

            IStatement stmt           = null;
            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;
                }
            }

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

            if (selectedASTNode == null)
            {
                return;
            }

            if (lastExpanded != null)
            {
                if (TreeView.GetRowExpanded(lastExpanded))
                {
                    TreeView.CollapseRow(lastExpanded);
                }
            }

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

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

                    return(true);
                }

                return(false);
            });
        }