Several days ago, JMarc wrote: > Actually, the right thing to do would be to have > kb_keymap::findbinding return a list of kb_sequence and expose only > that to the frontends. This is more reasonable than this business of > converting back and forth between strings and keys.
Some time later he wrote: >> 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). (This patch has now been applied.) JMarc also wrote in the mail with the patch: >> 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. And followed up most recently with: > Nevertheless, my original problem with LyX/Mac still stands, and I am > not sure what is the less painful way to handle it. So, now you can access a list of all bindings associated with a FuncRequest: class kb_keymap { public: typedef std::deque<kb_sequence> Bindings; Bindings findbindings(FuncRequest const & func) const; }; and you would like to generate a QString for each kb_sequence in this list. To do so, you need access to 'sequence' and the 'first ' part of 'modifiers', below: class kb_sequence { public: typedef boost::shared_ptr<LyXKeySym> LyXKeySymPtr; typedef std::vector<LyXKeySymPtr> KeySequence; private: /** * Array holding the current key sequence as KeySyms. * If sequence[length - 1] < 0xff it can be used as ISO8859 char */ KeySequence sequence; typedef std::pair<key_modifier::state, key_modifier::state> modifier_pair; /// modifiers for keys in the sequence std::vector<modifier_pair> modifiers; }; Have I got this right? Assuming that I have, why not add two functions to kb_sequence, as below. That would be guaranteed safe as everything is const... Angus // New class to hold a (keysym, modifier) pair. class key_sym { public: key_sym(LyXKeySymPtr const & lksp, key_modifier::state kms) : lksp_(lksp), kms_(kms) {} LyXKeySym const & sym() const { return *lksp.get(); } key_modifier::state modifier() const { return kms_; } private: LyXKeySymPtr lksp_; key_modifier::state kms_; }; class kb_sequence { public: size_type number_of_keysyms() const { return sequence.size(); } key_sym const keysym(size_type index) const { return key_sym(sequence(index), modifiers(index).first); } }; -- Angus