2002-06-12 03:16:41 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file kbsequence.C
|
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>
|
|
|
|
|
|
|
|
|
|
#include "kbsequence.h"
|
2003-09-06 20:08:10 +00:00
|
|
|
|
|
|
|
|
|
#include "gettext.h"
|
2000-02-04 09:38:32 +00:00
|
|
|
|
#include "kbmap.h"
|
2003-03-19 17:15:32 +00:00
|
|
|
|
#include "lfuns.h"
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
2003-09-06 20:08:10 +00:00
|
|
|
|
#include "frontends/LyXKeySym.h"
|
|
|
|
|
#include "frontends/LyXKeySymFactory.h"
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2002-05-26 17:33:14 +00:00
|
|
|
|
using std::make_pair;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
2003-09-21 23:00:47 +00:00
|
|
|
|
FuncRequest const &
|
|
|
|
|
kb_sequence::addkey(LyXKeySymPtr key,
|
|
|
|
|
key_modifier::state mod, key_modifier::state 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
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
|
if (curmap) {
|
2000-02-04 09:38:32 +00:00
|
|
|
|
return curmap->lookup(key, mod, this);
|
2001-11-30 13:25:38 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-09-21 23:00:47 +00:00
|
|
|
|
static FuncRequest unknown(LFUN_UNKNOWN_ACTION);
|
|
|
|
|
return unknown;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-10-01 15:31:59 +00:00
|
|
|
|
string::size_type kb_sequence::parse(string const & s)
|
2000-02-04 09:38:32 +00:00
|
|
|
|
{
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (s.empty()) return 1;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string::size_type i = 0;
|
2002-05-26 17:33:14 +00:00
|
|
|
|
key_modifier::state mod = key_modifier::none;
|
|
|
|
|
key_modifier::state nmod = key_modifier::none;
|
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':
|
2002-05-26 17:33:14 +00:00
|
|
|
|
mod |= key_modifier::shift;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
i += 2;
|
|
|
|
|
continue;
|
|
|
|
|
case 'c': case 'C':
|
2002-05-26 17:33:14 +00:00
|
|
|
|
mod |= key_modifier::ctrl;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
i += 2;
|
|
|
|
|
continue;
|
|
|
|
|
case 'm': case 'M':
|
2002-05-26 17:33:14 +00:00
|
|
|
|
mod |= key_modifier::alt;
|
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':
|
2002-05-26 17:33:14 +00:00
|
|
|
|
nmod |= key_modifier::shift;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
i += 3;
|
|
|
|
|
continue;
|
|
|
|
|
case 'c': case 'C':
|
2002-05-26 17:33:14 +00:00
|
|
|
|
nmod |= key_modifier::ctrl;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
i += 3;
|
|
|
|
|
continue;
|
|
|
|
|
case 'm': case 'M':
|
2002-05-26 17:33:14 +00:00
|
|
|
|
nmod |= key_modifier::alt;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
i += 3;
|
|
|
|
|
continue;
|
|
|
|
|
default:
|
|
|
|
|
return i + 2;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
string tbuf;
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string::size_type 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
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
LyXKeySymPtr key(LyXKeySymFactory::create());
|
|
|
|
|
key->init(tbuf);
|
2002-12-01 22:59:25 +00:00
|
|
|
|
|
2002-06-18 15:44:30 +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);
|
2002-05-26 17:33:14 +00:00
|
|
|
|
mod = key_modifier::none;
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
|
string const kb_sequence::print() const
|
2000-02-04 09:38:32 +00:00
|
|
|
|
{
|
2001-11-30 13:25:38 +00:00
|
|
|
|
string buf;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
2002-03-01 14:13:01 +00:00
|
|
|
|
//if (deleted_)
|
|
|
|
|
// return buf;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
KeySequence::size_type i, length = sequence.size();
|
2002-12-01 22:59:25 +00:00
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
for (i = 0; i < length; ++i) {
|
2004-08-05 15:14:29 +00:00
|
|
|
|
buf += sequence[i]->print(modifiers[i].first);
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
|
// append a blank
|
2002-06-18 15:44:30 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
|
string const kb_sequence::printOptions() const
|
2000-02-04 09:38:32 +00:00
|
|
|
|
{
|
2001-11-30 13:25:38 +00:00
|
|
|
|
string buf;
|
|
|
|
|
|
|
|
|
|
buf += print();
|
2001-12-10 15:59:20 +00:00
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
|
if (!curmap)
|
|
|
|
|
return buf;
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
buf += to_utf8(_(" options: "));
|
2001-11-30 13:25:38 +00:00
|
|
|
|
buf += curmap->print();
|
|
|
|
|
return buf;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
|
void kb_sequence::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void kb_sequence::reset()
|
|
|
|
|
{
|
2001-11-30 13:25:38 +00:00
|
|
|
|
mark_deleted();
|
2000-02-04 09:38:32 +00:00
|
|
|
|
curmap = stdmap;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
|
void kb_sequence::clear()
|
|
|
|
|
{
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|