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

View File

@ -61,13 +61,18 @@ public:
*/
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.
* @param forgui true if the string should use translations and
* special characters.
* @param format output format
* @see parse()
*/
docstring const print(bool forgui) const;
docstring const print(outputFormat format) const;
/**
* 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
<< " Key [action="
<< func.action << "]["
<< to_utf8(keyseq.print(false)) << ']'
<< to_utf8(keyseq.print(KeySequence::Portable)) << ']'
<< endl;
// 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)
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.
@ -894,7 +894,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
case LFUN_META_PREFIX:
meta_fake_bit = AltModifier;
setMessage(keyseq.print(true));
setMessage(keyseq.print(KeySequence::ForGui));
break;
case LFUN_BUFFER_TOGGLE_READ_ONLY: {
@ -1316,7 +1316,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
break;
case LFUN_SERVER_NOTIFY:
dispatch_buffer = keyseq.print(false);
dispatch_buffer = keyseq.print(KeySequence::Portable);
theServer().notifyClient(to_utf8(dispatch_buffer));
break;
@ -2311,7 +2311,7 @@ docstring const LyXFunc::viewStatusMessage()
{
// When meta-fake key is pressed, show the key sequence so far + "M-".
if (wasMetaKey())
return keyseq.print(true) + "M-";
return keyseq.print(KeySequence::ForGui) + "M-";
// Else, when a non-complete key sequence is pressed,
// show the available options.

View File

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

View File

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