]> git.lyx.org Git - lyx.git/blobdiff - src/KeyMap.cpp
cosmetics
[lyx.git] / src / KeyMap.cpp
index 8e4458d48593caf76cbf5aef41031c4a8a2f2bcf..e923abd63ee1f12c8215c36e6235d5cf62154218 100644 (file)
 #include "support/filetools.h"
 
 #include <sstream>
+#include <utility>
 
 using std::endl;
 using std::string;
+using std::make_pair;
 
 
 namespace lyx {
@@ -276,11 +278,18 @@ void KeyMap::defkey(KeySequence * seq, FuncRequest const & func, unsigned int r)
 
 docstring const KeyMap::printbindings(FuncRequest const & func) const
 {
-       odocstringstream res;
        Bindings bindings = findbindings(func);
-       for (Bindings::const_iterator cit = bindings.begin();
-            cit != bindings.end() ; ++cit)
-               res << '[' << cit->print(true) << ']';
+       if (bindings.empty())
+               return docstring();
+       
+       odocstringstream res;
+       Bindings::const_iterator cit = bindings.begin();
+       Bindings::const_iterator cit_end = bindings.end();
+       // prin the first item
+       res << cit->print(true);
+       // more than one shortcuts?
+       for (++cit; cit != cit_end; ++cit)
+               res << ", " << cit->print(true);
        return res.str();
 }
 
@@ -317,4 +326,49 @@ KeyMap::Bindings KeyMap::findbindings(FuncRequest const & func,
 }
 
 
+KeyMap::BindingList const KeyMap::listBindings(bool unbound) const
+{
+       BindingList list;
+       listBindings(list, KeySequence(0, 0));
+       if (unbound) {
+               LyXAction::const_func_iterator fit = lyxaction.func_begin();
+               LyXAction::const_func_iterator fit_end = lyxaction.func_end();
+               for (; fit != fit_end; ++fit) {
+                       kb_action action = fit->second;
+                       bool has_action = false;
+                       BindingList::const_iterator it = list.begin();
+                       BindingList::const_iterator it_end = list.end();
+                       for (; it != it_end; ++it)
+                               if (it->first.action == action) {
+                                       has_action = true;
+                                       break;
+                               }
+                       if (!has_action)
+                               list.push_back(make_pair(action, KeySequence(0, 0)));
+               }       
+       }
+       return list;
+}
+
+
+void KeyMap::listBindings(BindingList & list,
+       KeySequence const & prefix) const
+{
+       Table::const_iterator it = table.begin();
+       Table::const_iterator it_end = table.end();
+       for (; it != it_end; ++it) {
+               // a LFUN_COMMAND_PREFIX
+               if (it->table.get()) {
+                       KeySequence seq = prefix;
+                       seq.addkey(it->code, it->mod.first);
+                       it->table->listBindings(list, seq);
+               } else {
+                       KeySequence seq = prefix;
+                       seq.addkey(it->code, it->mod.first);
+                       list.push_back(make_pair(it->func, seq));
+               }
+       }
+}
+
+
 } // namespace lyx