2002-06-12 03:16:41 +00:00
|
|
|
|
/**
|
2007-04-27 08:19:12 +00:00
|
|
|
|
* \file KeySequence.cpp
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-11-30 13:25:38 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author John Levon
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-06-12 03:16:41 +00:00
|
|
|
|
*/
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2007-04-27 08:19:12 +00:00
|
|
|
|
#include "KeySequence.h"
|
2008-03-15 01:20:36 +00:00
|
|
|
|
#include "KeyMap.h"
|
2003-09-06 20:08:10 +00:00
|
|
|
|
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/gettext.h"
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
2007-04-27 08:43:38 +00:00
|
|
|
|
#include "frontends/KeySymbol.h"
|
2003-09-06 20:08:10 +00:00
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
using namespace std;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
2007-07-17 17:46:54 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2007-09-17 18:41:03 +00:00
|
|
|
|
FuncRequest const & KeySequence::addkey(KeySymbol const & key,
|
2007-10-02 21:51:54 +00:00
|
|
|
|
KeyModifier mod, KeyModifier nmod)
|
2000-02-04 09:38:32 +00:00
|
|
|
|
{
|
2001-11-30 13:25:38 +00:00
|
|
|
|
// adding a key to a deleted sequence
|
|
|
|
|
// starts a new sequence
|
|
|
|
|
if (deleted_) {
|
|
|
|
|
deleted_ = false;
|
2000-11-15 14:53:04 +00:00
|
|
|
|
sequence.clear();
|
|
|
|
|
modifiers.clear();
|
|
|
|
|
}
|
2000-11-17 00:07:41 +00:00
|
|
|
|
|
2002-05-26 17:33:14 +00:00
|
|
|
|
modifiers.push_back(make_pair(mod, nmod));
|
2000-11-15 14:53:04 +00:00
|
|
|
|
sequence.push_back(key);
|
2000-11-17 00:07:41 +00:00
|
|
|
|
|
2008-03-15 01:20:36 +00:00
|
|
|
|
if (curmap)
|
2000-02-04 09:38:32 +00:00
|
|
|
|
return curmap->lookup(key, mod, this);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2008-09-24 13:32:09 +00:00
|
|
|
|
return FuncRequest::unknown;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-27 08:19:12 +00:00
|
|
|
|
size_t KeySequence::parse(string const & s)
|
2000-02-04 09:38:32 +00:00
|
|
|
|
{
|
2007-04-27 08:19:12 +00:00
|
|
|
|
if (s.empty())
|
|
|
|
|
return 1;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
2007-04-27 08:19:12 +00:00
|
|
|
|
size_t i = 0;
|
2007-10-02 21:51:54 +00:00
|
|
|
|
KeyModifier mod = NoModifier;
|
|
|
|
|
KeyModifier nmod = NoModifier;
|
2002-12-01 22:59:25 +00:00
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
while (i < s.length()) {
|
2001-11-14 11:31:14 +00:00
|
|
|
|
if (s[i] == ' ')
|
|
|
|
|
++i;
|
|
|
|
|
if (i >= s.length())
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
|
if (i + 1 < s.length() && s[i + 1] == '-') {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (s[i]) {
|
2000-02-04 09:38:32 +00:00
|
|
|
|
case 's': case 'S':
|
2007-10-02 21:51:54 +00:00
|
|
|
|
mod |= ShiftModifier;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
i += 2;
|
|
|
|
|
continue;
|
|
|
|
|
case 'c': case 'C':
|
2007-10-02 21:51:54 +00:00
|
|
|
|
mod |= ControlModifier;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
i += 2;
|
|
|
|
|
continue;
|
|
|
|
|
case 'm': case 'M':
|
2007-10-02 21:51:54 +00:00
|
|
|
|
mod |= AltModifier;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
i += 2;
|
|
|
|
|
continue;
|
|
|
|
|
default:
|
|
|
|
|
return i + 1;
|
|
|
|
|
}
|
2001-05-29 14:16:39 +00:00
|
|
|
|
} else if (i + 2 < s.length() && s[i] == '~'
|
|
|
|
|
&& s[i + 2] == '-') {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (s[i + 1]) {
|
2000-02-04 09:38:32 +00:00
|
|
|
|
case 's': case 'S':
|
2007-10-02 21:51:54 +00:00
|
|
|
|
nmod |= ShiftModifier;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
i += 3;
|
|
|
|
|
continue;
|
|
|
|
|
case 'c': case 'C':
|
2007-10-02 21:51:54 +00:00
|
|
|
|
nmod |= ControlModifier;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
i += 3;
|
|
|
|
|
continue;
|
|
|
|
|
case 'm': case 'M':
|
2007-10-02 21:51:54 +00:00
|
|
|
|
nmod |= AltModifier;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
i += 3;
|
|
|
|
|
continue;
|
|
|
|
|
default:
|
|
|
|
|
return i + 2;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
string tbuf;
|
2007-04-27 08:19:12 +00:00
|
|
|
|
size_t j = i;
|
2001-11-14 11:31:14 +00:00
|
|
|
|
for (; j < s.length() && s[j] != ' '; ++j)
|
2000-02-04 09:38:32 +00:00
|
|
|
|
tbuf += s[j]; // (!!!check bounds :-)
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2007-09-17 18:41:03 +00:00
|
|
|
|
KeySymbol key;
|
|
|
|
|
key.init(tbuf);
|
2002-12-01 22:59:25 +00:00
|
|
|
|
|
2007-09-17 18:41:03 +00:00
|
|
|
|
if (!key.isOK())
|
2000-02-04 09:38:32 +00:00
|
|
|
|
return j;
|
2002-06-18 15:44:30 +00:00
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
i = j;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-12-10 15:59:20 +00:00
|
|
|
|
addkey(key, mod, nmod);
|
2007-10-02 21:51:54 +00:00
|
|
|
|
mod = NoModifier;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-11-14 11:31:14 +00:00
|
|
|
|
// empty sequence?
|
2002-06-18 15:44:30 +00:00
|
|
|
|
if (sequence.size() == 0)
|
2001-11-14 11:31:14 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
// everything is fine
|
|
|
|
|
return string::npos;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-10-20 20:28:05 +00:00
|
|
|
|
docstring const KeySequence::print(outputFormat format) const
|
2000-02-04 09:38:32 +00:00
|
|
|
|
{
|
2006-12-13 14:13:01 +00:00
|
|
|
|
docstring buf;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
2007-04-27 08:19:12 +00:00
|
|
|
|
size_t const length = sequence.size();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2007-09-17 18:41:03 +00:00
|
|
|
|
for (size_t i = 0; i != length; ++i) {
|
2007-10-20 20:28:05 +00:00
|
|
|
|
switch (format) {
|
|
|
|
|
case Portable:
|
|
|
|
|
buf += sequence[i].print(modifiers[i].first, false);
|
|
|
|
|
break;
|
|
|
|
|
case ForGui:
|
|
|
|
|
buf += sequence[i].print(modifiers[i].first, true);
|
|
|
|
|
break;
|
|
|
|
|
case BindFile:
|
|
|
|
|
KeyModifier mod = modifiers[i].first;
|
|
|
|
|
if (mod & ControlModifier)
|
|
|
|
|
buf += "C-";
|
|
|
|
|
if (mod & AltModifier)
|
|
|
|
|
buf += "M-";
|
2007-10-30 16:34:35 +00:00
|
|
|
|
if (mod & ShiftModifier)
|
|
|
|
|
buf += "S-";
|
2007-10-20 20:28:05 +00:00
|
|
|
|
|
|
|
|
|
buf += from_utf8(sequence[i].getSymbolName());
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-11-30 13:25:38 +00:00
|
|
|
|
// append a blank
|
2007-09-17 18:41:03 +00:00
|
|
|
|
if (i + 1 != length)
|
2000-02-04 09:38:32 +00:00
|
|
|
|
buf += ' ';
|
|
|
|
|
}
|
2001-11-30 13:25:38 +00:00
|
|
|
|
return buf;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-27 08:19:12 +00:00
|
|
|
|
docstring const KeySequence::printOptions(bool forgui) const
|
2000-02-04 09:38:32 +00:00
|
|
|
|
{
|
2007-10-20 20:28:05 +00:00
|
|
|
|
docstring buf = print(forgui ? ForGui : Portable);
|
2001-12-10 15:59:20 +00:00
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
|
if (!curmap)
|
|
|
|
|
return buf;
|
|
|
|
|
|
2006-12-13 14:13:01 +00:00
|
|
|
|
buf += _(" options: ");
|
2007-10-20 20:28:05 +00:00
|
|
|
|
buf += curmap->print(forgui ? ForGui : Portable);
|
2001-11-30 13:25:38 +00:00
|
|
|
|
return buf;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-27 08:19:12 +00:00
|
|
|
|
void KeySequence::mark_deleted()
|
2000-02-04 09:38:32 +00:00
|
|
|
|
{
|
2001-11-30 13:25:38 +00:00
|
|
|
|
deleted_ = true;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-27 08:19:12 +00:00
|
|
|
|
void KeySequence::reset()
|
2000-02-04 09:38:32 +00:00
|
|
|
|
{
|
2001-11-30 13:25:38 +00:00
|
|
|
|
mark_deleted();
|
2000-02-04 09:38:32 +00:00
|
|
|
|
curmap = stdmap;
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-17 22:51:03 +00:00
|
|
|
|
|
2007-04-27 08:19:12 +00:00
|
|
|
|
void KeySequence::clear()
|
2001-11-30 13:25:38 +00:00
|
|
|
|
{
|
2002-06-18 15:44:30 +00:00
|
|
|
|
sequence.clear();
|
2001-11-30 13:25:38 +00:00
|
|
|
|
reset();
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
2008-07-22 08:29:50 +00:00
|
|
|
|
void KeySequence::removeKey()
|
|
|
|
|
{
|
|
|
|
|
if (deleted_)
|
|
|
|
|
return;
|
|
|
|
|
sequence.pop_back();
|
|
|
|
|
modifiers.pop_back();
|
2009-04-03 11:46:44 +00:00
|
|
|
|
if (sequence.empty())
|
|
|
|
|
deleted_ = true;
|
2008-07-22 08:29:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
} // namespace lyx
|