add another format (BindFile) to KeySequence::print()

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21087 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Bo Peng 2007-10-20 20:28:05 +00:00
parent 6e35955ea3
commit 36f7fcdee0
6 changed files with 41 additions and 18 deletions

View File

@ -240,7 +240,7 @@ void KeyMap::defkey(KeySequence * seq, FuncRequest const & func, unsigned int r)
if (r + 1 == seq->length()) { if (r + 1 == seq->length()) {
LYXERR(Debug::KBMAP) LYXERR(Debug::KBMAP)
<< "Warning: New binding for '" << "Warning: New binding for '"
<< to_utf8(seq->print(false)) << to_utf8(seq->print(KeySequence::Portable))
<< "' is overriding old binding..." << "' is overriding old binding..."
<< endl; << endl;
if (it->table.get()) { if (it->table.get()) {
@ -251,7 +251,7 @@ void KeyMap::defkey(KeySequence * seq, FuncRequest const & func, unsigned int r)
return; return;
} else if (!it->table.get()) { } else if (!it->table.get()) {
lyxerr << "Error: New binding for '" lyxerr << "Error: New binding for '"
<< to_utf8(seq->print(false)) << to_utf8(seq->print(KeySequence::Portable))
<< "' is overriding old binding..." << "' is overriding old binding..."
<< endl; << endl;
return; return;
@ -286,10 +286,10 @@ docstring const KeyMap::printbindings(FuncRequest const & func) const
Bindings::const_iterator cit = bindings.begin(); Bindings::const_iterator cit = bindings.begin();
Bindings::const_iterator cit_end = bindings.end(); Bindings::const_iterator cit_end = bindings.end();
// prin the first item // prin the first item
res << cit->print(true); res << cit->print(KeySequence::ForGui);
// more than one shortcuts? // more than one shortcuts?
for (++cit; cit != cit_end; ++cit) for (++cit; cit != cit_end; ++cit)
res << ", " << cit->print(true); res << ", " << cit->print(KeySequence::ForGui);
return res.str(); return res.str();
} }

View File

@ -127,14 +127,32 @@ size_t KeySequence::parse(string const & s)
} }
docstring const KeySequence::print(bool forgui) const docstring const KeySequence::print(outputFormat format) const
{ {
docstring buf; docstring buf;
size_t const length = sequence.size(); size_t const length = sequence.size();
for (size_t i = 0; i != length; ++i) { for (size_t i = 0; i != length; ++i) {
buf += sequence[i].print(modifiers[i].first, forgui); 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 & ShiftModifier)
buf += "S-";
if (mod & ControlModifier)
buf += "C-";
if (mod & AltModifier)
buf += "M-";
buf += from_utf8(sequence[i].getSymbolName());
break;
}
// append a blank // append a blank
if (i + 1 != length) if (i + 1 != length)
buf += ' '; buf += ' ';
@ -145,13 +163,13 @@ docstring const KeySequence::print(bool forgui) const
docstring const KeySequence::printOptions(bool forgui) const docstring const KeySequence::printOptions(bool forgui) const
{ {
docstring buf = print(forgui); docstring buf = print(forgui ? ForGui : Portable);
if (!curmap) if (!curmap)
return buf; return buf;
buf += _(" options: "); buf += _(" options: ");
buf += curmap->print(forgui); buf += curmap->print(forgui ? ForGui : Portable);
return buf; return buf;
} }

View File

@ -61,13 +61,18 @@ public:
*/ */
size_t parse(std::string const & s); size_t parse(std::string const & s);
enum outputFormat {
Portable, //< use a more portable format
ForGui, //< use platform specific translations and special characters
BindFile //< the format used in lyx bind files
};
/** /**
* Return the current sequence as a string. * Return the current sequence as a string.
* @param forgui true if the string should use translations and * @param format output format
* special characters.
* @see parse() * @see parse()
*/ */
docstring const print(bool forgui) const; docstring const print(outputFormat format) const;
/** /**
* Return the current sequence and available options as * Return the current sequence and available options as

View File

@ -382,7 +382,7 @@ void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state)
LYXERR(Debug::KEY) << BOOST_CURRENT_FUNCTION LYXERR(Debug::KEY) << BOOST_CURRENT_FUNCTION
<< " Key [action=" << " Key [action="
<< func.action << "][" << func.action << "]["
<< to_utf8(keyseq.print(false)) << ']' << to_utf8(keyseq.print(KeySequence::Portable)) << ']'
<< endl; << endl;
// already here we know if it any point in going further // already here we know if it any point in going further
@ -390,7 +390,7 @@ void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state)
// num_bytes == 0? (Lgb) // num_bytes == 0? (Lgb)
if (keyseq.length() > 1) if (keyseq.length() > 1)
lyx_view_->message(keyseq.print(true)); lyx_view_->message(keyseq.print(KeySequence::ForGui));
// Maybe user can only reach the key via holding down shift. // Maybe user can only reach the key via holding down shift.
@ -894,7 +894,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
case LFUN_META_PREFIX: case LFUN_META_PREFIX:
meta_fake_bit = AltModifier; meta_fake_bit = AltModifier;
setMessage(keyseq.print(true)); setMessage(keyseq.print(KeySequence::ForGui));
break; break;
case LFUN_BUFFER_TOGGLE_READ_ONLY: { case LFUN_BUFFER_TOGGLE_READ_ONLY: {
@ -1316,7 +1316,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
break; break;
case LFUN_SERVER_NOTIFY: case LFUN_SERVER_NOTIFY:
dispatch_buffer = keyseq.print(false); dispatch_buffer = keyseq.print(KeySequence::Portable);
theServer().notifyClient(to_utf8(dispatch_buffer)); theServer().notifyClient(to_utf8(dispatch_buffer));
break; break;
@ -2311,7 +2311,7 @@ docstring const LyXFunc::viewStatusMessage()
{ {
// When meta-fake key is pressed, show the key sequence so far + "M-". // When meta-fake key is pressed, show the key sequence so far + "M-".
if (wasMetaKey()) if (wasMetaKey())
return keyseq.print(true) + "M-"; return keyseq.print(KeySequence::ForGui) + "M-";
// Else, when a non-complete key sequence is pressed, // Else, when a non-complete key sequence is pressed,
// show the available options. // show the available options.

View File

@ -141,7 +141,7 @@ docstring const MenuItem::binding(bool forgui) const
KeyMap::Bindings bindings = theTopLevelKeymap().findbindings(func_); KeyMap::Bindings bindings = theTopLevelKeymap().findbindings(func_);
if (bindings.size()) { if (bindings.size()) {
return bindings.begin()->print(forgui); return bindings.begin()->print(KeySequence::ForGui);
} else { } else {
LYXERR(Debug::KBMAP) LYXERR(Debug::KBMAP)
<< "No binding for " << "No binding for "

View File

@ -1757,7 +1757,7 @@ void PrefShortcuts::update(LyXRC const & rc)
string const action_name = lyxaction.getActionName(action); string const action_name = lyxaction.getActionName(action);
QString const lfun = toqstr(from_utf8(action_name) QString const lfun = toqstr(from_utf8(action_name)
+ " " + it->first.argument()); + " " + it->first.argument());
QString const shortcut = toqstr(it->second.print(false)); QString const shortcut = toqstr(it->second.print(KeySequence::Portable));
QTreeWidgetItem * newItem = NULL; QTreeWidgetItem * newItem = NULL;
// if an item with the same lfun already exists, insert as a // if an item with the same lfun already exists, insert as a