summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolan.mcnamara@collabora.com>2024-12-20 12:46:36 +0000
committerMiklos Vajna <vmiklos@collabora.com>2025-01-06 10:34:51 +0100
commit5a6527eea72a629ebc393b7d82f486c3a564ccec (patch)
tree30713be3bb4f5ee697e67bcc9edac78888fef39b
parent25de0024cb97b8cb0f92e33ab48267954c676644 (diff)
add uno:AddToWordbook for adding word to user dictionary
Change-Id: I1c679f62f554bfa112c505a545ceb8b5e31ef453 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178916 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
-rw-r--r--include/svx/svxids.hrc3
-rw-r--r--officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu5
-rw-r--r--svx/sdi/svx.sdi17
-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
6 files changed, 73 insertions, 33 deletions
diff --git a/include/svx/svxids.hrc b/include/svx/svxids.hrc
index 0a2bc143210a..7f5875ae8775 100644
--- a/include/svx/svxids.hrc
+++ b/include/svx/svxids.hrc
@@ -451,7 +451,8 @@ class XFillGradientItem;
#define SID_ATTR_TEXTCOLUMNS_NUMBER ( SID_SVX_START + 340 )
#define SID_ATTR_TEXTCOLUMNS_SPACING ( SID_SVX_START + 341 )
-// FREE ( SID_SVX_START + 342 )
+#define SID_ADD_TO_WORDBOOK ( SID_SVX_START + 342 )
+
// FREE ( SID_SVX_START + 343 )
// FREE ( SID_SVX_START + 344 )
// FREE ( SID_SVX_START + 345 )
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
index 30896cc0cdbc..33887fc92394 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
@@ -7182,6 +7182,11 @@ bit 3 (0x8): #define UICOMMANDDESCRIPTION_PROPERTIES_TOGGLEBUTTON 8
<value xml:lang="en-US">Language for All Text</value>
</prop>
</node>
+ <node oor:name=".uno:AddToWordbook" oor:op="replace">
+ <prop oor:name="Label" oor:type="xs:string">
+ <value xml:lang="en-US">Add To Dictionary</value>
+ </prop>
+ </node>
<node oor:name=".uno:MoreDictionaries" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">More Dictionaries Online...</value>
diff --git a/svx/sdi/svx.sdi b/svx/sdi/svx.sdi
index 197daf2edf2a..f682c37a5e50 100644
--- a/svx/sdi/svx.sdi
+++ b/svx/sdi/svx.sdi
@@ -12517,6 +12517,23 @@ SfxVoidItem SpellCheckIgnoreAll SID_SPELLCHECK_IGNORE_ALL
GroupId = SfxGroupId::Format;
]
+SfxVoidItem AddToWordbook SID_ADD_TO_WORDBOOK
+(SfxStringItem Wordbook 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)
[
diff --git a/sw/sdi/_textsh.sdi b/sw/sdi/_textsh.sdi
index d40c58ea6ba7..f4c47c6b1098 100644
--- a/sw/sdi/_textsh.sdi
+++ b/sw/sdi/_textsh.sdi
@@ -1910,6 +1910,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 acf06f2e41a7..d92920521d2b 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 66a92416f3b0..380b35cc2965 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>
@@ -939,6 +941,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;
@@ -2224,19 +2246,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: