On Tue, 3 Aug 2010 13:38:50 -0500
"Edward K. Ream" <[email protected]> wrote:

> Imo, the present code is easy enough to use.

But not for the 'context menu delete multiple selected nodes' (CMDMSN) case, 
where the selected nodes may not be contiguous.

> The essential problem is that iterators assume that the tree they are
> iterating over will not change.  

I guess CMDMSN uses vnodes rather than positions for that reason.  Appended.

Cheers -Terry

    def deletenodes_rclick_cb():

        c.endEditing()
        cull = []

        # try and find the best node to select when this is done
        nextviz = []
        tmp = pl[0].copy().moveToVisBack(c)
        if tmp:
            nextviz.append(tmp.v)
        tmp = pl[-1].copy().moveToVisNext(c)
        if tmp:
            nextviz.append(tmp.v)

        for nd in pl:
            cull.append((nd.v, nd.parent().v or None))
        u.beforeChangeGroup(current,undoType)
        for v, vp in cull:
            for pos in c.vnode2allPositions(v):
                if c.positionExists(pos) and pos.parent().v == vp:
                    bunch = u.beforeDeleteNode(pos)
                    pos.doDelete()
                    u.afterDeleteNode(pos,undoType,bunch)
                    c.setChanged(True)
                    break
        u.afterChangeGroup(current,undoType)

        # move to a node that still exists
        for v in nextviz:
            pos = c.vnode2position(v)
            if c.positionExists(pos):
                c.selectPosition(pos)
                break
        else:
            c.selectPosition(c.allNodes_iter().next())

        c.redraw()                        

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en.

Reply via email to