From 8bce5a05c950a2429f1dbb73706b6f5207d413c4 Mon Sep 17 00:00:00 2001 From: Cyril Jacquet Date: Sat, 30 Apr 2022 13:31:53 +0200 Subject: [PATCH] fix spellchecker fix " 's " showing as mispelled on user dict words with english fix behavior of add user dict word dialog fix refresh of text highlighting when adding word or changing dict language --- src/app/src/qml/Commons/WritingZone.qml | 358 +++++++++++------------ src/app/src/skrrootitem.cpp | 4 +- src/app/src/skrspellchecker.cpp | 43 ++- src/app/src/skrspellchecker.h | 2 +- src/plugins/projectPage/UserDictPage.qml | 124 ++++---- src/translations/skribisto_en_US.ts | 10 +- 6 files changed, 268 insertions(+), 273 deletions(-) diff --git a/src/app/src/qml/Commons/WritingZone.qml b/src/app/src/qml/Commons/WritingZone.qml index 1beed23ef..0883a0b12 100755 --- a/src/app/src/qml/Commons/WritingZone.qml +++ b/src/app/src/qml/Commons/WritingZone.qml @@ -40,7 +40,7 @@ WritingZoneForm { } property string placeholderText: "" onPlaceholderTextChanged: { - textArea.placeholderText = placeholderText + textArea.placeholderText = placeholderText } // clipboard : SKRClipboard { @@ -60,36 +60,37 @@ WritingZoneForm { property bool active: false onActiveChanged: { + //console.log("active",active ) } - Timer{ + Timer { id: deactivateTimer interval: 200 onTriggered: { root.active = false } } - //------------------------------------------------- + //------------------------------------------------- property int contentY: 0 - Binding{ - when: !active || leftScrollFlickable.active || rightScrollFlickable.active + Binding { + when: !active || leftScrollFlickable.active + || rightScrollFlickable.active target: flickable property: "contentY" value: root.contentY restoreMode: Binding.RestoreNone - } - Binding{ - when: active && !leftScrollFlickable.active && !rightScrollFlickable.active + Binding { + when: active && !leftScrollFlickable.active + && !rightScrollFlickable.active target: root property: "contentY" value: flickable.contentY restoreMode: Binding.RestoreNone - } //------------------------------------------------- @@ -216,7 +217,7 @@ WritingZoneForm { //----------------------------------------------------------- // ---------context menu :---------------------------------- //----------------------------------------------------------- - textArea.onPressed: function(event) { + textArea.onPressed: function (event) { if (event.buttons === Qt.RightButton) { callTextAreaContextMenu(event.x, event.y) } @@ -584,7 +585,6 @@ WritingZoneForm { SkrSettings.spellCheckingSettings.onSpellCheckingActivationChanged.connect( determineSpellCheckerActivation) determineSpellCheckerActivation() - } } Component.onDestruction: { @@ -627,9 +627,13 @@ WritingZoneForm { } function determineSpellCheckerActivation() { - var value = SkrSettings.spellCheckingSettings.spellCheckingActivation - highlighter.spellChecker.activate( - SkrSettings.spellCheckingSettings.spellCheckingActivation) + var activated = SkrSettings.spellCheckingSettings.spellCheckingActivation + + if (activated) { + highlighter.spellChecker.activate(false) + highlighter.spellChecker.activate(true) + } + highlighter.rehighlight() // needed to "shake" the highlighter @@ -663,7 +667,7 @@ WritingZoneForm { setProjectDictInSpellChecker(projectId) } - highlighter.rehighlight() + determineSpellCheckerActivation() //console.log("langCode :", langCode) } @@ -694,39 +698,29 @@ WritingZoneForm { } // scrollView : - - leftScrollFlickable.onActiveChanged: { - root.active = leftScrollFlickable.active + root.active = leftScrollFlickable.active } rightScrollFlickable.onActiveChanged: { root.active = rightScrollFlickable.active } - flickable.onContentYChanged:{ + flickable.onContentYChanged: { - if(textArea.active){ + if (textArea.active) { root.active = true - if(deactivateTimer.running){ + if (deactivateTimer.running) { deactivateTimer.stop() } deactivateTimer.start() } } - - - - - - - //-------------------------------------------------------------------------------- //--------Page Up/Down------------------------------------------------------------- //--------Text centering---------------------------------------------------------- //-------------------------------------------------------------------------------- - property alias contentYBehaviorEnabled: contentYBehavior.enabled textArea.viewHeight: flickable.height - textArea.topPadding - textArea.bottomPadding @@ -734,9 +728,8 @@ WritingZoneForm { target: textArea function onMoveViewYCalled(height, animationEnabled) { - root.active = true - if(deactivateTimer.running){ + if (deactivateTimer.running) { deactivateTimer.stop() } deactivateTimer.start() @@ -766,13 +759,10 @@ WritingZoneForm { flickable.contentY = flickable.contentHeight - textArea.viewHeight contentYBehavior.enabled = true return - } - else if(flickable.contentHeight < textArea.height){ + } else if (flickable.contentHeight < textArea.height) { return } - - // normal move flickable.contentY += value contentYBehavior.enabled = true @@ -797,7 +787,7 @@ WritingZoneForm { acceptedModifiers: Qt.NoModifier acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad target: leftScrollItem - onWheel: function(event) { + onWheel: function (event) { textArea.moveViewYCalled(-event.angleDelta.y / 2, false) } } @@ -807,7 +797,7 @@ WritingZoneForm { acceptedModifiers: Qt.NoModifier acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad target: rightScrollItem - onWheel: function(event) { + onWheel: function (event) { textArea.moveViewYCalled(-event.angleDelta.y / 2, false) } } @@ -817,160 +807,159 @@ WritingZoneForm { //-------------------------------------------------------------- //--------Highlighter--------------------------------------------- //-------------------------------------------------------------- -// property rect visibleRect: Qt.rect(0, 0, 0, 0) -// //-------------------------------------------------------------------------------- -// flickable.onContentYChanged: determineVisibleRect() - -// function determineVisibleRect() { -// visibleRect = Qt.rect(flickable.contentX, flickable.contentY, -// flickable.contentWidth, flickable.contentHeight) -// } - -// function paintUnderlineForSpellcheck(positionList, blockBegin, blockEnd, uniqueBlock) { -// if (paintUnderlineForSpellcheckTimer.running) { -// paintUnderlineForSpellcheckTimer.stop() -// } - -// paintUnderlineForSpellcheckTimer.positionList = positionList -// paintUnderlineForSpellcheckTimer.blockBegin = blockBegin -// paintUnderlineForSpellcheckTimer.blockEnd = blockEnd -// paintUnderlineForSpellcheckTimer.uniqueBlock = uniqueBlock -// paintUnderlineForSpellcheckTimer.start() -// } -// Timer { -// id: paintUnderlineForSpellcheckTimer -// property var positionList -// property int blockBegin -// property int blockEnd -// property bool uniqueBlock - -// interval: 20 -// onTriggered: { -// determineVisibleRect() -// canvas.positionList = positionList -// canvas.blockBegin = blockBegin -// canvas.blockEnd = blockEnd -// canvas.uniqueBlock = uniqueBlock -// canvas.requestPaint() -// } -// } - -// Connections { -// target: SkrSettings.spellCheckingSettings -// function onSpellCheckingActivationChanged() { -// canvas.spellcheckEnabled = SkrSettings.spellCheckingSettings.spellCheckingActivation -// if (canvas.available) { -// canvas.requestPaint() -// } -// } -// } - -// onVisibleRectChanged: { -// canvas.spellcheckEnabled = SkrSettings.spellCheckingSettings.spellCheckingActivation -// if (canvas.available) { -// canvas.requestPaint() -// } -// } - -// Canvas { -// id: canvas -// parent: scrollView -// anchors.fill: parent - -// //renderStrategy: Canvas.Immediate -// //renderTarget: Canvas.FramebufferObject -// property var positionList: [] -// property int blockBegin: -1 -// property int blockEnd: -1 -// property bool uniqueBlock: false -// property bool spellcheckEnabled: true - -// onPaint: { - -// var pointList = [] -// var charWidthList = [] -// var visiblePositionList = [] - -// //console.log(positionList) -// for (var i = 0; i < positionList.length; i++) { -// var position = positionList[i] -// var rectangle = textArea.positionToRectangle(position) - -// if (rectangle.y + rectangle.height > visibleRect.y -// && rectangle.y + rectangle.height < visibleRect.y + visibleRect.height) { -// visiblePositionList.push(position) -// } - -// // if(rectangle.height < font.pointSize){ -// // return -// } -// for (var j = 0; j < visiblePositionList.length; j++) { -// var position2 = visiblePositionList[j] -// var rectangle2 = textArea.positionToRectangle(position2) -// var nextRectangle = textArea.positionToRectangle(position2 + 1) -// pointList.push( -// Qt.point( -// rectangle2.x, -// rectangle2.y + rectangle2.height - visibleRect.y)) -// var charWidth = nextRectangle.x - rectangle2.x -// if (charWidth < 0) { -// charWidthList.push(charWidthList[charWidthList.lenght - 1]) -// } else { -// charWidthList.push(charWidth) -// } -// } - -// if (uniqueBlock) { -// var blockBeginRectangle = textArea.positionToRectangle( -// blockBegin) -// var blockEndRectangle = textArea.positionToRectangle(blockEnd) -// var blockRectangle = Qt.rect( -// 0, blockBeginRectangle.y - visibleRect.y, -// canvas.width, -// blockEndRectangle.y - blockBeginRectangle.y -// + blockBeginRectangle.height) -// } - -// var ctx = getContext("2d") -// ctx.setLineDash([2, 4]) -// ctx.strokeStyle = SkrTheme.spellcheck -// ctx.beginPath() - -// if (uniqueBlock) { -// ctx.clearRect(blockRectangle.x, blockRectangle.y, -// blockRectangle.width, blockRectangle.height) -// } else { -// ctx.clearRect(0, 0, canvas.width, canvas.height) -// } -// if (spellcheckEnabled) { -// for (var k = 0; k < pointList.length; k++) { -// var spellcheckPoint = pointList[k] - -// ctx.moveTo(spellcheckPoint.x, spellcheckPoint.y) -// ctx.lineTo(spellcheckPoint.x + charWidthList[k], -// spellcheckPoint.y) -// ctx.moveTo(spellcheckPoint.x, spellcheckPoint.y + 1) -// ctx.lineTo(spellcheckPoint.x + charWidthList[k], -// spellcheckPoint.y + 1) -// } - -// ctx.stroke() -// } -// } -// } + // property rect visibleRect: Qt.rect(0, 0, 0, 0) + // //-------------------------------------------------------------------------------- + // flickable.onContentYChanged: determineVisibleRect() + + // function determineVisibleRect() { + // visibleRect = Qt.rect(flickable.contentX, flickable.contentY, + // flickable.contentWidth, flickable.contentHeight) + // } + + // function paintUnderlineForSpellcheck(positionList, blockBegin, blockEnd, uniqueBlock) { + // if (paintUnderlineForSpellcheckTimer.running) { + // paintUnderlineForSpellcheckTimer.stop() + // } + + // paintUnderlineForSpellcheckTimer.positionList = positionList + // paintUnderlineForSpellcheckTimer.blockBegin = blockBegin + // paintUnderlineForSpellcheckTimer.blockEnd = blockEnd + // paintUnderlineForSpellcheckTimer.uniqueBlock = uniqueBlock + // paintUnderlineForSpellcheckTimer.start() + // } + // Timer { + // id: paintUnderlineForSpellcheckTimer + // property var positionList + // property int blockBegin + // property int blockEnd + // property bool uniqueBlock + + // interval: 20 + // onTriggered: { + // determineVisibleRect() + // canvas.positionList = positionList + // canvas.blockBegin = blockBegin + // canvas.blockEnd = blockEnd + // canvas.uniqueBlock = uniqueBlock + // canvas.requestPaint() + // } + // } + + // Connections { + // target: SkrSettings.spellCheckingSettings + // function onSpellCheckingActivationChanged() { + // canvas.spellcheckEnabled = SkrSettings.spellCheckingSettings.spellCheckingActivation + // if (canvas.available) { + // canvas.requestPaint() + // } + // } + // } + + // onVisibleRectChanged: { + // canvas.spellcheckEnabled = SkrSettings.spellCheckingSettings.spellCheckingActivation + // if (canvas.available) { + // canvas.requestPaint() + // } + // } + + // Canvas { + // id: canvas + // parent: scrollView + // anchors.fill: parent + + // //renderStrategy: Canvas.Immediate + // //renderTarget: Canvas.FramebufferObject + // property var positionList: [] + // property int blockBegin: -1 + // property int blockEnd: -1 + // property bool uniqueBlock: false + // property bool spellcheckEnabled: true + + // onPaint: { + + // var pointList = [] + // var charWidthList = [] + // var visiblePositionList = [] + + // //console.log(positionList) + // for (var i = 0; i < positionList.length; i++) { + // var position = positionList[i] + // var rectangle = textArea.positionToRectangle(position) + + // if (rectangle.y + rectangle.height > visibleRect.y + // && rectangle.y + rectangle.height < visibleRect.y + visibleRect.height) { + // visiblePositionList.push(position) + // } + + // // if(rectangle.height < font.pointSize){ + // // return + // } + // for (var j = 0; j < visiblePositionList.length; j++) { + // var position2 = visiblePositionList[j] + // var rectangle2 = textArea.positionToRectangle(position2) + // var nextRectangle = textArea.positionToRectangle(position2 + 1) + // pointList.push( + // Qt.point( + // rectangle2.x, + // rectangle2.y + rectangle2.height - visibleRect.y)) + // var charWidth = nextRectangle.x - rectangle2.x + // if (charWidth < 0) { + // charWidthList.push(charWidthList[charWidthList.lenght - 1]) + // } else { + // charWidthList.push(charWidth) + // } + // } + + // if (uniqueBlock) { + // var blockBeginRectangle = textArea.positionToRectangle( + // blockBegin) + // var blockEndRectangle = textArea.positionToRectangle(blockEnd) + // var blockRectangle = Qt.rect( + // 0, blockBeginRectangle.y - visibleRect.y, + // canvas.width, + // blockEndRectangle.y - blockBeginRectangle.y + // + blockBeginRectangle.height) + // } + + // var ctx = getContext("2d") + // ctx.setLineDash([2, 4]) + // ctx.strokeStyle = SkrTheme.spellcheck + // ctx.beginPath() + + // if (uniqueBlock) { + // ctx.clearRect(blockRectangle.x, blockRectangle.y, + // blockRectangle.width, blockRectangle.height) + // } else { + // ctx.clearRect(0, 0, canvas.width, canvas.height) + // } + // if (spellcheckEnabled) { + // for (var k = 0; k < pointList.length; k++) { + // var spellcheckPoint = pointList[k] + + // ctx.moveTo(spellcheckPoint.x, spellcheckPoint.y) + // ctx.lineTo(spellcheckPoint.x + charWidthList[k], + // spellcheckPoint.y) + // ctx.moveTo(spellcheckPoint.x, spellcheckPoint.y + 1) + // ctx.lineTo(spellcheckPoint.x + charWidthList[k], + // spellcheckPoint.y + 1) + // } + + // ctx.stroke() + // } + // } + // } //focus : onActiveFocusChanged: { if (activeFocus) { - if(priv.forceActiveFocusEnabled){ + if (priv.forceActiveFocusEnabled) { textArea.forceActiveFocus() } - } else { } } - QtObject{ + QtObject { id: priv property bool forceActiveFocusEnabled: true } @@ -982,9 +971,8 @@ WritingZoneForm { findPanel.highlighter: documentHandler.highlighter findPanel.textArea: textArea - - function showFindPanel(){ - if(textArea.selectedText.length > 0){ + function showFindPanel() { + if (textArea.selectedText.length > 0) { findPanel.stringToFind = textArea.selectedText } @@ -994,7 +982,6 @@ WritingZoneForm { priv.forceActiveFocusEnabled = true } - Action { id: findAction enabled: root.activeFocus @@ -1006,4 +993,3 @@ WritingZoneForm { } } } - diff --git a/src/app/src/skrrootitem.cpp b/src/app/src/skrrootitem.cpp index f5ee859ed..b9c23146f 100755 --- a/src/app/src/skrrootitem.cpp +++ b/src/app/src/skrrootitem.cpp @@ -221,8 +221,8 @@ QString SKRRootItem::getWritableAddonsPathsListDir() const { QString SKRRootItem::cleanUpHtml(const QString& html) { // QString text = html; - qDebug() << "§§§§§§§§§§§§§§§§§§§§§§§§"; - qDebug() << "pre" << html; + //qDebug() << "§§§§§§§§§§§§§§§§§§§§§§§§"; + //qDebug() << "pre" << html; QTextDocument doc; diff --git a/src/app/src/skrspellchecker.cpp b/src/app/src/skrspellchecker.cpp index 4e06d2526..8effb2899 100755 --- a/src/app/src/skrspellchecker.cpp +++ b/src/app/src/skrspellchecker.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -183,16 +184,29 @@ QStringList SKRSpellChecker::suggest(const QString& word) // NOTE maybe useless void SKRSpellChecker::ignoreWord(const QString& word) { - addWordToDict(word); + addWordToDict(word, ""); } -void SKRSpellChecker::addWordToDict(const QString& word) +void SKRSpellChecker::addWordToDict(const QString& word, const QString& affix) { if (word == "") return; - if (m_encodingFix == "latin1") m_hunspell->add(word.toLatin1().toStdString()); + qDebug() << "word added to user dict" << word << affix; - if (m_encodingFix == "utf8") m_hunspell->add(word.toUtf8().toStdString()); + if(affix.isEmpty()){ + + if (m_encodingFix == "latin1") m_hunspell->add(word.toLatin1().toStdString()); + + if (m_encodingFix == "utf8") m_hunspell->add(word.toUtf8().toStdString()); + + } + else{ + + if (m_encodingFix == "latin1") m_hunspell->add_with_affix(word.toLatin1().toStdString(), affix.toLatin1().toStdString()); + + if (m_encodingFix == "utf8") m_hunspell->add_with_affix(word.toUtf8().toStdString(), affix.toUtf8().toStdString()); + + } } // --------------------------------------------------------------------------------- @@ -204,7 +218,25 @@ void SKRSpellChecker::addWordToUserDict(const QString& word, bool emitSignal) return; } - addWordToDict(word); + QString affix = ""; + qDebug() << "m_langCode" << m_langCode; + if(m_langCode.contains("en")){ + affix = "M"; + } + + + addWordToDict(word, affix); + std::vector stringVector = m_hunspell->suffix_suggest(word.toUtf8().toStdString()); + QList stringList; + stringList.reserve(stringVector.size()); + std::copy(stringVector.begin(), stringVector.end(), std::back_inserter(stringList)); + + QStringList suffixList; + for(const std::string &str : stringList){ + qDebug()<< "suffix_suggest" << QString::fromStdString(str); + } + + if (!m_userDict.contains(word)) { m_userDict.append(word); @@ -394,6 +426,7 @@ void SKRSpellChecker::setLangCode(const QString& newLangCode) qWarning() << QString("Dict %1 not found, using en_US").arg(newLangCode); } this->setDict(dictPath); + m_langCode = newLangCode; emit langCodeChanged(newLangCode); diff --git a/src/app/src/skrspellchecker.h b/src/app/src/skrspellchecker.h index b52732752..6b2bfca44 100755 --- a/src/app/src/skrspellchecker.h +++ b/src/app/src/skrspellchecker.h @@ -86,7 +86,7 @@ class SKRSpellChecker : public QObject { // fix bug when hunspell gives me latin1 encoded results on several Linux // systems : QString testHunspellForEncoding(); - void addWordToDict(const QString& word); + void addWordToDict(const QString& word, const QString &affix); Hunspell *m_hunspell; bool m_isActive, m_hunspellLaunched; QStringList m_userDict; diff --git a/src/plugins/projectPage/UserDictPage.qml b/src/plugins/projectPage/UserDictPage.qml index bcba3080d..eb31f4d43 100644 --- a/src/plugins/projectPage/UserDictPage.qml +++ b/src/plugins/projectPage/UserDictPage.qml @@ -8,7 +8,6 @@ import "../../../../Items" import "../../../../Commons" import "../../../.." - UserDictPageForm { id: root @@ -21,18 +20,16 @@ UserDictPageForm { Connections { target: skrData.projectDictHub() function onProjectDictFullyChanged(projectId, projectDictList) { - if(root.projectId === projectId){ + if (root.projectId === projectId) { populateList() } } } - - Connections { target: skrData.projectDictHub() function onProjectDictWordAdded(projectId, newWord) { - if(root.projectId === projectId){ + if (root.projectId === projectId) { populateList() } } @@ -41,7 +38,7 @@ UserDictPageForm { Connections { target: skrData.projectDictHub() function onProjectDictWordRemoved(projectId, wordToRemove) { - if(root.projectId === projectId){ + if (root.projectId === projectId) { populateList() } } @@ -53,12 +50,15 @@ UserDictPageForm { listView.model: listModel - function populateList(){ + function populateList() { listModel.clear() - var dictList = skrData.projectDictHub().getProjectDictList(root.projectId) + var dictList = skrData.projectDictHub().getProjectDictList( + root.projectId) - dictList.forEach(word => listModel.append({"word": word})) + dictList.forEach(word => listModel.append({ + "word": word + })) } listView.delegate: Component { @@ -68,9 +68,6 @@ UserDictPageForm { height: 30 focus: true - - - Accessible.name: model.word Accessible.role: Accessible.ListItem @@ -88,7 +85,7 @@ UserDictPageForm { // delegateRoot.forceActiveFocus() // eventPoint.accepted = true // } - onSingleTapped: function(eventPoint) { + onSingleTapped: function (eventPoint) { //create relationship with note listView.currentIndex = model.index delegateRoot.forceActiveFocus() @@ -97,18 +94,11 @@ UserDictPageForm { eventPoint.accepted = true } - - onGrabChanged: function(transition, point) { + onGrabChanged: function (transition, point) { point.accepted = false } - - } - - - - SkrLabel { text: model.word anchors.fill: parent @@ -116,16 +106,15 @@ UserDictPageForm { anchors.rightMargin: 3 horizontalAlignment: Qt.AlignLeft verticalAlignment: Qt.AlignVCenter - } } } - listView.highlight: Component { + listView.highlight: Component { id: highlight Rectangle { radius: 5 - border.color: SkrTheme.accent + border.color: SkrTheme.accent border.width: 2 visible: listView.activeFocus Behavior on y { @@ -139,50 +128,47 @@ UserDictPageForm { } } - listView.onActiveFocusChanged: { - if(activeFocus){ - if(listView.count > 0){ + if (activeFocus) { + if (listView.count > 0) { listView.itemAtIndex(0).forceActiveFocus() } } - } - - Action { id: addWordAction text: qsTr("Add word to dictionary") icon.source: "qrc:///icons/backup/list-add.svg" onTriggered: { addWordToDProjectDictDialog.open() - } } addWordButton.action: addWordAction SKRSpellChecker { - id : spellChecker + id: spellChecker Component.onCompleted: { var lang = skrData.projectHub().getLangCode(root.projectId) - if(lang){ - spellChecker.setLangCode(skrData.projectHub().getLangCode(root.projectId)) - spellChecker.setUserDict(skrData.projectDictHub().getProjectDictList(root.projectId)) - - + if (lang) { + spellChecker.setLangCode(skrData.projectHub().getLangCode( + root.projectId)) + spellChecker.setUserDict(skrData.projectDictHub( + ).getProjectDictList( + root.projectId)) + } } } - } - - Connections{ + Connections { target: skrData.projectHub() - function onLangCodeChanged(projectId, newLang){ - if(projectId === root.projectId){ + function onLangCodeChanged(projectId, newLang) { + if (projectId === root.projectId) { spellChecker.setLangCode(newLang) - spellChecker.setUserDict(skrData.projectDictHub().getProjectDictList(root.projectId)) + spellChecker.setUserDict(skrData.projectDictHub( + ).getProjectDictList( + root.projectId)) } } } @@ -198,68 +184,63 @@ UserDictPageForm { Layout.fillWidth: true text: "" - onAccepted: { - if(spellChecker.spell(addWordTextField.text)){ - addWordToDProjectDictDialog.accept() - } - } - onTextChanged: { - if(!spellChecker.active){ + if (addWordTextField.text === "") { label.text = "" - - } - else if(spellChecker.spell(addWordTextField.text)){ + } else if (spellChecker.spell(addWordTextField.text)) { label.text = qsTr("Word already in dictionary") - } - else { + addWordToDProjectDictDialog.standardButtons = Dialog.Cancel + addWordToDProjectDictDialog.width = 401 + addWordToDProjectDictDialog.width = 400 + } else { label.text = "" + addWordToDProjectDictDialog.standardButtons = Dialog.Ok | Dialog.Cancel + addWordToDProjectDictDialog.width = 401 + addWordToDProjectDictDialog.width = 400 } } + + Keys.onReturnPressed: addWordToDProjectDictDialog.accept() + Keys.onEnterPressed: addWordToDProjectDictDialog.accept() + Keys.onEscapePressed: addWordToDProjectDictDialog.reject() } SkrLabel { id: label Layout.alignment: Qt.AlignCenter Layout.fillWidth: true - - } - } - standardButtons: Dialog.Ok | Dialog.Cancel + standardButtons: Dialog.Cancel onRejected: { addWordTextField.text = "" - } onDiscarded: { - addWordTextField.text = "" - } onAccepted: { - - skrData.projectDictHub().addWordToProjectDict(root.projectId, addWordTextField.text) + if (!spellChecker.spell(addWordTextField.text)) { + skrData.projectDictHub().addWordToProjectDict( + root.projectId, addWordTextField.text) + } addWordTextField.text = "" } onActiveFocusChanged: { - if(activeFocus){ + if (activeFocus) { addWordTextField.forceActiveFocus() } - } onOpened: { addWordTextField.text = "" addWordTextField.forceActiveFocus() } - } QtObject { @@ -267,19 +248,14 @@ UserDictPageForm { property string selectedWord: "" } - Action { id: removeWordAction text: qsTr("Remove word from dictionary") icon.source: "qrc:///icons/backup/list-remove.svg" onTriggered: { - skrData.projectDictHub().removeWordFromProjectDict(root.projectId, priv.selectedWord) + skrData.projectDictHub().removeWordFromProjectDict( + root.projectId, priv.selectedWord) } } removeWordButton.action: removeWordAction - - - - - } diff --git a/src/translations/skribisto_en_US.ts b/src/translations/skribisto_en_US.ts index 1804b3e9d..d89098e28 100644 --- a/src/translations/skribisto_en_US.ts +++ b/src/translations/skribisto_en_US.ts @@ -3706,22 +3706,22 @@ UserDictPage - + Add word to dictionary - + Add a word to the project dictionary - + Word already in dictionary - + Remove word from dictionary @@ -3820,7 +3820,7 @@ WritingZone - + Find