I'm going to +1 this request -- I've run into issues with needing the
"parent" of a top-level node myself.
Another implementation detail would be what do you get when you ask for
c.virtualRootPosition()'s parent? I suggest that it just returns
itself, so that we don't need icky guards in scripts.
-->Jake
On 9/23/2013 10:15 AM, Terry Brown wrote:
I've run in to this many times, the 'insertBefore' example was just the
most recent.
It seems to me that the API for handling top-level nodes is
inconveniently inconsistent with the API for handling non-top-level
nodes. Here's my (corrected) insertBefore() snippet:
nd = p.insertAfter()
nd.moveToNthChildOf(p.parent(), p.childIndex())
c.selectPosition(nd)
c.redraw()
c.editHeadline()
What's the simplest way to make it work when invoked on a top level
node? For top level nodes, p.parent() == None.
I can think of a few approaches, but they're quite verbose compared to
the simplicity of the above. Edward, perhaps you can show us your
simplest solution to make that work with top-level nodes, and if it
really is simple, then I'm wrong about the inconvenient inconsistency.
If I'm not wrong, then I wonder if it would be possible to add a method
c.virtualRootPosition(), which would be a position that behaves as if
it was the parent of top level nodes, so that in the above you could
write:
nd.moveToNthChildOf(p.parent() or c.virtualRootPosition(), p.childIndex())
Currently we have
c.hiddenRootNode - the vnode parent of all top level nodes
c.rootPosition() - the first top level node, i.e. the node at the top
of the tree display
c.rootVnode() - returns a *position*, alias for c.rootPosition()?
Is c.virtualRootPosition() doable? It should support
c.virtualRootPosition().insertAsNthChild()
to create a new top level node
c.virtualRootPosition().insertAsLastChild()
to create a new last top level node
currently
for nd in c.rootPosition().children():
print nd.h
lists the children of the first top level node, which is not what I'd
expect, but I'm not suggesting changing it. But
for nd in c.virtualRootPosition().children():
print nd.h
should do what you expect, same as c.all_positions(), the difference
being that you could pass the value of c.virtualRootPosition() to a
method expecting a position, which you can't do with c.all_positions().
BTW, c.vnode2position(c.hiddenRootNode) does execute and return a
position, but trying to use that position doesn't work. Conceptually
def virtualRootPosition(self):
c = self
return c.vnode2position(c.hiddenRootNode)
but it's not that simple, understandably.
"virtualRootPosition" is just a name distinct from "rootPosition".
Ideally you might rename rootPosition() firstPosition(), and call
virtualRootPosition() rootPosition(). "realRootPosition" just seems
wrong.
Cheers -Terry
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/groups/opt_out.