Esempio n. 1
0
        /* private methods */
        private bool SelectPointHelper(int x, int y, bool select)
        {
            TreeIter iter = TreeIter.Zero;

            if (!GetPointNear(x, y, out iter))
            {
                return(false);
            }

            TreePath path = model.GetPath(iter);

            // always focus
            focused_path = path.Copy();

            if (select)
            {
                // fire SelectionChanged if the
                // selection has actually
                // changed
                if (selected_path == null ||
                    path.Compare(selected_path) != 0)
                {
                    selected_path = path.Copy();
                    if (SelectionChanged != null)
                    {
                        SelectionChanged(this, new EventArgs());
                    }
                }
            }
            else
            {
                // deselect if we previously
                // had a selection
                if (selected_path != null)
                {
                    selected_path = null;
                    if (SelectionChanged != null)
                    {
                        SelectionChanged(this, new EventArgs());
                    }
                }
            }

            // always fire PointActivated
            if (PointActivated != null)
            {
                PointActivated(this, model, iter);
            }

            return(true);
        }
Esempio n. 2
0
        private void RemoveChildren(Node node, TreePath path)
        {
            if (node.Empty)
            {
                return;
            }

            TreePath children = path.Copy();

            children.Down();

            foreach (Node child in node)
            {
                RemoveChildren(child, children);
                children.Next();
            }

            children.Up();
            children.Down();

            // Then empty the node
            for (int i = 0; i < node.Count; ++i)
            {
                //Console.WriteLine("Row deleted recurse: {0}, {1}", children, node[i]);
                d_adapter.EmitRowDeleted(children.Copy());
            }
        }
Esempio n. 3
0
        private CellRenderer NextCell(CellRenderer renderer, TreePath path, bool prev, out TreeViewColumn column, out TreePath nextPath)
        {
            TreeViewColumn[] columns  = d_treeview.Columns;
            bool             getnext  = false;
            CellRenderer     prevedit = null;

            column = null;

            nextPath = path.Copy();

            for (int j = 0; j < columns.Length; ++j)
            {
                CellRenderer[] renderers = columns[j].CellRenderers;

                for (int i = 0; i < renderers.Length; ++i)
                {
                    if (renderer == renderers[i])
                    {
                        getnext = true;

                        if (prev)
                        {
                            if (prevedit == null && nextPath.Prev())
                            {
                                column   = columns[columns.Length - 1];
                                prevedit = column.CellRenderers[column.CellRenderers.Length - 1];
                            }

                            return(prevedit);
                        }
                    }
                    else if (getnext)
                    {
                        column = columns[j];
                        return(renderers[i]);
                    }
                    else
                    {
                        prevedit = renderers[i];
                        column   = columns[j];
                    }
                }
            }

            nextPath.Next();

            if (nextPath.Indices[0] < d_treeview.NodeStore.Count)
            {
                column = columns[0];
                return(column.CellRenderers[0]);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 4
0
        private void AddNodeToModel(Node node, TreePath path)
        {
            // First reorder the child if necessary
            if (path == null && IsSorted)
            {
                Comparison <Node> sorter = Sorter;

                for (int i = 0; i < node.Parent.Count; ++i)
                {
                    Node child = node.Parent[i];

                    if (node != child && sorter(node, child) < 0)
                    {
                        node.Parent.Move(node, i);
                        break;
                    }
                }
            }

            if (path == null)
            {
                path = node.Path;
            }

            //Console.WriteLine("Row inserted: {0}, {1}", path, node);
            d_adapter.EmitRowInserted(path.Copy(), node.Iter);

            TreePath children = path.Copy();

            children.Down();

            if (IsSorted)
            {
                node.Sort(Sorter);
            }

            // Then also its children
            foreach (Node child in node)
            {
                AddNodeToModel(child, children);
                children.Next();
            }
        }
Esempio n. 5
0
        private TreeViewColumn NextColumn(TreePath path, TreeViewColumn column, bool prev, out TreePath next)
        {
            TreeViewColumn[] columns = d_treeview.Columns;

            int idx = Array.IndexOf(columns, column);

            next = null;

            if (idx < 0)
            {
                return(null);
            }

            next = path.Copy();

            if (!prev && idx == columns.Length - 1)
            {
                next.Next();
                idx = 0;
            }
            else if (prev && idx == 0)
            {
                if (!next.Prev())
                {
                    return(null);
                }

                idx = columns.Length - 1;
            }
            else if (!prev)
            {
                ++idx;
            }
            else
            {
                --idx;
            }

            return(columns[idx]);
        }
Esempio n. 6
0
        public bool SelectType(Type t)
        {
            if (t != null && typeIters [t] != null)
            {
                TreeIter iter = (TreeIter)typeIters [t];

                TreePath path  = typeStore.GetPath(iter);
                Stack    stack = new Stack();
                while (path.Up())
                {
                    stack.Push(path.Copy());
                }
                while (stack.Count > 0)
                {
                    typeView.ExpandRow((TreePath)stack.Pop(), false);
                }
                typeView.Selection.SelectIter(iter);
                typeView.ScrollToCell(typeStore.GetPath(iter), typeView.GetColumn(0), true, (float)0.5, 0);

                return(true);
            }
            typeView.Selection.UnselectAll();
            return(false);
        }
Esempio n. 7
0
        private void OnDataRowDeleted(object o, RowDeletedArgs args)
        {
            if (model == null || args.Path == null)
            {
                return;
            }

            bool sel_paths_changed = false;

            // Don't update the real n_cells, as doing this will
            // throw off ScrollToPath if called before SizeAllocate
            // is run
            int n_cells = model.IterNChildren();

            for (int i = 0; i < selected_paths.Count; i++)
            {
                TreePath path = (TreePath)selected_paths[i];

                int cmp = path.Compare(args.Path);
                if (cmp == 0)
                {
                    selected_paths.RemoveAt(i);
                    i--;
                    sel_paths_changed = true;
                    continue;
                }

                // decrement each path that follows the one we
                // just deleted
                if (cmp > 0)
                {
                    path.Prev();
                    selected_paths[i] = path;
                    continue;
                }
            }

            if (sel_paths_changed && SelectionChanged != null)
            {
                SelectionChanged(this, new EventArgs());
            }

            if (focused_path != null &&
                focused_path.Equals(args.Path))
            {
                focused_path = focused_path.Copy();

                // try to advance the focus forward
                focused_path.Next();

                if (!PathIsValid(focused_path, n_cells) &&
                    !focused_path.Prev())
                {
                    focused_path = null;
                }
            }

            if (selection_anchor != null &&
                selection_anchor.Equals(args.Path))
            {
                selection_anchor = null;
            }

            QueueResize();
        }
Esempio n. 8
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);
            });
        }