sw/source/core/edit/edlingu.cxx | 10 +++--- sw/source/uibase/lingu/olmenu.cxx | 29 +----------------- sw/source/uibase/shells/textsh1.cxx | 58 +++++++++++++++++++++++++++++++++--- 3 files changed, 62 insertions(+), 35 deletions(-)
New commits: commit 352966952641eed80ae94de57065b0e0896116a6 Author: Tamás Zolnai <tamas.zol...@collabora.com> AuthorDate: Sun Nov 17 13:18:34 2019 +0100 Commit: Tamás Zolnai <tamas.zol...@collabora.com> CommitDate: Sat Nov 23 22:37:28 2019 +0100 SpellingPopup: Convert "IgnoreAll" menu item to use a slot ID (spelling). When the popup is in spelling mode. "IgnoreAll_Spelling" rule triggers this method. Change-Id: Ia1e1877f8501beff29f09bc33621c8f03008b7e8 Reviewed-on: https://gerrit.libreoffice.org/83588 Reviewed-by: Tamás Zolnai <tamas.zol...@collabora.com> Tested-by: Tamás Zolnai <tamas.zol...@collabora.com> diff --git a/sw/source/core/edit/edlingu.cxx b/sw/source/core/edit/edlingu.cxx index 1c03f321de69..f0220a8e7ef2 100644 --- a/sw/source/core/edit/edlingu.cxx +++ b/sw/source/core/edit/edlingu.cxx @@ -897,12 +897,13 @@ uno::Reference< XSpellAlternatives > return nullptr; SwPaM* pCursor = GetCursor(); SwPosition aPos( *pCursor->GetPoint() ); - Point aPt( *pPt ); SwCursorMoveState eTmpState( MV_SETONLYTEXT ); SwTextNode *pNode = nullptr; SwWrongList *pWrong = nullptr; - if (GetLayout()->GetCursorOfst( &aPos, aPt, &eTmpState )) + if (pPt && GetLayout()->GetCursorOfst( &aPos, *(const_cast<Point*>(pPt)), &eTmpState )) pNode = aPos.nNode.GetNode().GetTextNode(); + if (nullptr == pNode) + pNode = pCursor->GetNode().GetTextNode(); if (nullptr != pNode) pWrong = pNode->GetWrong(); if (nullptr != pWrong && !pNode->IsInProtectSect()) diff --git a/sw/source/uibase/lingu/olmenu.cxx b/sw/source/uibase/lingu/olmenu.cxx index 4d2e83131636..57260b5b4dd7 100644 --- a/sw/source/uibase/lingu/olmenu.cxx +++ b/sw/source/uibase/lingu/olmenu.cxx @@ -716,19 +716,8 @@ void SwSpellPopup::Execute( sal_uInt16 nId ) } else if (nId == m_nIgnoreWordId) { - uno::Reference< linguistic2::XDictionary > xDictionary = LinguMgr::GetIgnoreAllList(); - if (m_bGrammarResults) { - SfxStringItem aIgnoreString(FN_PARAM_1, "IgnoreAll_Grammar"); - m_pSh->GetView().GetViewFrame()->GetDispatcher()->ExecuteList(SID_APPLY_SPELLCHECKING, SfxCallMode::SYNCHRON, { &aIgnoreString }); - } else { - OUString sWord(m_xSpellAlt->getWord()); - linguistic::DictionaryError nAddRes = linguistic::AddEntryToDic( xDictionary, - sWord, false, OUString() ); - if (linguistic::DictionaryError::NONE != nAddRes && !xDictionary->getEntry(sWord).is()) - { - SvxDicError(m_pSh->GetView().GetFrameWeld(), nAddRes); - } - } + SfxStringItem aIgnoreString(FN_PARAM_1, m_bGrammarResults ? OUString("IgnoreAll_Grammar") : OUString("IgnoreAll_Spelling")); + m_pSh->GetView().GetViewFrame()->GetDispatcher()->ExecuteList(SID_APPLY_SPELLCHECKING, SfxCallMode::SYNCHRON, { &aIgnoreString }); } else if ((MN_DICTIONARIES_START <= nId && nId <= MN_DICTIONARIES_END) || nId == m_nAddId) { diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx index 510c25432e32..bff08a595f18 100644 --- a/sw/source/uibase/shells/textsh1.cxx +++ b/sw/source/uibase/shells/textsh1.cxx @@ -105,6 +105,7 @@ #include <com/sun/star/uno/Any.hxx> #include <com/sun/star/linguistic2/ProofreadingResult.hpp> #include <com/sun/star/linguistic2/XDictionary.hpp> +#include <com/sun/star/linguistic2/XSpellAlternatives.hpp> #include <editeng/unolingu.hxx> #include <unotools/syslocaleoptions.hxx> #include <doc.hxx> @@ -126,6 +127,7 @@ #include <memory> #include <xmloff/odffields.hxx> #include <bookmrk.hxx> +#include <linguistic/misc.hxx> using namespace ::com::sun::star; using namespace com::sun::star::beans; @@ -1440,7 +1442,7 @@ void SwTextShell::Execute(SfxRequest &rReq) const OUString sIgnoreString("Ignore"); const OUString sIgnoreAllPrefix("IgnoreAll_"); - //const OUString sSpellingRule("Spelling"); + const OUString sSpellingRule("Spelling"); const OUString sGrammarRule("Grammar"); //const OUString aReplacePrefix("Replace_"); @@ -1466,7 +1468,7 @@ void SwTextShell::Execute(SfxRequest &rReq) bool bCorrectionRes = rWrtSh.GetGrammarCorrection( aGrammarCheckRes, nErrorPosInText, nErrorInResult, aSuggestions, nullptr, aToFill ); if(bCorrectionRes) { - try{ + try { uno::Reference< linguistic2::XDictionary > xDictionary = LinguMgr::GetIgnoreAllList(); aGrammarCheckRes.xProofreader->ignoreRule( aGrammarCheckRes.aErrors[ nErrorInResult ].aRuleIdentifier, @@ -1484,6 +1486,19 @@ void SwTextShell::Execute(SfxRequest &rReq) } } } + else if (sApplyText == sSpellingRule) + { + SwRect aToFill; + uno::Reference< linguistic2::XSpellAlternatives > xSpellAlt( rWrtSh.GetCorrection(nullptr, aToFill) ); + uno::Reference< linguistic2::XDictionary > xDictionary = LinguMgr::GetIgnoreAllList(); + OUString sWord(xSpellAlt->getWord()); + linguistic::DictionaryError nAddRes = linguistic::AddEntryToDic( xDictionary, + sWord, false, OUString() ); + if (linguistic::DictionaryError::NONE != nAddRes && !xDictionary->getEntry(sWord).is()) + { + SvxDicError(rWrtSh.GetView().GetFrameWeld(), nAddRes); + } + } } } break; commit 8eedef976ee5393137298756ad53d199a543fede Author: Tamás Zolnai <tamas.zol...@collabora.com> AuthorDate: Sat Nov 16 15:17:57 2019 +0100 Commit: Tamás Zolnai <tamas.zol...@collabora.com> CommitDate: Sat Nov 23 22:37:14 2019 +0100 SpellingPopup: Convert "IgnoreAll" menu item to use a slot ID (grammar). When the popup is in grammar mode. "IgnoreAll_Grammar" rule triggers this method. When openning the spelling popup we have the suspicious text selected, so we don't need the mouse position to apply the changes. I updated GetGrammarCorrection() method accordingly. Change-Id: Iaf86544ea5f7dbc4afa2889772a5a38c5fd5707e Reviewed-on: https://gerrit.libreoffice.org/83587 Reviewed-by: Tamás Zolnai <tamas.zol...@collabora.com> Tested-by: Tamás Zolnai <tamas.zol...@collabora.com> diff --git a/sw/source/core/edit/edlingu.cxx b/sw/source/core/edit/edlingu.cxx index ef4c5af85743..1c03f321de69 100644 --- a/sw/source/core/edit/edlingu.cxx +++ b/sw/source/core/edit/edlingu.cxx @@ -963,12 +963,13 @@ bool SwEditShell::GetGrammarCorrection( SwPaM* pCursor = GetCursor(); SwPosition aPos( *pCursor->GetPoint() ); - Point aPt( *pPt ); SwCursorMoveState eTmpState( MV_SETONLYTEXT ); SwTextNode *pNode = nullptr; SwGrammarMarkUp *pWrong = nullptr; - if (GetLayout()->GetCursorOfst( &aPos, aPt, &eTmpState )) + if (pPt && GetLayout()->GetCursorOfst( &aPos, *(const_cast<Point*>(pPt)), &eTmpState )) pNode = aPos.nNode.GetNode().GetTextNode(); + if (nullptr == pNode) + pNode = pCursor->GetNode().GetTextNode(); if (nullptr != pNode) pWrong = pNode->GetGrammarCheck(); if (nullptr != pWrong && !pNode->IsInProtectSect()) diff --git a/sw/source/uibase/lingu/olmenu.cxx b/sw/source/uibase/lingu/olmenu.cxx index e627534fdf6e..4d2e83131636 100644 --- a/sw/source/uibase/lingu/olmenu.cxx +++ b/sw/source/uibase/lingu/olmenu.cxx @@ -718,22 +718,8 @@ void SwSpellPopup::Execute( sal_uInt16 nId ) { uno::Reference< linguistic2::XDictionary > xDictionary = LinguMgr::GetIgnoreAllList(); if (m_bGrammarResults) { - try - { - m_xGrammarResult.xProofreader->ignoreRule( - m_xGrammarResult.aErrors[ m_nGrammarError ].aRuleIdentifier, - m_xGrammarResult.aLocale ); - // refresh the layout of the actual paragraph (faster) - SwPaM *pPaM = m_pSh->GetCursor(); - if (pPaM) - SwEditShell::IgnoreGrammarErrorAt( *pPaM ); - // refresh the layout of all paragraphs (workaround to launch a dictionary event) - xDictionary->setActive(false); - xDictionary->setActive(true); - } - catch( const uno::Exception& ) - { - } + SfxStringItem aIgnoreString(FN_PARAM_1, "IgnoreAll_Grammar"); + m_pSh->GetView().GetViewFrame()->GetDispatcher()->ExecuteList(SID_APPLY_SPELLCHECKING, SfxCallMode::SYNCHRON, { &aIgnoreString }); } else { OUString sWord(m_xSpellAlt->getWord()); linguistic::DictionaryError nAddRes = linguistic::AddEntryToDic( xDictionary, diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx index fc940da44737..510c25432e32 100644 --- a/sw/source/uibase/shells/textsh1.cxx +++ b/sw/source/uibase/shells/textsh1.cxx @@ -103,6 +103,8 @@ #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <com/sun/star/util/XChangesBatch.hpp> #include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/linguistic2/ProofreadingResult.hpp> +#include <com/sun/star/linguistic2/XDictionary.hpp> #include <editeng/unolingu.hxx> #include <unotools/syslocaleoptions.hxx> #include <doc.hxx> @@ -1437,19 +1439,52 @@ void SwTextShell::Execute(SfxRequest &rReq) sApplyText = pItem2->GetValue(); const OUString sIgnoreString("Ignore"); - //const OUString sIgnoreAllPrefix("IgnoreAll_"); + const OUString sIgnoreAllPrefix("IgnoreAll_"); //const OUString sSpellingRule("Spelling"); - //const OUString sGrammarRule("Grammar"); + const OUString sGrammarRule("Grammar"); //const OUString aReplacePrefix("Replace_"); // Ignore the word at the cursor pos - //sal_Int32 nPos = 0; + sal_Int32 nPos = 0; if (sApplyText == sIgnoreString) { SwPaM *pPaM = rWrtSh.GetCursor(); if (pPaM) SwEditShell::IgnoreGrammarErrorAt( *pPaM ); } + // Ignore all similar items as the current word + else if (-1 != (nPos = sApplyText.indexOf( sIgnoreAllPrefix ))) + { + sApplyText = sApplyText.replaceAt(nPos, sIgnoreAllPrefix.getLength(), ""); + if(sApplyText == sGrammarRule) + { + linguistic2::ProofreadingResult aGrammarCheckRes; + sal_Int32 nErrorInResult = -1; + uno::Sequence< OUString > aSuggestions; + sal_Int32 nErrorPosInText = -1; + SwRect aToFill; + bool bCorrectionRes = rWrtSh.GetGrammarCorrection( aGrammarCheckRes, nErrorPosInText, nErrorInResult, aSuggestions, nullptr, aToFill ); + if(bCorrectionRes) + { + try{ + uno::Reference< linguistic2::XDictionary > xDictionary = LinguMgr::GetIgnoreAllList(); + aGrammarCheckRes.xProofreader->ignoreRule( + aGrammarCheckRes.aErrors[ nErrorInResult ].aRuleIdentifier, + aGrammarCheckRes.aLocale ); + // refresh the layout of the actual paragraph (faster) + SwPaM *pPaM = rWrtSh.GetCursor(); + if (pPaM) + SwEditShell::IgnoreGrammarErrorAt( *pPaM ); + // refresh the layout of all paragraphs (workaround to launch a dictionary event) + xDictionary->setActive(false); + xDictionary->setActive(true); + } + catch( const uno::Exception& ) + { + } + } + } + } } break; default: _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits