The following code copies the active node and its descendents into a
new structure. All nodes that have no children are cloned, not copied.

Why would anybody want that?

I am using Leo to write the specs of a task. Then I start implementing
the task. I want, in the spirit of LP, keep the code as close as
possible to its specs, so I'll interleaf code nodes with doc nodes.
Sometimes, when I decide the specs aren't that great after all, I want
to alter these. The code nodes should not get in the way of the specs
though. Of course the step from spec to code should be performed quite
late (some people say after the specs are final) so not many
alterations to the structure of the document (which will not be
cloned) will be made in the later process.


def copyOrClone(node, dest):
    if node.numberOfChildren() > 0:
        nodecopy = dest.insertAsLastChild()
        c.setHeadString(nodecopy, node.headString())
        c.setBodyString(nodecopy, node.bodyString())
        for child in node.children_iter():
            copyOrClone(child, nodecopy)
    else:
        nodeclone = node.clone()
        nodeclone.moveToLastChildOf(dest)


def cloneStructure():
    c.beginUpdate()
    thisnode = c.currentPosition()
    destnode = thisnode.insertAfter()
    c.setHeadString(destnode, "Copied Structure below here")
    copyOrClone(thisnode, destnode)
    c.endUpdate()

--~--~---------~--~----~------------~-------~--~----~
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