summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorCaolán McNamara <caolan.mcnamara@collabora.com>2024-12-20 12:46:36 +0000
committerCaolán McNamara <caolan.mcnamara@collabora.com>2024-12-20 15:54:12 +0100
commit2a47c0e3b74d7f4c60bba509644bd5b401ff1adb (patch)
tree63862ded4f0c14f6889e991a69ff1ff0e9c5ecd9 /sw
parentd52481325bc0dcc50af37d14cce68abfe9659564 (diff)
add uno:AddToWordbook for adding word to user dictionary
Change-Id: I1c679f62f554bfa112c505a545ceb8b5e31ef453 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178921 Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r--sw/sdi/_textsh.sdi6
-rw-r--r--sw/source/uibase/lingu/olmenu.cxx22
-rw-r--r--sw/source/uibase/shells/textsh1.cxx53
3 files changed, 49 insertions, 32 deletions
diff --git a/sw/sdi/_textsh.sdi b/sw/sdi/_textsh.sdi
index b0dd57ed8b3a..612f3d1955a9 100644
--- a/sw/sdi/_textsh.sdi
+++ b/sw/sdi/_textsh.sdi
@@ -1915,6 +1915,12 @@ interface BaseText
StateMethod = GetState ;
]
+ SID_ADD_TO_WORDBOOK
+ [
+ ExecMethod = Execute ;
+ StateMethod = GetState ;
+ ]
+
SID_SPELLCHECK_APPLY_SUGGESTION
[
ExecMethod = Execute ;
diff --git a/sw/source/uibase/lingu/olmenu.cxx b/sw/source/uibase/lingu/olmenu.cxx
index e2a992e841c7..acf36d89a113 100644
--- a/sw/source/uibase/lingu/olmenu.cxx
+++ b/sw/source/uibase/lingu/olmenu.cxx
@@ -771,9 +771,7 @@ void SwSpellPopup::Execute( sal_uInt16 nId )
}
else if ((MN_DICTIONARIES_START <= nId && nId <= MN_DICTIONARIES_END) || nId == m_nAddId)
{
- OUString sWord( m_xSpellAlt->getWord() );
OUString aDicName;
-
if (MN_DICTIONARIES_START <= nId && nId <= MN_DICTIONARIES_END)
{
PopupMenu *pMenu = m_xPopupMenu->GetPopupMenu(m_nAddMenuId);
@@ -782,24 +780,8 @@ void SwSpellPopup::Execute( sal_uInt16 nId )
else
aDicName = m_aDicNameSingle;
- uno::Reference< linguistic2::XDictionary > xDic;
- uno::Reference< linguistic2::XSearchableDictionaryList > xDicList( LinguMgr::GetDictionaryList() );
- if (xDicList.is())
- xDic = xDicList->getDictionaryByName( aDicName );
-
- if (xDic.is())
- {
- linguistic::DictionaryError nAddRes = linguistic::AddEntryToDic(xDic, sWord, false, OUString());
- // save modified user-dictionary if it is persistent
- uno::Reference< frame::XStorable > xSavDic( xDic, uno::UNO_QUERY );
- if (xSavDic.is())
- xSavDic->store();
-
- if (linguistic::DictionaryError::NONE != nAddRes && !xDic->getEntry(sWord).is())
- {
- SvxDicError(m_pSh->GetView().GetFrameWeld(), nAddRes);
- }
- }
+ SfxStringItem aDictString(FN_PARAM_1, aDicName);
+ m_pSh->GetView().GetViewFrame().GetDispatcher()->ExecuteList(SID_ADD_TO_WORDBOOK, SfxCallMode::SYNCHRON, { &aDictString });
}
else if ( nId == MN_EXPLANATION_LINK && !m_sExplanationLink.isEmpty() )
{
diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx
index 87865564da1b..01eb735e2aa3 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -22,6 +22,8 @@
#include <config_features.h>
#include <com/sun/star/i18n/WordType.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
+#include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
#include <com/sun/star/linguistic2/XThesaurus.hpp>
#include <com/sun/star/text/XContentControlsSupplier.hpp>
@@ -924,6 +926,26 @@ bool lcl_DeleteChartColumns(const uno::Reference<chart2::XChartDocument>& xChart
}
}
+static bool AddWordToWordbook(const uno::Reference<linguistic2::XDictionary>& xDictionary, SwWrtShell &rWrtSh)
+{
+ if (!xDictionary)
+ return false;
+
+ SwRect aToFill;
+ uno::Reference<linguistic2::XSpellAlternatives> xSpellAlt(rWrtSh.GetCorrection(nullptr, aToFill));
+ if (!xSpellAlt.is())
+ return false;
+
+ OUString sWord = xSpellAlt->getWord();
+ linguistic::DictionaryError nAddRes = linguistic::AddEntryToDic(xDictionary, sWord, false, OUString());
+ if (linguistic::DictionaryError::NONE != nAddRes && xDictionary.is() && !xDictionary->getEntry(sWord).is())
+ {
+ SvxDicError(rWrtSh.GetView().GetFrameWeld(), nAddRes);
+ return false;
+ }
+ return true;
+}
+
void SwTextShell::Execute(SfxRequest &rReq)
{
bool bUseDialog = true;
@@ -2316,19 +2338,26 @@ void SwTextShell::Execute(SfxRequest &rReq)
}
else if (sApplyText == "Spelling")
{
- SwRect aToFill;
- uno::Reference<linguistic2::XSpellAlternatives> xSpellAlt(rWrtSh.GetCorrection(nullptr, aToFill));
- if (!xSpellAlt.is())
- return;
- 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.is() && !xDictionary->getEntry(sWord).is())
- {
- SvxDicError(rWrtSh.GetView().GetFrameWeld(), nAddRes);
- }
+ AddWordToWordbook(LinguMgr::GetIgnoreAllList(), rWrtSh);
+ }
+ }
+ break;
+ case SID_ADD_TO_WORDBOOK:
+ {
+ OUString aDicName;
+ if (const SfxStringItem* pItem1 = rReq.GetArg<SfxStringItem>(FN_PARAM_1))
+ aDicName = pItem1->GetValue();
+
+ uno::Reference<linguistic2::XSearchableDictionaryList> xDicList(LinguMgr::GetDictionaryList());
+ uno::Reference<linguistic2::XDictionary> xDic = xDicList.is() ? xDicList->getDictionaryByName(aDicName) : nullptr;
+ if (AddWordToWordbook(xDic, rWrtSh))
+ {
+ // save modified user-dictionary if it is persistent
+ uno::Reference<frame::XStorable> xSavDic(xDic, uno::UNO_QUERY);
+ if (xSavDic.is())
+ xSavDic->store();
}
+ break;
}
break;
case SID_SPELLCHECK_APPLY_SUGGESTION: