include/unotools/resmgr.hxx | 1 sc/inc/global.hxx | 7 ++-- sc/source/core/data/global.cxx | 70 +++++++++++++++++++++++++--------------- unotools/source/i18n/resmgr.cxx | 7 ++++ 4 files changed, 57 insertions(+), 28 deletions(-)
New commits: commit 8b60301862d3107b2e164487e268f20b2bb54d88 Author: Pranam Lashkari <[email protected]> AuthorDate: Fri Aug 30 07:43:30 2024 +0200 Commit: Pranam Lashkari <[email protected]> CommitDate: Fri Aug 30 16:10:04 2024 +0200 sc: maintain calc function list per language problem: when multiple users used calc in kit in different languages, all the users will be shows formula autocomplete in first language list was created in, and later or new list creation was skipped. Change-Id: I92af9b3481825e554b6aaeb4b46e7873dadc39c1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172623 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Pranam Lashkari <[email protected]> Reviewed-by: Caolán McNamara <[email protected]> diff --git a/include/unotools/resmgr.hxx b/include/unotools/resmgr.hxx index 816f4fadf71b..fd72f3f80d51 100644 --- a/include/unotools/resmgr.hxx +++ b/include/unotools/resmgr.hxx @@ -69,6 +69,7 @@ namespace Translate { UNOTOOLS_DLLPUBLIC std::locale Create(std::string_view aPrefixName, const LanguageTag& rLocale = SvtSysLocale().GetUILanguageTag()); UNOTOOLS_DLLPUBLIC OUString get(TranslateId sContextAndId, const std::locale &loc); + UNOTOOLS_DLLPUBLIC OUString getLanguage(const std::locale& loc); UNOTOOLS_DLLPUBLIC OUString nget(TranslateNId aContextSingularPlural, int n, const std::locale &loc); UNOTOOLS_DLLPUBLIC void SetReadStringHook( ResHookProc pProc ); UNOTOOLS_DLLPUBLIC ResHookProc GetReadStringHook(); diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx index e140a7fb6ef0..1a0eb67647cb 100644 --- a/sc/inc/global.hxx +++ b/sc/inc/global.hxx @@ -39,6 +39,7 @@ #include <memory> #include <optional> #include <string_view> +#include <unordered_map> namespace com::sun::star::uno { template <typename > class Reference; } @@ -517,8 +518,8 @@ class ScGlobal static std::unique_ptr<SvxBrushItem> xEmptyBrushItem; static std::unique_ptr<SvxBrushItem> xButtonBrushItem; - static std::unique_ptr<ScFunctionList> xStarCalcFunctionList; - static std::unique_ptr<ScFunctionMgr> xStarCalcFunctionMgr; + static std::unordered_map<OUString, std::unique_ptr<ScFunctionList>> xStarCalcFunctionList; + static std::unordered_map<OUString, std::unique_ptr<ScFunctionMgr>> xStarCalcFunctionMgr; static std::atomic<ScUnitConverter*> pUnitConverter; @@ -536,7 +537,7 @@ class ScGlobal static std::atomic<sc::SharedStringPoolPurge*> pSharedStringPoolPurge; - static InputHandlerFunctionNames maInputHandlerFunctionNames; + static std::unordered_map<OUString, InputHandlerFunctionNames> maInputHandlerFunctionNames; static void InitPPT(); diff --git a/sc/source/core/data/global.cxx b/sc/source/core/data/global.cxx index 29a616c6b6e8..be834b8982b6 100644 --- a/sc/source/core/data/global.cxx +++ b/sc/source/core/data/global.cxx @@ -96,8 +96,8 @@ OUString ScGlobal::aStrClipDocName; std::unique_ptr<SvxBrushItem> ScGlobal::xEmptyBrushItem; std::unique_ptr<SvxBrushItem> ScGlobal::xButtonBrushItem; -std::unique_ptr<ScFunctionList> ScGlobal::xStarCalcFunctionList; -std::unique_ptr<ScFunctionMgr> ScGlobal::xStarCalcFunctionMgr; +std::unordered_map<OUString, std::unique_ptr<ScFunctionList>> ScGlobal::xStarCalcFunctionList; +std::unordered_map<OUString, std::unique_ptr<ScFunctionMgr>> ScGlobal::xStarCalcFunctionMgr; std::atomic<ScUnitConverter*> ScGlobal::pUnitConverter(nullptr); std::unique_ptr<SvNumberFormatter> ScGlobal::xEnglishFormatter; @@ -119,8 +119,7 @@ sal_uInt16 nScFillModeMouseModifier = 0; //FIXME: And this bool ScGlobal::bThreadedGroupCalcInProgress = false; -InputHandlerFunctionNames ScGlobal::maInputHandlerFunctionNames; - +std::unordered_map<OUString, InputHandlerFunctionNames> ScGlobal::maInputHandlerFunctionNames; // Static functions @@ -551,8 +550,9 @@ void ScGlobal::Clear() delete pLegacyFuncCollection.exchange(nullptr); delete pAddInCollection.exchange(nullptr); xUserList.reset(); - xStarCalcFunctionList.reset(); // Destroy before ResMgr! - xStarCalcFunctionMgr.reset(); + xStarCalcFunctionList.clear(); // Destroy before ResMgr! + xStarCalcFunctionMgr.clear(); + maInputHandlerFunctionNames.clear(); ScParameterClassification::Exit(); ScCompiler::DeInit(); ScInterpreter::GlobalExit(); // Delete static Stack @@ -628,39 +628,59 @@ OUString ScGlobal::GetCharsetString( rtl_TextEncoding eVal ) bool ScGlobal::HasStarCalcFunctionList() { - return bool(xStarCalcFunctionList); + OUString lang = Translate::getLanguage(SC_MOD()->GetResLocale()); + auto list = xStarCalcFunctionList.find(lang); + return list != xStarCalcFunctionList.end(); } ScFunctionList* ScGlobal::GetStarCalcFunctionList() { assert(!bThreadedGroupCalcInProgress); - if ( !xStarCalcFunctionList ) - xStarCalcFunctionList.reset( new ScFunctionList( SC_MOD()->GetFormulaOptions().GetUseEnglishFuncName())); - - return xStarCalcFunctionList.get(); + OUString lang = Translate::getLanguage(SC_MOD()->GetResLocale()); + if (auto list = xStarCalcFunctionList.find(lang); list != xStarCalcFunctionList.end()) + { + return xStarCalcFunctionList[lang].get(); + } + xStarCalcFunctionList.emplace( + lang, new ScFunctionList(SC_MOD()->GetFormulaOptions().GetUseEnglishFuncName())); + return xStarCalcFunctionList[lang].get(); } ScFunctionMgr* ScGlobal::GetStarCalcFunctionMgr() { assert(!bThreadedGroupCalcInProgress); - if ( !xStarCalcFunctionMgr ) - xStarCalcFunctionMgr.reset(new ScFunctionMgr); + OUString lang = Translate::getLanguage(SC_MOD()->GetResLocale()); + if (auto list = xStarCalcFunctionMgr.find(lang); list != xStarCalcFunctionMgr.end()) + { + return xStarCalcFunctionMgr[lang].get(); + } + xStarCalcFunctionMgr.emplace(lang, new ScFunctionMgr); - return xStarCalcFunctionMgr.get(); + return xStarCalcFunctionMgr[lang].get(); } void ScGlobal::ResetFunctionList() { // FunctionMgr has pointers into FunctionList, must also be updated - xStarCalcFunctionMgr.reset(); - xStarCalcFunctionList.reset(); + xStarCalcFunctionMgr.clear(); + xStarCalcFunctionList.clear(); // Building new names also needs InputHandler data to be refreshed. - maInputHandlerFunctionNames = InputHandlerFunctionNames(); + maInputHandlerFunctionNames.clear(); + maInputHandlerFunctionNames.emplace(Translate::getLanguage(SC_MOD()->GetResLocale()), + InputHandlerFunctionNames()); } const InputHandlerFunctionNames& ScGlobal::GetInputHandlerFunctionNames() { - if (maInputHandlerFunctionNames.maFunctionData.empty()) + OUString lang = Translate::getLanguage(SC_MOD()->GetResLocale()); + if (maInputHandlerFunctionNames.find(lang) == maInputHandlerFunctionNames.end()) + { + maInputHandlerFunctionNames.emplace(lang, InputHandlerFunctionNames()); + } + + InputHandlerFunctionNames& currentInputHandlerFunctionNames = maInputHandlerFunctionNames[lang]; + + if (currentInputHandlerFunctionNames.maFunctionData.empty()) { const OUString aParenthesesReplacement( cParenthesesReplacement); const ScFunctionList* pFuncList = GetStarCalcFunctionList(); @@ -676,18 +696,18 @@ const InputHandlerFunctionNames& ScGlobal::GetInputHandlerFunctionNames() OUString aFuncName(pCharClass->uppercase(*(pDesc->mxFuncName))); // fdo#75264 fill maFormulaChar with all characters used in formula names for (sal_Int32 j = 0; j < aFuncName.getLength(); j++) - maInputHandlerFunctionNames.maFunctionChar.insert(aFuncName[j]); - maInputHandlerFunctionNames.maFunctionData.insert( - ScTypedStrData(*(pDesc->mxFuncName) + aParenthesesReplacement, 0.0, 0.0, - ScTypedStrData::Standard)); + currentInputHandlerFunctionNames.maFunctionChar.insert(aFuncName[j]); + currentInputHandlerFunctionNames.maFunctionData.insert( + ScTypedStrData(*(pDesc->mxFuncName) + aParenthesesReplacement, 0.0, 0.0, + ScTypedStrData::Standard)); pDesc->initArgumentInfo(); OUString aEntry = pDesc->getSignature(); - maInputHandlerFunctionNames.maFunctionDataPara.insert( - ScTypedStrData(aEntry, 0.0, 0.0, ScTypedStrData::Standard)); + currentInputHandlerFunctionNames.maFunctionDataPara.insert( + ScTypedStrData(aEntry, 0.0, 0.0, ScTypedStrData::Standard)); } } } - return maInputHandlerFunctionNames; + return currentInputHandlerFunctionNames; } ScUnitConverter* ScGlobal::GetUnitConverter() diff --git a/unotools/source/i18n/resmgr.cxx b/unotools/source/i18n/resmgr.cxx index 2cf013d161d8..344d23b5e9b9 100644 --- a/unotools/source/i18n/resmgr.cxx +++ b/unotools/source/i18n/resmgr.cxx @@ -233,6 +233,13 @@ namespace Translate return result; } + OUString getLanguage(const std::locale& loc) + { + std::string lang = std::use_facet<boost::locale::info>(loc).name(); // en_US.UTF-8 + lang = lang.substr(0, lang.find('.')); // en_US + return createFromUtf8(lang.data(), lang.size()); + } + OUString nget(TranslateNId aContextSingularPlural, int n, const std::locale &loc) { //if it's a key id locale, generate it here
