On Jan 24, 10:38 am, "Edward K. Ream" <[email protected]> wrote:

> I'll be continuing to hack on Leo's settings-related code today...

I spent much of yesterday making clear, in the source code, the types
of elements contained in the list returned by config.getShortcut and
other methods.  Indeed, I took the unusual step of adding asserts
about the types, mostly as a form of documentation. This work is
inadequate in some fundamental sense, but absent a significant design
change this is about the best that can be done.

Hmm.  As I write this I see that perhaps the essence of the design
problem is that c.config.getShortcut returns values that are too low
level: the values expose too much of the internal shortcuts machinery
to the caller.  It would be better design to create shortcut getters
that deliver simpler values.  I won't follow up on this idea unless I
can do it very easily...

Moving on to happier topics, yesterday in the bath I saw an elegant
way to update merge two bindings dicts.

1.  The bindings dicts that are to be merged have keys that are
command names and values that are lists of ShortcutInfo nodes.  These
nodes specify strokes and command names, among other things.

2.  To update the shortcut dict, we want to *invert* the dictionary,
creating a dictionary whose keys are strokes and whose values are
lists of ShortcutInfo nodes. Similarly, given an inverted dictionary,
*uninverting* again creates a dictionary whose keys are strokes.  For
any dictionary d,

    d == uninvert(invert(d))

Note that the uninvert operation is *not* the same as the invert
operation.

3.  Let old_d and new_d be the dictionaries to be merged. For example,
old_d might come from leoSettings.leo and new_d would come from
myLeoSettings.leo.

We compute the result, merged_d, as follows::

    inverted_old_d = invert(old_d)
    inverted_new_d = invert(new_d)
    inverted_merged_d = inverted_old_d.update(inverted_new_d)
    merged_d = uninvert(inverted_merged_d)

Or in one line::

    merged_d = uninvert(invert(old_d).update(invert(new_d)))

Indeed, the update operation does exactly what we want: for each
stroke S in inverted_old.keys(), update *replaces* inverted_old[S] by
inverted_new[S].

Note:  Mode settings might "just work", but if not invert can create
"mode strokes", and uninvert can special case these mode strokes to
create the desired result.

4. merged_d becomes the new value for c.k.bindingsDict. The final step
will be to recompute various key dictionaries that depend upon
c.k.bindingsDict.

At last there appears to be a simple way forward.  I hope to complete
this work today.

Edward

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