mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 21:40:19 +00:00
SpellChecker context menu. Part of the continuous SpellChecker project.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29556 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
51978827f4
commit
47aca38a5e
@ -279,6 +279,7 @@ Menuset
|
||||
Item "Cut" "cut"
|
||||
Item "Copy" "copy"
|
||||
Item "Paste" "paste"
|
||||
spellingsuggestions
|
||||
Submenu "Paste Recent|e" "edit_pasterecent"
|
||||
Separator
|
||||
Item "Jump Back to Saved Bookmark|B" "bookmark-goto 0"
|
||||
|
@ -2965,4 +2965,32 @@ void Paragraph::updateWords()
|
||||
registerWords();
|
||||
}
|
||||
|
||||
|
||||
bool Paragraph::isMisspelled(pos_type pos) const
|
||||
{
|
||||
SpellChecker * speller = theSpellChecker();
|
||||
pos_type from = pos;
|
||||
pos_type to = pos;
|
||||
locateWord(from, to, WHOLE_WORD);
|
||||
docstring word = asString(from, to, false);
|
||||
if (!speller)
|
||||
return false;
|
||||
|
||||
string lang_code = lyxrc.spellchecker_use_alt_lang
|
||||
? lyxrc.spellchecker_alt_lang
|
||||
: getFontSettings(d->inset_owner_->buffer().params(), from).language()->code();
|
||||
WordLangTuple wl(word, lang_code);
|
||||
SpellChecker::Result res = speller->check(wl);
|
||||
// ... just ignore any error that the spellchecker reports.
|
||||
if (!speller->error().empty())
|
||||
return false;
|
||||
|
||||
bool const misspelled = res != SpellChecker::OK
|
||||
&& res != SpellChecker::IGNORED_WORD;
|
||||
if (lyxrc.spellcheck_continuously)
|
||||
d->fontlist_.setMisspelled(from, pos, misspelled);
|
||||
return misspelled;
|
||||
}
|
||||
|
||||
|
||||
} // namespace lyx
|
||||
|
@ -405,6 +405,9 @@ public:
|
||||
word_location const loc) const;
|
||||
///
|
||||
void updateWords();
|
||||
/// Spellcheck word at position \p pos.
|
||||
/// \return true if pointed word is misspelled.
|
||||
bool isMisspelled(pos_type pos) const;
|
||||
|
||||
private:
|
||||
///
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "Paragraph.h"
|
||||
#include "ParIterator.h"
|
||||
#include "Session.h"
|
||||
#include "SpellChecker.h"
|
||||
#include "TextClass.h"
|
||||
#include "TocBackend.h"
|
||||
#include "Toolbars.h"
|
||||
@ -160,7 +161,9 @@ public:
|
||||
/** Available citation styles for a given citation */
|
||||
CiteStyles,
|
||||
/** Available graphics groups */
|
||||
GraphicsGroups
|
||||
GraphicsGroups,
|
||||
/// Words suggested by the spellchecker.
|
||||
SpellingSuggestions
|
||||
};
|
||||
|
||||
explicit MenuItem(Kind kind) : kind_(kind), optional_(false) {}
|
||||
@ -317,6 +320,7 @@ public:
|
||||
void expandIndicesContext(Buffer const * buf, bool listof = false);
|
||||
void expandCiteStyles(BufferView const *);
|
||||
void expandGraphicsGroups(BufferView const *);
|
||||
void expandSpellingSuggestions(BufferView const *);
|
||||
///
|
||||
ItemList items_;
|
||||
///
|
||||
@ -422,7 +426,8 @@ void MenuDefinition::read(Lexer & lex)
|
||||
md_floatinsert,
|
||||
md_pasterecent,
|
||||
md_toolbars,
|
||||
md_graphicsgroups
|
||||
md_graphicsgroups,
|
||||
md_spellingsuggestions
|
||||
};
|
||||
|
||||
LexerKeyword menutags[] = {
|
||||
@ -449,6 +454,7 @@ void MenuDefinition::read(Lexer & lex)
|
||||
{ "optsubmenu", md_optsubmenu },
|
||||
{ "pasterecent", md_pasterecent },
|
||||
{ "separator", md_separator },
|
||||
{ "spellingsuggestions", md_spellingsuggestions },
|
||||
{ "submenu", md_submenu },
|
||||
{ "toc", md_toc },
|
||||
{ "toolbars", md_toolbars },
|
||||
@ -557,6 +563,10 @@ void MenuDefinition::read(Lexer & lex)
|
||||
add(MenuItem(MenuItem::GraphicsGroups));
|
||||
break;
|
||||
|
||||
case md_spellingsuggestions:
|
||||
add(MenuItem(MenuItem::SpellingSuggestions));
|
||||
break;
|
||||
|
||||
case md_indices:
|
||||
add(MenuItem(MenuItem::Indices));
|
||||
break;
|
||||
@ -702,6 +712,37 @@ void MenuDefinition::expandGraphicsGroups(BufferView const * bv)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MenuDefinition::expandSpellingSuggestions(BufferView const * bv)
|
||||
{
|
||||
if (!bv)
|
||||
return;
|
||||
Paragraph const & par = bv->cursor().paragraph();
|
||||
if (!par.isMisspelled(bv->cursor().pos()))
|
||||
return;
|
||||
LYXERR0("Misspelled Word!");
|
||||
|
||||
SpellChecker * speller = theSpellChecker();
|
||||
docstring word;
|
||||
int i = 0;
|
||||
MenuItem item(MenuItem::Submenu, qt_("more spelling suggestions"));
|
||||
item.setSubmenu(MenuDefinition(qt_("more spelling suggestions")));
|
||||
while (!(word = speller->nextMiss()).empty()) {
|
||||
LYXERR0("Misspelled Word = " << word);
|
||||
MenuItem w(MenuItem::Command, toqstr(word),
|
||||
FuncRequest(LFUN_WORD_REPLACE, word));
|
||||
if (i < 10) {
|
||||
add(w);
|
||||
} else {
|
||||
item.submenu().add(w);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
if (i >= 10)
|
||||
add(item);
|
||||
}
|
||||
|
||||
|
||||
void MenuDefinition::expandLastfiles()
|
||||
{
|
||||
LastFilesSection::LastFiles const & lf = theSession().lastFiles().lastFiles();
|
||||
@ -1561,6 +1602,10 @@ void Menus::Impl::expand(MenuDefinition const & frommenu,
|
||||
tomenu.expandGraphicsGroups(bv);
|
||||
break;
|
||||
|
||||
case MenuItem::SpellingSuggestions:
|
||||
tomenu.expandSpellingSuggestions(bv);
|
||||
break;
|
||||
|
||||
case MenuItem::Submenu: {
|
||||
MenuItem item(*cit);
|
||||
item.setSubmenu(MenuDefinition(cit->submenuname()));
|
||||
|
Loading…
Reference in New Issue
Block a user