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 663ad4abfc295741790daa77f733fb33b6013be9 Author: Pranam Lashkari <[email protected]> AuthorDate: Fri Aug 30 07:43:30 2024 +0200 Commit: Pranam Lashkari <[email protected]> CommitDate: Sat Aug 31 00:19:30 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/+/172669 Tested-by: Jenkins Reviewed-by: Pranam Lashkari <[email protected]> diff --git a/include/unotools/resmgr.hxx b/include/unotools/resmgr.hxx index 54f199d55857..973ec2ce3037 100644 --- a/include/unotools/resmgr.hxx +++ b/include/unotools/resmgr.hxx @@ -70,6 +70,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 f2b94c4d90f4..79d24030179b 100644 --- a/sc/inc/global.hxx +++ b/sc/inc/global.hxx @@ -40,6 +40,7 @@ #include <memory> #include <optional> #include <string_view> +#include <unordered_map> namespace com::sun::star::uno { template <typename > class Reference; } @@ -519,8 +520,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; @@ -538,7 +539,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 b81a73281256..903faa6207d0 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 @@ -548,8 +547,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 @@ -625,39 +625,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(); @@ -673,18 +693,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 64d4839aebb5..b1573c3f7c14 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
