Make autocorrect configurable in preferences file

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28171 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Martin Vermeer 2009-01-15 09:48:00 +00:00
parent a3111c9497
commit b4b47d783b
3 changed files with 39 additions and 28 deletions

View File

@ -58,6 +58,7 @@ LexerKeyword lyxrcTags[] = {
{ "\\auto_number", LyXRC::RC_AUTO_NUMBER },
{ "\\auto_region_delete", LyXRC::RC_AUTOREGIONDELETE },
{ "\\auto_reset_options", LyXRC::RC_AUTORESET_OPTIONS },
{ "\\autocorrection_math", LyXRC::RC_AUTOCORRECTION_MATH },
{ "\\autosave", LyXRC::RC_AUTOSAVE },
{ "\\backupdir_path", LyXRC::RC_BACKUPDIR_PATH },
{ "\\bibtex_command", LyXRC::RC_BIBTEX_COMMAND },
@ -314,6 +315,7 @@ void LyXRC::setDefaults()
completion_popup_text = false;
completion_popup_delay = 2.0;
completion_popup_after_complete = true;
autocorrection_math = false;
completion_inline_math = true;
completion_inline_text = false;
completion_inline_dots = -1;
@ -711,6 +713,10 @@ int LyXRC::read(Lexer & lexrc)
lexrc >> completion_inline_dots;
break;
case RC_AUTOCORRECTION_MATH:
lexrc >> autocorrection_math;
break;
case RC_COMPLETION_POPUP_DELAY:
lexrc >> completion_popup_delay;
break;
@ -1968,6 +1974,14 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
}
if (tag != RC_LAST)
break;
case RC_AUTOCORRECTION_MATH:
if (ignore_system_lyxrc ||
autocorrection_math != system_lyxrc.autocorrection_math) {
os << "\\autocorrection_math "
<< convert<string>(autocorrection_math) << '\n';
}
if (tag != RC_LAST)
break;
case RC_COMPLETION_POPUP_DELAY:
if (ignore_system_lyxrc ||
completion_popup_delay != system_lyxrc.completion_popup_delay) {
@ -2652,6 +2666,10 @@ string const LyXRC::getDescription(LyXRCTags tag)
str = _("Use \"...\" to shorten long completions.");
break;
case RC_AUTOCORRECTION_MATH:
str = _("Allow TeXMacs shorthand, like => converting to \Rightarrow.");
break;
case RC_NUMLASTFILES:
str = bformat(_("Maximal number of lastfiles. Up to %1$d can appear in the file menu."),
maxlastfiles);

View File

@ -38,6 +38,7 @@ public:
enum LyXRCTags {
RC_ACCEPT_COMPOUND = 1,
RC_ALT_LANG,
RC_AUTOCORRECTION_MATH,
RC_PLAINTEXT_LINELEN,
RC_PLAINTEXT_ROFF_COMMAND,
RC_AUTOREGIONDELETE,
@ -438,6 +439,8 @@ public:
///
int completion_inline_dots;
///
bool autocorrection_math;
///
double completion_popup_delay;
///
bool completion_popup_math;

View File

@ -10,8 +10,6 @@
#include <config.h>
//#define AUTOCORRECT
#include "InsetMathNest.h"
#include "InsetMathArray.h"
@ -27,9 +25,7 @@
#include "InsetMathSpace.h"
#include "InsetMathSymbol.h"
#include "InsetMathUnknown.h"
#ifdef AUTOCORRECT
#include "MathAutoCorrect.h"
#endif
#include "MathCompletionList.h"
#include "MathData.h"
#include "MathFactory.h"
@ -1519,22 +1515,18 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c)
return true;
}
// This is annoying as one has to press <space> far too often.
// Disable it.
#ifdef AUTOCORRECT
// leave autocorrect mode if necessary
if (c == ' ' && cur.autocorrect()) {
cur.autocorrect() = false;
cur.message(_("Autocorrect Off ('!' to enter)"));
return true;
}
if (c == '!' && !cur.autocorrect()) {
cur.autocorrect() = true;
cur.message(_("Autocorrect On (<space> to exit)"));
return true;
}
#endif
// leave autocorrect mode if necessary
if (lyxrc.autocorrection_math && c == ' ' && cur.autocorrect()) {
cur.autocorrect() = false;
cur.message(_("Autocorrect Off ('!' to enter)"));
return true;
}
if (lyxrc.autocorrection_math && c == '!' && !cur.autocorrect()) {
cur.autocorrect() = true;
cur.message(_("Autocorrect On (<space> to exit)"));
return true;
}
// just clear selection on pressing the space bar
if (cur.selection() && c == ' ') {
@ -1631,20 +1623,18 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c)
}
#ifdef AUTOCORRECT
// try auto-correction
if (cur.autocorrect() && cur.pos() != 0 && math_autocorrect(cur.prevAtom(), c))
if (lyxrc.autocorrection_math && cur.autocorrect() && cur.pos() != 0 && math_autocorrect(cur.prevAtom(), c))
return true;
#endif
// no special circumstances, so insert the character without any fuss
cur.insert(c);
#ifdef AUTOCORRECT
if (!cur.autocorrect())
cur.message(_("Autocorrect Off ('!' to enter)"));
else
cur.message(_("Autocorrect On (<space> to exit)"));
#endif
if (lyxrc.autocorrection_math) {
if (!cur.autocorrect())
cur.message(_("Autocorrect Off ('!' to enter)"));
else
cur.message(_("Autocorrect On (<space> to exit)"));
}
return true;
}