Jean-Marc Lasgouttes wrote:

>>>>>> "Angus" == Angus Leeming <[EMAIL PROTECTED]>
>>>>>> writes:
>>>> However, since we are supposedly in freeze time, I came up with
>>>> the attached kludgy but simple patch. It adds a method to
>>>> kb_keymap that returns the first 1-key binding to a FuncRequest.
>>>> This is much easier than writing the complete recursive version,
>>>> but I can try to do that if people prefer.
> 
> Angus> Would be nice. Kludges tend not to get fixed...
> 
> Jean-Marc> I'll wait to see what Lars prefers... This would mean some
> Jean-Marc> changes in how MenuBackend works. And since I would like to
> Jean-Marc> push some changes in there to fix the remaining OSX menu
> Jean-Marc> bug, I save my karma points for later :)
> 
> I began to look at better code, and came up with the following patch,
> which feels cleaner to me than what we have today. I attach it for
> your enjoyment and to gather some criticism about my command of the
> C++ idioms (I am sure some parts are not as they should be).
> 
> The main problem with this patch is that it does not help me a bit to
> solve my initial problem. The reason is that, once I get to get a
> keysequence associated to a given FuncRequest, I have no way to
> actually read it, since it is mainly private (kb_keymap can read it,
> since it is a friend class). So is it worth continuing this path? I do
> not think that it is going to be simpler than my original patch.
> Actually, both patches are mainly orthogonal.
> 
> Thoughts?

The patch is nice in that it returns a container of kb_sequences when
youask for a container of kb_sequences, rather than some stringified
version of the same.

If you're interested in reading the contents of kb_sequence, then why not
add to kb_sequence:

#include <boost/iterator/indirect_iterator.hpp>

        // This iterator, when de-referenced, 
        // returns 'LyXKeySym const &', which is exactly what
        // you're interested in. Moreover, the returned data is
        // immutable, also something that's good here.
        typedef boost::indirect_iterator<KeySequence::const_iterator>
        const_keysym_iterator;

        const_keysym_iterator begin_keysyms() const
        { return boost::make_indirect_iterator(sequence.begin()); }

        const_keysym_iterator end_keysyms() const
        { return boost::make_indirect_iterator(sequence.end()); }

The code below would probably be more efficient if you used an
ostringstream:

+string const kb_keymap::printbindings(FuncRequest const & func) const
 {
        string res;
+       Bindings bindings = findbindings(func);
+       for (Bindings::const_iterator cit = bindings.begin();
+            cit != bindings.end() ; ++cit)
+               res += '[' + cit->print() + ']';
+       return res;
+}

+string const kb_keymap::printbindings(FuncRequest const & func) const
 {
        ostringstream res;
+       Bindings bindings = findbindings(func);
+       for (Bindings::const_iterator cit = bindings.begin();
+            cit != bindings.end() ; ++cit)
+               res << '[' << cit->print() << ']';
+       return res.str();
+}



-- 
Angus

Reply via email to