]> git.lyx.org Git - features.git/blobdiff - src/KeyMap.cpp
PrefShortcuts: list all shortcuts (bound and unbound), using a better implementation
[features.git] / src / KeyMap.cpp
index 1a505582a80fc9e18a05f9eb8bd3a6bede671328..e923abd63ee1f12c8215c36e6235d5cf62154218 100644 (file)
 #include "support/filetools.h"
 
 #include <sstream>
+#include <utility>
 
 using std::endl;
 using std::string;
+using std::make_pair;
 
 
 namespace lyx {
@@ -324,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