LYXERR(Debug::KBMAP, "BIND: Sequence `" << seq << "' Action `"
<< func.action() << '\'');
- KeySequence k(0, 0);
+ KeySequence k(nullptr, nullptr);
string::size_type const res = k.parse(seq);
if (res == string::npos) {
size_t KeyMap::unbind(string const & seq, FuncRequest const & func)
{
- KeySequence k(0, 0);
+ KeySequence k(nullptr, nullptr);
string::size_type const res = k.parse(seq);
if (res == string::npos)
KeyModifier const mod2 = seq->modifiers[r].second;
// check if key is already there
+ // FIXME perf: Profiling shows that this is responsible of 99% of the
+ // cost of GuiPrefs::applyView()
Table::iterator end = table.end();
for (Table::iterator it = table.begin(); it != end; ++it) {
if (code == it->code
KeyModifier const mod2 = seq->modifiers[r].second;
// check if key is already there
+ vector <Table::iterator> removes;
Table::iterator end = table.end();
- Table::iterator remove = end;
for (Table::iterator it = table.begin(); it != end; ++it) {
if (code == it->code
&& mod1 == it->mod.first
&& mod2 == it->mod.second) {
// remove
if (r + 1 == seq->length()) {
- if (it->func == func) {
- remove = it;
+ if (it->func == func || func == FuncRequest::unknown) {
+ removes.push_back(it);
if (it->prefixes)
it->prefixes.reset();
}
} else if (it->prefixes) {
it->prefixes->unbind(seq, func, r + 1);
if (it->prefixes->empty())
- remove = it;
+ removes.push_back(it);
return;
}
}
}
- if (remove != end)
- table.erase(remove);
+
+ for (unsigned i = removes.size(); i > 0; --i)
+ table.erase(removes[i-1]);
}
LYXERR(Debug::KBMAP, "Reading bind file:" << bind_file.absFileName());
// format of pre-2.0 bind files, before this tag was introduced.
- unsigned int format = 0;
+ int format = 0;
bool error = false;
while (lexrc.isOK()) {
switch (lexrc.lex()) {
string cmd = lexrc.getString();
FuncRequest func = lyxaction.lookupFunc(cmd);
- if (func.action() == LFUN_UNKNOWN_ACTION) {
+ if (func == FuncRequest::unknown) {
lexrc.printError("BN_BIND: Unknown LyX function `$$Token'");
error = true;
break;
break;
}
string cmd = lexrc.getString();
-
- FuncRequest func = lyxaction.lookupFunc(cmd);
- if (func.action() == LFUN_UNKNOWN_ACTION) {
- lexrc.printError("BN_UNBIND: Unknown LyX"
- " function `$$Token'");
- error = true;
- break;
+ FuncRequest func;
+ if (cmd == "*")
+ func = FuncRequest::unknown;
+ else {
+ func = lyxaction.lookupFunc(cmd);
+ if (func == FuncRequest::unknown) {
+ lexrc.printError("BN_UNBIND: Unknown LyX function `$$Token'");
+ error = true;
+ break;
+ }
}
if (unbind_map)
<< "Format " << LFUN_FORMAT << "\n\n";
string tag = unbind ? "\\unbind" : "\\bind";
- BindingList const list = listBindings(false);
- BindingList::const_iterator it = list.begin();
- BindingList::const_iterator it_end = list.end();
- for (; it != it_end; ++it) {
- FuncCode action = it->request.action();
- string arg = to_utf8(it->request.argument());
-
- string const cmd = lyxaction.getActionName(action)
- + (arg.empty() ? string() : " " + arg) ;
+ for (auto const & bnd : listBindings(false)) {
+ FuncCode const action = bnd.request.action();
+ string const arg = to_utf8(bnd.request.argument());
+
+ string cmd;
+ if (unbind && bnd.request == FuncRequest::unknown)
+ cmd = "*";
+ else
+ cmd = lyxaction.getActionName(action) + (arg.empty() ? string() : " " + arg);
os << tag << " \""
- << to_utf8(it->sequence.print(KeySequence::BindFile))
+ << to_utf8(bnd.sequence.print(KeySequence::BindFile))
<< "\" " << Lexer::quoteString(cmd)
<< "\n";
}
docstring KeyMap::printBindings(FuncRequest const & func,
- KeySequence::outputFormat format) const
+ KeySequence::outputFormat format,
+ bool const untranslated) const
{
Bindings bindings = findBindings(func);
if (bindings.empty())
return docstring();
-
+
odocstringstream res;
Bindings::const_iterator cit = bindings.begin();
Bindings::const_iterator cit_end = bindings.end();
// print the first item
- res << cit->print(format);
+ res << cit->print(format, untranslated);
// more than one shortcuts?
for (++cit; cit != cit_end; ++cit)
- res << ", " << cit->print(format);
+ res << ", " << cit->print(format, untranslated);
return res.str();
}
KeyMap::Bindings KeyMap::findBindings(FuncRequest const & func) const
{
- return findBindings(func, KeySequence(0, 0));
+ return findBindings(func, KeySequence(nullptr, nullptr));
}
KeyMap::BindingList KeyMap::listBindings(bool unbound, KeyMap::ItemType tag) const
{
BindingList list;
- listBindings(list, KeySequence(0, 0), tag);
+ listBindings(list, KeySequence(nullptr, nullptr), tag);
if (unbound) {
- LyXAction::const_iterator fit = lyxaction.func_begin();
- LyXAction::const_iterator const fen = lyxaction.func_end();
- for (; fit != fen; ++fit) {
- FuncCode action = fit->second;
+ for (auto const & name_code : lyxaction) {
+ FuncCode action = name_code.second;
bool has_action = false;
BindingList::const_iterator bit = list.begin();
BindingList::const_iterator const ben = list.end();
break;
}
if (!has_action)
- list.push_back(Binding(FuncRequest(action), KeySequence(0, 0), tag));
- }
+ list.push_back(Binding(FuncRequest(action), KeySequence(nullptr, nullptr), tag));
+ }
}
return list;
}