diff options
author | Tamás Zolnai <tamas.zolnai@collabora.com> | 2019-11-18 19:15:07 +0100 |
---|---|---|
committer | Tamás Zolnai <tamas.zolnai@collabora.com> | 2019-11-24 12:17:41 +0100 |
commit | 6564a1ab1e873cbc9e36f7f301d4a3c14d86861e (patch) | |
tree | 3a03d94483dcf64ae3907445111f611443894d65 | |
parent | 3616bb68f247735c46c1a4cd9568775e77be6441 (diff) |
SpellingPopup: Create separate SID for Ignore / IgnoreAll / suggestion.
Change-Id: I20f41f511ea38f960f081f92bc36e095f7752d28
Reviewed-on: https://gerrit.libreoffice.org/83599
Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com>
Tested-by: Tamás Zolnai <tamas.zolnai@collabora.com>
-rw-r--r-- | include/svx/svxids.hrc | 4 | ||||
-rw-r--r-- | officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu | 14 | ||||
-rw-r--r-- | svx/sdi/svx.sdi | 36 | ||||
-rw-r--r-- | sw/sdi/_textsh.sdi | 14 | ||||
-rw-r--r-- | sw/source/uibase/lingu/olmenu.cxx | 23 | ||||
-rw-r--r-- | sw/source/uibase/shells/textsh1.cxx | 229 |
6 files changed, 193 insertions, 127 deletions
diff --git a/include/svx/svxids.hrc b/include/svx/svxids.hrc index 6e9cd310f9ad..2842dcf5a77f 100644 --- a/include/svx/svxids.hrc +++ b/include/svx/svxids.hrc @@ -355,7 +355,9 @@ 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 ) +#define SID_SPELLCHECK_IGNORE ( SID_SVX_START + 246 ) +#define SID_SPELLCHECK_IGNORE_ALL ( SID_SVX_START + 247 ) +#define SID_SPELLCHECK_APPLY_SUGGESTION ( SID_SVX_START + 248 ) // 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 aa5173877eae..75a6a98c62a2 100644 --- a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu +++ b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu @@ -2678,9 +2678,19 @@ <value xml:lang="en-US">Language Status</value> </prop> </node> - <node oor:name=".uno:ApplySpellChecking" oor:op="replace"> + <node oor:name=".uno:SpellCheckIgnore" oor:op="replace"> <prop oor:name="Label" oor:type="xs:string"> - <value xml:lang="en-US">Apply Spell Checking</value> + <value xml:lang="en-US">Ignore</value> + </prop> + </node> + <node oor:name=".uno:SpellCheckIgnoreAll" oor:op="replace"> + <prop oor:name="Label" oor:type="xs:string"> + <value xml:lang="en-US">IgnoreAll</value> + </prop> + </node> + <node oor:name=".uno:SpellCheckApplySuggestion" oor:op="replace"> + <prop oor:name="Label" oor:type="xs:string"> + <value xml:lang="en-US">Apply Suggestion</value> </prop> </node> <node oor:name=".uno:ChooseControls" oor:op="replace"> diff --git a/svx/sdi/svx.sdi b/svx/sdi/svx.sdi index d417b2ef9967..d191813d3ca6 100644 --- a/svx/sdi/svx.sdi +++ b/svx/sdi/svx.sdi @@ -12170,7 +12170,41 @@ SfxVoidItem EditQrCode SID_EDIT_QRCODE GroupId = SfxGroupId::Edit; ] -SfxVoidItem ApplySpellChecking SID_APPLY_SPELLCHECKING +SfxVoidItem SpellCheckIgnore SID_SPELLCHECK_IGNORE +(SfxStringItem Type 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; +] + +SfxVoidItem SpellCheckIgnoreAll SID_SPELLCHECK_IGNORE_ALL +(SfxStringItem Type 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; +] + +SfxVoidItem SpellCheckApplySuggestion SID_SPELLCHECK_APPLY_SUGGESTION (SfxStringItem ApplyRule FN_PARAM_1) [ AutoUpdate = FALSE, diff --git a/sw/sdi/_textsh.sdi b/sw/sdi/_textsh.sdi index 94bcc81cd5ac..102699cbad19 100644 --- a/sw/sdi/_textsh.sdi +++ b/sw/sdi/_textsh.sdi @@ -1740,7 +1740,19 @@ interface BaseText StateMethod = GetState ; ] - SID_APPLY_SPELLCHECKING + SID_SPELLCHECK_IGNORE + [ + ExecMethod = Execute ; + StateMethod = GetState ; + ] + + SID_SPELLCHECK_IGNORE_ALL + [ + ExecMethod = Execute ; + StateMethod = GetState ; + ] + + SID_SPELLCHECK_APPLY_SUGGESTION [ ExecMethod = Execute ; StateMethod = GetState ; diff --git a/sw/source/uibase/lingu/olmenu.cxx b/sw/source/uibase/lingu/olmenu.cxx index e09589de550b..ac0fad353974 100644 --- a/sw/source/uibase/lingu/olmenu.cxx +++ b/sw/source/uibase/lingu/olmenu.cxx @@ -599,21 +599,22 @@ void SwSpellPopup::InitItemCommands(const css::uno::Sequence< OUString >& aSugge { if (comphelper::LibreOfficeKit::isActive()) { + // None is added only for LOK, it means there is no need to execute anything m_xPopupMenu->SetItemCommand(MN_SHORT_COMMENT, ".uno:None"); m_xPopupMenu->SetItemCommand(m_nSpellDialogId, ".uno:SpellingAndGrammarDialog"); if(m_bGrammarResults) - m_xPopupMenu->SetItemCommand(m_nIgnoreWordId, ".uno:ApplySpellChecking?ApplyRule:string=IgnoreAll_Grammar"); + m_xPopupMenu->SetItemCommand(m_nIgnoreWordId, ".uno:SpellCheckIgnoreAll?Type:string=Grammar"); else - m_xPopupMenu->SetItemCommand(m_nIgnoreWordId, ".uno:ApplySpellChecking?ApplyRule:string=IgnoreAll_Spelling"); + m_xPopupMenu->SetItemCommand(m_nIgnoreWordId, ".uno:SpellCheckIgnoreAll?Type:string=Spelling"); if(m_bGrammarResults) - m_xPopupMenu->SetItemCommand(MN_IGNORE_SELECTION, ".uno:ApplySpellChecking?ApplyRule:string=Ignore_Grammar"); + m_xPopupMenu->SetItemCommand(MN_IGNORE_SELECTION, ".uno:SpellCheckIgnore?Type:string=Grammar"); else - m_xPopupMenu->SetItemCommand(MN_IGNORE_SELECTION, ".uno:ApplySpellChecking?ApplyRule:string=Ignore_Spelling"); + m_xPopupMenu->SetItemCommand(MN_IGNORE_SELECTION, ".uno:SpellCheckIgnore?Type:string=Spelling"); for(int i = 0; i < aSuggestions.getLength(); ++i) { sal_uInt16 nItemId = MN_SUGGESTION_START + i; - OUString sCommandString = OUString(".uno:ApplySpellChecking?ApplyRule:string=Replace_"); + OUString sCommandString = OUString(".uno:SpellCheckApplySuggestion?ApplyRule:string="); if(m_bGrammarResults) sCommandString += "Grammar_"; else if (m_xSpellAlt.is()) @@ -706,7 +707,7 @@ void SwSpellPopup::Execute( sal_uInt16 nId ) if (MN_SUGGESTION_START <= nId && nId <= MN_SUGGESTION_END) { - OUString sApplyRule("Replace_"); + OUString sApplyRule(""); if(m_bGrammarResults) sApplyRule += "Grammar_"; else if (m_xSpellAlt.is()) @@ -714,7 +715,7 @@ void SwSpellPopup::Execute( sal_uInt16 nId ) sApplyRule += m_xPopupMenu->GetItemText(nId); SfxStringItem aApplyItem(FN_PARAM_1, sApplyRule); - m_pSh->GetView().GetViewFrame()->GetDispatcher()->ExecuteList(SID_APPLY_SPELLCHECKING, SfxCallMode::SYNCHRON, { &aApplyItem }); + m_pSh->GetView().GetViewFrame()->GetDispatcher()->ExecuteList(SID_SPELLCHECK_APPLY_SUGGESTION, SfxCallMode::SYNCHRON, { &aApplyItem }); } else if(MN_AUTOCORR_START <= nId && nId <= MN_AUTOCORR_END) { @@ -788,13 +789,13 @@ void SwSpellPopup::Execute( sal_uInt16 nId ) } else if (nId == MN_IGNORE_SELECTION) { - SfxStringItem aIgnoreString(FN_PARAM_1, m_bGrammarResults ? OUString("Ignore_Grammar") : OUString("Ignore_Spelling")); - m_pSh->GetView().GetViewFrame()->GetDispatcher()->ExecuteList(SID_APPLY_SPELLCHECKING, SfxCallMode::SYNCHRON, { &aIgnoreString }); + SfxStringItem aIgnoreString(FN_PARAM_1, m_bGrammarResults ? OUString("Grammar") : OUString("Spelling")); + m_pSh->GetView().GetViewFrame()->GetDispatcher()->ExecuteList(SID_SPELLCHECK_IGNORE, SfxCallMode::SYNCHRON, { &aIgnoreString }); } else if (nId == m_nIgnoreWordId) { - 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 }); + SfxStringItem aIgnoreString(FN_PARAM_1, m_bGrammarResults ? OUString("Grammar") : OUString("Spelling")); + m_pSh->GetView().GetViewFrame()->GetDispatcher()->ExecuteList(SID_SPELLCHECK_IGNORE_ALL, 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 30c5607e51b6..6cc1d1d7b0c8 100644 --- a/sw/source/uibase/shells/textsh1.cxx +++ b/sw/source/uibase/shells/textsh1.cxx @@ -1434,55 +1434,57 @@ void SwTextShell::Execute(SfxRequest &rReq) } } break; - case SID_APPLY_SPELLCHECKING: + case SID_SPELLCHECK_IGNORE: { - OUString sApplyText; - const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(FN_PARAM_1); - if (pItem2) - sApplyText = pItem2->GetValue(); + // If there is not selection, we need to create one, before ignoring + if(!rWrtSh.HasSelection()) + { + OUString sApplyText; + const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(FN_PARAM_1); + if (pItem2) + sApplyText = pItem2->GetValue(); - const OUString sIgnorePrefix("Ignore_"); - const OUString sIgnoreAllPrefix("IgnoreAll_"); - const OUString sSpellingRule("Spelling"); - const OUString sGrammarRule("Grammar"); - const OUString aReplacePrefix("Replace_"); + const OUString sGrammarType("Grammar"); + const OUString sSpellingType("Spelling"); - // Ignore the word at the cursor pos - sal_Int32 nPos = 0; - if (-1 != (nPos = sApplyText.indexOf( sIgnorePrefix ))) - { - if(!rWrtSh.HasSelection()) + if (sApplyText == sGrammarType) { - sApplyText = sApplyText.replaceAt(nPos, sIgnorePrefix.getLength(), ""); - if (-1 != (nPos = sApplyText.indexOf( 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) - return; - } - else - { - SwRect aToFill; - uno::Reference< linguistic2::XSpellAlternatives > xSpellAlt( rWrtSh.GetCorrection(nullptr, aToFill) ); - if (!xSpellAlt.is()) - return; - } + 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) + return; + } + else if (sApplyText == sSpellingType) + { + SwRect aToFill; + uno::Reference< linguistic2::XSpellAlternatives > xSpellAlt( rWrtSh.GetCorrection(nullptr, aToFill) ); + if (!xSpellAlt.is()) + return; } - - SwPaM *pPaM = rWrtSh.GetCursor(); - if (pPaM) - SwEditShell::IgnoreGrammarErrorAt( *pPaM ); } - // Ignore all similar items as the current word - else if (-1 != (nPos = sApplyText.indexOf( sIgnoreAllPrefix ))) + + SwPaM *pPaM = rWrtSh.GetCursor(); + if (pPaM) + SwEditShell::IgnoreGrammarErrorAt( *pPaM ); + } + break; + case SID_SPELLCHECK_IGNORE_ALL: + { + if(!rWrtSh.HasSelection()) { - sApplyText = sApplyText.replaceAt(nPos, sIgnoreAllPrefix.getLength(), ""); - if(sApplyText == sGrammarRule) + OUString sApplyText; + const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(FN_PARAM_1); + if (pItem2) + sApplyText = pItem2->GetValue(); + + const OUString sGrammarType("Grammar"); + const OUString sSpellingType("Spelling"); + + if(sApplyText == sGrammarType) { linguistic2::ProofreadingResult aGrammarCheckRes; sal_Int32 nErrorInResult = -1; @@ -1510,7 +1512,7 @@ void SwTextShell::Execute(SfxRequest &rReq) } } } - else if (sApplyText == sSpellingRule) + else if (sApplyText == sSpellingType) { SwRect aToFill; uno::Reference< linguistic2::XSpellAlternatives > xSpellAlt( rWrtSh.GetCorrection(nullptr, aToFill) ); @@ -1524,95 +1526,100 @@ void SwTextShell::Execute(SfxRequest &rReq) } } } - // Replace text with the suggestion - else if (-1 != (nPos = sApplyText.indexOf( aReplacePrefix ))) - { - sApplyText = sApplyText.replaceAt(nPos, aReplacePrefix.getLength(), ""); + } + break; + case SID_SPELLCHECK_APPLY_SUGGESTION: + { + OUString sApplyText; + const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(FN_PARAM_1); + if (pItem2) + sApplyText = pItem2->GetValue(); + + const OUString sSpellingRule("Spelling_"); + const OUString sGrammarRule("Grammar_"); - const OUString sSpellingRule2(sSpellingRule + "_"); - const OUString sGrammarRule2(sGrammarRule + "_"); - bool bGrammar = false; - uno::Reference< linguistic2::XSpellAlternatives > xSpellAlt; - if(-1 != (nPos = sApplyText.indexOf( sGrammarRule2 ))) + bool bGrammar = false; + sal_Int32 nPos = 0; + uno::Reference< linguistic2::XSpellAlternatives > xSpellAlt; + if(-1 != (nPos = sApplyText.indexOf( sGrammarRule ))) + { + sApplyText = sApplyText.replaceAt(nPos, sGrammarRule.getLength(), ""); + if(rWrtSh.HasSelection()) { - sApplyText = sApplyText.replaceAt(nPos, sGrammarRule2.getLength(), ""); - if(rWrtSh.HasSelection()) - { - bGrammar = true; - } - else - { - 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 ); - } + bGrammar = true; } - else if (-1 != (nPos = sApplyText.indexOf( sSpellingRule2 ))) + else { - sApplyText = sApplyText.replaceAt(nPos, sSpellingRule2.getLength(), ""); + linguistic2::ProofreadingResult aGrammarCheckRes; + sal_Int32 nErrorInResult = -1; + uno::Sequence< OUString > aSuggestions; + sal_Int32 nErrorPosInText = -1; SwRect aToFill; - xSpellAlt.set(rWrtSh.GetCorrection(nullptr, aToFill)); - bGrammar = false; + bGrammar = rWrtSh.GetGrammarCorrection( aGrammarCheckRes, nErrorPosInText, nErrorInResult, aSuggestions, nullptr, aToFill ); } + } + else if (-1 != (nPos = sApplyText.indexOf( sSpellingRule ))) + { + sApplyText = sApplyText.replaceAt(nPos, sSpellingRule.getLength(), ""); + SwRect aToFill; + xSpellAlt.set(rWrtSh.GetCorrection(nullptr, aToFill)); + bGrammar = false; + } - if (!bGrammar && !xSpellAlt.is()) - return; + if (!bGrammar && !xSpellAlt.is()) + return; - bool bOldIns = rWrtSh.IsInsMode(); - rWrtSh.SetInsMode(); + bool bOldIns = rWrtSh.IsInsMode(); + rWrtSh.SetInsMode(); - OUString aTmp( sApplyText ); - OUString aOrig( bGrammar ? OUString() : xSpellAlt->getWord() ); + 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 += "."; - } + // 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; + SwRewriter aRewriter; - aRewriter.AddRule(UndoArg1, rWrtSh.GetCursorDescr()); - aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS)); + 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); + 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.StartUndo(SwUndoId::UI_REPLACE, &aRewriter); + rWrtSh.StartAction(); + rWrtSh.DelLeft(); - rWrtSh.Insert( aTmp ); + 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.*/ + /* #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(); + // 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 ); + OUString aOrigWord( bGrammar ? OUString() : xSpellAlt->getWord() ) ; + OUString aNewWord( sApplyText ); + SvxPrepareAutoCorrect( aOrigWord, aNewWord ); - if (xSpellAlt.is()) - pACorr->PutText( aOrigWord, aNewWord, LanguageTag( xSpellAlt->getLocale() ).getLanguageType() ); + 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(); + /* #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 ); - } + rWrtSh.SetInsMode( bOldIns ); } break; default: |