MCPcopy Create free account
hub / github.com/baumgarr/nixnote2 / spellCheckPressed

Method spellCheckPressed

gui/nbrowserwindow.cpp:3500–3556  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3498
3499
3500void NBrowserWindow::spellCheckPressed() {
3501 // Check if we have a plugin for Hunspell loaded. This could have been done at startup, but if this is
3502 // an external window we could need to load it again.
3503 if (!hunspellInterface) {
3504 this->loadPlugins();
3505 }
3506
3507 // If we STILL don't have a plugin then it can't be loaded. Quit out
3508 if (!hunspellPluginAvailable) {
3509 QMessageBox::critical(this, tr("Plugin Error"), tr("Hunspell plugin not found or could not be loaded."), QMessageBox::Ok);
3510 return;
3511 }
3512
3513 QWebPage *page = editor->page();
3514 page->action(QWebPage::MoveToStartOfDocument);
3515 page->mainFrame()->setFocus();
3516
3517 Qt::KeyboardModifier ctrl(Qt::ControlModifier);
3518
3519 QKeyEvent key(QEvent::KeyPress, Qt::Key_Home, ctrl);
3520 editor->keyPressEvent(&key);
3521 page->mainFrame()->setFocus();
3522
3523 QStringList words = page->mainFrame()->toPlainText().split(" ");
3524 QStringList ignoreWords;
3525 QStringList rwords;
3526 //SpellChecker checker;
3527 bool finished = false;
3528
3529 for (int i=0; i<words.size() && !finished; i++) {
3530 QString currentWord = words[i];
3531 page->findText(currentWord);
3532 rwords.clear();
3533 if (!hunspellInterface->spellCheck(currentWord, rwords) && !ignoreWords.contains(currentWord)) {
3534 SpellCheckDialog dialog(currentWord, rwords, this);
3535 dialog.move(0,0);
3536 dialog.exec();
3537 if (dialog.cancelPressed)
3538 finished = true;
3539 if (dialog.ignoreAllPressed)
3540 ignoreWords.append(currentWord);
3541 if (dialog.replacePressed) {
3542 QApplication::clipboard()->setText(dialog.replacement);
3543 pasteButtonPressed();
3544 }
3545 if (dialog.addToDictionaryPressed) {
3546 hunspellInterface->addWord(global.fileManager.getSpellDirPathUser() +"user.lst", currentWord);
3547 }
3548 }
3549 }
3550
3551 // Go to the end of the document & finish up
3552 QKeyEvent key2(QEvent::KeyPress, Qt::Key_End, ctrl);
3553 editor->keyPressEvent(&key2);
3554
3555 QMessageBox::information(this, tr("Spell Check Complete"), tr("Spell Check Complete."), QMessageBox::Ok);
3556}
3557

Callers 1

spellCheckCurrentNoteMethod · 0.80

Calls 8

loadPluginsMethod · 0.95
getSpellDirPathUserMethod · 0.80
keyPressEventMethod · 0.45
clearMethod · 0.45
spellCheckMethod · 0.45
execMethod · 0.45
setTextMethod · 0.45
addWordMethod · 0.45

Tested by

no test coverage detected