diff options
Diffstat (limited to 'editeng/source/misc/acorrcfg.cxx')
-rw-r--r-- | editeng/source/misc/acorrcfg.cxx | 123 |
1 files changed, 103 insertions, 20 deletions
diff --git a/editeng/source/misc/acorrcfg.cxx b/editeng/source/misc/acorrcfg.cxx index aa08f4196664..49e48bb48be1 100644 --- a/editeng/source/misc/acorrcfg.cxx +++ b/editeng/source/misc/acorrcfg.cxx @@ -22,20 +22,92 @@ #include <o3tl/any.hxx> #include <tools/debug.hxx> #include <tools/urlobj.hxx> +#include <comphelper/diagnose_ex.hxx> #include <ucbhelper/content.hxx> #include <unotools/pathoptions.hxx> #include <unotools/ucbhelper.hxx> +#include <svtools/langtab.hxx> +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <com/sun/star/sdbc/XRow.hpp> #include <editeng/svxacorr.hxx> #include <com/sun/star/uno/Sequence.hxx> -#include <rtl/instance.hxx> - using namespace utl; using namespace com::sun::star; using namespace com::sun::star::uno; +/** An autocorrection file dropped into such directory may create a language + list entry if one didn't exist already. + */ +static void scanAutoCorrectDirForLanguageTags( const OUString& rURL ) +{ + // Silently ignore all errors. + try + { + ::ucbhelper::Content aContent( rURL, + uno::Reference<ucb::XCommandEnvironment>(), comphelper::getProcessComponentContext()); + if (aContent.isFolder()) + { + // Title is file name here. + uno::Reference<sdbc::XResultSet> xResultSet = aContent.createCursor( + {"Title"}, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY); + uno::Reference<sdbc::XRow> xRow( xResultSet, UNO_QUERY); + if (xResultSet.is() && xRow.is()) + { + while (xResultSet->next()) + { + try + { + const OUString aTitle( xRow->getString(1)); + if (aTitle.getLength() <= 9 || !(aTitle.startsWith("acor_") && aTitle.endsWith(".dat"))) + continue; + + const OUString aBcp47( aTitle.copy( 5, aTitle.getLength() - 9)); + // Ignore invalid langtags and canonicalize for good, + // allow private-use tags. + const LanguageTag aLanguageTag (aBcp47, true); + if (!aLanguageTag.isValidBcp47()) + continue; + + if (SvtLanguageTable::HasLanguageType( aLanguageTag.getLanguageType())) + continue; + + // Insert language(-script)-only tags only if there is + // no known matching fallback locale, otherwise we'd + // end up with unwanted entries where a language + // autocorrection file covers several locales. We do + // know a few art-x-... though so exclude those and any + // other private-use tag (which should not fallback, + // but avoid). + if (aLanguageTag.getCountry().isEmpty() + && LanguageTag::isValidBcp47( aLanguageTag.getBcp47(), nullptr, + LanguageTag::PrivateUse::DISALLOW)) + { + LanguageTag aFallback( aLanguageTag); + aFallback.makeFallback(); + if (aFallback.getLanguageAndScript() == aLanguageTag.getLanguageAndScript()) + continue; + } + + // Finally add this one. + SvtLanguageTable::AddLanguageTag( aLanguageTag); + } + catch (const uno::Exception&) + { + TOOLS_WARN_EXCEPTION("editeng", "Unable to get a directory entry from '" << rURL << "'"); + } + } + } + } + } + catch (const uno::Exception&) + { + TOOLS_WARN_EXCEPTION("editeng", "Unable to iterate directory '" << rURL << "'"); + } +} + SvxAutoCorrCfg::SvxAutoCorrCfg() : aBaseConfig(*this), aSwConfig(*this), @@ -62,7 +134,8 @@ SvxAutoCorrCfg::SvxAutoCorrCfg() : for( OUString* pS : { &sSharePath, &sUserPath } ) { INetURLObject aPath( *pS ); - aPath.insertName("acor"); + scanAutoCorrectDirForLanguageTags( aPath.GetMainURL(INetURLObject::DecodeMechanism::ToIUri)); + aPath.insertName(u"acor"); *pS = aPath.GetMainURL(INetURLObject::DecodeMechanism::ToIUri); } pAutoCorrect.reset( new SvxAutoCorrect( sSharePath, sUserPath ) ); @@ -111,9 +184,10 @@ Sequence<OUString> SvxBaseAutoCorrCfg::GetPropertyNames() "DoubleQuoteAtEnd", // 16 "CorrectAccidentalCapsLock", // 17 "TransliterateRTL", // 18 - "ChangeAngleQuotes" // 19 + "ChangeAngleQuotes", // 19 + "SetDOIAttribute", // 20 }; - const int nCount = 20; + const int nCount = 21; Sequence<OUString> aNames(nCount); OUString* pNames = aNames.getArray(); for(int i = 0; i < nCount; i++) @@ -146,7 +220,7 @@ void SvxBaseAutoCorrCfg::Load(bool bInit) break;//"Exceptions/TwoCapitalsAtStart", case 1: if(*o3tl::doAccess<bool>(pValues[nProp])) - nFlags |= ACFlags::SaveWordWrdSttLst; + nFlags |= ACFlags::SaveWordWordStartLst; break;//"Exceptions/CapitalAtStartSentence", case 2: if(*o3tl::doAccess<bool>(pValues[nProp])) @@ -224,6 +298,10 @@ void SvxBaseAutoCorrCfg::Load(bool bInit) if(*o3tl::doAccess<bool>(pValues[nProp])) nFlags |= ACFlags::ChgAngleQuotes; break;//"ChangeAngleQuotes" + case 20: + if(*o3tl::doAccess<bool>(pValues[nProp])) + nFlags |= ACFlags::SetDOIAttr; + break;//"SetDOIAttr", } } } @@ -249,7 +327,7 @@ void SvxBaseAutoCorrCfg::ImplCommit() GetPropertyNames(), {css::uno::Any(bool(nFlags & ACFlags::SaveWordCplSttLst)), // "Exceptions/TwoCapitalsAtStart" - css::uno::Any(bool(nFlags & ACFlags::SaveWordWrdSttLst)), + css::uno::Any(bool(nFlags & ACFlags::SaveWordWordStartLst)), // "Exceptions/CapitalAtStartSentence" css::uno::Any(bool(nFlags & ACFlags::Autocorrect)), // "UseReplacementTable" css::uno::Any(bool(nFlags & ACFlags::CapitalStartWord)), @@ -279,9 +357,10 @@ void SvxBaseAutoCorrCfg::ImplCommit() // "CorrectAccidentalCapsLock" css::uno::Any(bool(nFlags & ACFlags::TransliterateRTL)), // "TransliterateRTL" - css::uno::Any(bool(nFlags & ACFlags::ChgAngleQuotes))}); + css::uno::Any(bool(nFlags & ACFlags::ChgAngleQuotes)), // "ChangeAngleQuotes" - + css::uno::Any(bool(nFlags & ACFlags::SetDOIAttr)), // "SetDOIAttribute" + }); } void SvxBaseAutoCorrCfg::Notify( const Sequence<OUString>& /* aPropertyNames */) @@ -340,8 +419,10 @@ Sequence<OUString> SvxSwAutoCorrCfg::GetPropertyNames() "Format/ByInput/ApplyNumbering/SpecialCharacter/FontFamily", //44 "Format/ByInput/ApplyNumbering/SpecialCharacter/FontCharset", //45 "Format/ByInput/ApplyNumbering/SpecialCharacter/FontPitch", //46 + "Format/Option/SetDOIAttribute", //47 + "Format/ByInput/ApplyBulletsAfterSpace", //48 }; - const int nCount = 47; + const int nCount = 49; Sequence<OUString> aNames(nCount); OUString* pNames = aNames.getArray(); for(int i = 0; i < nCount; i++) @@ -445,12 +526,12 @@ void SvxSwAutoCorrCfg::Load(bool bInit) { sal_Int32 nVal = 0; pValues[nProp] >>= nVal; rSwFlags.nAutoCmpltListLen = - sal::static_int_cast< sal_uInt16 >(nVal); + sal::static_int_cast< sal_uInt32 >(nVal); } break; // "Completion/MaxListLen", case 36: rSwFlags.bAutoCmpltCollectWords = *o3tl::doAccess<bool>(pValues[nProp]); break; // "Completion/CollectWords", case 37: rSwFlags.bAutoCmpltEndless = *o3tl::doAccess<bool>(pValues[nProp]); break; // "Completion/EndlessList", - case 38: rSwFlags.bAutoCmpltAppendBlanc = *o3tl::doAccess<bool>(pValues[nProp]); break; // "Completion/AppendBlank", + case 38: rSwFlags.bAutoCmpltAppendBlank = *o3tl::doAccess<bool>(pValues[nProp]); break; // "Completion/AppendBlank", case 39: rSwFlags.bAutoCmpltShowAsTip = *o3tl::doAccess<bool>(pValues[nProp]); break; // "Completion/ShowAsTip", case 40: { @@ -491,6 +572,8 @@ void SvxSwAutoCorrCfg::Load(bool bInit) rSwFlags.aByInputBulletFont.SetPitch(FontPitch(nVal)); } break;// "Format/ByInput/ApplyNumbering/SpecialCharacter/FontPitch", + case 47: rSwFlags.bSetDOIAttr = *o3tl::doAccess<bool>(pValues[nProp]); break; // "Format/Option/SetDOIAttribute", + case 48 : rSwFlags.bSetNumRuleAfterSpace = *o3tl::doAccess<bool>(pValues[nProp]); break; // "Format/ByInput/ApplyNumberingAfterSpace", } } } @@ -578,7 +661,7 @@ void SvxSwAutoCorrCfg::ImplCommit() css::uno::Any(rSwFlags.bAutoCmpltCollectWords), // "Completion/CollectWords" css::uno::Any(rSwFlags.bAutoCmpltEndless), // "Completion/EndlessList" - css::uno::Any(rSwFlags.bAutoCmpltAppendBlanc), + css::uno::Any(rSwFlags.bAutoCmpltAppendBlank), // "Completion/AppendBlank" css::uno::Any(rSwFlags.bAutoCmpltShowAsTip), // "Completion/ShowAsTip" css::uno::Any(sal_Int32(rSwFlags.nAutoCmpltExpandKey)), @@ -592,8 +675,12 @@ void SvxSwAutoCorrCfg::ImplCommit() // "Format/ByInput/ApplyNumbering/SpecialCharacter/FontFamily" css::uno::Any(sal_Int32(rSwFlags.aByInputBulletFont.GetCharSet())), // "Format/ByInput/ApplyNumbering/SpecialCharacter/FontCharset" - css::uno::Any(sal_Int32(rSwFlags.aByInputBulletFont.GetPitch()))}); + css::uno::Any(sal_Int32(rSwFlags.aByInputBulletFont.GetPitch())), // "Format/ByInput/ApplyNumbering/SpecialCharacter/FontPitch" + css::uno::Any(rSwFlags.bSetDOIAttr), + css::uno::Any(rSwFlags.bSetNumRuleAfterSpace), // "Format/ByInput/ApplyNumberingAfterSpace" + }); + // "Format/Option/SetDOIAttribute" } void SvxSwAutoCorrCfg::Notify( const Sequence<OUString>& /* aPropertyNames */ ) @@ -601,14 +688,10 @@ void SvxSwAutoCorrCfg::Notify( const Sequence<OUString>& /* aPropertyNames */ ) Load(false); } -namespace -{ - class theSvxAutoCorrCfg : public rtl::Static<SvxAutoCorrCfg, theSvxAutoCorrCfg>{}; -} - SvxAutoCorrCfg& SvxAutoCorrCfg::Get() { - return theSvxAutoCorrCfg::get(); + static SvxAutoCorrCfg theSvxAutoCorrCfg; + return theSvxAutoCorrCfg; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |