[Libreoffice-commits] core.git: Branch 'feature/spellig_popup_SID' - 5 commits - include/svx officecfg/registry svx/sdi sw/sdi sw/source
Tamás Zolnai (via logerrit)
logerrit at kemper.freedesktop.org
Sun Nov 17 13:25:37 UTC 2019
Rebased ref, commits from common ancestor:
commit 7d1bffb01eaaf7804969cfad3c4f05919d9b1b22
Author: Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Sun Nov 17 14:17:59 2019 +0100
Commit: Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Sun Nov 17 14:17:59 2019 +0100
SpellingPopup: Convert suggestion menu items to use a slot ID.
Change-Id: Icf1f50d04ab5e7ba467d68613f4101a3fe48589b
diff --git a/sw/source/uibase/lingu/olmenu.cxx b/sw/source/uibase/lingu/olmenu.cxx
index 06961610864a..3201a0926e0c 100644
--- a/sw/source/uibase/lingu/olmenu.cxx
+++ b/sw/source/uibase/lingu/olmenu.cxx
@@ -639,60 +639,15 @@ void SwSpellPopup::Execute( sal_uInt16 nId )
if ((MN_SUGGESTION_START <= nId && nId <= MN_SUGGESTION_END) ||
(MN_AUTOCORR_START <= nId && nId <= MN_AUTOCORR_END))
{
- if (m_bGrammarResults || m_xSpellAlt.is())
- {
- bool bOldIns = m_pSh->IsInsMode();
- m_pSh->SetInsMode();
-
- OUString aTmp( m_xPopupMenu->GetItemText(nId) );
- OUString aOrig( m_bGrammarResults ? OUString() : m_xSpellAlt->getWord() );
-
- // if original word has a trailing . (likely the end of a sentence)
- // and the replacement text hasn't, then add it to the replacement
- if (!aTmp.isEmpty() && !aOrig.isEmpty() &&
- aOrig.endsWith(".") && /* !IsAlphaNumeric ??*/
- !aTmp.endsWith("."))
- {
- aTmp += ".";
- }
-
- SwRewriter aRewriter;
-
- aRewriter.AddRule(UndoArg1, m_pSh->GetCursorDescr());
- aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS));
-
- OUString aTmpStr = SwResId(STR_START_QUOTE) +
- aTmp + SwResId(STR_END_QUOTE);
- aRewriter.AddRule(UndoArg3, aTmpStr);
-
- m_pSh->StartUndo(SwUndoId::UI_REPLACE, &aRewriter);
- m_pSh->StartAction();
- m_pSh->DelLeft();
-
- m_pSh->Insert( aTmp );
-
- /* #102505# EndAction/EndUndo moved down since insertion
- of temporary auto correction is now undoable two and
- must reside in the same undo group.*/
-
- // record only if it's NOT already present in autocorrection
- SvxAutoCorrect* pACorr = SvxAutoCorrCfg::Get().GetAutoCorrect();
-
- OUString aOrigWord( m_bGrammarResults ? OUString() : m_xSpellAlt->getWord() ) ;
- OUString aNewWord( m_xPopupMenu->GetItemText(nId) );
- SvxPrepareAutoCorrect( aOrigWord, aNewWord );
-
- if (MN_AUTOCORR_START <= nId && nId <= MN_AUTOCORR_END)
- pACorr->PutText( aOrigWord, aNewWord, m_nCheckedLanguage );
-
- /* #102505# EndAction/EndUndo moved down since insertion
- of temporary auto correction is now undoable two and
- must reside in the same undo group.*/
- m_pSh->EndAction();
- m_pSh->EndUndo();
-
- m_pSh->SetInsMode( bOldIns );
- }
+ OUString sApplyRule("Replace_");
+ if(m_bGrammarResults)
+ sApplyRule += "Grammar_";
+ else if (m_xSpellAlt.is())
+ sApplyRule += "Spelling_";
+ sApplyRule += m_xPopupMenu->GetItemText(nId);
+
+ SfxStringItem aApplyItem(FN_PARAM_1, sApplyRule);
+ m_pSh->GetView().GetViewFrame()->GetDispatcher()->ExecuteList(SID_APPLY_SPELLCHECKING, SfxCallMode::SYNCHRON, { &aApplyItem });
}
else if (nId == m_nSpellDialogId)
{
diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx
index bff08a595f18..ee4b862b2aba 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -128,6 +128,7 @@
#include <xmloff/odffields.hxx>
#include <bookmrk.hxx>
#include <linguistic/misc.hxx>
+#include <editeng/splwrap.hxx>
using namespace ::com::sun::star;
using namespace com::sun::star::beans;
@@ -1444,7 +1445,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
const OUString sIgnoreAllPrefix("IgnoreAll_");
const OUString sSpellingRule("Spelling");
const OUString sGrammarRule("Grammar");
- //const OUString aReplacePrefix("Replace_");
+ const OUString aReplacePrefix("Replace_");
// Ignore the word at the cursor pos
sal_Int32 nPos = 0;
@@ -1500,6 +1501,83 @@ void SwTextShell::Execute(SfxRequest &rReq)
}
}
}
+ // Replace text with the suggestion
+ else if (-1 != (nPos = sApplyText.indexOf( aReplacePrefix )))
+ {
+ sApplyText = sApplyText.replaceAt(nPos, aReplacePrefix.getLength(), "");
+
+ const OUString sSpellingRule2(sSpellingRule + "_");
+ const OUString sGrammarRule2(sGrammarRule + "_");
+ bool bGrammar = false;
+ uno::Reference< linguistic2::XSpellAlternatives > xSpellAlt;
+ if(-1 != (nPos = sApplyText.indexOf( sGrammarRule2 )))
+ {
+ sApplyText = sApplyText.replaceAt(nPos, sGrammarRule2.getLength(), "");
+ bGrammar = true;
+ }
+ else if (-1 != (nPos = sApplyText.indexOf( sSpellingRule2 )))
+ {
+ sApplyText = sApplyText.replaceAt(nPos, sSpellingRule2.getLength(), "");
+ SwRect aToFill;
+ xSpellAlt.set(rWrtSh.GetCorrection(nullptr, aToFill));
+ bGrammar = false;
+ }
+
+ if (!bGrammar && !xSpellAlt.is())
+ return;
+
+ bool bOldIns = rWrtSh.IsInsMode();
+ rWrtSh.SetInsMode();
+
+ OUString aTmp( sApplyText );
+ OUString aOrig( bGrammar ? OUString() : xSpellAlt->getWord() );
+
+ // if original word has a trailing . (likely the end of a sentence)
+ // and the replacement text hasn't, then add it to the replacement
+ if (!aTmp.isEmpty() && !aOrig.isEmpty() &&
+ aOrig.endsWith(".") && /* !IsAlphaNumeric ??*/
+ !aTmp.endsWith("."))
+ {
+ aTmp += ".";
+ }
+
+ SwRewriter aRewriter;
+
+ aRewriter.AddRule(UndoArg1, rWrtSh.GetCursorDescr());
+ aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS));
+
+ OUString aTmpStr = SwResId(STR_START_QUOTE) +
+ aTmp + SwResId(STR_END_QUOTE);
+ aRewriter.AddRule(UndoArg3, aTmpStr);
+
+ rWrtSh.StartUndo(SwUndoId::UI_REPLACE, &aRewriter);
+ rWrtSh.StartAction();
+ rWrtSh.DelLeft();
+
+ rWrtSh.Insert( aTmp );
+
+ /* #102505# EndAction/EndUndo moved down since insertion
+ of temporary auto correction is now undoable two and
+ must reside in the same undo group.*/
+
+ // record only if it's NOT already present in autocorrection
+ SvxAutoCorrect* pACorr = SvxAutoCorrCfg::Get().GetAutoCorrect();
+
+ OUString aOrigWord( bGrammar ? OUString() : xSpellAlt->getWord() ) ;
+ OUString aNewWord( sApplyText );
+ SvxPrepareAutoCorrect( aOrigWord, aNewWord );
+
+ if (xSpellAlt.is())
+ pACorr->PutText( aOrigWord, aNewWord, LanguageTag( xSpellAlt->getLocale() ).getLanguageType() );
+
+ /* #102505# EndAction/EndUndo moved down since insertion
+ of temporary auto correction is now undoable two and
+ must reside in the same undo group.*/
+ rWrtSh.EndAction();
+ rWrtSh.EndUndo();
+
+ rWrtSh.SetInsMode( bOldIns );
+ }
}
break;
default:
commit 64aaad77a52e299ea1978a8d08c90309fcde345c
Author: Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Sun Nov 17 13:33:51 2019 +0100
Commit: Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Sun Nov 17 13:33:56 2019 +0100
SpellingPopup: Remove m_aSuggestions member variable
We don't need it after the construction. The text is stored by the
menu item.
Change-Id: I54b0392b4564e76d405824bb297e6f993a24a5fb
diff --git a/sw/source/uibase/inc/olmenu.hxx b/sw/source/uibase/inc/olmenu.hxx
index db80e20e931a..984dfb759872 100644
--- a/sw/source/uibase/inc/olmenu.hxx
+++ b/sw/source/uibase/inc/olmenu.hxx
@@ -96,7 +96,6 @@ class SW_DLLPUBLIC SwSpellPopup
css::linguistic2::ProofreadingResult m_xGrammarResult;
sal_Int32 m_nGrammarError;
- css::uno::Sequence< OUString > m_aSuggestions;
OUString m_sExplanationLink;
LanguageType m_nCheckedLanguage;
diff --git a/sw/source/uibase/lingu/olmenu.cxx b/sw/source/uibase/lingu/olmenu.cxx
index 57260b5b4dd7..06961610864a 100644
--- a/sw/source/uibase/lingu/olmenu.cxx
+++ b/sw/source/uibase/lingu/olmenu.cxx
@@ -242,12 +242,13 @@ SwSpellPopup::SwSpellPopup(
bool bUseImagesInMenus = Application::GetSettings().GetStyleSettings().GetUseImagesInMenus();
m_nCheckedLanguage = LANGUAGE_NONE;
+ css::uno::Sequence< OUString > aSuggestions;
if (m_xSpellAlt.is())
{
m_nCheckedLanguage = LanguageTag( m_xSpellAlt->getLocale() ).getLanguageType();
- m_aSuggestions = m_xSpellAlt->getAlternatives();
+ aSuggestions = m_xSpellAlt->getAlternatives();
}
- sal_Int16 nStringCount = static_cast< sal_Int16 >( m_aSuggestions.getLength() );
+ sal_Int16 nStringCount = static_cast< sal_Int16 >( aSuggestions.getLength() );
SvtLinguConfig aCfg;
@@ -275,7 +276,7 @@ SwSpellPopup::SwSpellPopup(
sal_uInt16 nItemId = MN_SUGGESTION_START;
for (sal_uInt16 i = 0; i < nStringCount; ++i)
{
- const OUString aEntry = m_aSuggestions[ i ];
+ const OUString aEntry = aSuggestions[ i ];
m_xPopupMenu->InsertItem(nItemId, aEntry, MenuItemBits::NONE, OString(), i);
m_xPopupMenu->SetHelpId(nItemId, HID_LINGU_REPLACE);
if (!aSuggestionImageUrl.isEmpty())
@@ -443,7 +444,6 @@ SwSpellPopup::SwSpellPopup(
, m_nRedlinePrevId(m_xPopupMenu->GetItemId("prev"))
, m_pSh(pWrtSh)
, m_xGrammarResult(rResult)
- , m_aSuggestions(rSuggestions)
, m_sExplanationLink()
, m_bGrammarResults(true)
{
@@ -480,7 +480,7 @@ SwSpellPopup::SwSpellPopup(
m_xPopupMenu->SetMenuFlags(MenuFlags::NoAutoMnemonics);
m_xPopupMenu->InsertSeparator(OString(), nPos++);
- if ( m_aSuggestions.hasElements() ) // suggestions available...
+ if ( rSuggestions.hasElements() ) // suggestions available...
{
Image aImage;
OUString aSuggestionImageUrl;
@@ -496,7 +496,7 @@ SwSpellPopup::SwSpellPopup(
}
sal_uInt16 nItemId = MN_SUGGESTION_START;
- for (const OUString& aEntry : std::as_const(m_aSuggestions))
+ for (const OUString& aEntry : std::as_const(rSuggestions))
{
m_xPopupMenu->InsertItem(nItemId, aEntry, MenuItemBits::NONE, OString(), nPos++);
m_xPopupMenu->SetHelpId(nItemId, HID_LINGU_REPLACE);
@@ -639,15 +639,12 @@ void SwSpellPopup::Execute( sal_uInt16 nId )
if ((MN_SUGGESTION_START <= nId && nId <= MN_SUGGESTION_END) ||
(MN_AUTOCORR_START <= nId && nId <= MN_AUTOCORR_END))
{
- sal_Int32 nAltIdx = (MN_SUGGESTION_START <= nId && nId <= MN_SUGGESTION_END) ?
- nId - MN_SUGGESTION_START : nId - MN_AUTOCORR_START;
- OSL_ENSURE(nAltIdx < m_aSuggestions.getLength(), "index out of range");
- if (nAltIdx < m_aSuggestions.getLength() && (m_bGrammarResults || m_xSpellAlt.is()))
+ if (m_bGrammarResults || m_xSpellAlt.is())
{
bool bOldIns = m_pSh->IsInsMode();
m_pSh->SetInsMode();
- OUString aTmp( m_aSuggestions[ nAltIdx ] );
+ OUString aTmp( m_xPopupMenu->GetItemText(nId) );
OUString aOrig( m_bGrammarResults ? OUString() : m_xSpellAlt->getWord() );
// if original word has a trailing . (likely the end of a sentence)
@@ -682,7 +679,7 @@ void SwSpellPopup::Execute( sal_uInt16 nId )
SvxAutoCorrect* pACorr = SvxAutoCorrCfg::Get().GetAutoCorrect();
OUString aOrigWord( m_bGrammarResults ? OUString() : m_xSpellAlt->getWord() ) ;
- OUString aNewWord( m_aSuggestions[ nAltIdx ] );
+ OUString aNewWord( m_xPopupMenu->GetItemText(nId) );
SvxPrepareAutoCorrect( aOrigWord, aNewWord );
if (MN_AUTOCORR_START <= nId && nId <= MN_AUTOCORR_END)
commit 16af8d3802a582c9dd60b5ec81e07769517696f0
Author: Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Sun Nov 17 13:18:34 2019 +0100
Commit: Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Sun Nov 17 13:18:34 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
diff --git a/sw/source/core/edit/edlingu.cxx b/sw/source/core/edit/edlingu.cxx
index 49b81a757f57..aca39c36fd1f 100644
--- a/sw/source/core/edit/edlingu.cxx
+++ b/sw/source/core/edit/edlingu.cxx
@@ -889,12 +889,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 aad5066476aa7cbdf2c36afdd02e314b370dea7e
Author: Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Sat Nov 16 15:17:57 2019 +0100
Commit: Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Sun Nov 17 13:18:02 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
diff --git a/sw/source/core/edit/edlingu.cxx b/sw/source/core/edit/edlingu.cxx
index fa1078cdecf7..49b81a757f57 100644
--- a/sw/source/core/edit/edlingu.cxx
+++ b/sw/source/core/edit/edlingu.cxx
@@ -955,12 +955,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:
commit 4fad0a99e05265e3692194e03d4dde50de17d82b
Author: Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Sat Nov 16 15:14:20 2019 +0100
Commit: Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Sun Nov 17 13:16:28 2019 +0100
SpellingPopup: Convert "Ignore" menu item to use a slot ID.
Introduced a new slot id SID_APPLY_SPELLING, which can be used
to apply any spelling / grammar related changes (e.g. ignore,
ignore all, replace with suggestion, add to dictionary).
In this commit, only the simple ignore is implemented.
Change-Id: I06ab84efeb955cc02ce3ff531bd8b5c20ddced9e
diff --git a/include/svx/svxids.hrc b/include/svx/svxids.hrc
index 100d2f4fbaf8..6e9cd310f9ad 100644
--- a/include/svx/svxids.hrc
+++ b/include/svx/svxids.hrc
@@ -355,6 +355,7 @@ class SvxSetItem;
#define SID_SPELL_DIALOG ( SID_SVX_START + 243 )
#define SID_INSERT_DRAW ( SID_SVX_START + 244 )
#define SID_THESAURUS ( SID_SVX_START + 245 )
+#define SID_APPLY_SPELLCHECKING ( SID_SVX_START + 246 )
// CAUTION! Range <250 .. 250> used by EditEngine (!)
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
index 34cdc64758af..143727cec71a 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
@@ -2678,6 +2678,11 @@
<value xml:lang="en-US">Language Status</value>
</prop>
</node>
+ <node oor:name=".uno:ApplySpellChecking" oor:op="replace">
+ <prop oor:name="Label" oor:type="xs:string">
+ <value xml:lang="en-US">Apply Spell Checking</value>
+ </prop>
+ </node>
<node oor:name=".uno:ChooseControls" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">Insert Controls</value>
diff --git a/svx/sdi/svx.sdi b/svx/sdi/svx.sdi
index b501e546e7bb..d417b2ef9967 100644
--- a/svx/sdi/svx.sdi
+++ b/svx/sdi/svx.sdi
@@ -12169,3 +12169,20 @@ SfxVoidItem EditQrCode SID_EDIT_QRCODE
ToolBoxConfig = TRUE,
GroupId = SfxGroupId::Edit;
]
+
+SfxVoidItem ApplySpellChecking SID_APPLY_SPELLCHECKING
+(SfxStringItem ApplyRule FN_PARAM_1)
+[
+ AutoUpdate = FALSE,
+ FastCall = TRUE,
+ ReadOnlyDoc = FALSE,
+ Toggle = FALSE,
+ Container = FALSE,
+ RecordAbsolute = FALSE,
+ RecordPerSet;
+
+ AccelConfig = FALSE,
+ MenuConfig = FALSE,
+ ToolBoxConfig = FALSE,
+ GroupId = SfxGroupId::Format;
+]
diff --git a/sw/sdi/_textsh.sdi b/sw/sdi/_textsh.sdi
index bfd47719ca35..94bcc81cd5ac 100644
--- a/sw/sdi/_textsh.sdi
+++ b/sw/sdi/_textsh.sdi
@@ -1740,5 +1740,11 @@ interface BaseText
StateMethod = GetState ;
]
+ SID_APPLY_SPELLCHECKING
+ [
+ ExecMethod = Execute ;
+ StateMethod = GetState ;
+ ]
+
} // end of interface text
diff --git a/sw/source/uibase/lingu/olmenu.cxx b/sw/source/uibase/lingu/olmenu.cxx
index 23435104bfc5..e627534fdf6e 100644
--- a/sw/source/uibase/lingu/olmenu.cxx
+++ b/sw/source/uibase/lingu/olmenu.cxx
@@ -711,9 +711,8 @@ void SwSpellPopup::Execute( sal_uInt16 nId )
}
else if (nId == MN_IGNORE_SELECTION)
{
- SwPaM *pPaM = m_pSh->GetCursor();
- if (pPaM)
- SwEditShell::IgnoreGrammarErrorAt( *pPaM );
+ SfxStringItem aIgnoreString(FN_PARAM_1, "Ignore");
+ m_pSh->GetView().GetViewFrame()->GetDispatcher()->ExecuteList(SID_APPLY_SPELLCHECKING, SfxCallMode::SYNCHRON, { &aIgnoreString });
}
else if (nId == m_nIgnoreWordId)
{
diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx
index 41d2fbded1da..fc940da44737 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -1429,6 +1429,29 @@ void SwTextShell::Execute(SfxRequest &rReq)
}
}
break;
+ case SID_APPLY_SPELLCHECKING:
+ {
+ OUString sApplyText;
+ const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
+ if (pItem2)
+ sApplyText = pItem2->GetValue();
+
+ const OUString sIgnoreString("Ignore");
+ //const OUString sIgnoreAllPrefix("IgnoreAll_");
+ //const OUString sSpellingRule("Spelling");
+ //const OUString sGrammarRule("Grammar");
+ //const OUString aReplacePrefix("Replace_");
+
+ // Ignore the word at the cursor pos
+ //sal_Int32 nPos = 0;
+ if (sApplyText == sIgnoreString)
+ {
+ SwPaM *pPaM = rWrtSh.GetCursor();
+ if (pPaM)
+ SwEditShell::IgnoreGrammarErrorAt( *pPaM );
+ }
+ }
+ break;
default:
OSL_ENSURE(false, "wrong dispatcher");
return;
More information about the Libreoffice-commits
mailing list