Terry,

Thanks.  That's a great solution. I'll use it.

Before I read your post, I didn't know that monkey patching the
commander (as you suggest doing) is allowed.  Consequently, I came up
with a roundabout way that does not monkey patch the commander:

Very simple works for only one file open at a time.  Put a global in
your plugin module:

_cloneNav = None

@g.command('clone-nav')
def clone_nav(event):
    if _cloneNav:
        _cloneNav._buttonClicked(event)

Now, clone_nav is a global command and can be assigned a shortcut in
leoSettings.leo or myLeoSettings.leo.

But, if you open a second file using this same instance of Leo-editor
(for example, in a second tab), then the single global _cloneNav is
overwritten and the clone_nav for the first file is executed on the
second file instead.

A little more complicated is (I hope) a general solution:

_cAndObj = []

@g.command('clone-nav')
def clone_nav(event):
    c = event.get('c')
    for cs, obj in _cAndObj:
        if c == cs:
            g.es('obj=',obj)
            obj._buttonClicked(event)
            break

That is, maintain a list that allows you to map each commander to the
appropriate instance of your plugin control object.

Would it be safe to hash the commander and use hash(c) as the key of a
dictionary (which would replace the list)?

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