diff options
author | Tamás Zolnai <tamas.zolnai@collabora.com> | 2019-11-17 14:17:59 +0100 |
---|---|---|
committer | Tamás Zolnai <tamas.zolnai@collabora.com> | 2019-11-23 23:22:08 +0100 |
commit | 5efa7d4605c8c683bb54a1723d0916e6f0166b52 (patch) | |
tree | 46e96bc2950fd181be4745eec266ea6a43cf9bd2 /sw | |
parent | 4549de73090284f149ed6ba62818e27739bdaf19 (diff) |
SpellingPopup: Convert suggestion menu items to use slot ID.
Change-Id: Icf1f50d04ab5e7ba467d68613f4101a3fe48589b
(cherry picked from commit c2f58bc25cedf8a13a978b52a5bf012809fc38ed)
Reviewed-on: https://gerrit.libreoffice.org/83590
Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com>
Tested-by: Tamás Zolnai <tamas.zolnai@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/uibase/lingu/olmenu.cxx | 41 | ||||
-rw-r--r-- | sw/source/uibase/shells/textsh1.cxx | 85 |
2 files changed, 106 insertions, 20 deletions
diff --git a/sw/source/uibase/lingu/olmenu.cxx b/sw/source/uibase/lingu/olmenu.cxx index f04fb6b71880..e08c5f4a2804 100644 --- a/sw/source/uibase/lingu/olmenu.cxx +++ b/sw/source/uibase/lingu/olmenu.cxx @@ -636,26 +636,29 @@ void SwSpellPopup::Execute( sal_uInt16 nId ) if (/*m_bGrammarResults && */nId == MN_SHORT_COMMENT) return; // nothing to do since it is the error message (short comment) - if ((MN_SUGGESTION_START <= nId && nId <= MN_SUGGESTION_END) || - (MN_AUTOCORR_START <= nId && nId <= MN_AUTOCORR_END)) + if (MN_SUGGESTION_START <= nId && nId <= MN_SUGGESTION_END) { - OUString sNewWord; - if (MN_AUTOCORR_START <= nId && nId <= MN_AUTOCORR_END) - { - PopupMenu* pMenu = m_xPopupMenu->GetPopupMenu(m_nCorrectMenuId); - assert(pMenu); - sNewWord = pMenu->GetItemText(nId); - } - else - sNewWord = m_xPopupMenu->GetItemText(nId); - - if (m_bGrammarResults || m_xSpellAlt.is()) + 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(MN_AUTOCORR_START <= nId && nId <= MN_AUTOCORR_END) + { + if (m_xSpellAlt.is()) { bool bOldIns = m_pSh->IsInsMode(); m_pSh->SetInsMode(); - OUString aTmp( sNewWord ); - OUString aOrig( m_bGrammarResults ? OUString() : m_xSpellAlt->getWord() ); + PopupMenu* pMenu = m_xPopupMenu->GetPopupMenu(m_nCorrectMenuId); + assert(pMenu); + OUString aTmp( pMenu->GetItemText(nId) ); + OUString aOrig( 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 @@ -688,11 +691,11 @@ void SwSpellPopup::Execute( sal_uInt16 nId ) // record only if it's NOT already present in autocorrection SvxAutoCorrect* pACorr = SvxAutoCorrCfg::Get().GetAutoCorrect(); - OUString aOrigWord( m_bGrammarResults ? OUString() : m_xSpellAlt->getWord() ) ; - SvxPrepareAutoCorrect( aOrigWord, sNewWord ); + OUString aOrigWord( m_xSpellAlt->getWord() ) ; + OUString aNewWord( pMenu->GetItemText(nId) ); + SvxPrepareAutoCorrect( aOrigWord, aNewWord ); - if (MN_AUTOCORR_START <= nId && nId <= MN_AUTOCORR_END) - pACorr->PutText( aOrigWord, sNewWord, m_nCheckedLanguage ); + pACorr->PutText( aOrigWord, aNewWord, m_nCheckedLanguage ); /* #102505# EndAction/EndUndo moved down since insertion of temporary auto correction is now undoable two and diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx index bff08a595f18..4db7fd030846 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,88 @@ 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(), ""); + linguistic2::ProofreadingResult aGrammarCheckRes; + sal_Int32 nErrorInResult = -1; + uno::Sequence< OUString > aSuggestions; + sal_Int32 nErrorPosInText = -1; + SwRect aToFill; + bGrammar = rWrtSh.GetGrammarCorrection( aGrammarCheckRes, nErrorPosInText, nErrorInResult, aSuggestions, nullptr, aToFill ); + } + 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: |