On Wed, Oct 23, 2013 at 8:54 AM, Jacob Peck <[email protected]> wrote:

> 
So, I wrote a function that will create a hierarchy of nodes with a list of
given headlines.

Interesting.

> 
With the proper undo code added, I think that it would be right at home as
c.create_node_hierarchy
...

I agree.


> 
I would find this immensely useful in the API.  Currently I have to
redefine it in each outline I want to use it in.

No, you don't.  Just add an @command node in myLeoSettings.leo::

    + @settings
        + @commands
            + @command create-hierarchy


> 
I'd add it myself, but I don't understand the undo code for the life of
me...

As a fairly advance Leo script writer, it's time for you to mine Leo's
source code for patterns.  This is what I do.

The clone-find-all command creates a tree of nodes, so it would be a good
place to look.  After a bit of searching, I found:

    @file leoFind.py-->class leoFind-->Find/change utils-->
    findAll & helper (leoFind)

Take a look at this node.  The pattern is, in essence::

    u = c.undoer
    undoType = 'Name of command, for the undo menu'
    ...
    undoData = u.beforeInsertNode(c.p)
    found = self.createCloneFindAllNode()
    ...
    u.afterInsertNode(found,undoType,undoData,dirtyVnodeList=[])

Your code will be something similar.  There is no need to understand the
undo code in detail.

Give it a try, and feel free to ask questions.  This will never be in the
tutorial, and even if it were, you're ready to fly on your own now.

Edward

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to