Beispiel #1
0
        public void OnModifyEntry(Entry ent, TreeNodeAdv node)
        {
            ModifyEntryDialog diag = new ModifyEntryDialog();

            if (ent != null)
            {
                diag.Edited = ent.Clone();
            }
            diag.ShowDialog();

            if (diag.Confirmed)
            {
                TreePath     path   = node.Tree.GetPath(node);
                SectionEntry parent = (SectionEntry)node.Parent.Tag;

                int nodeIndex = node.Index;
                if (ent != null)
                {//if the entry is different, we need to remove the old one
                    parent.Entries.Remove(ent);
                    this.NodesRemoved(this, new TreeModelEventArgs(path.Up(), new int[] { node.Index }, new object[] { ent }));
                }
                if (diag.Edited != null)
                {//if the new entry exists (this was not just a deletion), we need to add it to the tree
                    parent.Entries.Insert(nodeIndex, diag.Edited);
                    diag.Edited.Parent = parent;
                    this.NodesInserted(this, new TreeModelEventArgs(path.Up(), new int[] { nodeIndex }, new object[] { diag.Edited }));
                }
            }
        }
Beispiel #2
0
        /// <summary>Deletes the specified node.</summary>
        /// <param name="nodePath">The node path.</param>
        public void Delete(string nodePath)
        {
            TreeIter node = FindNode(nodePath);

            // We will typically be deleting the currently selected node. If this is the case,
            // Gtk will not automatically move the cursor for us.
            // We need to work out where we want selection to be after this node is deleted
            TreePath       cursorPath;
            TreeViewColumn cursorCol;

            treeview1.GetCursor(out cursorPath, out cursorCol);
            TreeIter nextSel      = node;
            TreePath pathToSelect = treemodel.GetPath(node);

            if (pathToSelect.Compare(cursorPath) != 0)
            {
                pathToSelect = null;
            }
            else if (!treemodel.IterNext(ref nextSel)) // If there's a "next" sibling, the current TreePath will do
            {                                          // Otherwise
                if (!pathToSelect.Prev())              // If there's a "previous" sibling, use that
                {
                    pathToSelect.Up();                 // and if that didn't work, use the parent
                }
            }
            treemodel.Remove(ref node);
            if (pathToSelect != null)
            {
                treeview1.SetCursor(pathToSelect, treeview1.GetColumn(0), false);
            }
        }
Beispiel #3
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());
            }
        }
Beispiel #4
0
        public override bool IterParent(out TreeIter aParent, TreeIter aChild)
        {
            aParent = TreeIter.Zero;
            object node = NodeFromIter(aChild);

            if (node == null)
            {
                return(false);
            }
            if (RespectHierarchy == true)
            {
                TreePath tp = PathFromNode(node);
                if ((tp.Indices == null) || (tp.Indices.Length <= 1))
                {
                    return(false);
                }
                if (tp.Up() == false)
                {
                    return(false);
                }
                object o = HierarchicalList.Get(Items, tp.Indices);
                if (o != null)
                {
                    aParent = IterFromNode(o);
                    return(true);
                }
            }
            return(false);
        }
Beispiel #5
0
        // TODO remove this function again. It is redundant to the existing ExpandToPath() function which does exactly the same, see http://wrapl.sourceforge.net/doc/Gtk/Gtk/TreeView.html
        public static void ExpandRowWithParents(this TreeView treeView, TreeIter iter)
        {
            Stack <TreePath> stack     = new Stack <TreePath>();
            TreeStore        treeStore = treeView.Model as TreeStore;
            TreePath         tp        = treeStore.GetPath(iter);

            do
            {
                stack.Push(new TreePath(tp.ToString())); // clone
            }while (tp.Up());
            while (stack.Count > 0)
            {
                treeView.ExpandRow(stack.Pop(), false);
            }
        }
Beispiel #6
0
        /// <summary>Deletes the specified node.</summary>
        /// <param name="nodePath">The node path.</param>
        public void Delete(string nodePath)
        {
            TreeIter node = FindNode(nodePath);

            if (node.Equals(TreeIter.Zero))
            {
                return;
            }

            // We will typically be deleting the currently selected node. If this is the case,
            // Gtk will not automatically move the cursor for us.
            // We need to work out where we want selection to be after this node is deleted
            TreePath       cursorPath;
            TreeViewColumn cursorCol;

            treeview1.GetCursor(out cursorPath, out cursorCol);
            TreeIter nextSel      = node;
            TreePath pathToSelect = treemodel.GetPath(node);

            if (pathToSelect.Compare(cursorPath) != 0)
            {
                pathToSelect = null;
            }
            else if (treemodel.IterNext(ref nextSel)) // If there's a "next" sibling, the current TreePath will do
            {
                pathToSelect = treemodel.GetPath(nextSel);
            }
            else
            {                                     // Otherwise
                if (!pathToSelect.Prev())         // If there's a "previous" sibling, use that
                {
                    pathToSelect.Up();            // and if that didn't work, use the parent
                }
            }

            // Note: gtk_tree_store_remove() seems quite slow if the node being
            // deleted is selected. Therefore, we select the next node *before*
            // deleting the specified node.
            if (pathToSelect != null)
            {
                treeview1.SetCursor(pathToSelect, treeview1.GetColumn(0), false);
            }

            treemodel.Remove(ref node);
        }
Beispiel #7
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);
        }
Beispiel #8
0
        public void TryRemove()
        {
            TreePath[] tp = Selection.GetSelectedRows();
            Array.Reverse(tp);

            foreach (TreePath t in tp)
            {
                TreeIter iter;
                (Model as TreeStore).GetIter(out iter, t);

                // FIXME removes first occurence of element in list, not selected
                // FIXME removal of first element should change thumbnail displayed next to category name
                if (HasParent(t))
                {
                    TreePath parent = t.Copy();
                    parent.Up();

                    TreeIter piter;
                    (Model as TreeStore).GetIter(out piter, parent);

                    string name       = (string)Model.GetValue(iter, 3);
                    string parentname = (string)Model.GetValue(piter, 0);

                    foreach (Category c in cat)
                    {
                        if (c.Name == parentname)
                        {
                            foreach (Img img in c.Files)
                            {
                                if (img.Name == name)
                                {
                                    c.Files.Remove(img);

                                    if (c.Files.Count == 0)
                                    {
                                        (Model as TreeStore).Remove(ref piter);
                                        cat.Remove(c);
                                    }
                                    else
                                    {
                                        (Model as TreeStore).Remove(ref iter);
                                    }

                                    break;
                                }
                            }
                            break;
                        }
                    }
                }
                else
                {
                    string name = (string)Model.GetValue(iter, 0);

                    foreach (Category c in cat)
                    {
                        if (c.Name == name)
                        {
                            cat.Remove(c);
                            (Model as TreeStore).Remove(ref iter);
                            break;
                        }
                    }
                }
                b.Invalidate();
            }
        }
        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);
            });
        }