mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-25 05:55:34 +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 "Cut" "cut"
|
||||||
Item "Copy" "copy"
|
Item "Copy" "copy"
|
||||||
Item "Paste" "paste"
|
Item "Paste" "paste"
|
||||||
|
spellingsuggestions
|
||||||
Submenu "Paste Recent|e" "edit_pasterecent"
|
Submenu "Paste Recent|e" "edit_pasterecent"
|
||||||
Separator
|
Separator
|
||||||
Item "Jump Back to Saved Bookmark|B" "bookmark-goto 0"
|
Item "Jump Back to Saved Bookmark|B" "bookmark-goto 0"
|
||||||
|
@ -2965,4 +2965,32 @@ void Paragraph::updateWords()
|
|||||||
registerWords();
|
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
|
} // namespace lyx
|
||||||
|
@ -405,6 +405,9 @@ public:
|
|||||||
word_location const loc) const;
|
word_location const loc) const;
|
||||||
///
|
///
|
||||||
void updateWords();
|
void updateWords();
|
||||||
|
/// Spellcheck word at position \p pos.
|
||||||
|
/// \return true if pointed word is misspelled.
|
||||||
|
bool isMisspelled(pos_type pos) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
///
|
///
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
#include "Paragraph.h"
|
#include "Paragraph.h"
|
||||||
#include "ParIterator.h"
|
#include "ParIterator.h"
|
||||||
#include "Session.h"
|
#include "Session.h"
|
||||||
|
#include "SpellChecker.h"
|
||||||
#include "TextClass.h"
|
#include "TextClass.h"
|
||||||
#include "TocBackend.h"
|
#include "TocBackend.h"
|
||||||
#include "Toolbars.h"
|
#include "Toolbars.h"
|
||||||
@ -160,7 +161,9 @@ public:
|
|||||||
/** Available citation styles for a given citation */
|
/** Available citation styles for a given citation */
|
||||||
CiteStyles,
|
CiteStyles,
|
||||||
/** Available graphics groups */
|
/** Available graphics groups */
|
||||||
GraphicsGroups
|
GraphicsGroups,
|
||||||
|
/// Words suggested by the spellchecker.
|
||||||
|
SpellingSuggestions
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit MenuItem(Kind kind) : kind_(kind), optional_(false) {}
|
explicit MenuItem(Kind kind) : kind_(kind), optional_(false) {}
|
||||||
@ -317,6 +320,7 @@ public:
|
|||||||
void expandIndicesContext(Buffer const * buf, bool listof = false);
|
void expandIndicesContext(Buffer const * buf, bool listof = false);
|
||||||
void expandCiteStyles(BufferView const *);
|
void expandCiteStyles(BufferView const *);
|
||||||
void expandGraphicsGroups(BufferView const *);
|
void expandGraphicsGroups(BufferView const *);
|
||||||
|
void expandSpellingSuggestions(BufferView const *);
|
||||||
///
|
///
|
||||||
ItemList items_;
|
ItemList items_;
|
||||||
///
|
///
|
||||||
@ -422,7 +426,8 @@ void MenuDefinition::read(Lexer & lex)
|
|||||||
md_floatinsert,
|
md_floatinsert,
|
||||||
md_pasterecent,
|
md_pasterecent,
|
||||||
md_toolbars,
|
md_toolbars,
|
||||||
md_graphicsgroups
|
md_graphicsgroups,
|
||||||
|
md_spellingsuggestions
|
||||||
};
|
};
|
||||||
|
|
||||||
LexerKeyword menutags[] = {
|
LexerKeyword menutags[] = {
|
||||||
@ -449,6 +454,7 @@ void MenuDefinition::read(Lexer & lex)
|
|||||||
{ "optsubmenu", md_optsubmenu },
|
{ "optsubmenu", md_optsubmenu },
|
||||||
{ "pasterecent", md_pasterecent },
|
{ "pasterecent", md_pasterecent },
|
||||||
{ "separator", md_separator },
|
{ "separator", md_separator },
|
||||||
|
{ "spellingsuggestions", md_spellingsuggestions },
|
||||||
{ "submenu", md_submenu },
|
{ "submenu", md_submenu },
|
||||||
{ "toc", md_toc },
|
{ "toc", md_toc },
|
||||||
{ "toolbars", md_toolbars },
|
{ "toolbars", md_toolbars },
|
||||||
@ -557,6 +563,10 @@ void MenuDefinition::read(Lexer & lex)
|
|||||||
add(MenuItem(MenuItem::GraphicsGroups));
|
add(MenuItem(MenuItem::GraphicsGroups));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case md_spellingsuggestions:
|
||||||
|
add(MenuItem(MenuItem::SpellingSuggestions));
|
||||||
|
break;
|
||||||
|
|
||||||
case md_indices:
|
case md_indices:
|
||||||
add(MenuItem(MenuItem::Indices));
|
add(MenuItem(MenuItem::Indices));
|
||||||
break;
|
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()
|
void MenuDefinition::expandLastfiles()
|
||||||
{
|
{
|
||||||
LastFilesSection::LastFiles const & lf = theSession().lastFiles().lastFiles();
|
LastFilesSection::LastFiles const & lf = theSession().lastFiles().lastFiles();
|
||||||
@ -1561,6 +1602,10 @@ void Menus::Impl::expand(MenuDefinition const & frommenu,
|
|||||||
tomenu.expandGraphicsGroups(bv);
|
tomenu.expandGraphicsGroups(bv);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MenuItem::SpellingSuggestions:
|
||||||
|
tomenu.expandSpellingSuggestions(bv);
|
||||||
|
break;
|
||||||
|
|
||||||
case MenuItem::Submenu: {
|
case MenuItem::Submenu: {
|
||||||
MenuItem item(*cit);
|
MenuItem item(*cit);
|
||||||
item.setSubmenu(MenuDefinition(cit->submenuname()));
|
item.setSubmenu(MenuDefinition(cit->submenuname()));
|
||||||
|
Loading…
Reference in New Issue
Block a user