Skip to content

Commit f88fc8e

Browse files
committed
#3496 languagetool: add persisting of ignored rules and handling of ignored words
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
1 parent abb6832 commit f88fc8e

9 files changed

Lines changed: 445 additions & 161 deletions

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
## 26.4.0
44

5+
- **LanguageTool** ignored rules and ignored words are now **persisted** across
6+
application restarts; previously, ignored rules were only stored in memory and
7+
lost when the application was closed
8+
(for [#3496](https://github.com/pbek/QOwnNotes/issues/3496))
9+
- Added a new **"Ignore word"** option to the LanguageTool context menu that
10+
allows ignoring specific words (e.g. proper nouns, technical terms) without
11+
disabling the entire rule; ignored words are persisted across restarts
12+
(for [#3496](https://github.com/pbek/QOwnNotes/issues/3496))
13+
- Added **"Reset ignored rules"** and **"Reset ignored words"** buttons to the
14+
LanguageTool settings page to clear all previously ignored rules and words
15+
(for [#3496](https://github.com/pbek/QOwnNotes/issues/3496))
516
- The last selected **Nextcloud Deck** card is now re-selected after the card
617
list is reloaded when a card is stored or the archived cards view is toggled
718
(for [#3357](https://github.com/pbek/QOwnNotes/issues/3357))

src/dialogs/settingsdialog.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "scriptrepositorydialog.h"
5454
#include "services/databaseservice.h"
5555
#ifdef LANGUAGETOOL_ENABLED
56+
#include "services/languagetoolchecker.h"
5657
#include "services/languagetoolclient.h"
5758
#endif
5859
#include "services/nextclouddeckservice.h"
@@ -2168,6 +2169,48 @@ void SettingsDialog::on_languageToolTestConnectionButton_clicked() {
21682169

21692170
client->checkText(options);
21702171
}
2172+
2173+
void SettingsDialog::on_languageToolResetIgnoredRulesButton_clicked() {
2174+
auto *checker = LanguageToolChecker::instance();
2175+
if (checker == nullptr) {
2176+
return;
2177+
}
2178+
2179+
const int count = checker->ignoredRules().size();
2180+
if (count == 0) {
2181+
QMessageBox::information(this, tr("LanguageTool"),
2182+
tr("There are no ignored rules to reset."));
2183+
return;
2184+
}
2185+
2186+
if (QMessageBox::question(this, tr("LanguageTool"), tr("Reset %n ignored rule(s)?", "", count),
2187+
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
2188+
checker->clearIgnoredRules();
2189+
QMessageBox::information(this, tr("LanguageTool"),
2190+
tr("All ignored rules have been reset."));
2191+
}
2192+
}
2193+
2194+
void SettingsDialog::on_languageToolResetIgnoredWordsButton_clicked() {
2195+
auto *checker = LanguageToolChecker::instance();
2196+
if (checker == nullptr) {
2197+
return;
2198+
}
2199+
2200+
const int count = checker->ignoredWords().size();
2201+
if (count == 0) {
2202+
QMessageBox::information(this, tr("LanguageTool"),
2203+
tr("There are no ignored words to reset."));
2204+
return;
2205+
}
2206+
2207+
if (QMessageBox::question(this, tr("LanguageTool"), tr("Reset %n ignored word(s)?", "", count),
2208+
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
2209+
checker->clearIgnoredWords();
2210+
QMessageBox::information(this, tr("LanguageTool"),
2211+
tr("All ignored words have been reset."));
2212+
}
2213+
}
21712214
#endif
21722215

21732216
void SettingsDialog::onLayoutSettingsStored(const QString &workspaceIdentifier) {

src/dialogs/settingsdialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ class SettingsDialog : public MasterDialog {
363363
#ifdef LANGUAGETOOL_ENABLED
364364
void on_languageToolTestConnectionButton_clicked();
365365
void on_languageToolEnabledCheckBox_toggled(bool checked);
366+
void on_languageToolResetIgnoredRulesButton_clicked();
367+
void on_languageToolResetIgnoredWordsButton_clicked();
366368
#endif
367369

368370
private:

src/dialogs/settingsdialog.ui

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7788,16 +7788,65 @@ Just test yourself if you get sync conflicts and set a higher value if so.</stri
77887788
</widget>
77897789
</item>
77907790
</layout>
7791-
</widget>
7792-
</item>
7793-
</layout>
7794-
</widget>
7795-
</item>
7796-
</layout>
7797-
</widget>
7798-
</item>
7799-
<item row="1" column="0">
7800-
<spacer name="verticalSpacer_languageTool">
7791+
</widget>
7792+
</item>
7793+
<item row="5" column="0">
7794+
<widget class="QLabel" name="languageToolIgnoredLabel">
7795+
<property name="text">
7796+
<string>Ignored:</string>
7797+
</property>
7798+
<property name="alignment">
7799+
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
7800+
</property>
7801+
</widget>
7802+
</item>
7803+
<item row="5" column="1" colspan="2">
7804+
<widget class="QWidget" name="languageToolIgnoredWidget" native="true">
7805+
<layout class="QHBoxLayout" name="horizontalLayout_languageToolIgnored">
7806+
<item>
7807+
<widget class="QPushButton" name="languageToolResetIgnoredRulesButton">
7808+
<property name="toolTip">
7809+
<string>Reset all ignored LanguageTool rules so they are checked again</string>
7810+
</property>
7811+
<property name="text">
7812+
<string>Reset ignored rules</string>
7813+
</property>
7814+
</widget>
7815+
</item>
7816+
<item>
7817+
<widget class="QPushButton" name="languageToolResetIgnoredWordsButton">
7818+
<property name="toolTip">
7819+
<string>Reset all ignored words so they are checked by LanguageTool again</string>
7820+
</property>
7821+
<property name="text">
7822+
<string>Reset ignored words</string>
7823+
</property>
7824+
</widget>
7825+
</item>
7826+
<item>
7827+
<spacer name="horizontalSpacer_languageToolIgnored">
7828+
<property name="orientation">
7829+
<enum>Qt::Horizontal</enum>
7830+
</property>
7831+
<property name="sizeHint" stdset="0">
7832+
<size>
7833+
<width>40</width>
7834+
<height>20</height>
7835+
</size>
7836+
</property>
7837+
</spacer>
7838+
</item>
7839+
</layout>
7840+
</widget>
7841+
</item>
7842+
</layout>
7843+
</widget>
7844+
</item>
7845+
</layout>
7846+
</widget>
7847+
</item>
7848+
<item row="1" column="0">
7849+
<spacer name="verticalSpacer_languageTool">
78017850
<property name="orientation">
78027851
<enum>Qt::Vertical</enum>
78037852
</property>

src/helpers/qownnotesmarkdownhighlighter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@ void QOwnNotesMarkdownHighlighter::highlightLanguageTool(const QString &text) {
324324
continue;
325325
}
326326

327+
// Skip matches where the matched word is in the ignored words list
328+
const QString matchedText = text.mid(blockMatch.match.offset, blockMatch.match.length);
329+
if (checker->isWordIgnored(matchedText)) {
330+
continue;
331+
}
332+
327333
if (blockMatch.match.length <= 0) {
328334
continue;
329335
}

0 commit comments

Comments
 (0)