diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2024-01-27 00:33:56 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2024-02-01 02:47:56 +0100 |
commit | 2cac2ee38445c19c9281f54c2b961bbc9149cc00 (patch) | |
tree | 3830941e3df14794823b59630f13f7dbcb531b41 /svx | |
parent | cc2e1e29489994fd28660cff384820e6676cce06 (diff) |
sc: put used currencies on top of the currency pop-up list
The list of currencies is fairly long and there is no easy way
to search the list, so to make it easier to concurrently fint the
desired currency, put the currencies that are used in the document
on top of the list.
This adds a DocumentModelAccessor class, which is used to access
parts of the document model from other modules throught the
SfxObjectShell.
Change-Id: I81a180b674ae69b373b0422f363678e8bab37194
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162638
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit 79da840fac78f11c156801c43d8b79d6d4f32869)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162755
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/items/numfmtsh.cxx | 5 | ||||
-rw-r--r-- | svx/source/tbxctrls/tbcontrl.cxx | 59 |
2 files changed, 50 insertions, 14 deletions
diff --git a/svx/source/items/numfmtsh.cxx b/svx/source/items/numfmtsh.cxx index 8605817491ba..4f0825a88bca 100644 --- a/svx/source/items/numfmtsh.cxx +++ b/svx/source/items/numfmtsh.cxx @@ -30,6 +30,7 @@ #include <svx/numfmtsh.hxx> #include <svx/flagsdef.hxx> #include <svx/tbcontrl.hxx> +#include <sfx2/IDocumentModelAccessor.hxx> #include <limits> @@ -1397,7 +1398,9 @@ void SvxNumberFormatShell::GetCurrencySymbols(std::vector<OUString>& rList, sal_ bool bFlag = (pTmpCurrencyEntry == nullptr); - SvxCurrencyToolBoxControl::GetCurrencySymbols(rList, bFlag, aCurCurrencyList); + std::vector<sfx::CurrencyID> aDocumentCurrencyIDs; + SvxCurrencyToolBoxControl::GetCurrencySymbols(rList, bFlag, aCurCurrencyList, + aDocumentCurrencyIDs); if (pPos == nullptr) return; diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx index 192bf6c6fdd5..d3f89aad706c 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -92,16 +92,19 @@ #include <svx/xfillit0.hxx> #include <svx/xflclit.hxx> #include <svl/currencytable.hxx> +#include <svl/zformat.hxx> #include <svtools/langtab.hxx> #include <cppu/unotype.hxx> #include <cppuhelper/supportsservice.hxx> #include <officecfg/Office/Common.hxx> +#include <o3tl/temporary.hxx> #include <o3tl/safeint.hxx> #include <o3tl/string_view.hxx> #include <o3tl/typed_flags_set.hxx> #include <bitmaps.hlst> #include <sal/log.hxx> #include <unotools/collatorwrapper.hxx> +#include <sfx2/IDocumentModelAccessor.hxx> #include <comphelper/lok.hxx> #include <tools/json_writer.hxx> @@ -3919,7 +3922,13 @@ namespace SvNumberFormatter aFormatter( m_xControl->getContext(), LANGUAGE_SYSTEM ); m_eFormatLanguage = aFormatter.GetLanguage(); - SvxCurrencyToolBoxControl::GetCurrencySymbols( aList, true, aCurrencyList ); + std::vector<sfx::CurrencyID> aCurrencyIDs; + + SfxObjectShell* pDocShell = SfxObjectShell::Current(); + if (auto pModelAccessor = pDocShell->GetDocumentModelAccessor()) + aCurrencyIDs = pModelAccessor->getDocumentCurrencies(); + + SvxCurrencyToolBoxControl::GetCurrencySymbols(aList, true, aCurrencyList, aCurrencyIDs); sal_uInt16 nPos = 0, nCount = 0; sal_Int32 nSelectedPos = -1; @@ -4109,8 +4118,9 @@ Reference< css::accessibility::XAccessible > SvxFontNameBox_Impl::CreateAccessib } //static -void SvxCurrencyToolBoxControl::GetCurrencySymbols( std::vector<OUString>& rList, bool bFlag, - std::vector<sal_uInt16>& rCurrencyList ) +void SvxCurrencyToolBoxControl::GetCurrencySymbols(std::vector<OUString>& rList, bool bFlag, + std::vector<sal_uInt16>& rCurrencyList, + std::vector<sfx::CurrencyID> const& rDocumentCurrencyIDs) { rCurrencyList.clear(); @@ -4120,8 +4130,7 @@ void SvxCurrencyToolBoxControl::GetCurrencySymbols( std::vector<OUString>& rList sal_uInt16 nStart = 1; OUString aString( ApplyLreOrRleEmbedding( rCurrencyTable[0].GetSymbol() ) + " " ); - aString += ApplyLreOrRleEmbedding( SvtLanguageTable::GetLanguageString( - rCurrencyTable[0].GetLanguage() ) ); + aString += ApplyLreOrRleEmbedding(SvtLanguageTable::GetLanguageString(rCurrencyTable[0].GetLanguage())); rList.push_back( aString ); rCurrencyList.push_back( sal_uInt16(-1) ); // nAuto @@ -4140,17 +4149,40 @@ void SvxCurrencyToolBoxControl::GetCurrencySymbols( std::vector<OUString>& rList for( sal_uInt16 i = 1; i < nCount; ++i ) { - OUString aStr( ApplyLreOrRleEmbedding( rCurrencyTable[i].GetBankSymbol() ) ); + auto& rCurrencyEntry = rCurrencyTable[i]; + + OUString aStr( ApplyLreOrRleEmbedding(rCurrencyEntry.GetBankSymbol())); aStr += aTwoSpace; - aStr += ApplyLreOrRleEmbedding( rCurrencyTable[i].GetSymbol() ); + aStr += ApplyLreOrRleEmbedding(rCurrencyEntry.GetSymbol()); aStr += aTwoSpace; - aStr += ApplyLreOrRleEmbedding( SvtLanguageTable::GetLanguageString( - rCurrencyTable[i].GetLanguage() ) ); + aStr += ApplyLreOrRleEmbedding(SvtLanguageTable::GetLanguageString(rCurrencyEntry.GetLanguage())); std::vector<OUString>::size_type j = nStart; - for( ; j < rList.size(); ++j ) - if ( aCollator.compareString( aStr, rList[j] ) < 0 ) - break; // insert before first greater than + + // Search if the currency is present in the document + auto iter = std::find_if(rDocumentCurrencyIDs.begin(), rDocumentCurrencyIDs.end(), [rCurrencyEntry](sfx::CurrencyID const& rCurrency) + { + const NfCurrencyEntry* pEntry = SvNumberFormatter::GetCurrencyEntry(o3tl::temporary(bool()), rCurrency.aSymbol, rCurrency.aExtension, rCurrency.eLanguage); + + if (pEntry) + return rCurrencyEntry.GetLanguage() == pEntry->GetLanguage() && rCurrencyEntry.GetSymbol() == pEntry->GetSymbol(); + + return false; + }); + + // If currency is in document, insert it on top + if (iter != rDocumentCurrencyIDs.end()) + { + nStart++; + } + else + { + for( ; j < rList.size(); ++j ) + { + if ( aCollator.compareString( aStr, rList[j] ) < 0 ) + break; // insert before first greater than + } + } rList.insert( rList.begin() + j, aStr ); rCurrencyList.insert( rCurrencyList.begin() + j, i ); @@ -4164,7 +4196,8 @@ void SvxCurrencyToolBoxControl::GetCurrencySymbols( std::vector<OUString>& rList for ( sal_uInt16 i = 1; i < nCount; ++i ) { bool bInsert = true; - OUString aStr( ApplyLreOrRleEmbedding( rCurrencyTable[i].GetBankSymbol() ) ); + auto& rCurrencyEntry = rCurrencyTable[i]; + OUString aStr( ApplyLreOrRleEmbedding(rCurrencyEntry.GetBankSymbol())); std::vector<OUString>::size_type j = nCont; for ( ; j < rList.size() && bInsert; ++j ) |