diff options
author | Yiğit Akçay <yigit.akcay@icloud.com> | 2024-01-25 23:05:59 +0300 |
---|---|---|
committer | Andreas Heinisch <andreas.heinisch@yahoo.de> | 2024-02-28 10:37:50 +0100 |
commit | a7dd2e5a4712083cc5934e1d677e7dff86ceb7e6 (patch) | |
tree | 06f78ac305dd36215bbf8108d26328c57aff43db /sw/source/uibase/config/usrpref.cxx | |
parent | 9d3366f5b392418dc83bc0adbe3d215cff4b3605 (diff) |
tdf#151710 Enable enclosing of selected text with characters
This patch implements a new setting in Tools -> Options -> Writer ->
Formatting Aids -> Autocomplete -> Enclose with characters.
When this option is enabled (default), selected text is enclosed
with parentheses, square brackets, curly braces or quotation marks,
depending on which character is pressed.
For example, if the selected text is "abcd", the option is enabled and
the button for the character '(' is hit, the text is replaced with
"(abcd)".
Change-Id: Ibc5b7be3cc96f00217dd068971e7c07e68439700
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162583
Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
Tested-by: Jenkins
Diffstat (limited to 'sw/source/uibase/config/usrpref.cxx')
-rw-r--r-- | sw/source/uibase/config/usrpref.cxx | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/sw/source/uibase/config/usrpref.cxx b/sw/source/uibase/config/usrpref.cxx index 8928e8e5470f..0d1ee2859a5d 100644 --- a/sw/source/uibase/config/usrpref.cxx +++ b/sw/source/uibase/config/usrpref.cxx @@ -52,6 +52,7 @@ SwMasterUsrPref::SwMasterUsrPref(bool bWeb) : m_aGridConfig(bWeb, *this), m_aCursorConfig(*this), m_pWebColorConfig(bWeb ? new SwWebColorConfig(*this) : nullptr), + m_aFmtAidsAutoComplConfig(*this), m_bApplyCharUnit(false) { if (comphelper::IsFuzzing()) @@ -73,6 +74,7 @@ SwMasterUsrPref::SwMasterUsrPref(bool bWeb) : m_aCursorConfig.Load(); if(m_pWebColorConfig) m_pWebColorConfig->Load(); + m_aFmtAidsAutoComplConfig.Load(); } SwMasterUsrPref::~SwMasterUsrPref() @@ -568,6 +570,75 @@ void SwCursorConfig::Load() void SwCursorConfig::Notify( const css::uno::Sequence< OUString >& ) {} +Sequence<OUString> SwFmtAidsAutoComplConfig::GetPropertyNames() +{ + static const char* aPropNames[] = { + "EncloseWithCharacters", // 0 + }; + const int nCount = SAL_N_ELEMENTS(aPropNames); + Sequence<OUString> aNames(nCount); + OUString* pNames = aNames.getArray(); + for (int i = 0; i < nCount; i++) + pNames[i] = OUString::createFromAscii(aPropNames[i]); + return aNames; +} + +SwFmtAidsAutoComplConfig::SwFmtAidsAutoComplConfig(SwMasterUsrPref& rPar) + : ConfigItem("Office.Writer/FmtAidsAutocomplete", ConfigItemMode::ReleaseTree) + , m_rParent(rPar) +{ +} + +SwFmtAidsAutoComplConfig::~SwFmtAidsAutoComplConfig() {} + +void SwFmtAidsAutoComplConfig::ImplCommit() +{ + Sequence<OUString> aNames = GetPropertyNames(); + + Sequence<Any> aValues(aNames.getLength()); + Any* pValues = aValues.getArray(); + + for (int nProp = 0; nProp < aNames.getLength(); nProp++) + { + switch (nProp) + { + case 0: + pValues[nProp] <<= m_rParent.IsEncloseWithCharactersOn(); + break; // "FmtAidsAutocomplete/EncloseWithCharacters" + } + } + PutProperties(aNames, aValues); +} + +void SwFmtAidsAutoComplConfig::Load() +{ + Sequence<OUString> aNames = GetPropertyNames(); + Sequence<Any> aValues = GetProperties(aNames); + const Any* pValues = aValues.getConstArray(); + OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed"); + if (aValues.getLength() != aNames.getLength()) + return; + + for (int nProp = 0; nProp < aNames.getLength(); nProp++) + { + if (pValues[nProp].hasValue()) + { + switch (nProp) + { + case 0: + { + bool bSet = false; + pValues[nProp] >>= bSet; + m_rParent.SetEncloseWithCharactersOn(bSet); + break; // "FmtAidsAutocomplete/EncloseWithCharacters" + } + } + } + } +} + +void SwFmtAidsAutoComplConfig::Notify(const css::uno::Sequence<OUString>&) {} + SwWebColorConfig::SwWebColorConfig(SwMasterUsrPref& rPar) : ConfigItem("Office.WriterWeb/Background", ConfigItemMode::ReleaseTree), m_rParent(rPar), |