Enhance LyX by fixing #6760. New preference to set minimum length of

automatically spellchecked words.



git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34889 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2010-07-13 14:08:44 +00:00
parent f27ea2457d
commit e611cc2d4a
5 changed files with 115 additions and 61 deletions

View File

@ -180,6 +180,7 @@ LexerKeyword lyxrcTags[] = {
{ "\\sort_layouts", LyXRC::RC_SORT_LAYOUTS }, { "\\sort_layouts", LyXRC::RC_SORT_LAYOUTS },
{ "\\spell_command", LyXRC::RC_SPELL_COMMAND }, { "\\spell_command", LyXRC::RC_SPELL_COMMAND },
{ "\\spellcheck_continuously", LyXRC::RC_SPELLCHECK_CONTINUOUSLY }, { "\\spellcheck_continuously", LyXRC::RC_SPELLCHECK_CONTINUOUSLY },
{ "\\spellcheck_minlength", LyXRC::RC_SPELL_MINLENGTH },
{ "\\spellcheck_notes", LyXRC::RC_SPELLCHECK_NOTES }, { "\\spellcheck_notes", LyXRC::RC_SPELLCHECK_NOTES },
{ "\\spellchecker", LyXRC::RC_SPELLCHECKER }, { "\\spellchecker", LyXRC::RC_SPELLCHECKER },
{ "\\splitindex_command", LyXRC::RC_SPLITINDEX_COMMAND }, { "\\splitindex_command", LyXRC::RC_SPLITINDEX_COMMAND },
@ -297,6 +298,7 @@ void LyXRC::setDefaults()
#endif #endif
spellchecker_accept_compound = false; spellchecker_accept_compound = false;
spellcheck_continuously = false; spellcheck_continuously = false;
spellcheck_minlength = 6;
spellcheck_notes = true; spellcheck_notes = true;
use_kbmap = false; use_kbmap = false;
rtl_support = true; rtl_support = true;
@ -921,6 +923,19 @@ int LyXRC::read(Lexer & lexrc)
case RC_SPELLCHECKER: case RC_SPELLCHECKER:
lexrc >> spellchecker; lexrc >> spellchecker;
break; break;
case RC_SPELL_MINLENGTH: {
int len;
lexrc >> len;
// make sure we have a sensible value
// these should be kept in sync with the min and max
// values for the spinbox in PrefSpellcheckerUi.ui
if (len < 5)
len = 5;
else if (len > 15)
len = 15;
spellcheck_minlength = len;
break;
}
case RC_ALT_LANG: case RC_ALT_LANG:
lexrc >> spellchecker_alt_lang; lexrc >> spellchecker_alt_lang;
break; break;
@ -2421,6 +2436,15 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
if (tag != RC_LAST) if (tag != RC_LAST)
break; break;
case RC_SPELL_MINLENGTH:
if (ignore_system_lyxrc ||
spellcheck_minlength != system_lyxrc.spellcheck_minlength) {
os << "\\spellcheck_minlength " << convert<string>(spellcheck_minlength)
<< '\n';
}
if (tag != RC_LAST)
break;
case RC_SPELLCHECK_NOTES: case RC_SPELLCHECK_NOTES:
if (ignore_system_lyxrc || if (ignore_system_lyxrc ||
spellcheck_notes != system_lyxrc.spellcheck_notes) { spellcheck_notes != system_lyxrc.spellcheck_notes) {
@ -2872,6 +2896,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
case LyXRC::RC_SPELLCHECKER: case LyXRC::RC_SPELLCHECKER:
case LyXRC::RC_SPELLCHECK_CONTINUOUSLY: case LyXRC::RC_SPELLCHECK_CONTINUOUSLY:
case LyXRC::RC_SPELLCHECK_NOTES: case LyXRC::RC_SPELLCHECK_NOTES:
case LyXRC::RC_SPELL_MINLENGTH:
case LyXRC::RC_SPLITINDEX_COMMAND: case LyXRC::RC_SPLITINDEX_COMMAND:
case LyXRC::RC_TEMPDIRPATH: case LyXRC::RC_TEMPDIRPATH:
case LyXRC::RC_TEMPLATEPATH: case LyXRC::RC_TEMPLATEPATH:

View File

@ -165,6 +165,7 @@ public:
RC_SPELLCHECK_CONTINUOUSLY, RC_SPELLCHECK_CONTINUOUSLY,
RC_SPELLCHECK_NOTES, RC_SPELLCHECK_NOTES,
RC_SPELLCHECKER, RC_SPELLCHECKER,
RC_SPELL_MINLENGTH,
RC_SPLITINDEX_COMMAND, RC_SPLITINDEX_COMMAND,
RC_TEMPDIRPATH, RC_TEMPDIRPATH,
RC_TEMPLATEPATH, RC_TEMPLATEPATH,
@ -362,6 +363,8 @@ public:
bool spellcheck_continuously; bool spellcheck_continuously;
/// spellcheck notes and comments? /// spellcheck notes and comments?
bool spellcheck_notes; bool spellcheck_notes;
/// minimum length of words to complete
unsigned int spellcheck_minlength;
/// ///
bool use_kbmap; bool use_kbmap;
/// ///

View File

@ -3126,16 +3126,13 @@ void Paragraph::locateWord(pos_type & from, pos_type & to,
void Paragraph::collectWords() void Paragraph::collectWords()
{ {
// This is the value that needs to be exposed in the preferences
// to resolve bug #6760.
static int minlength = 6;
pos_type n = size(); pos_type n = size();
for (pos_type pos = 0; pos < n; ++pos) { for (pos_type pos = 0; pos < n; ++pos) {
if (isWordSeparator(pos)) if (isWordSeparator(pos))
continue; continue;
pos_type from = pos; pos_type from = pos;
locateWord(from, pos, WHOLE_WORD); locateWord(from, pos, WHOLE_WORD);
if (pos - from >= minlength) { if (pos - from >= lyxrc.spellcheck_minlength) {
docstring word = asString(from, pos, AS_STR_NONE); docstring word = asString(from, pos, AS_STR_NONE);
FontList::const_iterator cit = d->fontlist_.fontIterator(pos); FontList::const_iterator cit = d->fontlist_.fontIterator(pos);
if (cit == d->fontlist_.end()) if (cit == d->fontlist_.end())

View File

@ -1365,6 +1365,7 @@ PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
this, SIGNAL(changed())); this, SIGNAL(changed()));
connect(spellcheckNotesCB, SIGNAL(clicked()), connect(spellcheckNotesCB, SIGNAL(clicked()),
this, SIGNAL(changed())); this, SIGNAL(changed()));
connect(minlengthSB, SIGNAL(changed()), this, SIGNAL(changed()));
#else #else
spellcheckerCB->setEnabled(false); spellcheckerCB->setEnabled(false);
altLanguageED->setEnabled(false); altLanguageED->setEnabled(false);
@ -1372,6 +1373,7 @@ PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
compoundWordCB->setEnabled(false); compoundWordCB->setEnabled(false);
spellcheckContinuouslyCB->setEnabled(false); spellcheckContinuouslyCB->setEnabled(false);
spellcheckNotesCB->setEnabled(false); spellcheckNotesCB->setEnabled(false);
minlengthSB->setEnabled(false);
#endif #endif
} }
@ -1384,6 +1386,7 @@ void PrefSpellchecker::apply(LyXRC & rc) const
rc.spellchecker_esc_chars = fromqstr(escapeCharactersED->text()); rc.spellchecker_esc_chars = fromqstr(escapeCharactersED->text());
rc.spellchecker_accept_compound = compoundWordCB->isChecked(); rc.spellchecker_accept_compound = compoundWordCB->isChecked();
rc.spellcheck_continuously = spellcheckContinuouslyCB->isChecked(); rc.spellcheck_continuously = spellcheckContinuouslyCB->isChecked();
rc.spellcheck_minlength = minlengthSB->value();
rc.spellcheck_notes = spellcheckNotesCB->isChecked(); rc.spellcheck_notes = spellcheckNotesCB->isChecked();
} }
@ -1395,7 +1398,10 @@ void PrefSpellchecker::update(LyXRC const & rc)
altLanguageED->setText(toqstr(rc.spellchecker_alt_lang)); altLanguageED->setText(toqstr(rc.spellchecker_alt_lang));
escapeCharactersED->setText(toqstr(rc.spellchecker_esc_chars)); escapeCharactersED->setText(toqstr(rc.spellchecker_esc_chars));
compoundWordCB->setChecked(rc.spellchecker_accept_compound); compoundWordCB->setChecked(rc.spellchecker_accept_compound);
spellcheckContinuouslyCB->setChecked(rc.spellcheck_continuously); bool const continuous = rc.spellcheck_continuously;
spellcheckContinuouslyCB->setChecked(continuous);
minlengthSB->setValue(rc.spellcheck_minlength);
minlengthSB->setEnabled(continuous);
spellcheckNotesCB->setChecked(rc.spellcheck_notes); spellcheckNotesCB->setChecked(rc.spellcheck_notes);
} }

View File

@ -1,33 +1,33 @@
<ui version="4.0" > <ui version="4.0">
<class>PrefSpellcheckerUi</class> <class>PrefSpellcheckerUi</class>
<widget class="QWidget" name="PrefSpellcheckerUi" > <widget class="QWidget" name="PrefSpellcheckerUi">
<property name="geometry" > <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>519</width> <width>519</width>
<height>224</height> <height>241</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle">
<string/> <string/>
</property> </property>
<layout class="QGridLayout" > <layout class="QGridLayout">
<property name="margin" > <property name="margin">
<number>9</number> <number>9</number>
</property> </property>
<property name="spacing" > <property name="spacing">
<number>6</number> <number>6</number>
</property> </property>
<item row="6" column="0" colspan="3" > <item row="8" column="0" colspan="3">
<spacer> <spacer>
<property name="orientation" > <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeType" > <property name="sizeType">
<enum>QSizePolicy::Expanding</enum> <enum>QSizePolicy::Expanding</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0">
<size> <size>
<width>501</width> <width>501</width>
<height>21</height> <height>21</height>
@ -35,58 +35,48 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="5" column="0" colspan="2" > <item row="0" column="0">
<widget class="QCheckBox" name="spellcheckNotesCB" > <widget class="QLabel" name="spellcheckerLA">
<property name="toolTip" > <property name="text">
<string>If unchecked, notes and comments will be excluded from spell checking</string>
</property>
<property name="text" >
<string>Spellcheck &amp;notes and comments</string>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="spellcheckerLA" >
<property name="text" >
<string>&amp;Spellchecker engine:</string> <string>&amp;Spellchecker engine:</string>
</property> </property>
<property name="buddy" > <property name="buddy">
<cstring>altLanguageED</cstring> <cstring>altLanguageED</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1" > <item row="0" column="1">
<widget class="QComboBox" name="spellcheckerCB" /> <widget class="QComboBox" name="spellcheckerCB"/>
</item> </item>
<item row="3" column="0" colspan="2" > <item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="compoundWordCB" > <widget class="QCheckBox" name="compoundWordCB">
<property name="toolTip" > <property name="toolTip">
<string>Accept words such as "diskdrive"</string> <string>Accept words such as &quot;diskdrive&quot;</string>
</property> </property>
<property name="text" > <property name="text">
<string>Accept compound &amp;words</string> <string>Accept compound &amp;words</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0" colspan="2" > <item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="spellcheckContinuouslyCB" > <widget class="QCheckBox" name="spellcheckContinuouslyCB">
<property name="toolTip" > <property name="toolTip">
<string>Mark misspelled words with a wavy underline.</string> <string>Mark misspelled words with a wavy underline.</string>
</property> </property>
<property name="text" > <property name="text">
<string>S&amp;pellcheck continuously</string> <string>S&amp;pellcheck continuously</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="2" > <item row="3" column="2">
<spacer> <spacer>
<property name="orientation" > <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeType" > <property name="sizeType">
<enum>QSizePolicy::Expanding</enum> <enum>QSizePolicy::Expanding</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0">
<size> <size>
<width>41</width> <width>41</width>
<height>22</height> <height>22</height>
@ -94,40 +84,73 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="2" column="1" > <item row="2" column="1">
<widget class="QLineEdit" name="escapeCharactersED" > <widget class="QLineEdit" name="escapeCharactersED">
<property name="toolTip" > <property name="toolTip">
<string>The characters inserted here are ignored by the spellchecker. </string> <string>The characters inserted here are ignored by the spellchecker. </string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0" > <item row="2" column="0">
<widget class="QLabel" name="escapeCharactersLA" > <widget class="QLabel" name="escapeCharactersLA">
<property name="text" > <property name="text">
<string>&amp;Escape characters:</string> <string>&amp;Escape characters:</string>
</property> </property>
<property name="buddy" > <property name="buddy">
<cstring>escapeCharactersED</cstring> <cstring>escapeCharactersED</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1" > <item row="1" column="1">
<widget class="QLineEdit" name="altLanguageED" > <widget class="QLineEdit" name="altLanguageED">
<property name="toolTip" > <property name="toolTip">
<string>Override the language used for the spellchecker</string> <string>Override the language used for the spellchecker</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0" > <item row="1" column="0">
<widget class="QLabel" name="altLanguageLA" > <widget class="QLabel" name="altLanguageLA">
<property name="text" > <property name="text">
<string>Al&amp;ternative language:</string> <string>Al&amp;ternative language:</string>
</property> </property>
<property name="buddy" > <property name="buddy">
<cstring>altLanguageED</cstring> <cstring>altLanguageED</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Minimum word length for completion</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QSpinBox" name="minlengthSB">
<property name="toolTip">
<string/>
</property>
<property name="minimum">
<number>5</number>
</property>
<property name="maximum">
<number>15</number>
</property>
<property name="value">
<number>6</number>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="spellcheckNotesCB">
<property name="toolTip">
<string>If unchecked, notes and comments will be excluded from spell checking</string>
</property>
<property name="text">
<string>Spellcheck &amp;notes and comments</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<tabstops> <tabstops>
@ -136,7 +159,7 @@
<tabstop>compoundWordCB</tabstop> <tabstop>compoundWordCB</tabstop>
</tabstops> </tabstops>
<includes> <includes>
<include location="local" >qt_i18n.h</include> <include location="local">qt_i18n.h</include>
</includes> </includes>
<resources/> <resources/>
<connections/> <connections/>